Skip to content

Commit a996790

Browse files
authored
Support Hive SHOW VIEWS & SHOW MATERIALIZED VIEWS & SHOW PARTITIONS statement parse (#36263)
* support show statement * Update DALStatement.g4 * update release-notes
1 parent bf39b7d commit a996790

File tree

9 files changed

+199
-1
lines changed

9 files changed

+199
-1
lines changed

RELEASE-NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
1. SQL Parser: Support Hive DROP FUNCTION statement parse - [#36196](https://github.com/apache/shardingsphere/pull/36196)
7676
1. SQL Parser: Support Hive RELOAD FUNCTION statement parse - [#36200](https://github.com/apache/shardingsphere/pull/36200)
7777
1. SQL Parser: Support Hive SHOW DATABASES & SHOW CONNECTORS & SHOW TABLES statement parse - [#36221](https://github.com/apache/shardingsphere/pull/36221)
78+
1. SQL Parser: Support Hive SHOW VIEWS & SHOW MATERIALIZED VIEWS & SHOW PARTITIONS statement parse - [#36263](https://github.com/apache/shardingsphere/pull/36263)
7879
1. SQL Parser: Support SQL Server xml methods parse - [#35911](https://github.com/apache/shardingsphere/pull/35911)
7980
1. SQL Parser: Support SQL Server CHANGETABLE function parse - [#35920](https://github.com/apache/shardingsphere/pull/35920)
8081
1. SQL Parser: Support SQL Server AI_GENERATE_EMBEDDINGS function parse - [#35922](https://github.com/apache/shardingsphere/pull/35922)

parser/sql/dialect/hive/src/main/antlr4/imports/hive/DALStatement.g4

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717

1818
grammar DALStatement;
1919

20-
import BaseRule;
20+
import BaseRule, DMLStatement;
2121

2222
show
2323
: showDatabases
2424
| showConnectors
2525
| showTables
26+
| showViews
27+
| showMaterializedViews
28+
| showPartitions
2629
;
2730

2831
showDatabases
@@ -37,6 +40,22 @@ showTables
3740
: SHOW TABLES (IN databaseName)? stringLiterals?
3841
;
3942

43+
showViews
44+
: SHOW VIEWS showFrom? showLike?
45+
;
46+
47+
showMaterializedViews
48+
: SHOW MATERIALIZED VIEWS showFrom? showLike?
49+
;
50+
51+
showPartitions
52+
: SHOW PARTITIONS tableName partitionSpec? whereClause? orderByClause? limitClause?
53+
;
54+
55+
showFrom
56+
: (IN | FROM) databaseName
57+
;
58+
4059
showLike
4160
: LIKE stringLiterals
4261
;

parser/sql/dialect/hive/src/main/antlr4/imports/hive/HiveKeyword.g4

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,6 +2947,10 @@ VIEW
29472947
: V I E W
29482948
;
29492949

2950+
VIEWS
2951+
: V I E W S
2952+
;
2953+
29502954
VIRTUAL
29512955
: V I R T U A L
29522956
;

parser/sql/dialect/hive/src/main/java/org/apache/shardingsphere/sql/parser/hive/visitor/statement/type/HiveDALStatementVisitor.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.ShowLikeContext;
2626
import org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.ShowConnectorsContext;
2727
import org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.ShowTablesContext;
28+
import org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.ShowViewsContext;
29+
import org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.ShowMaterializedViewsContext;
30+
import org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.ShowPartitionsContext;
2831
import org.apache.shardingsphere.sql.parser.hive.visitor.statement.HiveStatementVisitor;
2932
import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.FromDatabaseSegment;
3033
import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ShowFilterSegment;
@@ -33,6 +36,9 @@
3336
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
3437
import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.StringLiteralValue;
3538
import org.apache.shardingsphere.sql.parser.statement.hive.dal.show.HiveShowConnectorsStatement;
39+
import org.apache.shardingsphere.sql.parser.statement.hive.dal.show.HiveShowMaterializedViewsStatement;
40+
import org.apache.shardingsphere.sql.parser.statement.hive.dal.show.HiveShowPartitionsStatement;
41+
import org.apache.shardingsphere.sql.parser.statement.hive.dal.show.HiveShowViewsStatement;
3642
import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLUseStatement;
3743
import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.database.MySQLShowDatabasesStatement;
3844
import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.table.MySQLShowTablesStatement;
@@ -93,4 +99,19 @@ public ASTNode visitShowTables(final ShowTablesContext ctx) {
9399
result.addParameterMarkers(getParameterMarkerSegments());
94100
return result;
95101
}
102+
103+
@Override
104+
public ASTNode visitShowViews(final ShowViewsContext ctx) {
105+
return new HiveShowViewsStatement(getDatabaseType());
106+
}
107+
108+
@Override
109+
public ASTNode visitShowMaterializedViews(final ShowMaterializedViewsContext ctx) {
110+
return new HiveShowMaterializedViewsStatement(getDatabaseType());
111+
}
112+
113+
@Override
114+
public ASTNode visitShowPartitions(final ShowPartitionsContext ctx) {
115+
return new HiveShowPartitionsStatement(getDatabaseType());
116+
}
96117
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* 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, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.shardingsphere.sql.parser.statement.hive.dal.show;
19+
20+
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
21+
import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.SQLStatementAttributes;
22+
import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.TablelessDataSourceBroadcastRouteSQLStatementAttribute;
23+
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.DALStatement;
24+
25+
/**
26+
* Show materialized views statement for Hive.
27+
*/
28+
public final class HiveShowMaterializedViewsStatement extends DALStatement {
29+
30+
public HiveShowMaterializedViewsStatement(final DatabaseType databaseType) {
31+
super(databaseType);
32+
}
33+
34+
@Override
35+
public SQLStatementAttributes getAttributes() {
36+
return new SQLStatementAttributes(new TablelessDataSourceBroadcastRouteSQLStatementAttribute());
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* 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, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.shardingsphere.sql.parser.statement.hive.dal.show;
19+
20+
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
21+
import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.SQLStatementAttributes;
22+
import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.TablelessDataSourceBroadcastRouteSQLStatementAttribute;
23+
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.DALStatement;
24+
25+
/**
26+
* Show partitions statement for Hive.
27+
*/
28+
public final class HiveShowPartitionsStatement extends DALStatement {
29+
30+
public HiveShowPartitionsStatement(final DatabaseType databaseType) {
31+
super(databaseType);
32+
}
33+
34+
@Override
35+
public SQLStatementAttributes getAttributes() {
36+
return new SQLStatementAttributes(new TablelessDataSourceBroadcastRouteSQLStatementAttribute());
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* 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, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.shardingsphere.sql.parser.statement.hive.dal.show;
19+
20+
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
21+
import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.SQLStatementAttributes;
22+
import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.TablelessDataSourceBroadcastRouteSQLStatementAttribute;
23+
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.DALStatement;
24+
25+
/**
26+
* Show views statement for Hive.
27+
*/
28+
public final class HiveShowViewsStatement extends DALStatement {
29+
30+
public HiveShowViewsStatement(final DatabaseType databaseType) {
31+
super(databaseType);
32+
}
33+
34+
@Override
35+
public SQLStatementAttributes getAttributes() {
36+
return new SQLStatementAttributes(new TablelessDataSourceBroadcastRouteSQLStatementAttribute());
37+
}
38+
}

test/it/parser/src/main/resources/case/dal/show.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,4 +916,24 @@
916916
<like pattern="order_*" start-delimiter="'" end-delimiter="'" start-index="24" stop-index="32" />
917917
</filter>
918918
</show-tables>
919+
920+
<show sql-case-id="show_views_basic" />
921+
<show sql-case-id="show_views_with_like_wildcard" />
922+
<show sql-case-id="show_views_from_database" />
923+
<show sql-case-id="show_views_in_database" />
924+
<show sql-case-id="show_views_in_db_with_like" />
925+
<show sql-case-id="show_views_from_db_with_like" />
926+
<show sql-case-id="show_materialized_views_basic" />
927+
<show sql-case-id="show_materialized_views_with_like" />
928+
<show sql-case-id="show_materialized_views_in_database" />
929+
<show sql-case-id="show_materialized_views_from_database" />
930+
<show sql-case-id="show_materialized_views_in_db_with_like" />
931+
<show sql-case-id="show_materialized_views_from_db_with_like" />
932+
<show sql-case-id="show_partitions_basic" />
933+
<show sql-case-id="show_partitions_with_db" />
934+
<show sql-case-id="show_partitions_with_partition_spec" />
935+
<show sql-case-id="show_partitions_with_where" />
936+
<show sql-case-id="show_partitions_with_order_by" />
937+
<show sql-case-id="show_partitions_with_limit" />
938+
<show sql-case-id="show_partitions_all_options" />
919939
</sql-parser-test-cases>

test/it/parser/src/main/resources/sql/supported/dal/show.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,23 @@
156156
<sql-case id="show_tables_in_database" value="SHOW TABLES IN sales_db;" db-types="Hive" />
157157
<sql-case id="show_tables_with_wildcard" value="SHOW TABLES 'order_*';" db-types="Hive" />
158158
<sql-case id="show_tables_in_db_with_wildcard" value="SHOW TABLES IN sales_db 'order_*';" db-types="Hive" />
159+
<sql-case id="show_views_basic" value="SHOW VIEWS;" db-types="Hive" />
160+
<sql-case id="show_views_with_like_wildcard" value="SHOW VIEWS LIKE 'user_*';" db-types="Hive" />
161+
<sql-case id="show_views_from_database" value="SHOW VIEWS FROM analytics_db;" db-types="Hive" />
162+
<sql-case id="show_views_in_database" value="SHOW VIEWS IN reports_db;" db-types="Hive" />
163+
<sql-case id="show_views_in_db_with_like" value="SHOW VIEWS IN sales_db LIKE 'quarterly_*|annual_*';" db-types="Hive" />
164+
<sql-case id="show_views_from_db_with_like" value="SHOW VIEWS FROM inventory_db LIKE 'low_stock_|out_of_stock';" db-types="Hive" />
165+
<sql-case id="show_materialized_views_basic" value="SHOW MATERIALIZED VIEWS;" db-types="Hive" />
166+
<sql-case id="show_materialized_views_with_like" value="SHOW MATERIALIZED VIEWS LIKE 'sales_*';" db-types="Hive" />
167+
<sql-case id="show_materialized_views_in_database" value="SHOW MATERIALIZED VIEWS IN analytics_db;" db-types="Hive" />
168+
<sql-case id="show_materialized_views_from_database" value="SHOW MATERIALIZED VIEWS FROM reports_db;" db-types="Hive" />
169+
<sql-case id="show_materialized_views_in_db_with_like" value="SHOW MATERIALIZED VIEWS IN inventory_db LIKE 'stock_*|supply_*';" db-types="Hive" />
170+
<sql-case id="show_materialized_views_from_db_with_like" value="SHOW MATERIALIZED VIEWS FROM orders_db LIKE 'daily_*|monthly_*';" db-types="Hive" />
171+
<sql-case id="show_partitions_basic" value="SHOW PARTITIONS orders;" db-types="Hive" />
172+
<sql-case id="show_partitions_with_db" value="SHOW PARTITIONS sales.orders;" db-types="Hive" />
173+
<sql-case id="show_partitions_with_partition_spec" value="SHOW PARTITIONS access_logs PARTITION(year='2023');" db-types="Hive" />
174+
<sql-case id="show_partitions_with_where" value="SHOW PARTITIONS products WHERE month >= 6;" db-types="Hive" />
175+
<sql-case id="show_partitions_with_order_by" value="SHOW PARTITIONS user_activity ORDER BY day DESC;" db-types="Hive" />
176+
<sql-case id="show_partitions_with_limit" value="SHOW PARTITIONS transactions LIMIT 50;" db-types="Hive" />
177+
<sql-case id="show_partitions_all_options" value="SHOW PARTITIONS retail.sales PARTITION(region='north') WHERE quarter=4 AND revenue > 50000 ORDER BY revenue DESC LIMIT 20;" db-types="Hive" />
159178
</sql-cases>

0 commit comments

Comments
 (0)