1313 */
1414package com .facebook .presto .nativeworker ;
1515
16- import com .facebook .presto .common .type .ArrayType ;
17- import com .facebook .presto .common .type .BigintType ;
18- import com .facebook .presto .common .type .BooleanType ;
19- import com .facebook .presto .common .type .CharType ;
20- import com .facebook .presto .common .type .DateType ;
21- import com .facebook .presto .common .type .DecimalType ;
22- import com .facebook .presto .common .type .DoubleType ;
23- import com .facebook .presto .common .type .IntegerType ;
24- import com .facebook .presto .common .type .RealType ;
25- import com .facebook .presto .common .type .SmallintType ;
26- import com .facebook .presto .common .type .TimeType ;
27- import com .facebook .presto .common .type .TimestampType ;
28- import com .facebook .presto .common .type .TimestampWithTimeZoneType ;
29- import com .facebook .presto .common .type .TinyintType ;
30- import com .facebook .presto .common .type .Type ;
31- import com .facebook .presto .common .type .TypeSignature ;
32- import com .facebook .presto .common .type .TypeSignatureParameter ;
33- import com .facebook .presto .common .type .UnknownType ;
34- import com .facebook .presto .common .type .VarbinaryType ;
35- import com .facebook .presto .common .type .VarcharType ;
16+ import com .facebook .presto .common .type .*;
3617import com .facebook .presto .testing .MaterializedResult ;
3718import com .facebook .presto .testing .MaterializedRow ;
3819
4526import java .sql .ResultSet ;
4627import java .sql .ResultSetMetaData ;
4728import java .sql .SQLException ;
48- import java .util .ArrayList ;
49- import java .util .Arrays ;
50- import java .util .List ;
51- import java .util .Map ;
52- import java .util .Properties ;
29+ import java .util .*;
5330
5431public class ContainerQueryRunnerUtils
5532{
@@ -82,20 +59,35 @@ public static void createNativeWorkerTpchProperties(String nodeId)
8259 createPropertiesFile ("testcontainers/" + nodeId + "/etc/catalog/tpch.properties" , properties );
8360 }
8461
85- public static void createNativeWorkerConfigProperties (int coordinatorPort , String nodeId )
62+ public static void createNativeWorkerConfigProperties (
63+ int coordinatorPort ,
64+ String nodeId ,
65+ boolean isSidecarEnabled ,
66+ boolean isSidecarNode )
8667 throws IOException
8768 {
8869 Properties properties = new Properties ();
8970 properties .setProperty ("presto.version" , "testversion" );
9071 properties .setProperty ("http-server.http.port" , "7777" );
9172 properties .setProperty ("discovery.uri" , "http://presto-coordinator:" + coordinatorPort );
9273 properties .setProperty ("system-memory-gb" , "2" );
93- properties .setProperty ("native.sidecar" , "false" );
74+
75+ if (isSidecarEnabled ) {
76+ properties .setProperty ("presto.default-namespace" , "native.default" );
77+ }
78+
79+ properties .setProperty ("native-sidecar" , String .valueOf (isSidecarNode ));
9480 createPropertiesFile ("testcontainers/" + nodeId + "/etc/config.properties" , properties );
9581 }
9682
9783 public static void createCoordinatorConfigProperties (int port )
9884 throws IOException
85+ {
86+ createCoordinatorConfigProperties (port , true , false );
87+ }
88+
89+ public static void createCoordinatorConfigProperties (int port , boolean isNativeCluster , boolean isSidecarEnabled )
90+ throws IOException
9991 {
10092 Properties properties = new Properties ();
10193 properties .setProperty ("coordinator" , "true" );
@@ -104,16 +96,58 @@ public static void createCoordinatorConfigProperties(int port)
10496 properties .setProperty ("http-server.http.port" , Integer .toString (port ));
10597 properties .setProperty ("discovery-server.enabled" , "true" );
10698 properties .setProperty ("discovery.uri" , "http://presto-coordinator:" + port );
99+ if (isSidecarEnabled ) {
100+ properties .setProperty ("presto.default-namespace" , "native.default" );
101+ properties .setProperty ("coordinator-sidecar-enabled" , "true" );
102+ properties .setProperty ("exclude-invalid-worker-session-properties" , "true" );
103+ }
107104
108- // Get native worker system properties and add them to the coordinator properties
109- Map <String , String > nativeWorkerProperties = NativeQueryRunnerUtils .getNativeWorkerSystemProperties ();
110- for (Map .Entry <String , String > entry : nativeWorkerProperties .entrySet ()) {
111- properties .setProperty (entry .getKey (), entry .getValue ());
105+ if (isNativeCluster ) {
106+ // Get native worker system properties and add them to the coordinator properties
107+ Map <String , String > nativeWorkerProperties = NativeQueryRunnerUtils .getNativeWorkerSystemProperties ();
108+ for (Map .Entry <String , String > entry : nativeWorkerProperties .entrySet ()) {
109+ properties .setProperty (entry .getKey (), entry .getValue ());
110+ }
112111 }
113112
114113 createPropertiesFile ("testcontainers/coordinator/etc/config.properties" , properties );
115114 }
116115
116+ public static void createJavaWorkerConfigProperties (int port , int coordinatorPort , String nodeId )
117+ throws IOException
118+ {
119+ Properties properties = new Properties ();
120+ properties .setProperty ("coordinator" , "false" );
121+ properties .setProperty ("presto.version" , "testversion" );
122+ properties .setProperty ("node-scheduler.include-coordinator" , "false" );
123+ properties .setProperty ("http-server.http.port" , Integer .toString (port ));
124+ properties .setProperty ("discovery.uri" , "http://presto-coordinator:" + coordinatorPort );
125+ createPropertiesFile ("testcontainers/" + nodeId + "/etc/config.properties" , properties );
126+ }
127+
128+ public static void createCoordinatorSidecarProperties ()
129+ throws IOException
130+ {
131+ Properties properties1 = new Properties ();
132+ properties1 .setProperty ("function-namespace-manager.name" , "native" );
133+ properties1 .setProperty ("function-implementation-type" , "CPP" );
134+ properties1 .setProperty ("supported-function-languages" , "CPP" );
135+
136+ createPropertiesFile ("testcontainers/coordinator/etc/function-namespace/native.properties" , properties1 );
137+
138+ Properties properties2 = new Properties ();
139+ properties2 .setProperty ("session-property-provider.name" , "native" );
140+ createPropertiesFile ("testcontainers/coordinator/etc/session-property-provider/native.properties" , properties2 );
141+
142+ Properties properties3 = new Properties ();
143+ properties3 .setProperty ("type-manager.name" , "native" );
144+ createPropertiesFile ("testcontainers/coordinator/etc/type-managers/native.properties" , properties3 );
145+
146+ Properties properties4 = new Properties ();
147+ properties4 .setProperty ("plan-checker-provider.name" , "native" );
148+ createPropertiesFile ("testcontainers/coordinator/etc/plan-checker-providers/native.properties" , properties4 );
149+ }
150+
117151 public static void createCoordinatorJvmConfig ()
118152 throws IOException
119153
@@ -170,10 +204,7 @@ public static void createNativeWorkerVeloxProperties(String nodeId)
170204 public static void createCoordinatorEntryPointScript ()
171205 throws IOException
172206 {
173- String scriptContent = "#!/bin/sh\n " +
174- "set -e\n " +
175- "$PRESTO_HOME/bin/launcher run\n " ;
176- createScriptFile ("testcontainers/coordinator/entrypoint.sh" , scriptContent );
207+ createJavaEntryPointScript ("coordinator" );
177208 }
178209
179210 public static void createNativeWorkerEntryPointScript (String nodeId )
@@ -185,6 +216,15 @@ public static void createNativeWorkerEntryPointScript(String nodeId)
185216 createScriptFile ("testcontainers/" + nodeId + "/entrypoint.sh" , scriptContent );
186217 }
187218
219+ public static void createJavaEntryPointScript (String nodeId )
220+ throws IOException
221+ {
222+ String scriptContent = "#!/bin/sh\n " +
223+ "set -e\n " +
224+ "$PRESTO_HOME/bin/launcher run\n " ;
225+ createScriptFile ("testcontainers/" + nodeId + "/entrypoint.sh" , scriptContent );
226+ }
227+
188228 public static void deleteDirectory (String directoryPath )
189229 {
190230 File directory = new File (directoryPath );
@@ -353,6 +393,9 @@ private static Type mapSqlTypeToType(int sqlType, String typeName)
353393 case java .sql .Types .VARBINARY :
354394 case java .sql .Types .LONGVARBINARY :
355395 return VarbinaryType .VARBINARY ;
396+ case java .sql .Types .NULL :
397+ // This happens in select fail() or similar cases
398+ return VarcharType .createUnboundedVarcharType ();
356399 case java .sql .Types .OTHER :
357400 // Attempt to map based on type name
358401 return mapSqlTypeNameToType (typeName );
@@ -363,6 +406,40 @@ private static Type mapSqlTypeToType(int sqlType, String typeName)
363406
364407 private static Type mapSqlTypeNameToType (String typeName )
365408 {
409+ String upperTypeName = typeName .toUpperCase (Locale .ENGLISH ).trim ();
410+
411+ // Handle flat ROW types like ROW(VARCHAR, INTEGER) or ROW(a VARCHAR, b INTEGER)
412+ if (upperTypeName .startsWith ("ROW(" ) && upperTypeName .endsWith (")" )) {
413+ String fieldsPart = upperTypeName .substring (4 , upperTypeName .length () - 1 ).trim ();
414+
415+ // Split fields by comma (no nested ROWs expected)
416+ String [] fieldTokens = fieldsPart .split ("," );
417+
418+ List <RowType .Field > rowFields = new ArrayList <>();
419+ for (int i = 0 ; i < fieldTokens .length ; i ++) {
420+ String token = fieldTokens [i ].trim ();
421+
422+ // Handle both: "a VARCHAR" and "VARCHAR"
423+ String [] parts = token .split ("\\ s+" , 2 );
424+ String fieldName ;
425+ String fieldType ;
426+
427+ if (parts .length == 2 ) {
428+ fieldName = parts [0 ];
429+ fieldType = parts [1 ];
430+ }
431+ else {
432+ fieldName = "field" + i ;
433+ fieldType = parts [0 ];
434+ }
435+
436+ Type innerType = mapSqlTypeNameToType (fieldType );
437+ rowFields .add (new RowType .Field (Optional .of (fieldName ), innerType ));
438+ }
439+
440+ return RowType .from (rowFields );
441+ }
442+
366443 switch (typeName .toUpperCase ()) {
367444 case "INT" :
368445 case "INTEGER" :
0 commit comments