Skip to content

[GLUTEN-13416][FLINK] Support MD5 and SHA1 - #13420

Open
zhang-jianq wants to merge 3 commits into
apache:mainfrom
zhang-jianq:hashExprMD5AndSha1
Open

zhang-jianq wants to merge 3 commits into
apache:mainfrom
zhang-jianq:hashExprMD5AndSha1

Conversation

@zhang-jianq

@zhang-jianq zhang-jianq commented Oct 23, 2026 •

Copy link
Copy Markdown

What changes are proposed in this pull request?

Adds the planner-side wiring so Flink's MD5(string) and SHA1(string) offload to the velox flinksql md5/sha1 functions (bigo-sg/velox#87 adds the functions themselves):

  • RexCallConverterFactory: map the MD5 and SHA1 RexCalls to md5/sha1 via the default name converter. Both take exactly one VARCHAR argument and return VARCHAR, so a plain name mapping suffices.
  • Tests: HashFunctionsTest covers end-to-end execution with 8 symmetric cases (4 per function) — basic / multibyte / NULL / long-input rows, literal inputs incl. the empty string, a nested call over LOWER, and non-string inputs (CAST(n AS STRING) plus the rejected bare MD5(n)/SHA1(n)). The MD5/SHA1 mappings are plain name mappings, so no separate converter unit test is added.

How was this patch tested?

  • gluten-flink/ut: HashFunctionsTest (8 cases — basic / multibyte / NULL / long-input, literal incl. empty string, nested LOWER, and non-string CAST/rejected bare int) passes.

  • End-to-end dual-run on Flink 1.19.2 (native vs gluten-offloaded, identical VALUES inputs, changelog multiset exact comparison): md5.sql and sha1.sql match native exactly (7 rows each). md5.sql differs only in projecting md5(s) into a md5_s column; the query is:

    CREATE TABLE snk (
      id     BIGINT,
      s      STRING,
      md5_s  STRING
    ) WITH ('connector' = 'print');
    
    INSERT INTO snk
    SELECT id, s, MD5(s)
    FROM (
      VALUES
      (1, CAST('test' AS STRING)),
      (2, CAST('abc' AS STRING)),
      (3, CAST('' AS STRING)),
      (4, CAST('你好' AS STRING)),
      (5, CAST('ABC' AS STRING)),
      (6, CAST(NULL AS STRING)),
      (7, CAST('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' AS STRING))
    ) AS src (id, s);

Related issue: #13416

@zhang-jianq
zhang-jianq force-pushed the hashExprMD5AndSha1 branch 2 times, most recently from 7d4666f to 7d3d172 Compare October 27, 2026 09:05
@zhang-jianq

Copy link
Copy Markdown
Author

@KevinyhZou @lgbo-ustc @ggjh-159 Would you mind reviewing this PR?

@ggjh-159 ggjh-159 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the minimal mapping and the end-to-end coverage.

  1. The repo's spotless check (bound to the build's validate phase) FAILED — HashFunctionsTest.java is missing the trailing newline at EOF. Please run mvn spotless:apply (or add the final newline).
  2. Please add the SQL details of the dual-run to the PR description — the queries in md5.sql/sha1.sql that were run against Flink 1.19.2.

@zhang-jianq
zhang-jianq force-pushed the hashExprMD5AndSha1 branch 2 times, most recently from 2a2c0ca to ad7c9e1 Compare October 29, 2026 12:38
@zhang-jianq

Copy link
Copy Markdown
Author

@ggjh-159 Thanks for the review. I have fixed both:
• added the trailing newline to HashFunctionsTest.java (via mvn spotless:apply).
• added the dual-run queries to the PR description — the INSERT ... SELECT MD5(s) / SHA1(s)over the 7-row VALUES covering basic / empty / multibyte / case-variant / NULL / long inputs.

@zhang-jianq
zhang-jianq force-pushed the hashExprMD5AndSha1 branch 6 times, most recently from 95f411c to ff527ea Compare November 3, 2026 08:09
@zhang-jianq
zhang-jianq requested a review from ggjh-159 November 3, 2026 08:12

@ggjh-159 ggjh-159 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment on test coverage — details in the line comment on HashFunctionsTest.java.

import java.util.List;

class HashFunctionsTest extends GlutenStreamingTestBase {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extend HashFunctionsTest with: empty-string and long-input rows for both MD5 and SHA1 (as in the dual-run set), a constant-input case (e.g. MD5('abc')), a nested-call case (e.g. MD5(UPPER(s))), and non-string input cases — MD5(CAST(n AS STRING)) over an int column plus the rejected bare MD5(n) asserting the validation error.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. Extended HashFunctionsTest to 8 symmetric cases (4 per function):

  • testMd5Basic / testSha1Basic — plain / multibyte / NULL plus a 32-char long input.
  • testMd5Constant / testSha1Constant — literal inputs, including the empty string (MD5('') / SHA1('')). The empty string is covered via a literal because the values connector's from_elements drops an empty-string row field, so an empty-string row can't be exercised through a table.
  • testMd5Nested / testSha1Nested — MD5(LOWER(s)) / SHA1(LOWER(s)). I used LOWER rather than UPPER because UPPER is not registered in gluten yet.
  • testMd5NonStringInput / testSha1NonStringInput — MD5(CAST(n AS STRING)) / SHA1(CAST(n AS STRING)) over an int column, plus assertThatThrownBy on the bare MD5(n) / SHA1(n) asserting the Flink ValidationException.

@ggjh-159

ggjh-159 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

@zhang-jianq please update velox4j version and Flink.md

@zhang-jianq

Copy link
Copy Markdown
Author

@zhang-jianq please update velox4j version and Flink.md

@ggjh-159 The velox4j-side PR (#68) is merged — flink.yml and Flink.md now pin bigo-sg/velox4j gluten-20260829 at 69485bb. Please take another look.

@zhang-jianq
zhang-jianq requested a review from ggjh-159 November 3, 2026 11:24
@zhang-jianq
zhang-jianq force-pushed the hashExprMD5AndSha1 branch 2 times, most recently from b1a1f86 to e6f1fa5 Compare November 5, 2026 12:07
@github-actions github-actions Bot removed the INFRA label Nov 5, 2026
Signed-off-by: zhangjianqiu <1726110962@qq.com>

@ggjh-159 ggjh-159 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for expanding the tests to the constant, nested, and non-string forms.

The PR description's "What changes" section still lists two changes that are no longer in the diff: "CI routing: .github/workflows/flink.yml clones the pinned velox4j branch" and "Docs: gluten-flink/docs/Flink.md build notes synced" — after the rebase onto main, the velox4j ref is managed by main's central gluten-flink/velox4j-ref.txt and the diff no longer touches either file. Please remove these two bullets.

[?] (no anchor) 一般——body——The PR description's "What changes" section still lists two changes that are no longer in the diff: "CI routing: .github/workflows/flink.yml clones the pinned velox4j branch" and "Docs: gluten-flink/docs/Flink.md build notes synced" — after the rebase onto main, the velox4j ref is managed by main's central gluten-flink/velox4j-ref.txt and the diff no longer touches either file. Please remove these two bullets.

@zhang-jianq

Copy link
Copy Markdown
Author

Thanks for expanding the tests to the constant, nested, and non-string forms.

The PR description's "What changes" section still lists two changes that are no longer in the diff: "CI routing: .github/workflows/flink.yml clones the pinned velox4j branch" and "Docs: gluten-flink/docs/Flink.md build notes synced" — after the rebase onto main, the velox4j ref is managed by main's central gluten-flink/velox4j-ref.txt and the diff no longer touches either file. Please remove these two bullets.

[?] (no anchor) 一般——body——The PR description's "What changes" section still lists two changes that are no longer in the diff: "CI routing: .github/workflows/flink.yml clones the pinned velox4j branch" and "Docs: gluten-flink/docs/Flink.md build notes synced" — after the rebase onto main, the velox4j ref is managed by main's central gluten-flink/velox4j-ref.txt and the diff no longer touches either file. Please remove these two bullets.

@ggjh-159 Thanks for your review. It's fixed now. please review it again.

@zhang-jianq
zhang-jianq requested a review from ggjh-159 November 6, 2026 07:55
@ggjh-159

Copy link
Copy Markdown
Contributor

@KevinyhZou @lgbo-ustc @philo-he cc

@ggjh-159 ggjh-159 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants