Skip to content

Commit

Permalink
feat: support more BigQuery Date/Time functions
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Reichel <andreas@manticore-projects.com>
  • Loading branch information
manticore-projects committed Mar 21, 2024
1 parent 3dd6918 commit 0599f38
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/com/manticore/transpiler/ExpressionTranspiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ enum TranspiledFunction {

, LAST_DAY

, PARSE_DATE, PARSE_DATETIME, PARSE_TIME, PARSE_TIMESTAMP, DATE_FROM_UNIX_DATE, UNIX_DATE, TIMESTAMP_MICROS, TIMESTAMP_MILLIS, TIMESTAMP_SECONDS
, PARSE_DATE, PARSE_DATETIME, PARSE_TIME, PARSE_TIMESTAMP, DATE_FROM_UNIX_DATE, UNIX_DATE, TIMESTAMP_MICROS, TIMESTAMP_MILLIS, TIMESTAMP_SECONDS, UNIX_MICROS, UNIX_MILLIS, UNIX_SECONDS

, STRING

Expand Down Expand Up @@ -522,6 +522,15 @@ public void visit(Function function) {
function.setParameters(new ExpressionList<Expression>(new Multiplication()
.withLeftExpression(castExpression).withRightExpression(new LongValue(1000))));
break;
case UNIX_MICROS:
function.setName("EPOCH_US");
break;
case UNIX_MILLIS:
function.setName("EPOCH_MS");
break;
case UNIX_SECONDS:
function.setName("EPOCH");
break;
case NVL:
function.setName("Coalesce");
break;
Expand Down
Binary file modified src/main/resources/doc/JSQLTranspiler.ods
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,48 @@ SELECT EPOCH_MS(Cast(1230219000 AS INT64) * 1000) AS timestamp_value;
"2008-12-25 15:30:00"


-- provided
SELECT UNIX_MICROS(TIMESTAMP '2008-12-25 15:30:00+00') AS micros;

-- expected
SELECT EPOCH_US(TIMESTAMP '2008-12-25 15:30:00+00') AS micros
;

-- result
"micros"
"1230219000000000"


-- provided
SELECT UNIX_MILLIS(TIMESTAMP '2008-12-25 15:30:00+00') AS millis;

-- expected
SELECT EPOCH_MS(TIMESTAMP '2008-12-25 15:30:00+00') AS millis
;

-- result
"millis"
"1230219000000"


-- provided
SELECT UNIX_MILLIS(TIMESTAMP '1970-01-01 00:00:00.0018+00') AS millis;

-- expected
SELECT EPOCH_MS(TIMESTAMP '1970-01-01 00:00:00.0018+00') AS millis
;

-- result
"millis"
"1"


-- provided
SELECT UNIX_SECONDS(TIMESTAMP '2008-12-25 15:30:00+00') AS seconds;

-- expected
SELECT EPOCH(TIMESTAMP '2008-12-25 15:30:00+00') AS seconds;

-- result
"seconds"
"1230219000"

0 comments on commit 0599f38

Please sign in to comment.