-
Notifications
You must be signed in to change notification settings - Fork 330
feat: support size() for MapType input #4580
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
base: main
Are you sure you want to change the base?
Changes from all commits
4f17386
0b3c451
ff01bbc
92789ac
8e8f6c5
206fbd0
22407c5
4ed725f
1921d5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,9 +21,21 @@ CREATE TABLE test_size(arr array<int>, m map<string, int>) USING parquet | |
| statement | ||
| INSERT INTO test_size VALUES (array(1, 2, 3), map('a', 1, 'b', 2)), (array(), map()), (NULL, NULL) | ||
|
|
||
| query spark_answer_only | ||
| query | ||
| SELECT size(arr), size(m) FROM test_size | ||
|
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. Could you also add literal map cases below the existing literal-args query? Something like: query
SELECT size(map('a', 1, 'b', 2)), size(map()), size(cast(NULL as map<string,int>))That way the literal path is covered for both shapes. While you're here, a
Contributor
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. I think literal map is not supported yet
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. Done — all three items added:
ScalarValue::Map unit tests also added per review (ff01bbc), and stale docs notes cleared (b1d177a). Should I file a follow-up issue for |
||
|
|
||
| -- literal arguments | ||
| -- literal array arguments | ||
| query | ||
| SELECT size(array(1, 2, 3)), size(array()), size(cast(NULL as array<int>)) | ||
|
|
||
| -- literal map via CreateMap (falls back: Comet has no CreateMap serde; | ||
| -- cast(NULL as map) avoids CreateMap and goes through CometLiteral instead) | ||
| query spark_answer_only | ||
| SELECT size(map('a', 1, 'b', 2)), size(map()) | ||
|
|
||
| query | ||
| SELECT size(cast(NULL as map<string,int>)) | ||
|
|
||
| -- cardinality is a SQL alias for size | ||
| query | ||
| SELECT cardinality(arr), cardinality(m) FROM test_size | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| -- 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. | ||
|
|
||
| -- Config: spark.sql.legacy.sizeOfNull=false | ||
|
|
||
| statement | ||
| CREATE TABLE test_size_legacy_off(arr array<int>, m map<string, int>) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO test_size_legacy_off VALUES (array(1, 2, 3), map('a', 1, 'b', 2)), (array(), map()), (NULL, NULL) | ||
|
|
||
| -- With sizeOfNull=false, size(NULL) returns NULL instead of -1 | ||
| query | ||
| SELECT size(arr), size(m) FROM test_size_legacy_off | ||
|
|
||
| query | ||
| SELECT size(cast(NULL as array<int>)), size(cast(NULL as map<string,int>)) | ||
|
|
||
| query | ||
| SELECT cardinality(arr), cardinality(m) FROM test_size_legacy_off |
Uh oh!
There was an error while loading. Please reload this page.