fix(duckdb): add ParseDatetime transpilation for BigQuery to DuckDB#7704
fix(duckdb): add ParseDatetime transpilation for BigQuery to DuckDB#7704william-goode wants to merge 5 commits into
Conversation
BigQuery's PARSE_DATETIME is parsed into exp.ParseDatetime but DuckDB's generator has no handler, so it falls through to function_fallback_sql and emits PARSE_DATETIME(...) verbatim, which DuckDB rejects. Add parsedatetime_sql method that maps to STRPTIME. Unlike ParseTime (which needs CAST to TIME) or StrToDate (which needs CAST to DATE), STRPTIME already returns TIMESTAMP which matches PARSE_DATETIME semantics, so no cast is needed. ParseDatetime has no safe arg, so no TRY_STRPTIME conditional is required. [CLAUDE]
Cover three format variations for BigQuery PARSE_DATETIME -> DuckDB STRPTIME to avoid a second review round requesting additional coverage: - Standard datetime format (%Y-%m-%d %H:%M:%S) - Named day/month with 12-hour time (%a %b %e %I:%M:%S %Y) - Microsecond precision (%H:%M:%E6S) [CLAUDE]
Reviewer flagged that time-only PARSE_DATETIME produces different default dates between engines (BQ: 1970-01-01, DuckDB: 1900-01-01). Specify the date explicitly to avoid the degenerate case. [CLAUDE]
|
@william-goode let's move on with the concatenation for the solution. So let's do the following:
|
|
Hey @william-goode, any plans to take this to the finish line? |
|
@georgesittas Yes! Sorry, got caught up with work. @geooo109 Yes chef. Thanks for the feedback fellas - changes coming shortly. |
|
Cool, no worries & thanks for following up! |
BigQuery defaults to 1970 for missing year components in
PARSE_DATETIME, while DuckDB defaults to 1900. Add a default_year
flag to ParseDatetime AST node, set by the BigQuery parser, and
generate STRPTIME('1970 ' || <value>, '%Y ' || <format>) in DuckDB
to match BigQuery semantics. [CLAUDE]
|
Patched with concatenation approach and ready for review. A knock-on effect: The BigQuery parser sets |
Summary
BigQuery's
PARSE_DATETIMEis parsed intoexp.ParseDatetimebut DuckDB's generator has no handler. Falls through tofunction_fallback_sqland emitsPARSE_DATETIME(...)verbatim — DuckDB rejects this.Fix: Add
parsedatetime_sqltoDuckDBGeneratormapping toSTRPTIME. NoCASTneeded (unlikeParseTime/StrToDate) sinceSTRPTIMEalready returnsTIMESTAMP. NoTRY_STRPTIMEconditional sinceParseDatetimehas nosafearg.Reproduction
Test plan
validate_alltests: standard datetime format, named day/month with 12-hour clock, microsecond precision (%E6S)make unit: 1219 passed, 0 failures