From 484e73b7d58c4dcc0e52ed7ae93981999335e0c7 Mon Sep 17 00:00:00 2001 From: Syed Albiz Date: Fri, 19 Aug 2011 02:59:46 -0700 Subject: [PATCH 1/1] check that index handler is table-based before doing things (HIVE-1503) diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java index c031f40..b6b2da6 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java @@ -809,6 +809,11 @@ public class DDLTask extends Task implements Serializable { if( crtIndex.getSerde() != null) { validateSerDe(crtIndex.getSerde()); } + Table baseTable = db.getTable(crtIndex.getTableName()); + if (baseTable.getProperty("EXTERNAL") != null && + baseTable.getProperty("EXTERNAL").equalsIgnoreCase("TRUE")) { + throw new HiveException("ERROR: Cannot build index on external table"); + } db .createIndex( 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 3054f76..56123a1 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java @@ -726,6 +726,12 @@ public class DDLSemanticAnalyzer extends BaseSemanticAnalyzer { throw new SemanticException("class name provided for index handler not found.", e); } } + HiveIndexHandler handler; + try { + handler = HiveUtils.getIndexHandler(conf, typeName); + } catch (HiveException e) { + throw new SemanticException(e); + } String indexTableName = null; boolean deferredRebuild = false; @@ -748,6 +754,9 @@ public class DDLSemanticAnalyzer extends BaseSemanticAnalyzer { rowFormatParams.analyzeRowFormat(shared, child); break; case HiveParser.TOK_CREATEINDEX_INDEXTBLNAME: + if (!handler.usesIndexTable()) { + throw new SemanticException("Cannot specify index table if index format does not use index table"); + } ASTNode ch = (ASTNode) child.getChild(0); indexTableName = getUnescapedName((ASTNode)ch); break; @@ -764,6 +773,9 @@ public class DDLSemanticAnalyzer extends BaseSemanticAnalyzer { idxProps = DDLSemanticAnalyzer.getProps((ASTNode) child.getChild(0)); break; case HiveParser.TOK_TABLESERIALIZER: + if (!handler.usesIndexTable()) { + throw new SemanticException("Cannot specify index table format if index format does not use index table"); + } child = (ASTNode) child.getChild(0); shared.serde = unescapeSQLString(child.getChild(0).getText()); if (child.getChildCount() == 2) { -- 1.7.4.4