|
| 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 | +-- ConfigMatrix: parquet.enable.dictionary=false,true |
| 19 | + |
| 20 | +statement |
| 21 | +CREATE TABLE test_cast_decimal(d10 decimal(10,2), d5 decimal(5,0)) USING parquet |
| 22 | + |
| 23 | +statement |
| 24 | +INSERT INTO test_cast_decimal VALUES |
| 25 | + (123.45, 123), |
| 26 | + (-67.89, -67), |
| 27 | + (0.00, 0), |
| 28 | + (0.01, 1), |
| 29 | + (-0.01, -1), |
| 30 | + (99999999.99, 99999), |
| 31 | + (-99999999.99, -99999), |
| 32 | + (NULL, NULL) |
| 33 | + |
| 34 | +-- decimal(10,2) column to FLOAT |
| 35 | +query |
| 36 | +SELECT cast(d10 as float) FROM test_cast_decimal |
| 37 | + |
| 38 | +-- decimal(10,2) column to DOUBLE |
| 39 | +query |
| 40 | +SELECT cast(d10 as double) FROM test_cast_decimal |
| 41 | + |
| 42 | +-- decimal(10,2) column to INT |
| 43 | +query |
| 44 | +SELECT cast(d10 as int) FROM test_cast_decimal |
| 45 | + |
| 46 | +-- decimal(10,2) column to LONG |
| 47 | +query |
| 48 | +SELECT cast(d10 as long) FROM test_cast_decimal |
| 49 | + |
| 50 | +-- decimal(10,2) column to BOOLEAN |
| 51 | +query |
| 52 | +SELECT cast(d10 as boolean) FROM test_cast_decimal |
| 53 | + |
| 54 | +-- decimal(5,0) column to FLOAT |
| 55 | +query |
| 56 | +SELECT cast(d5 as float) FROM test_cast_decimal |
| 57 | + |
| 58 | +-- decimal(5,0) column to DOUBLE |
| 59 | +query |
| 60 | +SELECT cast(d5 as double) FROM test_cast_decimal |
| 61 | + |
| 62 | +-- decimal(5,0) column to INT |
| 63 | +query |
| 64 | +SELECT cast(d5 as int) FROM test_cast_decimal |
| 65 | + |
| 66 | +-- decimal(5,0) column to LONG |
| 67 | +query |
| 68 | +SELECT cast(d5 as long) FROM test_cast_decimal |
| 69 | + |
| 70 | +-- decimal(5,0) column to BOOLEAN |
| 71 | +query |
| 72 | +SELECT cast(d5 as boolean) FROM test_cast_decimal |
| 73 | + |
| 74 | +-- decimal(38,18) table: covers boundary values that exercise the i128 code path |
| 75 | +statement |
| 76 | +CREATE TABLE test_cast_decimal_high_precision(d38 decimal(38,18)) USING parquet |
| 77 | + |
| 78 | +statement |
| 79 | +INSERT INTO test_cast_decimal_high_precision VALUES |
| 80 | + (CAST('99999999999999999999.999999999999999999' AS decimal(38,18))), |
| 81 | + (CAST('-99999999999999999999.999999999999999999' AS decimal(38,18))), |
| 82 | + (CAST('9223372036854775807.000000000000000000' AS decimal(38,18))), |
| 83 | + (CAST('-9223372036854775808.000000000000000000' AS decimal(38,18))), |
| 84 | + (CAST('1.000000000000000000' AS decimal(38,18))), |
| 85 | + (CAST('-1.000000000000000000' AS decimal(38,18))), |
| 86 | + (CAST('0.000000000000000000' AS decimal(38,18))), |
| 87 | + (NULL) |
| 88 | + |
| 89 | +-- decimal(38,18) column to FLOAT |
| 90 | +query |
| 91 | +SELECT cast(d38 as float) FROM test_cast_decimal_high_precision |
| 92 | + |
| 93 | +-- decimal(38,18) column to DOUBLE |
| 94 | +query |
| 95 | +SELECT cast(d38 as double) FROM test_cast_decimal_high_precision |
| 96 | + |
| 97 | +-- decimal(38,18) column to INT |
| 98 | +query |
| 99 | +SELECT cast(d38 as int) FROM test_cast_decimal_high_precision |
| 100 | + |
| 101 | +-- decimal(38,18) column to LONG |
| 102 | +query |
| 103 | +SELECT cast(d38 as long) FROM test_cast_decimal_high_precision |
| 104 | + |
| 105 | +-- decimal(38,18) column to BOOLEAN |
| 106 | +query |
| 107 | +SELECT cast(d38 as boolean) FROM test_cast_decimal_high_precision |
| 108 | + |
| 109 | +-- additional precision/scale combinations: decimal(15,5) has fractional part with int overflow |
| 110 | +-- possible; decimal(20,0) has no fractional part with long overflow possible |
| 111 | +statement |
| 112 | +CREATE TABLE test_cast_decimal_extra( |
| 113 | + d15_5 decimal(15,5), |
| 114 | + d20_0 decimal(20,0) |
| 115 | +) USING parquet |
| 116 | + |
| 117 | +statement |
| 118 | +INSERT INTO test_cast_decimal_extra VALUES |
| 119 | + (2147483648.12345, 9223372036854775808), -- d15_5 overflows INT; d20_0 overflows LONG |
| 120 | + (-2147483649.12345, -9223372036854775809), |
| 121 | + (123.45678, 2147483648), -- fractional truncation; d20_0 overflows INT only |
| 122 | + (0.00001, 1), |
| 123 | + (-0.00001, -1), |
| 124 | + (0.00000, 0), |
| 125 | + (NULL, NULL) |
| 126 | + |
| 127 | +-- decimal(15,5) to INT (exercises fractional truncation and int overflow) |
| 128 | +query |
| 129 | +SELECT cast(d15_5 as int) FROM test_cast_decimal_extra |
| 130 | + |
| 131 | +-- decimal(15,5) to LONG |
| 132 | +query |
| 133 | +SELECT cast(d15_5 as long) FROM test_cast_decimal_extra |
| 134 | + |
| 135 | +-- decimal(15,5) to BOOLEAN |
| 136 | +query |
| 137 | +SELECT cast(d15_5 as boolean) FROM test_cast_decimal_extra |
| 138 | + |
| 139 | +-- decimal(20,0) to INT |
| 140 | +query |
| 141 | +SELECT cast(d20_0 as int) FROM test_cast_decimal_extra |
| 142 | + |
| 143 | +-- decimal(20,0) to LONG (exercises long overflow) |
| 144 | +query |
| 145 | +SELECT cast(d20_0 as long) FROM test_cast_decimal_extra |
| 146 | + |
| 147 | +-- decimal(20,0) to BOOLEAN |
| 148 | +query |
| 149 | +SELECT cast(d20_0 as boolean) FROM test_cast_decimal_extra |
| 150 | + |
| 151 | +-- literal casts: decimal(10,2) to float |
| 152 | +query |
| 153 | +SELECT cast(cast(1.50 as decimal(10,2)) as float), |
| 154 | + cast(cast(0.00 as decimal(10,2)) as float), |
| 155 | + cast(cast(-1.50 as decimal(10,2)) as float), |
| 156 | + cast(cast(NULL as decimal(10,2)) as float) |
| 157 | + |
| 158 | +-- literal casts: decimal(5,0) to float |
| 159 | +query |
| 160 | +SELECT cast(cast(123 as decimal(5,0)) as float), |
| 161 | + cast(cast(0 as decimal(5,0)) as float), |
| 162 | + cast(cast(-123 as decimal(5,0)) as float), |
| 163 | + cast(cast(NULL as decimal(5,0)) as float) |
| 164 | + |
| 165 | +-- literal casts: decimal(10,2) to boolean |
| 166 | +query |
| 167 | +SELECT cast(cast(1.50 as decimal(10,2)) as boolean), |
| 168 | + cast(cast(0.00 as decimal(10,2)) as boolean), |
| 169 | + cast(cast(NULL as decimal(10,2)) as boolean) |
| 170 | + |
| 171 | +-- literal casts: decimal(5,0) to boolean |
| 172 | +query |
| 173 | +SELECT cast(cast(1 as decimal(5,0)) as boolean), |
| 174 | + cast(cast(0 as decimal(5,0)) as boolean), |
| 175 | + cast(cast(NULL as decimal(5,0)) as boolean) |
0 commit comments