-
Notifications
You must be signed in to change notification settings - Fork 283
Feat: map_from_entries #2905
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
Merged
Merged
Feat: map_from_entries #2905
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
768b3e9
impl map_from_entries
e6b3cc0
impl map_from_entries
cd1b754
fix fmt
348fb32
Add to configs.md
50801fa
Add fuzz test
4f22cc9
Add fuzz test
4a6e0f6
Add fuzz test
cad6a95
fix tests
c68c342
Revert "impl map_from_entries"
d887555
Merge branch 'apache:main' into main
kazantsev-maksim 1839d61
Merge remote-tracking branch 'origin/main' into map_from_entries
582e248
fix tests
9f68d08
fix fmt
231aa90
Merge branch 'apache:main' into main
kazantsev-maksim 9500bbb
Merge branch 'apache:main' into main
kazantsev-maksim 4f3670b
Merge remote-tracking branch 'origin/main' into map_from_entries
70599d5
resolve conflicts
9577481
Merge branch 'apache:main' into main
kazantsev-maksim 3791557
Merge branch 'apache:main' into main
kazantsev-maksim 7c2f082
Merge branch 'apache:main' into main
kazantsev-maksim 609a605
Merge branch 'apache:main' into main
kazantsev-maksim a151b2c
Merge branch 'apache:main' into main
kazantsev-maksim bce0839
Merge remote-tracking branch 'origin/main' into map_from_entries
628364d
Add more test
ad3e7f5
Merge branch 'apache:main' into main
kazantsev-maksim ea92e4b
Merge branch 'apache:main' into main
kazantsev-maksim 8dfeca3
Merge branch 'apache:main' into main
kazantsev-maksim 559741e
Merge branch 'apache:main' into main
kazantsev-maksim ebda14e
Merge branch 'apache:main' into main
kazantsev-maksim 408152e
Merge branch 'apache:main' into main
kazantsev-maksim d7857b2
Merge branch 'apache:main' into main
kazantsev-maksim 941c354
Merge remote-tracking branch 'origin/main' into map_from_entries
aef41be
Merge branch 'apache:main' into main
kazantsev-maksim 5ac1c58
Merge branch 'apache:main' into main
kazantsev-maksim 9cb59bd
Merge remote-tracking branch 'origin/main' into map_from_entries
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,9 @@ import org.apache.hadoop.fs.Path | |
| import org.apache.spark.sql.CometTestBase | ||
| import org.apache.spark.sql.functions._ | ||
| import org.apache.spark.sql.internal.SQLConf | ||
| import org.apache.spark.sql.types.BinaryType | ||
|
|
||
| import org.apache.comet.serde.CometMapFromEntries | ||
| import org.apache.comet.testing.{DataGenOptions, ParquetGenerator, SchemaGenOptions} | ||
|
|
||
| class CometMapExpressionSuite extends CometTestBase { | ||
|
|
@@ -157,4 +159,90 @@ class CometMapExpressionSuite extends CometTestBase { | |
| } | ||
| } | ||
|
|
||
| test("map_from_entries - convert from Parquet") { | ||
| withTempDir { dir => | ||
| val path = new Path(dir.toURI.toString, "test.parquet") | ||
| val filename = path.toString | ||
| val random = new Random(42) | ||
| withSQLConf(CometConf.COMET_ENABLED.key -> "false") { | ||
| val schemaGenOptions = | ||
| SchemaGenOptions( | ||
| generateArray = false, | ||
| generateStruct = false, | ||
| primitiveTypes = SchemaGenOptions.defaultPrimitiveTypes.filterNot(_ == BinaryType)) | ||
| val dataGenOptions = DataGenOptions(allowNull = false, generateNegativeZero = false) | ||
| ParquetGenerator.makeParquetFile( | ||
| random, | ||
| spark, | ||
| filename, | ||
| 100, | ||
| schemaGenOptions, | ||
| dataGenOptions) | ||
| } | ||
| withSQLConf( | ||
| CometConf.COMET_NATIVE_SCAN_ENABLED.key -> "false", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kazantsev-maksim Could you also add a test where native scan is enabled
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @andygrove. I have added a test |
||
| CometConf.COMET_SPARK_TO_ARROW_ENABLED.key -> "true", | ||
| CometConf.COMET_CONVERT_FROM_PARQUET_ENABLED.key -> "true") { | ||
| val df = spark.read.parquet(filename) | ||
| df.createOrReplaceTempView("t1") | ||
| for (field <- df.schema.fieldNames) { | ||
| checkSparkAnswerAndOperator( | ||
| spark.sql( | ||
| s"SELECT map_from_entries(array(struct($field as a, $field as b))) FROM t1")) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("map_from_entries - native Parquet reader") { | ||
| withTempDir { dir => | ||
| val path = new Path(dir.toURI.toString, "test.parquet") | ||
| val filename = path.toString | ||
| val random = new Random(42) | ||
| withSQLConf(CometConf.COMET_ENABLED.key -> "false") { | ||
| val schemaGenOptions = | ||
| SchemaGenOptions( | ||
| generateArray = false, | ||
| generateStruct = false, | ||
| primitiveTypes = SchemaGenOptions.defaultPrimitiveTypes.filterNot(_ == BinaryType)) | ||
| val dataGenOptions = DataGenOptions(allowNull = false, generateNegativeZero = false) | ||
| ParquetGenerator.makeParquetFile( | ||
| random, | ||
| spark, | ||
| filename, | ||
| 100, | ||
| schemaGenOptions, | ||
| dataGenOptions) | ||
| } | ||
| val df = spark.read.parquet(filename) | ||
| df.createOrReplaceTempView("t1") | ||
| for (field <- df.schema.fieldNames) { | ||
| checkSparkAnswerAndOperator( | ||
| spark.sql(s"SELECT map_from_entries(array(struct($field as a, $field as b))) FROM t1")) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("map_from_entries - fallback for binary type") { | ||
| def fallbackReason(reason: String) = { | ||
| if (CometConf.COMET_NATIVE_SCAN_IMPL.key == CometConf.SCAN_NATIVE_COMET || sys.env | ||
| .getOrElse("COMET_PARQUET_SCAN_IMPL", "") == CometConf.SCAN_NATIVE_COMET) { | ||
| "Unsupported schema" | ||
| } else { | ||
| reason | ||
| } | ||
| } | ||
| val table = "t2" | ||
| withTable(table) { | ||
| sql( | ||
| s"create table $table using parquet as select cast(array() as array<binary>) as c1 from range(10)") | ||
| checkSparkAnswerAndFallbackReason( | ||
| sql(s"select map_from_entries(array(struct(c1, 0))) from $table"), | ||
| fallbackReason(CometMapFromEntries.keyUnsupportedReason)) | ||
| checkSparkAnswerAndFallbackReason( | ||
| sql(s"select map_from_entries(array(struct(0, c1))) from $table"), | ||
| fallbackReason(CometMapFromEntries.valueUnsupportedReason)) | ||
| } | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
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.
sorry for disrupting you, should we implement those scalar function with inheriting
CometExpressionSerdeor,CometScalarFunction. just want to make sure the standard.cause I'm also working on some map expression support. eg. #3369