@@ -880,210 +880,7 @@ void aliasingTableToResolveAmbiguityWorks() throws Exception {
880
880
}
881
881
}
882
882
}
883
-
884
- @ Test
885
- void testDistinctFrom () throws Exception {
886
- final String schema = "CREATE TYPE AS STRUCT contact_detail(phone_number string, address string) " +
887
- "CREATE TABLE student(id bigint, name string, contact contact_detail, score bigint, primary key(id))" ;
888
- try (var ddl = Ddl .builder ().database (URI .create ("/TEST/QT" )).relationalExtension (relationalExtension ).schemaTemplate (schema ).build ()) {
889
- try (var statement = ddl .setSchemaAndGetConnection ().createStatement ()) {
890
- final var row1 = EmbeddedRelationalStruct .newBuilder ()
891
- .addLong ("ID" , 1L )
892
- .addString ("NAME" , "Alice" )
893
- .addLong ("SCORE" , 100 )
894
- .build ();
895
- final var row2 = EmbeddedRelationalStruct .newBuilder ()
896
- .addLong ("ID" , 2L )
897
- .addString ("NAME" , "Bob" )
898
- .build ();
899
- Assertions .assertEquals (1 , statement .executeInsert ("STUDENT" , row1 ), "Incorrect insertion count" );
900
- Assertions .assertEquals (1 , statement .executeInsert ("STUDENT" , row2 ), "Incorrect insertion count" );
901
-
902
- Assertions .assertTrue (statement .execute ("SELECT * from STUDENT WHERE score is distinct from null" ), "Did not return a result set from a select statement!" );
903
- try (final RelationalResultSet resultSet = statement .getResultSet ()) {
904
- ResultSetAssert .assertThat (resultSet )
905
- .hasNextRow ()
906
- .hasColumn ("NAME" , "Alice" )
907
- .hasNoNextRow ();
908
- }
909
-
910
- Assertions .assertTrue (statement .execute ("SELECT * from STUDENT WHERE score is distinct from 100" ), "Did not return a result set from a select statement!" );
911
- try (final RelationalResultSet resultSet = statement .getResultSet ()) {
912
- ResultSetAssert .assertThat (resultSet )
913
- .hasNextRow ()
914
- .hasColumn ("NAME" , "Bob" )
915
- .hasNoNextRow ();
916
- }
917
-
918
- Assertions .assertTrue (statement .execute ("SELECT * from STUDENT f WHERE null is distinct from score" ), "Did not return a result set from a select statement!" );
919
- try (final RelationalResultSet resultSet = statement .getResultSet ()) {
920
- ResultSetAssert .assertThat (resultSet )
921
- .hasNextRow ()
922
- .hasColumn ("NAME" , "Alice" )
923
- .hasNoNextRow ();
924
- }
925
-
926
- Assertions .assertTrue (statement .execute ("SELECT * from STUDENT f WHERE 100 is distinct from score" ), "Did not return a result set from a select statement!" );
927
- try (final RelationalResultSet resultSet = statement .getResultSet ()) {
928
- ResultSetAssert .assertThat (resultSet )
929
- .hasNextRow ()
930
- .hasColumn ("NAME" , "Bob" )
931
- .hasNoNextRow ();
932
- }
933
-
934
- Assertions .assertTrue (statement .execute ("SELECT * from STUDENT f WHERE 100 is distinct from 100" ), "Did not return a result set from a select statement!" );
935
- try (final RelationalResultSet resultSet = statement .getResultSet ()) {
936
- ResultSetAssert .assertThat (resultSet )
937
- .hasNoNextRow ();
938
- }
939
-
940
- Assertions .assertTrue (statement .execute ("SELECT * from STUDENT f WHERE null is distinct from null" ), "Did not return a result set from a select statement!" );
941
- try (final RelationalResultSet resultSet = statement .getResultSet ()) {
942
- ResultSetAssert .assertThat (resultSet )
943
- .hasNoNextRow ();
944
- }
945
- }
946
- }
947
- }
948
-
949
- @ Test
950
- void testNotDistinctFrom () throws Exception {
951
- final String schema = "CREATE TYPE AS STRUCT contact_detail(phone_number string, address string) " +
952
- "CREATE TABLE student(id bigint, name string, contact contact_detail, score bigint, primary key(id))" ;
953
- try (var ddl = Ddl .builder ().database (URI .create ("/TEST/QT" )).relationalExtension (relationalExtension ).schemaTemplate (schema ).build ()) {
954
- try (var statement = ddl .setSchemaAndGetConnection ().createStatement ()) {
955
- final var row1 = EmbeddedRelationalStruct .newBuilder ()
956
- .addLong ("ID" , 1L )
957
- .addString ("NAME" , "Alice" )
958
- .addLong ("SCORE" , 100 )
959
- .build ();
960
- final var row2 = EmbeddedRelationalStruct .newBuilder ()
961
- .addLong ("ID" , 2L )
962
- .addString ("NAME" , "Bob" )
963
- .build ();
964
- Assertions .assertEquals (1 , statement .executeInsert ("STUDENT" , row1 ), "Incorrect insertion count" );
965
- Assertions .assertEquals (1 , statement .executeInsert ("STUDENT" , row2 ), "Incorrect insertion count" );
966
-
967
- Assertions .assertTrue (statement .execute ("SELECT * from STUDENT WHERE score is not distinct from null" ), "Did not return a result set from a select statement!" );
968
- try (final RelationalResultSet resultSet = statement .getResultSet ()) {
969
- ResultSetAssert .assertThat (resultSet )
970
- .hasNextRow ()
971
- .hasColumn ("NAME" , "Bob" )
972
- .hasNoNextRow ();
973
- }
974
-
975
- Assertions .assertTrue (statement .execute ("SELECT * from STUDENT WHERE score is not distinct from 100" ), "Did not return a result set from a select statement!" );
976
- try (final RelationalResultSet resultSet = statement .getResultSet ()) {
977
- ResultSetAssert .assertThat (resultSet )
978
- .hasNextRow ()
979
- .hasColumn ("NAME" , "Alice" )
980
- .hasNoNextRow ();
981
- }
982
-
983
- Assertions .assertTrue (statement .execute ("SELECT * from STUDENT WHERE null is not distinct from score" ), "Did not return a result set from a select statement!" );
984
- try (final RelationalResultSet resultSet = statement .getResultSet ()) {
985
- ResultSetAssert .assertThat (resultSet )
986
- .hasNextRow ()
987
- .hasColumn ("NAME" , "Bob" )
988
- .hasNoNextRow ();
989
- }
990
-
991
- Assertions .assertTrue (statement .execute ("SELECT * from STUDENT WHERE 100 is not distinct from score" ), "Did not return a result set from a select statement!" );
992
- try (final RelationalResultSet resultSet = statement .getResultSet ()) {
993
- ResultSetAssert .assertThat (resultSet )
994
- .hasNextRow ()
995
- .hasColumn ("NAME" , "Alice" )
996
- .hasNoNextRow ();
997
- }
998
-
999
- Assertions .assertTrue (statement .execute ("SELECT * from STUDENT WHERE 100 is not distinct from 100" ), "Did not return a result set from a select statement!" );
1000
- try (final RelationalResultSet resultSet = statement .getResultSet ()) {
1001
- ResultSetAssert .assertThat (resultSet )
1002
- .hasNextRow ()
1003
- .hasColumn ("NAME" , "Alice" )
1004
- .hasNextRow ()
1005
- .hasColumn ("NAME" , "Bob" )
1006
- .hasNoNextRow ();
1007
- }
1008
-
1009
- Assertions .assertTrue (statement .execute ("SELECT * from STUDENT WHERE null is not distinct from null" ), "Did not return a result set from a select statement!" );
1010
- try (final RelationalResultSet resultSet = statement .getResultSet ()) {
1011
- ResultSetAssert .assertThat (resultSet )
1012
- .hasNextRow ()
1013
- .hasColumn ("NAME" , "Alice" )
1014
- .hasNextRow ()
1015
- .hasColumn ("NAME" , "Bob" )
1016
- .hasNoNextRow ();
1017
- }
1018
- }
1019
- }
1020
- }
1021
-
1022
- @ Test
1023
- void testExplainDistinctFrom () throws Exception {
1024
- final String schemaTemplate = "CREATE TYPE AS STRUCT contact_detail(phone_number string, address string) " +
1025
- "CREATE TABLE STUDENT(id bigint, name string, contact contact_detail, score bigint, primary key(id)) " +
1026
- "CREATE index score_idx as select score from STUDENT" ;
1027
- try (var ddl = Ddl .builder ().database (URI .create ("/TEST/QT" )).relationalExtension (relationalExtension ).schemaTemplate (schemaTemplate ).build ()) {
1028
- try (var statement = ddl .setSchemaAndGetConnection ().createStatement ()) {
1029
- try (final RelationalResultSet resultSet = statement .executeQuery ("EXPLAIN SELECT name FROM STUDENT where score is distinct from null" )) {
1030
- resultSet .next ();
1031
- String plan = resultSet .getString (1 );
1032
- assertThat (plan ).matches ("ISCAN\\ (SCORE_IDX \\ (\\ [null\\ ],>\\ ) \\ | MAP \\ (_\\ .NAME AS NAME\\ )" );
1033
- }
1034
- }
1035
- try (var statement = ddl .setSchemaAndGetConnection ().createStatement ()) {
1036
- try (final RelationalResultSet resultSet = statement .executeQuery ("EXPLAIN SELECT name FROM STUDENT where score is distinct from 100" )) {
1037
- resultSet .next ();
1038
- String plan = resultSet .getString (1 );
1039
- assertThat (plan ).matches ("COVERING\\ (SCORE_IDX <,> -> \\ [ID: KEY\\ [.*], SCORE: KEY\\ [.*]\\ ]\\ ) \\ | FILTER _\\ .SCORE IS_DISTINCT_FROM promote\\ (@.* AS LONG\\ ) \\ | FETCH \\ | MAP \\ (_\\ .NAME AS NAME\\ )" );
1040
- }
1041
- }
1042
- try (var statement = ddl .setSchemaAndGetConnection ().createStatement ()) {
1043
- try (final RelationalResultSet resultSet = statement .executeQuery ("EXPLAIN SELECT name FROM STUDENT where null is distinct from score" )) {
1044
- resultSet .next ();
1045
- String plan = resultSet .getString (1 );
1046
- assertThat (plan ).matches ("ISCAN\\ (SCORE_IDX \\ (\\ [null\\ ],>\\ ) \\ | MAP \\ (_\\ .NAME AS NAME\\ )" );
1047
- }
1048
- }
1049
- try (var statement = ddl .setSchemaAndGetConnection ().createStatement ()) {
1050
- try (final RelationalResultSet resultSet = statement .executeQuery ("EXPLAIN SELECT name FROM STUDENT where 100 is distinct from score" )) {
1051
- resultSet .next ();
1052
- String plan = resultSet .getString (1 );
1053
- assertThat (plan ).matches ("COVERING\\ (SCORE_IDX <,> -> \\ [ID: KEY\\ [.*], SCORE: KEY\\ [.*]\\ ]\\ ) \\ | FILTER _\\ .SCORE IS_DISTINCT_FROM promote\\ (@.* AS LONG\\ ) \\ | FETCH \\ | MAP \\ (_\\ .NAME AS NAME\\ )" );
1054
- }
1055
- }
1056
- try (var statement = ddl .setSchemaAndGetConnection ().createStatement ()) {
1057
- try (final RelationalResultSet resultSet = statement .executeQuery ("EXPLAIN SELECT name FROM STUDENT where score is not distinct from null" )) {
1058
- resultSet .next ();
1059
- String plan = resultSet .getString (1 );
1060
- assertThat (plan ).matches ("ISCAN\\ (SCORE_IDX \\ [\\ [null\\ ],\\ [null\\ ]\\ ]\\ ) \\ | MAP \\ (_\\ .NAME AS NAME\\ )" );
1061
- }
1062
- }
1063
- try (var statement = ddl .setSchemaAndGetConnection ().createStatement ()) {
1064
- try (final RelationalResultSet resultSet = statement .executeQuery ("EXPLAIN SELECT name FROM STUDENT where score is not distinct from 100" )) {
1065
- resultSet .next ();
1066
- String plan = resultSet .getString (1 );
1067
- assertThat (plan ).matches ("COVERING\\ (SCORE_IDX <,> -> \\ [ID: KEY\\ [.*], SCORE: KEY\\ [.*]\\ ]\\ ) \\ | FILTER _\\ .SCORE NOT_DISTINCT_FROM promote\\ (@.* AS LONG\\ ) \\ | FETCH \\ | MAP \\ (_\\ .NAME AS NAME\\ )" );
1068
- }
1069
- }
1070
- try (var statement = ddl .setSchemaAndGetConnection ().createStatement ()) {
1071
- try (final RelationalResultSet resultSet = statement .executeQuery ("EXPLAIN SELECT name FROM STUDENT where null is not distinct from score" )) {
1072
- resultSet .next ();
1073
- String plan = resultSet .getString (1 );
1074
- assertThat (plan ).matches ("ISCAN\\ (SCORE_IDX \\ [\\ [null\\ ],\\ [null\\ ]\\ ]\\ ) \\ | MAP \\ (_\\ .NAME AS NAME\\ )" );
1075
- }
1076
- }
1077
- try (var statement = ddl .setSchemaAndGetConnection ().createStatement ()) {
1078
- try (final RelationalResultSet resultSet = statement .executeQuery ("EXPLAIN SELECT name FROM STUDENT where 100 is not distinct from score" )) {
1079
- resultSet .next ();
1080
- String plan = resultSet .getString (1 );
1081
- assertThat (plan ).matches ("COVERING\\ (SCORE_IDX <,> -> \\ [ID: KEY\\ [.*], SCORE: KEY\\ [.*]\\ ]\\ ) \\ | FILTER _\\ .SCORE NOT_DISTINCT_FROM promote\\ (@.* AS LONG\\ ) \\ | FETCH \\ | MAP \\ (_\\ .NAME AS NAME\\ )" );
1082
- }
1083
- }
1084
- }
1085
- }
1086
-
883
+
1087
884
@ Test
1088
885
void testBitmap () throws Exception {
1089
886
final String query = "SELECT BITMAP_CONSTRUCT_AGG(BITMAP_BIT_POSITION(uid)) as bitmap, category, BITMAP_BUCKET_OFFSET(uid) as offset FROM T1\n " +
0 commit comments