Skip to content

Commit 36ecac2

Browse files
committed
Consolidate and expand ident normalization tests
1 parent 0edc3d9 commit 36ecac2

File tree

3 files changed

+134
-62
lines changed

3 files changed

+134
-62
lines changed

datafusion/sqllogictest/test_files/ddl.slt

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -633,50 +633,6 @@ select * from table_without_values;
633633
----
634634
10 20
635635

636-
# Enable information_schema, so we can execute show create table
637-
statement ok
638-
set datafusion.catalog.information_schema = true;
639-
640-
statement ok
641-
CREATE OR REPLACE TABLE TABLE_WITH_NORMALIZATION(FIELD1 BIGINT, FIELD2 BIGINT);
642-
643-
# Check table name is in lowercase
644-
query TTTT
645-
show create table table_with_normalization
646-
----
647-
datafusion public table_with_normalization NULL
648-
649-
# Check column name is in uppercase
650-
query TTT
651-
describe table_with_normalization
652-
----
653-
field1 Int64 YES
654-
field2 Int64 YES
655-
656-
# Disable ident normalization
657-
statement ok
658-
set datafusion.sql_parser.enable_ident_normalization = false;
659-
660-
statement ok
661-
CREATE TABLE TABLE_WITHOUT_NORMALIZATION(FIELD1 BIGINT, FIELD2 BIGINT) AS VALUES (1,2);
662-
663-
# Check table name is in uppercase
664-
query TTTT
665-
show create table TABLE_WITHOUT_NORMALIZATION
666-
----
667-
datafusion public TABLE_WITHOUT_NORMALIZATION NULL
668-
669-
# Check column name is in uppercase
670-
query TTT
671-
describe TABLE_WITHOUT_NORMALIZATION
672-
----
673-
FIELD1 Int64 YES
674-
FIELD2 Int64 YES
675-
676-
statement ok
677-
set datafusion.sql_parser.enable_ident_normalization = true;
678-
679-
680636
statement ok
681637
create table foo(x int);
682638

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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

datafusion/sqllogictest/test_files/scalar.slt

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,24 +1802,6 @@ SELECT acos();
18021802
statement error
18031803
SELECT isnan();
18041804

1805-
# turn off enable_ident_normalization
1806-
statement ok
1807-
set datafusion.sql_parser.enable_ident_normalization = false;
1808-
1809-
query I
1810-
SELECT LENGTH('str');
1811-
----
1812-
3
1813-
1814-
query T
1815-
SELECT CONCAT('Hello', 'World')
1816-
----
1817-
HelloWorld
1818-
1819-
# turn on enable_ident_normalization
1820-
statement ok
1821-
set datafusion.sql_parser.enable_ident_normalization = true;
1822-
18231805
query I
18241806
SELECT LENGTH('str');
18251807
----

0 commit comments

Comments
 (0)