fsk119 commented on a change in pull request #15402: URL: https://github.com/apache/flink/pull/15402#discussion_r602994006
########## File path: flink-table/flink-sql-parser-hive/src/main/codegen/includes/parserImpls.ftl ########## @@ -1605,3 +1605,17 @@ SqlShowModules SqlShowModules() : return new SqlShowModules(startPos.plus(getPos()), requireFull); } } + +/** +* Parses a explain module statement. +*/ +SqlNode SqlRichExplain() : +{ + SqlNode stmt; +} +{ + <EXPLAIN> (<PLAN> <FOR>)* + stmt = SqlQueryOrDml() { + return new SqlRichExplain(getPos(),stmt); + } +} Review comment: Add a new line ########## File path: flink-table/flink-sql-parser-hive/src/test/java/org/apache/flink/sql/parser/hive/FlinkHiveSqlParserImplTest.java ########## @@ -482,4 +482,54 @@ public void testShowModules() { sql("show full modules").ok("SHOW FULL MODULES"); } + + @Test + public void testExplain() { + String sql = "explain plan for select * from emps"; + String expected = "EXPLAIN SELECT *\n" + "FROM `EMPS`"; + this.sql(sql).ok(expected); + } + + @Test + public void testExplainJsonFormat() { + // unsupport testExplainJsonFormat now + } + + @Test + public void testExplainWithImpl() { + // unsupport testExplainWithImpl now + } + + @Test + public void testExplainWithoutImpl() { + // unsupport testExplainWithoutImpl now + } + + @Test + public void testExplainWithType() { + // unsupport testExplainWithType now + } + + @Test + public void testExplainAsXml() { + // unsupport testExplainWithType now + } + + @Test + public void testExplainAsJson() { + // unsupport testExplainWithType now + } Review comment: Add comment: // TODO: FLINK-20562 ########## File path: flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/calcite/FlinkPlannerImpl.scala ########## @@ -146,6 +146,10 @@ class FlinkPlannerImpl( val validated = validator.validate(explain.getExplicandum) explain.setOperand(0, validated) explain + case richExplain: SqlRichExplain => + val validated = validator.validate(richExplain.getStatement) + richExplain.setOperand(0,validated) + richExplain Review comment: Move forward before `SqlExplain`? Do we really need SqlExplain? ########## File path: flink-table/flink-sql-parser/src/test/java/org/apache/flink/sql/parser/FlinkSqlParserImplTest.java ########## @@ -1215,6 +1214,56 @@ public void testEnd() { sql("end").ok("END"); } + @Test + public void testExplain() { + String sql = "explain plan for select * from emps"; + String expected = "EXPLAIN SELECT *\n" + "FROM `EMPS`"; + this.sql(sql).ok(expected); + } + + @Test + public void testExplainJsonFormat() { + // unsupport testExplainJsonFormat now + } + + @Test + public void testExplainWithImpl() { + // unsupport testExplainWithImpl now + } + + @Test + public void testExplainWithoutImpl() { + // unsupport testExplainWithoutImpl now + } + + @Test + public void testExplainWithType() { + // unsupport testExplainWithType now + } + + @Test + public void testExplainAsXml() { + // unsupport testExplainWithType now + } + + @Test + public void testExplainAsJson() { + // unsupport testExplainWithType now Review comment: ditto ########## File path: flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/calcite/FlinkPlannerImpl.scala ########## @@ -18,28 +18,26 @@ package org.apache.flink.table.calcite -import org.apache.flink.sql.parser.ExtendedSqlNode -import org.apache.flink.sql.parser.dql.{SqlRichDescribeTable, SqlShowCatalogs, SqlShowCurrentCatalog, SqlShowCurrentDatabase, SqlShowDatabases, SqlShowFunctions, SqlShowTables, SqlShowViews} -import org.apache.flink.table.api.{TableException, ValidationException} -import org.apache.flink.table.catalog.CatalogReader -import org.apache.flink.table.parse.CalciteParser +import _root_.java.lang.{Boolean => JBoolean} +import _root_.java.util +import _root_.java.util.function.{Function => JFunction} import org.apache.calcite.plan.RelOptTable.ViewExpander import org.apache.calcite.plan._ import org.apache.calcite.rel.RelRoot import org.apache.calcite.rel.`type`.RelDataType import org.apache.calcite.rex.RexBuilder -import org.apache.calcite.sql.advise.{SqlAdvisor, SqlAdvisorValidator} +import org.apache.calcite.sql.advise.SqlAdvisorValidator import org.apache.calcite.sql.validate.SqlValidator import org.apache.calcite.sql.{SqlExplain, SqlKind, SqlNode, SqlOperatorTable} import org.apache.calcite.sql2rel.{SqlRexConvertletTable, SqlToRelConverter} import org.apache.calcite.tools.{FrameworkConfig, RelConversionException} +import org.apache.flink.sql.parser.ExtendedSqlNode +import org.apache.flink.sql.parser.dql._ +import org.apache.flink.table.api.{TableException, ValidationException} +import org.apache.flink.table.catalog.CatalogReader +import org.apache.flink.table.parse.CalciteParser Review comment: Rollback ########## File path: flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/dql/SqlRichExplain.java ########## @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.sql.parser.dql; + +import org.apache.calcite.sql.SqlCall; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.SqlNode; +import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.SqlSpecialOperator; +import org.apache.calcite.sql.SqlWriter; +import org.apache.calcite.sql.parser.SqlParserPos; + +import java.util.Collections; +import java.util.List; + +/** EXPLAIN (plan for)* STATEMENT sql call. */ +public class SqlRichExplain extends SqlCall { + + public static final SqlSpecialOperator OPERATOR = + new SqlSpecialOperator("EXPLAIN", SqlKind.EXPLAIN); + + private SqlNode statement; + + public SqlRichExplain(SqlParserPos pos, SqlNode statement) { + super(pos); + this.statement = statement; + } + + public SqlNode getStatement() { + return statement; + } + + @Override + public SqlOperator getOperator() { + return OPERATOR; + } + + @Override + public List<SqlNode> getOperandList() { + return Collections.singletonList(statement); + } + + @Override + public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { + writer.keyword("EXPLAIN"); + statement.unparse(writer, leftPrec, rightPrec); + } + + @Override + public void setOperand(int i, SqlNode operand) { + if (i == 0) { + statement = operand; + } else { + throw new AssertionError(i); Review comment: Please use meaningful exception message. ########## File path: flink-table/flink-sql-parser-hive/src/test/java/org/apache/flink/sql/parser/hive/FlinkHiveSqlParserImplTest.java ########## @@ -482,4 +482,54 @@ public void testShowModules() { sql("show full modules").ok("SHOW FULL MODULES"); } + + @Test + public void testExplain() { + String sql = "explain plan for select * from emps"; + String expected = "EXPLAIN SELECT *\n" + "FROM `EMPS`"; + this.sql(sql).ok(expected); + } + + @Test + public void testExplainJsonFormat() { + // unsupport testExplainJsonFormat now + } + + @Test + public void testExplainWithImpl() { + // unsupport testExplainWithImpl now + } + + @Test + public void testExplainWithoutImpl() { + // unsupport testExplainWithoutImpl now + } + + @Test + public void testExplainWithType() { + // unsupport testExplainWithType now + } + + @Test + public void testExplainAsXml() { + // unsupport testExplainWithType now + } Review comment: Add comment: Don't supported feature. Escape the test. ########## File path: flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/ExplainOperation.java ########## @@ -21,8 +21,8 @@ import java.util.Collections; /** - * Operation to describe an EXPLAIN statement. NOTES: currently, only default behavior(EXPLAIN PLAN - * FOR xx) is supported. + * Operation to describe an EXPLAIN statement. NOTES: currently, only default behavior(EXPLAIN xx) + * is supported. Review comment: Explain plan for is also supported. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org