Skip to content

Commit 82e4ea2

Browse files
committed
fix test_unit
1 parent c64c20b commit 82e4ea2

File tree

9 files changed

+159
-39
lines changed

9 files changed

+159
-39
lines changed

src/query/ast/src/ast/statements/columns.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ impl Display for ShowColumnsStmt {
3333
if self.full {
3434
write!(f, " FULL")?;
3535
}
36-
write!(f, " COLUMNS FROM")?;
36+
write!(f, " COLUMNS FROM {}", self.table)?;
3737

3838
if let Some(database) = &self.database {
39+
write!(f, " FROM ")?;
3940
if let Some(catalog) = &self.catalog {
4041
write!(f, "{catalog}.",)?;
4142
}
42-
write!(f, "{database}.",)?;
43+
write!(f, "{database}")?;
4344
}
4445

45-
write!(f, " {}", self.table)?;
4646
if let Some(limit) = &self.limit {
4747
write!(f, " {limit}")?;
4848
}

src/query/ast/src/parser/statement.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,14 @@ pub fn statement(i: Input) -> IResult<StatementMsg> {
399399
);
400400
let show_columns = map(
401401
rule! {
402-
SHOW ~ FULL? ~ COLUMNS ~ ( FROM | IN ) ~ #period_separated_idents_1_to_3 ~ #show_limit?
402+
SHOW ~ FULL? ~ COLUMNS ~ ( FROM | IN ) ~ #ident ~ ((FROM | IN) ~ #period_separated_idents_1_to_2)? ~ #show_limit?
403403
},
404-
|(_, opt_full, _, _, (catalog, database, table), limit)| {
404+
|(_, opt_full, _, _, table, ctl_db, limit)| {
405+
let (catalog, database) = match ctl_db {
406+
Some((_, (Some(c), d))) => (Some(c), Some(d)),
407+
Some((_, (None, d))) => (None, Some(d)),
408+
_ => (None, None),
409+
};
405410
Statement::ShowColumns(ShowColumnsStmt {
406411
catalog,
407412
database,
@@ -1108,7 +1113,7 @@ pub fn statement(i: Input) -> IResult<StatementMsg> {
11081113
),
11091114
rule!(
11101115
#show_tables : "`SHOW [FULL] TABLES [FROM <database>] [<show_limit>]`"
1111-
| #show_columns : "`SHOW [FULL] COLUMNS FROM [[<database>.]<table>] [<show_limit>]`"
1116+
| #show_columns : "`SHOW [FULL] COLUMNS FROM <table> [FROM|IN <catalog>.<database>] [<show_limit>]`"
11121117
| #show_create_table : "`SHOW CREATE TABLE [<database>.]<table>`"
11131118
| #describe_table : "`DESCRIBE [<database>.]<table>`"
11141119
| #show_fields : "`SHOW FIELDS FROM [<database>.]<table>`"

src/query/ast/tests/it/parser.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ fn test_statement() {
7070
r#"show full tables"#,
7171
r#"show full tables from db"#,
7272
r#"show full tables from ctl.db"#,
73+
r#"show full columns in t in db"#,
74+
r#"show columns in t from ctl.db"#,
75+
r#"show full columns from t from db like 'id%'"#,
7376
r#"show processlist;"#,
7477
r#"show create table a.b;"#,
7578
r#"show create table a.b format TabSeparatedWithNamesAndTypes;"#,

src/query/ast/tests/it/testdata/statement-error.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ error:
275275
--> SQL:1:6
276276
|
277277
1 | SHOW GRANT FOR ROLE role1;
278-
| ^^^^^ expected `SETTINGS`, `STAGES`, `ENGINES`, `PROCESSLIST`, `METRICS`, `FUNCTIONS`, or 14 more ...
278+
| ^^^^^ expected `SETTINGS`, `STAGES`, `ENGINES`, `PROCESSLIST`, `METRICS`, `FUNCTIONS`, or 15 more ...
279279

280280

281281
---------- Input ----------

src/query/ast/tests/it/testdata/statement.txt

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,108 @@ ShowTables(
138138
)
139139

140140

141+
---------- Input ----------
142+
show full columns in t in db
143+
---------- Output ---------
144+
SHOW FULL COLUMNS FROM t FROM db
145+
---------- AST ------------
146+
ShowColumns(
147+
ShowColumnsStmt {
148+
catalog: None,
149+
database: Some(
150+
Identifier {
151+
name: "db",
152+
quote: None,
153+
span: Some(
154+
26..28,
155+
),
156+
},
157+
),
158+
table: Identifier {
159+
name: "t",
160+
quote: None,
161+
span: Some(
162+
21..22,
163+
),
164+
},
165+
full: true,
166+
limit: None,
167+
},
168+
)
169+
170+
171+
---------- Input ----------
172+
show columns in t from ctl.db
173+
---------- Output ---------
174+
SHOW COLUMNS FROM t FROM ctl.db
175+
---------- AST ------------
176+
ShowColumns(
177+
ShowColumnsStmt {
178+
catalog: Some(
179+
Identifier {
180+
name: "ctl",
181+
quote: None,
182+
span: Some(
183+
23..26,
184+
),
185+
},
186+
),
187+
database: Some(
188+
Identifier {
189+
name: "db",
190+
quote: None,
191+
span: Some(
192+
27..29,
193+
),
194+
},
195+
),
196+
table: Identifier {
197+
name: "t",
198+
quote: None,
199+
span: Some(
200+
16..17,
201+
),
202+
},
203+
full: false,
204+
limit: None,
205+
},
206+
)
207+
208+
209+
---------- Input ----------
210+
show full columns from t from db like 'id%'
211+
---------- Output ---------
212+
SHOW FULL COLUMNS FROM t FROM db LIKE 'id%'
213+
---------- AST ------------
214+
ShowColumns(
215+
ShowColumnsStmt {
216+
catalog: None,
217+
database: Some(
218+
Identifier {
219+
name: "db",
220+
quote: None,
221+
span: Some(
222+
30..32,
223+
),
224+
},
225+
),
226+
table: Identifier {
227+
name: "t",
228+
quote: None,
229+
span: Some(
230+
23..24,
231+
),
232+
},
233+
full: true,
234+
limit: Some(
235+
Like {
236+
pattern: "id%",
237+
},
238+
),
239+
},
240+
)
241+
242+
141243
---------- Input ----------
142244
show processlist;
143245
---------- Output ---------

src/query/sql/src/planner/binder/ddl/column.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,33 +66,36 @@ impl Binder {
6666
table
6767
};
6868

69-
let mut select_builder = SelectBuilder::from("system.columns");
69+
let mut select_builder = SelectBuilder::from("information_schema.columns");
7070

7171
select_builder
72-
.with_column("name AS Field")
73-
.with_column("type AS Type")
72+
.with_column("column_name AS `Field`")
73+
.with_column("column_type AS `Type`")
7474
.with_column("is_nullable AS `Null`")
75-
.with_column("data_type AS Data_Type")
76-
.with_column("default_kind AS Default_Kind")
77-
.with_column("default_expression AS Default_Expression");
75+
.with_column("default AS `Default`")
76+
.with_column("extra AS `Extra`")
77+
.with_column("column_key AS `Key`");
7878

7979
if *full {
80-
select_builder.with_column("comment AS Comment");
80+
select_builder
81+
.with_column("collation_name AS `Collation`")
82+
.with_column("privileges AS `Privileges`")
83+
.with_column("column_comment AS Comment");
8184
}
8285

8386
select_builder
84-
.with_order_by("database")
85-
.with_order_by("table")
86-
.with_order_by("name");
87+
.with_order_by("table_schema")
88+
.with_order_by("table_name")
89+
.with_order_by("column_name");
8790

8891
select_builder
89-
.with_filter(format!("database = '{database}'"))
90-
.with_filter(format!("table = '{table}'"));
92+
.with_filter(format!("table_schema = '{database}'"))
93+
.with_filter(format!("table_name = '{table}'"));
9194

9295
let query = match limit {
9396
None => select_builder.build(),
9497
Some(ShowLimit::Like { pattern }) => {
95-
select_builder.with_filter(format!("name LIKE '{pattern}'"));
98+
select_builder.with_filter(format!("column_name LIKE '{pattern}'"));
9699
select_builder.build()
97100
}
98101
Some(ShowLimit::Where { selection }) => {

src/query/storages/information-schema/src/columns_table.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl ColumnsTable {
3939
when is_nullable='YES' then 1
4040
end as nullable,
4141
is_nullable AS is_nullable,
42-
data_type AS data_type,
42+
type AS data_type,
4343
data_type AS column_type,
4444
NULL AS character_maximum_length,
4545
NULL AS character_octet_length,
@@ -56,6 +56,8 @@ impl ColumnsTable {
5656
NULL AS domain_catalog,
5757
NULL AS domain_schema,
5858
NULL AS domain_name,
59+
NULL AS privileges,
60+
default_expression as default,
5961
NULL AS extra
6062
FROM system.columns;";
6163

tests/sqllogictests/suites/base/06_show/06_0015_show_columns

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,45 @@ statement ok
1111
CREATE TABLE showcolumn.t2(c1 int) ENGINE = Null
1212

1313
statement ok
14-
CREATE TABLE showcolumn.t3(c1 int null default null, c2 Datetime, c3 String Default 'c3') ENGINE = Null;
14+
CREATE TABLE showcolumn.t3(c1 int null default 4, c2 Datetime default '2022-02-02 12:00:00', c3 String Default 'c3') ENGINE = Null;
1515

1616
query TTTTTT
17-
SHOW COLUMNS FROM showcolumn.t3
17+
SHOW COLUMNS FROM t3 FROM showcolumn
1818
----
19-
c1 Nullable(Int32) YES INT DEFAULT NULL
20-
c2 Timestamp NO TIMESTAMP (empty) (empty)
21-
c3 String NO VARCHAR DEFAULT 'c3'
19+
c1 INT YES 4 NULL NULL
20+
c2 TIMESTAMP NO '2022-02-02 12:00:00' NULL NULL
21+
c3 VARCHAR NO 'c3' NULL NULL
2222

2323
statement ok
2424
use showcolumn
2525

2626
query TTTTTTT
2727
SHOW FULL COLUMNS IN t3
2828
----
29-
c1 Nullable(Int32) YES INT DEFAULT NULL (empty)
30-
c2 Timestamp NO TIMESTAMP (empty) (empty) (empty)
31-
c3 String NO VARCHAR DEFAULT 'c3' (empty)
29+
c1 INT YES 4 NULL NULL NULL NULL NULL
30+
c2 TIMESTAMP NO '2022-02-02 12:00:00' NULL NULL NULL NULL NULL
31+
c3 VARCHAR NO 'c3' NULL NULL NULL NULL NULL
3232

3333
query T
3434
explain show full columns in t3
3535
----
3636
Sort
3737
├── sort keys: [database ASC NULLS LAST, table ASC NULLS LAST, name ASC NULLS LAST]
3838
├── estimated rows: 0.00
39-
└── Filter
40-
├── filters: [columns.database (#1) = "showcolumn", columns.table (#2) = "t3"]
39+
└── EvalScalar
40+
├── expressions: [NULL, NULL, NULL, NULL, NULL]
4141
├── estimated rows: 0.00
42-
└── TableScan
43-
├── table: default.system.columns
44-
├── read rows: 0
45-
├── read bytes: 0
46-
├── partitions total: 0
47-
├── partitions scanned: 0
48-
├── push downs: [filters: [columns.database (#1) = "showcolumn" AND columns.table (#2) = "t3"], limit: NONE]
49-
└── estimated rows: 0.00
42+
└── Filter
43+
├── filters: [columns.table_schema (#1) = "showcolumn", columns.table_name (#2) = "t3"]
44+
├── estimated rows: 0.00
45+
└── TableScan
46+
├── table: default.system.columns
47+
├── read rows: 0
48+
├── read bytes: 0
49+
├── partitions total: 0
50+
├── partitions scanned: 0
51+
├── push downs: [filters: [columns.table_schema (#1) = "showcolumn" AND columns.table_name (#2) = "t3"], limit: NONE]
52+
└── estimated rows: 0.00
5053

5154
statement ok
5255
DROP DATABASE showcolumn

tests/sqllogictests/suites/base/20+_others/20_0000_describe_table

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ collation_name NULL NO NULL (empty)
8181
domain_catalog NULL NO NULL (empty)
8282
domain_schema NULL NO NULL (empty)
8383
domain_name NULL NO NULL (empty)
84+
privileges NULL NO NULL (empty)
85+
default VARCHAR NO "" (empty)
8486
extra NULL NO NULL (empty)
8587

8688
query TTT

0 commit comments

Comments
 (0)