-
Notifications
You must be signed in to change notification settings - Fork 330
test: cover nested complex casts #4608
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
manuzhang
wants to merge
2
commits into
apache:main
Choose a base branch
from
manuzhang:codex/complex-cast-coverage
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.
+151
−0
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
151 changes: 151 additions & 0 deletions
151
spark/src/test/resources/sql-tests/expressions/cast/cast_complex.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,151 @@ | ||
| -- 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. | ||
|
|
||
| statement | ||
| CREATE TABLE test_cast_complex( | ||
| id int, | ||
| struct_arr struct<items:array<int>,label:string>, | ||
| deep struct<outer:struct<middle:struct<value:string,flag:boolean>,numbers:array<string>>,note:string>, | ||
| arr_struct array<struct<id:int,score:string>> | ||
| ) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO test_cast_complex VALUES | ||
| ( | ||
| 1, | ||
| named_struct( | ||
| 'items', array(1, 2, cast(null as int)), | ||
| 'label', 'first'), | ||
| named_struct( | ||
| 'outer', | ||
| named_struct( | ||
| 'middle', named_struct('value', '1', 'flag', true), | ||
| 'numbers', array('2', '3')), | ||
| 'note', 'alpha'), | ||
| array( | ||
| named_struct('id', 1, 'score', '10'), | ||
| named_struct('id', 2, 'score', cast(null as string))) | ||
| ), | ||
| ( | ||
| 2, | ||
| named_struct( | ||
| 'items', cast(array() as array<int>), | ||
| 'label', cast(null as string)), | ||
| named_struct( | ||
| 'outer', | ||
| named_struct( | ||
| 'middle', named_struct('value', cast(null as string), 'flag', false), | ||
| 'numbers', array(cast(null as string))), | ||
| 'note', cast(null as string)), | ||
| array(named_struct('id', cast(null as int), 'score', '30')) | ||
| ), | ||
| ( | ||
| 3, | ||
| cast(null as struct<items:array<int>,label:string>), | ||
| cast(null as | ||
| struct<outer:struct<middle:struct<value:string,flag:boolean>,numbers:array<string>>, | ||
| note:string>), | ||
| cast(array() as array<struct<id:int,score:string>>) | ||
| ), | ||
| ( | ||
| 4, | ||
| named_struct( | ||
| 'items', array(-1, 0, 2147483647), | ||
| 'label', 'edge'), | ||
| named_struct( | ||
| 'outer', | ||
| named_struct( | ||
| 'middle', named_struct('value', '-4', 'flag', true), | ||
| 'numbers', array('-5', '0')), | ||
| 'note', 'omega'), | ||
| cast(null as array<struct<id:int,score:string>>) | ||
| ) | ||
|
|
||
| -- struct field containing an array | ||
| query | ||
| SELECT cast(struct_arr as struct<items:array<string>,label:string>), id | ||
| FROM test_cast_complex | ||
| ORDER BY id | ||
|
|
||
| -- struct fields can be renamed by the target type | ||
| query | ||
| SELECT cast(struct_arr as struct<numbers:array<string>,name:string>), id | ||
| FROM test_cast_complex | ||
| ORDER BY id | ||
|
|
||
| -- struct target field names are applied positionally | ||
| query | ||
| SELECT cast(struct_arr as struct<label:array<string>,items:string>), id | ||
| FROM test_cast_complex | ||
| ORDER BY id | ||
|
|
||
| -- missing struct fields are rejected | ||
| query expect_error(DATATYPE_MISMATCH) | ||
| SELECT cast(struct_arr as struct<items:array<string>>) | ||
| FROM test_cast_complex | ||
|
|
||
| -- extra struct fields are rejected | ||
| query expect_error(DATATYPE_MISMATCH) | ||
| SELECT cast(struct_arr as struct<items:array<string>,label:string,extra:int>) | ||
| FROM test_cast_complex | ||
|
|
||
| -- deeply nested struct to struct | ||
| query | ||
| SELECT cast(deep as | ||
| struct<outer:struct<middle:struct<value:int,flag:string>,numbers:array<int>>,note:string>), id | ||
| FROM test_cast_complex | ||
| ORDER BY id | ||
|
|
||
| -- deeply nested struct to string | ||
| query | ||
| SELECT cast(deep as string), id | ||
| FROM test_cast_complex | ||
| ORDER BY id | ||
|
|
||
| -- array of structs to array of structs | ||
| query | ||
| SELECT cast(arr_struct as array<struct<id:bigint,score:int>>), id | ||
| FROM test_cast_complex | ||
| ORDER BY id | ||
|
|
||
| -- array of structs with renamed fields | ||
| query | ||
| SELECT cast(arr_struct as array<struct<item_id:bigint,total:int>>), id | ||
| FROM test_cast_complex | ||
| ORDER BY id | ||
|
|
||
| -- array of structs with target field names applied positionally | ||
| query | ||
| SELECT cast(arr_struct as array<struct<score:bigint,id:int>>), id | ||
| FROM test_cast_complex | ||
| ORDER BY id | ||
|
|
||
| -- array of structs with missing nested fields is rejected | ||
| query expect_error(DATATYPE_MISMATCH) | ||
| SELECT cast(arr_struct as array<struct<id:bigint>>) | ||
| FROM test_cast_complex | ||
|
|
||
| -- array of structs with extra nested fields is rejected | ||
| query expect_error(DATATYPE_MISMATCH) | ||
| SELECT cast(arr_struct as array<struct<id:bigint,score:int,extra:string>>) | ||
| FROM test_cast_complex | ||
|
|
||
| -- array of structs to string | ||
| query | ||
| SELECT cast(arr_struct as string), id | ||
| FROM test_cast_complex | ||
| ORDER BY id | ||
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.
we prob also need some negative scenarios.
Nested cast is super deep topic, WDYT if we can have more test combinations?
structs can be tested to cast to objects with missing, extra, renamed, different order fields.