|
| 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 | +# Enable information_schema, so we can execute show create table |
| 19 | +statement ok |
| 20 | +set datafusion.catalog.information_schema = true; |
| 21 | + |
| 22 | +# Check ident normalization is enabled by default |
| 23 | + |
| 24 | +statement ok |
| 25 | +CREATE OR REPLACE TABLE TABLE_WITH_NORMALIZATION(FIELD1 BIGINT, FIELD2 BIGINT); |
| 26 | + |
| 27 | +# Check table name is in lowercase |
| 28 | +query TTTT |
| 29 | +show create table table_with_normalization |
| 30 | +---- |
| 31 | +datafusion public table_with_normalization NULL |
| 32 | + |
| 33 | +# Check column name is in uppercase |
| 34 | +query TTT |
| 35 | +describe table_with_normalization |
| 36 | +---- |
| 37 | +field1 Int64 YES |
| 38 | +field2 Int64 YES |
| 39 | + |
| 40 | +# Disable ident normalization |
| 41 | +statement ok |
| 42 | +set datafusion.sql_parser.enable_ident_normalization = false; |
| 43 | + |
| 44 | +statement ok |
| 45 | +CREATE TABLE TABLE_WITHOUT_NORMALIZATION(FIELD1 BIGINT, FIELD2 BIGINT) AS VALUES (1,2); |
| 46 | + |
| 47 | +# Check table name is in uppercase |
| 48 | +query TTTT |
| 49 | +show create table TABLE_WITHOUT_NORMALIZATION |
| 50 | +---- |
| 51 | +datafusion public TABLE_WITHOUT_NORMALIZATION NULL |
| 52 | + |
| 53 | +# Check column name is in uppercase |
| 54 | +query TTT |
| 55 | +describe TABLE_WITHOUT_NORMALIZATION |
| 56 | +---- |
| 57 | +FIELD1 Int64 YES |
| 58 | +FIELD2 Int64 YES |
| 59 | + |
| 60 | +statement ok |
| 61 | +DROP TABLE TABLE_WITHOUT_NORMALIZATION |
| 62 | + |
| 63 | +############ |
| 64 | +## Column Name Normalization |
| 65 | +############ |
| 66 | + |
| 67 | +# Table x (lowercase) with a column named "A" (uppercase) |
| 68 | +statement ok |
| 69 | +create table x as select 1 "A" |
| 70 | + |
| 71 | +query TTT |
| 72 | +describe x |
| 73 | +---- |
| 74 | +A Int64 NO |
| 75 | + |
| 76 | +# Expect error as 'a' is not a column -- "A" is and the identifiers |
| 77 | +# are not normalized |
| 78 | +query error DataFusion error: Schema error: No field named a\. Valid fields are x\."A"\. |
| 79 | +select a from x; |
| 80 | + |
| 81 | +# should work (note the uppercase 'A') |
| 82 | +query I |
| 83 | +select A from x; |
| 84 | +---- |
| 85 | +1 |
| 86 | + |
| 87 | +statement ok |
| 88 | +drop table x; |
| 89 | + |
| 90 | +############ |
| 91 | +## Table Name Normalization |
| 92 | +############ |
| 93 | + |
| 94 | +# Table Y (uppercase) with a column named a (lower case) |
| 95 | +statement ok |
| 96 | +create table Y as select 1 a; |
| 97 | + |
| 98 | +query TTT |
| 99 | +describe Y |
| 100 | +---- |
| 101 | +a Int64 NO |
| 102 | + |
| 103 | +# Expect error as y is not a a table -- "Y" is |
| 104 | +query error DataFusion error: Error during planning: table 'datafusion\.public\.y' not found |
| 105 | +select * from y; |
| 106 | + |
| 107 | +# should work (note the uppercase 'Y') |
| 108 | +query I |
| 109 | +select * from Y; |
| 110 | +---- |
| 111 | +1 |
| 112 | + |
| 113 | +statement ok |
| 114 | +drop table Y; |
| 115 | + |
| 116 | +############ |
| 117 | +## Function Name Normalization |
| 118 | +############ |
| 119 | + |
| 120 | +## Check function names are still normalized even though column names are not |
| 121 | +query I |
| 122 | +SELECT length('str'); |
| 123 | +---- |
| 124 | +3 |
| 125 | + |
| 126 | +query I |
| 127 | +SELECT LENGTH('str'); |
| 128 | +---- |
| 129 | +3 |
| 130 | + |
| 131 | +query T |
| 132 | +SELECT CONCAT('Hello', 'World') |
| 133 | +---- |
| 134 | +HelloWorld |
0 commit comments