Skip to content

Commit

Permalink
fix: BigQuery default sort order
Browse files Browse the repository at this point in the history
- fixes #10

Signed-off-by: Andreas Reichel <andreas@manticore-projects.com>
  • Loading branch information
manticore-projects committed Jun 13, 2024
1 parent bd56173 commit 2c3090e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/test/java/ai/starlake/transpiler/JSQLTranspilerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ static synchronized void init()
new File(EXTRACTION_PATH, JSQLTranspilerTest.class.getSimpleName() + ".duckdb");
Properties info = new Properties();
info.put("old_implicit_casting", "true");
// info.put("default_null_order", "NULLS FIRST");
// info.put("default_order", "ASC");
connDuck = DriverManager.getConnection("jdbc:duckdb:" + fileDuckDB.getAbsolutePath(), info);

if (!isInitialised) {
Expand Down Expand Up @@ -482,6 +484,11 @@ public static void executeTest(Connection connDuck, SQLTest t, String transpiled
try (Statement st = connDuck.createStatement()) {
st.executeUpdate("set timezone='Asia/Bangkok'");

if (t.inputDialect == JSQLTranspiler.Dialect.GOOGLE_BIG_QUERY) {
st.executeUpdate("set default_null_order='NULLS FIRST'");
st.executeUpdate("set default_order='ASC'");
}

try (ResultSet rs = st.executeQuery(transpiledSqlStr);) {
while (rs.next()) {
i++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ FROM (select UNNEST([0, 2, NULL, 4, 4, 5]) AS x) as x;

-- result
"x","avg"
"",""
"0","0.0"
"2","1.0"
"4","3.0"
"4","4.0"
"5","4.5"
"","5.0"


-- provided
Expand Down Expand Up @@ -230,7 +230,7 @@ order by 1 NULLS FIRST;

-- result
"x","num_negative"
"","1"
"","0"
"-10","2"
"-7","2"
"-2","1"
Expand Down Expand Up @@ -261,12 +261,12 @@ ORDER BY product_name, product_type;

-- result
"product_type","product_name","product_sum","product_type_agg","product_name_agg"
"","","42","1","1"
"pants","","6","0","1"
"shirt","","36","0","1"
"","jeans","6","1","0"
"","polo","25","1","0"
"","t-shirt","11","1","0"
"pants","","6","0","1"
"shirt","","36","0","1"
"","","42","1","1"


-- provided
Expand Down Expand Up @@ -394,11 +394,11 @@ FROM( SELECT UNNEST( ['apple',NULL,'pear','banana','pear'] )AS FRUIT ) AS FRUIT

-- result
"fruit","string_agg"
"",""
"pear","pear & pear"
"pear","pear & pear"
"apple","pear & pear & apple"
"banana","pear & pear & apple & banana"
"","pear & pear & apple & banana"


-- provided
Expand Down

0 comments on commit 2c3090e

Please sign in to comment.