diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java index 747f387..da39ee3 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -1930,24 +1930,6 @@ private void getMetaData(QB qb, ReadEntity parentInput) } } - // Disallow INSERT INTO on bucketized tables - boolean isAcid = AcidUtils.isAcidTable(tab); - boolean isTableWrittenTo = qb.getParseInfo().isInsertIntoTable(tab.getDbName(), tab.getTableName()); - if (isTableWrittenTo && - tab.getNumBuckets() > 0 && !isAcid) { - throw new SemanticException(ErrorMsg.INSERT_INTO_BUCKETIZED_TABLE. - getMsg("Table: " + tabName)); - } - // Disallow update and delete on non-acid tables - if ((updating() || deleting()) && !isAcid && isTableWrittenTo) { - //isTableWrittenTo: delete from acidTbl where a in (select id from nonAcidTable) - //so only assert this if we are actually writing to this table - // Whether we are using an acid compliant transaction manager has already been caught in - // UpdateDeleteSemanticAnalyzer, so if we are updating or deleting and getting nonAcid - // here, it means the table itself doesn't support it. - throw new SemanticException(ErrorMsg.ACID_OP_ON_NONACID_TABLE, tabName); - } - if (tab.isView()) { if (qb.getParseInfo().isAnalyzeCommand()) { throw new SemanticException(ErrorMsg.ANALYZE_VIEW.getMsg()); @@ -2069,6 +2051,26 @@ private void getMetaData(QB qb, ReadEntity parentInput) throw new SemanticException(ErrorMsg.INVALID_OUTPUT_FORMAT_TYPE .getMsg(ast, "The class is " + outputFormatClass.toString())); } + boolean isTableWrittenTo = qb.getParseInfo().isInsertIntoTable(ts.tableHandle.getDbName(), + ts.tableHandle.getTableName()); + assert isTableWrittenTo : + "Inconsistent data structure detected: we are writing to " + ts.tableHandle + " in " + + name + " but it's not inisInsertIntoTable()"; + // Disallow INSERT INTO on bucketized tables + boolean isAcid = AcidUtils.isAcidTable(ts.tableHandle); + if(ts.tableHandle.getNumBuckets() > 0 && !isAcid) { + throw new SemanticException(ErrorMsg.INSERT_INTO_BUCKETIZED_TABLE. + getMsg("Table: " + ts.tableName)); + } + // Disallow update and delete on non-acid tables + if ((updating() || deleting()) && !isAcid) { + //isTableWrittenTo: delete from acidTbl where a in (select id from nonAcidTable) + //so only assert this if we are actually writing to this table + // Whether we are using an acid compliant transaction manager has already been caught in + // UpdateDeleteSemanticAnalyzer, so if we are updating or deleting and getting nonAcid + // here, it means the table itself doesn't support it. + throw new SemanticException(ErrorMsg.ACID_OP_ON_NONACID_TABLE, ts.tableName); + } // TableSpec ts is got from the query (user specified), // which means the user didn't specify partitions in their query,