Skip to content

Commit

Permalink
fix: BigQuery GENERATE_DATE_ARRAY with only 2 parameters
Browse files Browse the repository at this point in the history
- fixes #14

Signed-off-by: Andreas Reichel <andreas@manticore-projects.com>
  • Loading branch information
manticore-projects committed Jun 10, 2024
1 parent 469af1c commit 0264ea1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/main/java/ai/starlake/transpiler/JSQLExpressionTranspiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -977,13 +977,22 @@ public void visit(Column column) {
break;

case GENERATE_DATE_ARRAY:
function.setName("Generate_Series");
function.setParameters(new CastExpression(parameters.get(0), "DATE"),
new CastExpression(parameters.get(1), "DATE"),
new CastExpression(parameters.get(2), "INTERVAL"));
rewrittenExpression = new CastExpression(function, "DATE[]");
switch (paramCount) {
case 2:
function.setName("Generate_Series");
function.setParameters(new CastExpression(parameters.get(0), "DATE"),
new CastExpression(parameters.get(1), "DATE"), new IntervalExpression(1, "DAY"));
rewrittenExpression = new CastExpression(function, "DATE[]");
break;
case 3:
function.setName("Generate_Series");
function.setParameters(new CastExpression(parameters.get(0), "DATE"),
new CastExpression(parameters.get(1), "DATE"),
new CastExpression(parameters.get(2), "INTERVAL"));
rewrittenExpression = new CastExpression(function, "DATE[]");
break;
}
break;

case GENERATE_TIMESTAMP_ARRAY:
function.setName("Generate_Series");
function.setParameters(new CastExpression(parameters.get(0), "TIMESTAMP"),
Expand Down
Binary file modified src/site/sphinx/_static/JSQLTranspiler.ods
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ FROM (
"[2016-07-01, 2016-07-08, 2016-07-15, 2016-07-22, 2016-07-29]"
"[2016-10-01, 2016-10-08, 2016-10-15, 2016-10-22, 2016-10-29]"

-- provided
SELECT GENERATE_DATE_ARRAY('2016-10-05', '2016-10-08') AS example;

-- expected
SELECT GENERATE_SERIES('2016-10-05'::DATE,'2016-10-08'::DATE,INTERVAL 1 DAY)::DATE[]AS EXAMPLE;

-- result
"example"
"[2016-10-05, 2016-10-06, 2016-10-07, 2016-10-08]"

-- provided
SELECT GENERATE_TIMESTAMP_ARRAY(start_timestamp, end_timestamp, INTERVAL 1 HOUR)
Expand Down

0 comments on commit 0264ea1

Please sign in to comment.