diff --git ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java index afec18f..64f0ee6 100644 --- ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java +++ ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java @@ -1500,4 +1500,14 @@ public class Hive { } } + public List getIndexes(String dbName, String tblName, short max) throws HiveException { + List names = null; + try { + names = getMSC().listIndexNames(dbName, tblName, max); + } catch (Exception e) { + LOG.error(StringUtils.stringifyException(e)); + throw new HiveException(e); + } + return names; + } }; diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java index b99c191..f59e3c0 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java @@ -75,17 +75,18 @@ import org.apache.hadoop.hive.ql.plan.DropDatabaseDesc; import org.apache.hadoop.hive.ql.plan.DropIndexDesc; import org.apache.hadoop.hive.ql.plan.DropTableDesc; import org.apache.hadoop.hive.ql.plan.FetchWork; +import org.apache.hadoop.hive.ql.plan.LockTableDesc; import org.apache.hadoop.hive.ql.plan.MsckDesc; import org.apache.hadoop.hive.ql.plan.ShowDatabasesDesc; import org.apache.hadoop.hive.ql.plan.ShowFunctionsDesc; +import org.apache.hadoop.hive.ql.plan.ShowIndexesDesc; +import org.apache.hadoop.hive.ql.plan.ShowLocksDesc; import org.apache.hadoop.hive.ql.plan.ShowPartitionsDesc; import org.apache.hadoop.hive.ql.plan.ShowTableStatusDesc; import org.apache.hadoop.hive.ql.plan.ShowTablesDesc; -import org.apache.hadoop.hive.ql.plan.ShowLocksDesc; -import org.apache.hadoop.hive.ql.plan.LockTableDesc; -import org.apache.hadoop.hive.ql.plan.UnlockTableDesc; import org.apache.hadoop.hive.ql.plan.SwitchDatabaseDesc; import org.apache.hadoop.hive.ql.plan.TableDesc; +import org.apache.hadoop.hive.ql.plan.UnlockTableDesc; import org.apache.hadoop.hive.ql.plan.AlterTableDesc.AlterTableTypes; import org.apache.hadoop.hive.serde.Constants; import org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe; @@ -232,6 +233,9 @@ public class DDLSemanticAnalyzer extends BaseSemanticAnalyzer { } else if (ast.getToken().getType() == HiveParser.TOK_SHOWPARTITIONS) { ctx.setResFile(new Path(ctx.getLocalTmpFileURI())); analyzeShowPartitions(ast); + } else if (ast.getToken().getType() == HiveParser.TOK_SHOWINDEXES) { + ctx.setResFile(new Path(ctx.getLocalTmpFileURI())); + analyzeShowIndexes(ast); } else if (ast.getToken().getType() == HiveParser.TOK_LOCKTABLE) { analyzeLockTable(ast); } else if (ast.getToken().getType() == HiveParser.TOK_UNLOCKTABLE) { @@ -792,7 +796,7 @@ public class DDLSemanticAnalyzer extends BaseSemanticAnalyzer { partSpec, isExt); rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), descTblDesc), conf)); - setFetchTask(createFetchTask(DescTableDesc.getSchema())); + setFetchTask(createFetchTask(descTblDesc.getSchema())); LOG.info("analyzeDescribeTable done"); } @@ -876,6 +880,14 @@ public class DDLSemanticAnalyzer extends BaseSemanticAnalyzer { setFetchTask(createFetchTask(showTblStatusDesc.getSchema())); } + private void analyzeShowIndexes(ASTNode ast) throws SemanticException { + ShowIndexesDesc showIndexesDesc; + String tableName = unescapeIdentifier(ast.getChild(0).getText()); + showIndexesDesc = new ShowIndexesDesc(tableName, ctx.getResFile()); + rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), + showIndexesDesc), conf)); + setFetchTask(createFetchTask(showIndexesDesc.getSchema())); + } /** * Add the task according to the parsed command tree. This is used for the CLI * command "SHOW FUNCTIONS;". diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g index 9745b63..95eae3c 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g +++ ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g @@ -183,6 +183,7 @@ TOK_LEFTSEMIJOIN; TOK_LATERAL_VIEW; TOK_TABALIAS; TOK_ANALYZE; +TOK_SHOWINDEXES; } @@ -640,6 +641,8 @@ showStatement | KW_SHOW KW_TABLE KW_EXTENDED ((KW_FROM|KW_IN) db_name=Identifier)? KW_LIKE showStmtIdentifier partitionSpec? -> ^(TOK_SHOW_TABLESTATUS showStmtIdentifier $db_name? partitionSpec?) | KW_SHOW KW_LOCKS -> ^(TOK_SHOWLOCKS) + | KW_SHOW (KW_INDEX|KW_INDEXES) (KW_FROM|KW_IN) showStmtIdentifier ((KW_FROM|KW_IN) db_name=Ident)? + -> ^(TOK_SHOWINDEXES showStmtIdentifier $db_name?) ; lockStatement @@ -1725,6 +1728,7 @@ KW_PARTITIONS : 'PARTITIONS'; KW_TABLE: 'TABLE'; KW_TABLES: 'TABLES'; KW_INDEX: 'INDEX'; +KW_INDEXES: 'INDEXES'; KW_REBUILD: 'REBUILD'; KW_FUNCTIONS: 'FUNCTIONS'; KW_SHOW: 'SHOW'; diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java index 3b78d25..6f25aea 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java @@ -60,6 +60,7 @@ public final class SemanticAnalyzerFactory { commandType.put(HiveParser.TOK_SHOW_TABLESTATUS, "SHOW_TABLESTATUS"); commandType.put(HiveParser.TOK_SHOWFUNCTIONS, "SHOWFUNCTIONS"); commandType.put(HiveParser.TOK_SHOWPARTITIONS, "SHOWPARTITIONS"); + commandType.put(HiveParser.TOK_SHOWINDEXES, "SHOWINDEXES"); commandType.put(HiveParser.TOK_SHOWLOCKS, "SHOWLOCKS"); commandType.put(HiveParser.TOK_CREATEFUNCTION, "CREATEFUNCTION"); commandType.put(HiveParser.TOK_DROPFUNCTION, "DROPFUNCTION"); @@ -120,6 +121,7 @@ public final class SemanticAnalyzerFactory { case HiveParser.TOK_SHOW_TABLESTATUS: case HiveParser.TOK_SHOWFUNCTIONS: case HiveParser.TOK_SHOWPARTITIONS: + case HiveParser.TOK_SHOWINDEXES: case HiveParser.TOK_SHOWLOCKS: case HiveParser.TOK_CREATEINDEX: case HiveParser.TOK_DROPINDEX: diff --git ql/src/java/org/apache/hadoop/hive/ql/plan/DDLWork.java ql/src/java/org/apache/hadoop/hive/ql/plan/DDLWork.java index d445be1..dc0efe8 100644 --- ql/src/java/org/apache/hadoop/hive/ql/plan/DDLWork.java +++ ql/src/java/org/apache/hadoop/hive/ql/plan/DDLWork.java @@ -53,6 +53,7 @@ public class DDLWork implements Serializable { private AlterTableSimpleDesc alterTblSimpleDesc; private MsckDesc msckDesc; private ShowTableStatusDesc showTblStatusDesc; + private ShowIndexesDesc showIndexesDesc; /** * ReadEntitites that are passed to the hooks. @@ -295,6 +296,12 @@ public class DDLWork implements Serializable { this.dropIdxDesc = dropIndexDesc; } + public DDLWork(HashSet inputs, HashSet outputs, + ShowIndexesDesc showIndexesDesc) { + this(inputs, outputs); + this.showIndexesDesc = showIndexesDesc; + } + /** * @return Create Database descriptor */ diff --git ql/src/java/org/apache/hadoop/hive/ql/plan/ShowIndexesDesc.java ql/src/java/org/apache/hadoop/hive/ql/plan/ShowIndexesDesc.java new file mode 100644 index 0000000..05e3ad7 --- /dev/null +++ ql/src/java/org/apache/hadoop/hive/ql/plan/ShowIndexesDesc.java @@ -0,0 +1,55 @@ +/** + * 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.hadoop.hive.ql.plan; + +import java.io.Serializable; + +import org.apache.hadoop.fs.Path; + +/** + * ShowIndexesDesc. + * Returns table index information per SQL syntax. + */ +@Explain(displayName = "Show Indexes") +public class ShowIndexesDesc extends DDLDesc implements Serializable { + private static final long serialVersionUID = 1L; + String tableName; + String resFile; + + /** + * thrift ddl for the result of show indexes. + */ + private static final String schema = "index_name#string"; + + public String getSchema() { + return schema; + } + + /** + * + * @param tableName + * Name of the table whose indexes need to be listed. + * @param resFile + * File to store the results in. + */ + public ShowIndexesDesc(String tableName, Path resFile) { + this.tableName = tableName; + this.resFile = resFile.toString(); + } +}