|
| 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 | +# Validate arithmetic operator output type |
| 19 | + |
| 20 | +statement ok |
| 21 | +create table numeric_types as |
| 22 | +SELECT |
| 23 | + arrow_cast(1, 'Int8') as int8, |
| 24 | + arrow_cast(1, 'Int16') as int16, |
| 25 | + arrow_cast(1, 'Int32') as int32, |
| 26 | + arrow_cast(1, 'Int64') as int64, |
| 27 | + arrow_cast(1, 'UInt8') as uint8, |
| 28 | + arrow_cast(1, 'UInt16') as uint16, |
| 29 | + arrow_cast(1, 'UInt32') as uint32, |
| 30 | + arrow_cast(1, 'UInt64') as uint64, |
| 31 | + arrow_cast(1.23, 'Float32') as float32, |
| 32 | + arrow_cast(1.23, 'Float64') as float64, |
| 33 | + arrow_cast(1.25, 'Decimal128(5, 2)') as decimal |
| 34 | +; |
| 35 | + |
| 36 | +# Plus with the same operand type, expect the same output type |
| 37 | +# except for decimal which is promoted to the highest precision |
| 38 | +query TTTTTTTTTTT |
| 39 | +select |
| 40 | + arrow_typeof(int8 + int8), |
| 41 | + arrow_typeof(int16 + int16), |
| 42 | + arrow_typeof(int32 + int32), |
| 43 | + arrow_typeof(int64 + int64), |
| 44 | + arrow_typeof(uint8 + uint8), |
| 45 | + arrow_typeof(uint16 + uint16), |
| 46 | + arrow_typeof(uint32 + uint32), |
| 47 | + arrow_typeof(uint64 + uint64), |
| 48 | + arrow_typeof(float32 + float32), |
| 49 | + arrow_typeof(float64 + float64), |
| 50 | + arrow_typeof(decimal + decimal) |
| 51 | +from numeric_types; |
| 52 | +---- |
| 53 | +Int8 Int16 Int32 Int64 UInt8 UInt16 UInt32 UInt64 Float32 Float64 Decimal128(6, 2) |
| 54 | + |
| 55 | + |
| 56 | +# Minus with the same operand type, expect the same output type |
| 57 | +# except for decimal which is promoted to the highest precision |
| 58 | +query TTTTTTTTTTT |
| 59 | +select |
| 60 | + arrow_typeof(int8 - int8), |
| 61 | + arrow_typeof(int16 - int16), |
| 62 | + arrow_typeof(int32 - int32), |
| 63 | + arrow_typeof(int64 - int64), |
| 64 | + arrow_typeof(uint8 - uint8), |
| 65 | + arrow_typeof(uint16 - uint16), |
| 66 | + arrow_typeof(uint32 - uint32), |
| 67 | + arrow_typeof(uint64 - uint64), |
| 68 | + arrow_typeof(float32 - float32), |
| 69 | + arrow_typeof(float64 - float64), |
| 70 | + arrow_typeof(decimal - decimal) |
| 71 | +from numeric_types; |
| 72 | +---- |
| 73 | +Int8 Int16 Int32 Int64 UInt8 UInt16 UInt32 UInt64 Float32 Float64 Decimal128(6, 2) |
| 74 | + |
| 75 | +# Multiply with the same operand type, expect the same output type |
| 76 | +# except for decimal which is promoted to the highest precision |
| 77 | +query TTTTTTTTTTT |
| 78 | +select |
| 79 | + arrow_typeof(int8 * int8), |
| 80 | + arrow_typeof(int16 * int16), |
| 81 | + arrow_typeof(int32 * int32), |
| 82 | + arrow_typeof(int64 * int64), |
| 83 | + arrow_typeof(uint8 * uint8), |
| 84 | + arrow_typeof(uint16 * uint16), |
| 85 | + arrow_typeof(uint32 * uint32), |
| 86 | + arrow_typeof(uint64 * uint64), |
| 87 | + arrow_typeof(float32 * float32), |
| 88 | + arrow_typeof(float64 * float64), |
| 89 | + arrow_typeof(decimal * decimal) |
| 90 | +from numeric_types; |
| 91 | +---- |
| 92 | +Int8 Int16 Int32 Int64 UInt8 UInt16 UInt32 UInt64 Float32 Float64 Decimal128(11, 4) |
| 93 | + |
| 94 | +# Divide with the same operand type, expect the same output type |
| 95 | +# except for decimal which is promoted to the highest precision |
| 96 | +query TTTTTTTTTTT |
| 97 | +select |
| 98 | + arrow_typeof(int8 / int8), |
| 99 | + arrow_typeof(int16 / int16), |
| 100 | + arrow_typeof(int32 / int32), |
| 101 | + arrow_typeof(int64 / int64), |
| 102 | + arrow_typeof(uint8 / uint8), |
| 103 | + arrow_typeof(uint16 / uint16), |
| 104 | + arrow_typeof(uint32 / uint32), |
| 105 | + arrow_typeof(uint64 / uint64), |
| 106 | + arrow_typeof(float32 / float32), |
| 107 | + arrow_typeof(float64 / float64), |
| 108 | + arrow_typeof(decimal / decimal) |
| 109 | +from numeric_types; |
| 110 | +---- |
| 111 | +Int8 Int16 Int32 Int64 UInt8 UInt16 UInt32 UInt64 Float32 Float64 Decimal128(11, 6) |
| 112 | + |
| 113 | +statement ok |
| 114 | +drop table numeric_types |
0 commit comments