|
| 1 | +-- Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +-- or more contributor license agreements. See the NOTICE file |
| 3 | +-- distributed with this work for additional information |
| 4 | +-- regarding copyright ownership. The ASF licenses this file |
| 5 | +-- to you under the Apache License, Version 2.0 (the |
| 6 | +-- "License"); you may not use this file except in compliance |
| 7 | +-- with the License. You may obtain a copy of the License at |
| 8 | +-- |
| 9 | +-- http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +-- |
| 11 | +-- Unless required by applicable law or agreed to in writing, |
| 12 | +-- software distributed under the License is distributed on an |
| 13 | +-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +-- KIND, either express or implied. See the License for the |
| 15 | +-- specific language governing permissions and limitations |
| 16 | +-- under the License. |
| 17 | + |
| 18 | +statement |
| 19 | +CREATE TABLE test_cast_complex( |
| 20 | + id int, |
| 21 | + struct_arr struct<items:array<int>,label:string>, |
| 22 | + deep struct<outer:struct<middle:struct<value:string,flag:boolean>,numbers:array<string>>,note:string>, |
| 23 | + arr_struct array<struct<id:int,score:string>> |
| 24 | +) USING parquet |
| 25 | + |
| 26 | +statement |
| 27 | +INSERT INTO test_cast_complex VALUES |
| 28 | + ( |
| 29 | + 1, |
| 30 | + named_struct( |
| 31 | + 'items', array(1, 2, cast(null as int)), |
| 32 | + 'label', 'first'), |
| 33 | + named_struct( |
| 34 | + 'outer', |
| 35 | + named_struct( |
| 36 | + 'middle', named_struct('value', '1', 'flag', true), |
| 37 | + 'numbers', array('2', '3')), |
| 38 | + 'note', 'alpha'), |
| 39 | + array( |
| 40 | + named_struct('id', 1, 'score', '10'), |
| 41 | + named_struct('id', 2, 'score', cast(null as string))) |
| 42 | + ), |
| 43 | + ( |
| 44 | + 2, |
| 45 | + named_struct( |
| 46 | + 'items', cast(array() as array<int>), |
| 47 | + 'label', cast(null as string)), |
| 48 | + named_struct( |
| 49 | + 'outer', |
| 50 | + named_struct( |
| 51 | + 'middle', named_struct('value', cast(null as string), 'flag', false), |
| 52 | + 'numbers', array(cast(null as string))), |
| 53 | + 'note', cast(null as string)), |
| 54 | + array(named_struct('id', cast(null as int), 'score', '30')) |
| 55 | + ), |
| 56 | + ( |
| 57 | + 3, |
| 58 | + cast(null as struct<items:array<int>,label:string>), |
| 59 | + cast(null as |
| 60 | + struct<outer:struct<middle:struct<value:string,flag:boolean>,numbers:array<string>>, |
| 61 | + note:string>), |
| 62 | + cast(array() as array<struct<id:int,score:string>>) |
| 63 | + ), |
| 64 | + ( |
| 65 | + 4, |
| 66 | + named_struct( |
| 67 | + 'items', array(-1, 0, 2147483647), |
| 68 | + 'label', 'edge'), |
| 69 | + named_struct( |
| 70 | + 'outer', |
| 71 | + named_struct( |
| 72 | + 'middle', named_struct('value', '-4', 'flag', true), |
| 73 | + 'numbers', array('-5', '0')), |
| 74 | + 'note', 'omega'), |
| 75 | + cast(null as array<struct<id:int,score:string>>) |
| 76 | + ) |
| 77 | + |
| 78 | +-- struct field containing an array |
| 79 | +query |
| 80 | +SELECT cast(struct_arr as struct<items:array<string>,label:string>), id |
| 81 | +FROM test_cast_complex |
| 82 | +ORDER BY id |
| 83 | + |
| 84 | +-- deeply nested struct to struct |
| 85 | +query |
| 86 | +SELECT cast(deep as |
| 87 | + struct<outer:struct<middle:struct<value:int,flag:string>,numbers:array<int>>,note:string>), id |
| 88 | +FROM test_cast_complex |
| 89 | +ORDER BY id |
| 90 | + |
| 91 | +-- deeply nested struct to string |
| 92 | +query |
| 93 | +SELECT cast(deep as string), id |
| 94 | +FROM test_cast_complex |
| 95 | +ORDER BY id |
| 96 | + |
| 97 | +-- array of structs to array of structs |
| 98 | +query |
| 99 | +SELECT cast(arr_struct as array<struct<id:bigint,score:int>>), id |
| 100 | +FROM test_cast_complex |
| 101 | +ORDER BY id |
| 102 | + |
| 103 | +-- array of structs to string |
| 104 | +query |
| 105 | +SELECT cast(arr_struct as string), id |
| 106 | +FROM test_cast_complex |
| 107 | +ORDER BY id |
0 commit comments