Jackie-Jiang commented on code in PR #12537: URL: https://github.com/apache/pinot/pull/12537#discussion_r1597256279
########## pinot-common/src/main/codegen/includes/parserImpls.ftl: ########## @@ -109,3 +109,14 @@ SqlNode SqlPhysicalExplain() : nDynamicParams); } } +SqlNode SqlShowTables() : Review Comment: (format) Add an empty line in front of the function ########## pinot-common/src/main/java/org/apache/pinot/sql/parsers/parser/SqlShowTables.java: ########## @@ -0,0 +1,52 @@ +/** + * 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.pinot.sql.parsers.parser; + +import java.util.List; +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; + +public class SqlShowTables extends SqlCall { + + private static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("UDF", SqlKind.OTHER); + + protected SqlShowTables(SqlParserPos pos) { + super(pos); + } + + @Override public SqlOperator getOperator() { Review Comment: (format) Reformat the changes, same for other places ########## pinot-common/src/main/codegen/includes/parserImpls.ftl: ########## @@ -109,3 +109,14 @@ SqlNode SqlPhysicalExplain() : nDynamicParams); } } +SqlNode SqlShowTables() : +{ + SqlParserPos pos; +} +{ + <SHOW> { pos = getPos(); } Review Comment: Here is the example of `SqlShowTables` in Calcite, should we keep `<SHOW>` and `<TABLES>` together? ``` Example of SqlShowTables() implementation: SqlNode SqlShowTables() { ...local variables... } { <SHOW> <TABLES> ... { return SqlShowTables(...) } } ``` ########## pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java: ########## @@ -421,6 +423,9 @@ public static PinotQuery compileSqlNodeToPinotQuery(SqlNode sqlNode) { sqlNode = ((SqlExplain) sqlNode).getExplicandum(); pinotQuery.setExplain(true); } + if (sqlNode instanceof SqlShowTables || sqlNode instanceof SqlDescribeTable) { + return pinotQuery; Review Comment: Does it work if we directly return empty query here? ########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotQueryResource.java: ########## @@ -261,9 +263,19 @@ private String getQueryResponse(String query, @Nullable SqlNode sqlNode, String return QueryException.getException(QueryException.QUERY_VALIDATION_ERROR, e).toString(); } try { - String inputTableName = - sqlNode != null ? RequestUtils.getTableNames(CalciteSqlParser.compileSqlNodeToPinotQuery(sqlNode)).iterator() - .next() : CalciteSqlCompiler.compileToBrokerRequest(query).getQuerySource().getTableName(); + String inputTableName; + if (sqlNode != null) { + if (sqlNode instanceof SqlShowTables) { + inputTableName = "*"; Review Comment: Trying to follow how does this work. What does `_pinotHelixResourceManager.getActualTableName("*", database)` return? ########## pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/BaseBrokerRequestHandler.java: ########## @@ -1558,6 +1571,60 @@ private void computeResultsForLiteral(Literal literal, List<String> columnNames, } } + private BrokerResponseNative processShowTablesQuery(long compilationStartTimeNs, + RequestContext requestContext) { + BrokerResponseNative brokerResponse = new BrokerResponseNative(); + String[] columnNames = {"Tables"}; + DataSchema.ColumnDataType[] columnTypes = {DataSchema.ColumnDataType.STRING}; + + + DataSchema dataSchema = new DataSchema(columnNames, columnTypes); + List<Object[]> rows = new ArrayList<>(); + _tableCache.getTableConfigs().stream().map(TableConfig::getTableName).sorted().forEach(a -> { Review Comment: We cannot return all tables here. It needs to filter on the database, and only return the tables within the database ########## pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/BaseBrokerRequestHandler.java: ########## @@ -1558,6 +1571,60 @@ private void computeResultsForLiteral(Literal literal, List<String> columnNames, } } + private BrokerResponseNative processShowTablesQuery(long compilationStartTimeNs, + RequestContext requestContext) { + BrokerResponseNative brokerResponse = new BrokerResponseNative(); + String[] columnNames = {"Tables"}; + DataSchema.ColumnDataType[] columnTypes = {DataSchema.ColumnDataType.STRING}; + Review Comment: (format) Multiple empty lines ########## pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/BaseBrokerRequestHandler.java: ########## @@ -1558,6 +1571,60 @@ private void computeResultsForLiteral(Literal literal, List<String> columnNames, } } + private BrokerResponseNative processShowTablesQuery(long compilationStartTimeNs, + RequestContext requestContext) { + BrokerResponseNative brokerResponse = new BrokerResponseNative(); + String[] columnNames = {"Tables"}; + DataSchema.ColumnDataType[] columnTypes = {DataSchema.ColumnDataType.STRING}; + + + DataSchema dataSchema = new DataSchema(columnNames, columnTypes); + List<Object[]> rows = new ArrayList<>(); + _tableCache.getTableConfigs().stream().map(TableConfig::getTableName).sorted().forEach(a -> { + a = a.replace("_OFFLINE", "").replace("_REALTIME", ""); + rows.add(new String[] {a}); + }); + ResultTable resultTable = new ResultTable(dataSchema, rows); + brokerResponse.setResultTable(resultTable); + + long totalTimeMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - compilationStartTimeNs); + brokerResponse.setTimeUsedMs(totalTimeMs); + requestContext.setQueryProcessingTime(totalTimeMs); + augmentStatistics(requestContext, brokerResponse); + return brokerResponse; + } + + private BrokerResponseNative processDescribeTableQuery(String tableName, long compilationStartTimeNs, Review Comment: We need to handle `database` and access control here -- 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. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org