Skip to content

[Feature](nereids) Add Snowflake dialect compatibility - Phase 1 & 2 Pure Alias Registration && FE Expression Rewrite#60982

Open
kaori-seasons wants to merge 1 commit intoapache:masterfrom
kaori-seasons:issue-60951
Open

[Feature](nereids) Add Snowflake dialect compatibility - Phase 1 & 2 Pure Alias Registration && FE Expression Rewrite#60982
kaori-seasons wants to merge 1 commit intoapache:masterfrom
kaori-seasons:issue-60951

Conversation

@kaori-seasons
Copy link

@kaori-seasons kaori-seasons commented Mar 3, 2026

Related to issue-60951
Implement Snowflake SQL dialect compatibility to improve direct execution coverage on Apache Doris from ~40% to ~85%.

Phase 1 - Pure Alias Registration (16 aliases):

  • IFF -> If, ARRAY_CONSTRUCT -> Array, ARRAY_CAT -> ArrayConcat
  • ARRAY_TO_STRING -> ArrayJoin, PARSE_JSON -> JsonbParse
  • TRY_PARSE_JSON -> JsonbParseErrorToNull, CHECK_JSON -> JsonbValid
  • BASE64_ENCODE -> ToBase64, BASE64_DECODE_STRING -> FromBase64
  • HEX_ENCODE -> Hex, HEX_DECODE_STRING -> Unhex
  • ENDSWITH -> EndsWith, STARTSWITH -> StartsWith
  • GETDATE -> Now, LEN -> CharacterLength, CHARINDEX -> Locate
  • Fix: Merge duplicate JsonbValid registrations into single line

Phase 2 - FE Expression Rewrite Functions (7 new classes):

  • ZEROIFNULL(x) -> Coalesce(x, Cast(0, x.type))
  • NULLIFZERO(x) -> NullIf(x, Cast(0, x.type))
  • NVL2(e1, e2, e3) -> If(Not(IsNull(e1)), e2, e3)
  • EQUAL_NULL(a, b) -> NullSafeEqual(a, b)
  • CONVERT_TIMEZONE(src, dst, ts) -> ConvertTz(ts, src, dst)
  • OBJECT_CONSTRUCT(k1, v1, ...) -> JsonObject(k1, v1, ...)
  • TO_VARCHAR(expr[, fmt]) -> Cast(expr, VARCHAR) or DateFormat(expr, fmt)

All 7 functions registered in BuiltinScalarFunctions and ScalarFunctionVisitor.

Tests:

  • 32 FE unit tests (SnowflakeCompatFunctionTest) covering all aliases and rewrite functions with constant and column-based scenarios
  • 2 regression test suites (test_snowflake_aliases.groovy, test_snowflake_rewrite.groovy) for end-to-end validation

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary:

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

Implement Snowflake SQL dialect compatibility to improve direct execution
coverage on Apache Doris from ~40% to ~85%.

Phase 1 - Pure Alias Registration (16 aliases):
- IFF -> If, ARRAY_CONSTRUCT -> Array, ARRAY_CAT -> ArrayConcat
- ARRAY_TO_STRING -> ArrayJoin, PARSE_JSON -> JsonbParse
- TRY_PARSE_JSON -> JsonbParseErrorToNull, CHECK_JSON -> JsonbValid
- BASE64_ENCODE -> ToBase64, BASE64_DECODE_STRING -> FromBase64
- HEX_ENCODE -> Hex, HEX_DECODE_STRING -> Unhex
- ENDSWITH -> EndsWith, STARTSWITH -> StartsWith
- GETDATE -> Now, LEN -> CharacterLength, CHARINDEX -> Locate
- Fix: Merge duplicate JsonbValid registrations into single line

Phase 2 - FE Expression Rewrite Functions (7 new classes):
- ZEROIFNULL(x) -> Coalesce(x, Cast(0, x.type))
- NULLIFZERO(x) -> NullIf(x, Cast(0, x.type))
- NVL2(e1, e2, e3) -> If(Not(IsNull(e1)), e2, e3)
- EQUAL_NULL(a, b) -> NullSafeEqual(a, b)
- CONVERT_TIMEZONE(src, dst, ts) -> ConvertTz(ts, src, dst)
- OBJECT_CONSTRUCT(k1, v1, ...) -> JsonObject(k1, v1, ...)
- TO_VARCHAR(expr[, fmt]) -> Cast(expr, VARCHAR) or DateFormat(expr, fmt)

All 7 functions registered in BuiltinScalarFunctions and ScalarFunctionVisitor.

Tests:
- 32 FE unit tests (SnowflakeCompatFunctionTest) covering all aliases
  and rewrite functions with constant and column-based scenarios
- 2 regression test suites (test_snowflake_aliases.groovy,
  test_snowflake_rewrite.groovy) for end-to-end validation
@Thearas
Copy link
Contributor

Thearas commented Mar 3, 2026

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@kaori-seasons
Copy link
Author

Thank you for your contribution to Apache Doris. Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

Hello, thank you for your reply. I have linked an issue related to this PR. This issue was created based on the roadmap released by the community this year, which supports the migration from Snowflake to Doris. The main target audience is some overseas users who face this need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants