-
Notifications
You must be signed in to change notification settings - Fork 342
feat: route translate and to_csv through codegen dispatch by default #5032
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
andygrove
wants to merge
2
commits into
apache:main
Choose a base branch
from
andygrove:feat/incompat-codegen-dispatch
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 all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
77 changes: 77 additions & 0 deletions
77
spark/src/test/resources/sql-tests/expressions/csv/to_csv.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,77 @@ | ||
| -- 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. | ||
|
|
||
| -- to_csv runs through the codegen dispatcher by default so results match Spark exactly, including | ||
| -- quoting and escaping. The native path is opt-in via | ||
| -- spark.comet.expression.StructsToCsv.allowIncompatible. | ||
|
|
||
| statement | ||
| CREATE TABLE test_to_csv(a int, b string, c double) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO test_to_csv VALUES | ||
| (1, 'x', 2.5), | ||
| (-3, 'hello,world', 0.0), | ||
| (0, 'has "quote"', -1.5), | ||
| (NULL, NULL, NULL), | ||
| (7, '', 3.0) | ||
|
|
||
| -- column struct: values with delimiters and quotes exercise Spark's CSV quoting rules | ||
| query | ||
| SELECT to_csv(named_struct('a', a, 'b', b, 'c', c)) FROM test_to_csv | ||
|
|
||
| -- literal struct (constant folding is disabled by the test suite) | ||
| query | ||
| SELECT | ||
| to_csv(named_struct('a', 1, 'b', 'x', 'c', 2.5)), | ||
| to_csv(named_struct('s', 'a,b', 'n', CAST(NULL AS INT))) | ||
|
|
||
| -- Options are the main axis of behavior difference for this expression, and the dispatcher path | ||
| -- had no options coverage anywhere (CometCsvExpressionSuite only varies them under | ||
| -- allowIncompatible=true). `sep` also changes which values need quoting. | ||
| query | ||
| SELECT to_csv(named_struct('a', a, 'b', b, 'c', c), map('sep', ';')) FROM test_to_csv | ||
|
|
||
| -- timestampFormat over date and timestamp fields: these are the #3232 types that were | ||
| -- Incompatible before this change and now route through the dispatcher. | ||
| -- BinaryType is the other #3232 type but is deliberately absent: Spark's CSV converter renders it | ||
| -- with Java's default Object.toString(), e.g. "[B@10bc15e4", an identity hash that differs between | ||
| -- any two evaluations, so the value is not assertable by any engine including Spark itself. | ||
| statement | ||
| CREATE TABLE test_to_csv_temporal(d date, t timestamp) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO test_to_csv_temporal VALUES | ||
| (DATE '2024-01-31', TIMESTAMP '2024-01-31 12:34:56.789'), | ||
| (DATE '1970-01-01', TIMESTAMP '1970-01-01 00:00:00'), | ||
| (NULL, NULL) | ||
|
|
||
| query | ||
| SELECT to_csv(named_struct('d', d, 't', t)) FROM test_to_csv_temporal | ||
|
|
||
| query | ||
| SELECT to_csv(named_struct('d', d, 't', t), map('timestampFormat', 'yyyy/MM/dd HH:mm', 'dateFormat', 'dd-MM-yyyy')) FROM test_to_csv_temporal | ||
|
|
||
| -- Complex field types (arrays, maps, nested structs) are deliberately not asserted here. | ||
| -- StructsToCsv.checkInputDataTypes accepts them, so they reach the converter, but Spark's own | ||
| -- output for them is not a value that can be compared: a non-null array/map/struct renders as a | ||
| -- Java identity string such as "org.apache.spark.sql.vectorized.ColumnarArray@1ada50f0", and any | ||
| -- null complex value throws NullPointerException inside Spark's UnsafeWriter.write. Both were | ||
| -- confirmed against Spark 3.5 with Comet disabled entirely, so they are Spark behavior, not | ||
| -- Comet's. Before this change these schemas were Unsupported and fell the projection back to | ||
| -- Spark; now they reach the dispatcher, which runs the same Spark code, so the observable result | ||
| -- is unchanged either way. | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optionsis the main axis of behavior difference for this expression and nothing in the new fixture varies it.CometCsvExpressionSuite:71-161covers delimiter, escape, quoteAll and nullValue but only underallowIncompatible=true, so the dispatcher path has no options coverage anywhere.to_csv(s, map('sep', ';'))plus atimestampFormatover a timestamp field would cover both this and the #3232 types in one query.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 26994c9.
to_csv.sqlnow coversmap('sep', ';')over the existing rows (which also changes which values need quoting), plus atimestampFormat/dateFormatquery over a new date+timestamp table — so the same query exercises both the options axis and the #3232 types that previously fell back. The dispatcher path had no options coverage anywhere before this.