1515// specific language governing permissions and limitations
1616// under the License.
1717
18+ import org.apache.arrow.driver.jdbc.shaded.com.google.protobuf.Any
1819import org.apache.arrow.driver.jdbc.shaded.org.apache.arrow.flight.CallOptions
1920import org.apache.arrow.driver.jdbc.shaded.org.apache.arrow.flight.FlightClient
2021import org.apache.arrow.driver.jdbc.shaded.org.apache.arrow.flight.Location
2122import org.apache.arrow.driver.jdbc.shaded.org.apache.arrow.flight.sql.FlightSqlClient
23+ import org.apache.arrow.driver.jdbc.shaded.org.apache.arrow.flight.sql.impl.FlightSql
2224import org.apache.arrow.driver.jdbc.shaded.org.apache.arrow.memory.RootAllocator
2325
2426import java.util.concurrent.TimeUnit
@@ -39,11 +41,26 @@ suite("test_flight_native_variant", "arrow_flight_sql") {
3941 Location . forGrpcInsecure(frontend.Host . toString(), frontend.ArrowFlightSqlPort . toString(). toInteger())). build()
4042 def client = new FlightSqlClient (feClient)
4143 def auth
42- def read = { String query , Closure inspect ->
44+ def read = { String query , Closure inspect , boolean parallel = false , int resultBackendCount = 1 ->
4345 int count = 0
44- client. execute(query, auth). endpoints. each { endpoint ->
46+ def info = client. execute(query, auth)
47+ assertFalse (info. endpoints. isEmpty())
48+ // Multiple buckets alone do not prove coverage of native output from different result BEs.
49+ if (parallel) {
50+ def resultAddresses = info. endpoints. collect { endpoint ->
51+ def fields = Any . parseFrom(endpoint. ticket. bytes). unpack(FlightSql.TicketStatementQuery . class)
52+ .statementHandle. toStringUtf8(). split(" &" )
53+ " ${ fields[1]} :${ fields[2]} " . toString()
54+ }
55+ assertEquals (info. endpoints. size(), resultAddresses. toSet(). size(), " Duplicate result backends" )
56+ if (resultBackendCount > 1 ) {
57+ assertTrue (info. endpoints. size() > 1 , " Expected multiple native Variant result backends" )
58+ }
59+ }
60+ info. endpoints. each { endpoint ->
4561 FlightClient . builder(allocator, endpoint. locations[0 ]). build(). withCloseable { beClient ->
4662 beClient. getStream(endpoint. ticket, auth, CallOptions . timeout(30 , TimeUnit . SECONDS )). withCloseable { stream ->
63+ assertEquals (info. schema, stream. schema, " Result endpoints must share the published schema" )
4764 while (stream. next()) {
4865 inspect(stream. root)
4966 count + = stream. root. rowCount
@@ -58,19 +75,25 @@ suite("test_flight_native_variant", "arrow_flight_sql") {
5875 auth = feClient. authenticateBasicToken(context. config. otherConfigs. get(" extArrowFlightSqlUser" ),
5976 context. config. otherConfigs. get(" extArrowFlightSqlPassword" )). get()
6077 executeSetting(" SET enable_sql_cache=false" )
78+ executeSetting(" SET enable_nereids_distribute_planner=true" )
79+ executeSetting(" SET parallel_pipeline_task_num=8" )
6180 jdbc_sql(" DROP TABLE IF EXISTS ${ table} " )
6281 jdbc_sql(""" CREATE TABLE ${ table} (id INT, v VARIANT)
63- DUPLICATE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 3
82+ DUPLICATE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 60
6483 PROPERTIES("replication_num"="1")""" )
65- jdbc_sql(""" INSERT INTO ${ table} VALUES
66- (1, ${ variantV2Function} ('42')), (2, ${ variantV2Function} ('"text"')),
67- (3, ${ variantV2Function} ('{"a":[1,null,"x"]}')), (4, NULL)""" )
84+ jdbc_sql(""" INSERT INTO ${ table}
85+ SELECT number + 1, ${ variantV2Function} (CASE number % 4
86+ WHEN 0 THEN '42' WHEN 1 THEN '"text"'
87+ WHEN 2 THEN '{"a":[1,null,"x"]}' ELSE NULL END)
88+ FROM numbers("number"="60")""" )
89+ def resultBackendCount = jdbc_sql_return_maparray(" SHOW TABLETS FROM ${ table} " )
90+ .collect { it.BackendId }. unique(). size()
6891 [false , true ]. each { parallel ->
6992 executeSetting(" SET enable_parallel_result_sink=${ parallel} " )
7093 [false , true , false ]. each { nativeVariant ->
7194 executeSetting(" SET enable_arrow_flight_sql_native_variant=${ nativeVariant} " )
7295 def seen = []
73- assertEquals (4 , read(" SELECT id, v FROM ${ table} " , { root ->
96+ assertEquals (60 , read(" SELECT id, v FROM ${ table} " , { root ->
7497 def vector = root. getVector(1 )
7598 def field = vector. field
7699 if (nativeVariant) {
@@ -87,19 +110,19 @@ suite("test_flight_native_variant", "arrow_flight_sql") {
87110 for (int i = 0 ; i < root. rowCount; i++ ) {
88111 int id = root. getVector(0 ). get(i)
89112 seen. add(id)
90- assertEquals (id == 4 , vector. isNull(i))
91- if (nativeVariant && id != 4 ) {
113+ assertEquals (id % 4 == 0 , vector. isNull(i))
114+ if (nativeVariant && id % 4 != 0 ) {
92115 assertTrue (vector. getChild(" metadata" ). get(i). length > 0 )
93116 assertTrue (vector. getChild(" value" ). get(i). length > 0 )
94- if (id == 1 ) {
117+ if (id % 4 == 1 ) {
95118 assertEquals ([12 , 42 ], vector. getChild(" value" ). get(i). collect { it & 0xff })
96119 }
97- } else if (! nativeVariant && id == 1 ) {
120+ } else if (! nativeVariant && id % 4 == 1 ) {
98121 assertEquals (" 42" , vector. getObject(i). toString())
99122 }
100123 }
101- }))
102- assertEquals ([ 1 , 2 , 3 , 4 ] , seen. sort())
124+ }, parallel, resultBackendCount ))
125+ assertEquals (( 1 .. 60 ) . toList() , seen. sort())
103126 }
104127 }
105128 executeSetting(" SET enable_arrow_flight_sql_native_variant=true" )
0 commit comments