|
| 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 | +// Regression test for: length() / char_length() on dict-encoded (low-cardinality) |
| 19 | +// varchar columns must not throw NOT_IMPLEMENTED_ERROR when the "only_read_offsets" |
| 20 | +// optimisation is active (i.e. when the storage layer resolves dict codes to string |
| 21 | +// lengths without materialising actual character data). |
| 22 | +suite("test_length_dict_encoded") { |
| 23 | + sql "DROP TABLE IF EXISTS test_length_dict_varchar" |
| 24 | + sql """ |
| 25 | + CREATE TABLE test_length_dict_varchar ( |
| 26 | + col_int_undef_signed int NULL, |
| 27 | + col_int_undef_signed_not_null int NOT NULL, |
| 28 | + col_date_undef_signed date NULL, |
| 29 | + col_date_undef_signed_not_null date NOT NULL, |
| 30 | + col_varchar_5__undef_signed varchar(5) NULL, |
| 31 | + col_varchar_5__undef_signed_not_null varchar(5) NOT NULL, |
| 32 | + pk int NULL |
| 33 | + ) ENGINE=OLAP |
| 34 | + DUPLICATE KEY(col_int_undef_signed) |
| 35 | + PARTITION BY RANGE(col_int_undef_signed) ( |
| 36 | + PARTITION p0 VALUES [('-2147483648'), ('4')), |
| 37 | + PARTITION p1 VALUES [('4'), ('6')), |
| 38 | + PARTITION p2 VALUES [('6'), ('7')), |
| 39 | + PARTITION p3 VALUES [('7'), ('8')), |
| 40 | + PARTITION p4 VALUES [('8'), ('10')), |
| 41 | + PARTITION p5 VALUES [('10'), ('83647')), |
| 42 | + PARTITION p100 VALUES [('83647'), ('2147483647')) |
| 43 | + ) |
| 44 | + DISTRIBUTED BY HASH(pk) BUCKETS 10 |
| 45 | + PROPERTIES ('replication_allocation' = 'tag.location.default: 1') |
| 46 | + """ |
| 47 | + |
| 48 | + sql """ |
| 49 | + INSERT INTO test_length_dict_varchar VALUES |
| 50 | + (6, 5, '2023-12-13', '2023-12-11', 'o', 'i', 30), |
| 51 | + (6, 6, NULL, '2023-12-18', 'w', 'l', 24), |
| 52 | + (8, -8278102, '2023-12-13', '2023-12-11', 'x', 'c', 28), |
| 53 | + (15971, 8, NULL, '2015-06-11', 'h', 'r', 41), |
| 54 | + (6, 5, '2023-12-11', '2023-12-17', 'd', 'q', 5), |
| 55 | + (7, 100, '2023-12-14', '2023-12-15', NULL, 'a', 50), |
| 56 | + (7, 101, '2023-12-15', '2023-12-16', NULL, 'b', 51), |
| 57 | + (9, 200, NULL, '2023-12-17', 'ab', 'd', 60) |
| 58 | + """ |
| 59 | + |
| 60 | + // length() on nullable dict-encoded varchar filtered by IS NOT NULL predicate |
| 61 | + order_qt_length_nullable_not_null """ |
| 62 | + SELECT length(col_varchar_5__undef_signed) |
| 63 | + FROM test_length_dict_varchar |
| 64 | + WHERE col_varchar_5__undef_signed IS NOT NULL |
| 65 | + """ |
| 66 | + |
| 67 | + // length() on NOT NULL dict-encoded varchar (no predicate needed) |
| 68 | + order_qt_length_not_null_col """ |
| 69 | + SELECT length(col_varchar_5__undef_signed_not_null) |
| 70 | + FROM test_length_dict_varchar |
| 71 | + """ |
| 72 | + |
| 73 | + // length() returns NULL for NULL varchar values |
| 74 | + order_qt_length_with_nulls """ |
| 75 | + SELECT length(col_varchar_5__undef_signed), pk |
| 76 | + FROM test_length_dict_varchar |
| 77 | + ORDER BY pk |
| 78 | + """ |
| 79 | + |
| 80 | + // char_length() is a synonym and must work as well |
| 81 | + order_qt_char_length_nullable_not_null """ |
| 82 | + SELECT char_length(col_varchar_5__undef_signed) |
| 83 | + FROM test_length_dict_varchar |
| 84 | + WHERE col_varchar_5__undef_signed IS NOT NULL |
| 85 | + """ |
| 86 | + |
| 87 | + // length() returns NULL for NULL values — verify NULL passthrough |
| 88 | + order_qt_length_nullable_is_null """ |
| 89 | + SELECT length(col_varchar_5__undef_signed) |
| 90 | + FROM test_length_dict_varchar |
| 91 | + WHERE col_varchar_5__undef_signed IS NULL |
| 92 | + """ |
| 93 | + |
| 94 | + // char_length() on all rows including NULLs — verify dict code path with mixed null/non-null |
| 95 | + order_qt_char_length_all_rows """ |
| 96 | + SELECT char_length(col_varchar_5__undef_signed), pk |
| 97 | + FROM test_length_dict_varchar |
| 98 | + ORDER BY pk |
| 99 | + """ |
| 100 | + |
| 101 | + // char_length() on NULL-only rows |
| 102 | + order_qt_char_length_nullable_is_null """ |
| 103 | + SELECT char_length(col_varchar_5__undef_signed) |
| 104 | + FROM test_length_dict_varchar |
| 105 | + WHERE col_varchar_5__undef_signed IS NULL |
| 106 | + """ |
| 107 | +} |
0 commit comments