fix(e6): preserve DBR DATE_ADD arity under E6_EXECUTOR_TYPE=native#255
Merged
ArnavBorkarE6x merged 1 commit intoMay 8, 2026
Merged
Conversation
DBR 2-arg DATE_ADD(date, n) returns DATE; 3-arg DATE_ADD(unit, n, ts) returns TIMESTAMP. The transpiler previously collapsed both to e6 3-arg, which broke patterns like CONCAT(DATE_ADD(ts, 0), SUBSTR(ts, 11)) by producing a doubled time portion (Samsung zero-row issue). Changes: - databricks parser: default_unit=None so 2-arg parses with unit=None while 3-arg keeps the explicit unit. Mirrors clickhouse.py pattern. No DBR output change since date_delta_sql falls back to DAY. - e6 generator: new dateadd_sql checks E6_EXECUTOR_TYPE. - native: emit 2-arg when unit is None, 3-arg otherwise. - java (default): always 3-arg with DAY filled in (unchanged). - e6 read parser handles both arities for round-trips.
ArnavBorkarE6x
approved these changes
May 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DATE_ADD(date, n)returns DATE; 3-argDATE_ADD(unit, n, ts)returns TIMESTAMP. The transpiler previously collapsed both to e6 3-argDATE_ADD('DAY', n, ts), switching the return type and breakingCONCAT(DATE_ADD(ts, 0), SUBSTR(ts, 11))patterns by producing a doubled time portion (Samsung zero-row issue).E6_EXECUTOR_TYPE=native(the same flag used by PR fix(e6): gate TO_UNIX_TIMESTAMP /1000 on executor type #253). Java executor default is unchanged.E6_EXECUTOR_TYPE=native: 2-arg DBR -> e6 2-argDATE_ADD(ts, n); 3-arg DBR -> e6 3-argDATE_ADD(unit, n, ts).java): 2-arg and 3-arg DBR both emit e6 3-arg withDAYfilled in (prior behavior preserved).DATE_ADD('YEAR', 5, d)) always stay 3-arg in both modes.Mechanism
sqlglot/dialects/databricks.py: passdefault_unit=Nonetobuild_date_deltaforDATE_ADD/DATEADD. Now 2-arg DBR parses withunit=None, 3-arg with an explicit unit. Matches the pattern atclickhouse.py:310. No DBR output change sincedate_delta_sqlfalls back toDAYviaunit_to_var.sqlglot/dialects/e6.py: new auto-discovereddateadd_sqlmethod readsE6_EXECUTOR_TYPEand emits 2-arg only when native ANDunit is None. Replaces the previousexp.DateAdd: lambdaTRANSFORMS entry. Read parser also handles 2-argDATE_ADD(date, n)for round-trips.Context
The Samsung repro pattern:
With prior 3-arg conversion,
DATE_ADDreturned TIMESTAMP ->CONCAT(<full ts>, ' 00:00:00')-> doubled time portion -> invalid timestamp -> NULL after outerCAST, predicate becomes unknown, rows dropped.Test plan
test_date_add_native_executorcovering both modes (2-arg/3-arg input, 2-arg/3-arg expected output).test_dialect_specific_functionsextended with the java-default case (DATE_ADD(ts, 2)->DATE_ADD('DAY', 2, ts)).python -m unittest discover tests/dialects-> 545/545 pass (e6, databricks, spark, hive, etc.) -- no regressions.