|
| 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_substring_index(s string, delim string, cnt int) USING parquet |
| 22 | + |
| 23 | +statement |
| 24 | +INSERT INTO test_substring_index VALUES |
| 25 | + ('www.apache.org', '.', 1), |
| 26 | + ('www.apache.org', '.', 2), |
| 27 | + ('www.apache.org', '.', 3), |
| 28 | + ('www.apache.org', '.', -1), |
| 29 | + ('www.apache.org', '.', -2), |
| 30 | + ('www.apache.org', '.', -3), |
| 31 | + ('www.apache.org', '.', 0), |
| 32 | + ('hello', '.', 1), |
| 33 | + ('', '.', 1), |
| 34 | + ('www.apache.org', '', 1), |
| 35 | + (NULL, '.', 1), |
| 36 | + ('www.apache.org', NULL, 1), |
| 37 | + ('www.apache.org', '.', NULL) |
| 38 | + |
| 39 | +-- all columns |
| 40 | +query |
| 41 | +SELECT substring_index(s, delim, cnt) FROM test_substring_index |
| 42 | + |
| 43 | +-- literal arguments |
| 44 | +query |
| 45 | +SELECT substring_index('www.apache.org', '.', 1), |
| 46 | + substring_index('www.apache.org', '.', 2), |
| 47 | + substring_index('www.apache.org', '.', -1), |
| 48 | + substring_index('www.apache.org', '.', -2), |
| 49 | + substring_index('www.apache.org', '.', 0) |
| 50 | + |
| 51 | +-- NULL literal arguments |
| 52 | +query |
| 53 | +SELECT substring_index(NULL, '.', 1), |
| 54 | + substring_index('www.apache.org', NULL, 1), |
| 55 | + substring_index('www.apache.org', '.', NULL) |
| 56 | + |
| 57 | +-- column string, literal delimiter and count |
| 58 | +query |
| 59 | +SELECT substring_index(s, '.', 1) FROM test_substring_index |
| 60 | + |
| 61 | +-- literal string, column delimiter and count |
| 62 | +query |
| 63 | +SELECT substring_index('www.apache.org', delim, cnt) FROM test_substring_index |
| 64 | + |
| 65 | +-- count exceeds number of delimiters (returns full string) |
| 66 | +query |
| 67 | +SELECT substring_index('www.apache.org', '.', 10), |
| 68 | + substring_index('www.apache.org', '.', -10) |
| 69 | + |
| 70 | +-- multi-character delimiter |
| 71 | +query |
| 72 | +SELECT substring_index('one::two::three', '::', 1), |
| 73 | + substring_index('one::two::three', '::', 2), |
| 74 | + substring_index('one::two::three', '::', -1), |
| 75 | + substring_index('one::two::three', '::', -2) |
| 76 | + |
| 77 | +-- delimiter not found |
| 78 | +query |
| 79 | +SELECT substring_index('hello world', 'xyz', 1), |
| 80 | + substring_index('hello world', 'xyz', -1) |
| 81 | + |
| 82 | +-- empty string input |
| 83 | +query |
| 84 | +SELECT substring_index('', '.', 1), |
| 85 | + substring_index('', '.', -1) |
| 86 | + |
| 87 | +-- empty delimiter |
| 88 | +query |
| 89 | +SELECT substring_index('www.apache.org', '', 1), |
| 90 | + substring_index('www.apache.org', '', -1) |
| 91 | + |
| 92 | +-- multibyte UTF-8 characters |
| 93 | +query |
| 94 | +SELECT substring_index('a.b.c', '.', 2), |
| 95 | + substring_index('中文.测试.数据', '.', 1), |
| 96 | + substring_index('中文.测试.数据', '.', -1), |
| 97 | + substring_index('中文.测试.数据', '.', 2) |
| 98 | + |
| 99 | +-- delimiter at start of string |
| 100 | +query |
| 101 | +SELECT substring_index('.www.apache.org', '.', 1), |
| 102 | + substring_index('.www.apache.org', '.', 2), |
| 103 | + substring_index('.www.apache.org', '.', -1) |
| 104 | + |
| 105 | +-- delimiter at end of string |
| 106 | +query |
| 107 | +SELECT substring_index('www.apache.org.', '.', -1), |
| 108 | + substring_index('www.apache.org.', '.', 3), |
| 109 | + substring_index('www.apache.org.', '.', -2) |
| 110 | + |
| 111 | +-- delimiter equals the full string |
| 112 | +query |
| 113 | +SELECT substring_index('abc', 'abc', 1), |
| 114 | + substring_index('abc', 'abc', -1) |
| 115 | + |
| 116 | +-- large count values |
| 117 | +query |
| 118 | +SELECT substring_index('www.apache.org', '.', 2147483647), |
| 119 | + substring_index('www.apache.org', '.', -2147483647) |
0 commit comments