-
Notifications
You must be signed in to change notification settings - Fork 319
feat: Support Spark Expression Encode #4315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
YutaLin
wants to merge
13
commits into
apache:main
Choose a base branch
from
YutaLin:3183_support_spark_expression_encode
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
fdc962a
feat: add stringEncode in CommonStringExprs
YutaLin 91f1b57
feat: add encode check in CometExprShim
YutaLin d46c128
chore: spotless check
YutaLin 8ff9922
test: add encode sql
YutaLin 3c08105
docs: support encode
YutaLin ef35199
Merge branch 'main' into 3183_support_spark_expression_encode
YutaLin 16d4f89
refactor: extract encode to common shim
YutaLin bc1bbcf
feat: add null check
YutaLin f507beb
Merge branch 'main' into 3183_support_spark_expression_encode
YutaLin 3e55030
fix: lint issue
YutaLin 0b54aef
Merge branch '3183_support_spark_expression_encode' of work:YutaLin/d…
YutaLin dd2f63d
fix: scalafix check
YutaLin 4448c18
Merge branch 'main' into 3183_support_spark_expression_encode
YutaLin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
61 changes: 61 additions & 0 deletions
61
spark/src/test/resources/sql-tests/expressions/string/encode.sql
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| -- Licensed to the Apache Software Foundation (ASF) under one | ||
| -- or more contributor license agreements. See the NOTICE file | ||
| -- distributed with this work for additional information | ||
| -- regarding copyright ownership. The ASF licenses this file | ||
| -- to you under the Apache License, Version 2.0 (the | ||
| -- "License"); you may not use this file except in compliance | ||
| -- with the License. You may obtain a copy of the License at | ||
| -- | ||
| -- http://www.apache.org/licenses/LICENSE-2.0 | ||
| -- | ||
| -- Unless required by applicable law or agreed to in writing, | ||
| -- software distributed under the License is distributed on an | ||
| -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| -- KIND, either express or implied. See the License for the | ||
| -- specific language governing permissions and limitations | ||
| -- under the License. | ||
|
|
||
| -- Tests for the SQL `encode(str, charset)` function. | ||
| -- | ||
| -- Spark 3.x: Encode is a BinaryExpression(value, charset). | ||
| -- Spark 4.x+: Encode is RuntimeReplaceable; the analyzer rewrites it to | ||
| -- StaticInvoke(classOf[Encode], BinaryType, "encode", ...) | ||
|
|
||
| statement | ||
| CREATE TABLE test_encode_utf8(s string) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO test_encode_utf8 VALUES ('hello'), ('world'), (''), ('café'), (NULL) | ||
|
|
||
| query | ||
| SELECT encode(s, 'utf-8') FROM test_encode_utf8 | ||
|
|
||
| query | ||
| SELECT encode(s, 'UTF-8') FROM test_encode_utf8 | ||
|
|
||
| -- Mixed-case charset literal exercises toLowerCase normalization | ||
| query | ||
| SELECT encode(s, 'Utf-8') FROM test_encode_utf8 | ||
|
|
||
| query | ||
| SELECT encode('hello', 'utf-8'), encode('', 'utf-8'), encode(CAST(NULL AS STRING), 'utf-8') | ||
|
|
||
| -- Different language(French, Japanese) | ||
| query | ||
| SELECT encode('café', 'utf-8'), encode('日本語', 'utf-8') | ||
|
|
||
| -- non-UTF-8 falls back to Spark JVM | ||
| statement | ||
| CREATE TABLE test_encode_charset_safe(s string) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO test_encode_charset_safe VALUES ('hello'), ('world'), (''), (NULL) | ||
|
|
||
| query expect_fallback(Comet only supports encoding with 'utf-8'.) | ||
| SELECT encode(s, 'UTF-16BE') FROM test_encode_charset_safe | ||
|
|
||
| query expect_fallback(Comet only supports encoding with 'utf-8'.) | ||
| SELECT encode(s, 'US-ASCII') FROM test_encode_charset_safe | ||
|
|
||
| query expect_fallback(Comet only supports encoding with 'utf-8'.) | ||
| SELECT encode(s, 'ISO-8859-1') FROM test_encode_charset_safe |
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.
Uh oh!
There was an error while loading. Please reload this page.