diff --git ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/OptiqSemanticException.java ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/OptiqSemanticException.java new file mode 100644 index 0000000..d2b08fa --- /dev/null +++ ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/OptiqSemanticException.java @@ -0,0 +1,51 @@ +/** + * 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.optimizer.optiq; + +import org.apache.hadoop.hive.ql.ErrorMsg; +import org.apache.hadoop.hive.ql.parse.SemanticException; + +/** + * Exception from SemanticAnalyzer. + */ + +public class OptiqSemanticException extends SemanticException { + + private static final long serialVersionUID = 1L; + + public OptiqSemanticException() { + super(); + } + + public OptiqSemanticException(String message) { + super(message); + } + + public OptiqSemanticException(Throwable cause) { + super(cause); + } + + public OptiqSemanticException(String message, Throwable cause) { + super(message, cause); + } + + public OptiqSemanticException(ErrorMsg errorMsg, String... msgArgs) { + super(errorMsg, msgArgs); + } +} 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 cb21ac1..d91a83a 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -113,6 +113,7 @@ import org.apache.hadoop.hive.ql.optimizer.unionproc.UnionProcContext; import org.apache.hadoop.hive.ql.optimizer.optiq.HiveDefaultRelMetadataProvider; import org.apache.hadoop.hive.ql.optimizer.optiq.HiveOptiqUtil; +import org.apache.hadoop.hive.ql.optimizer.optiq.OptiqSemanticException; import org.apache.hadoop.hive.ql.optimizer.optiq.Pair; import org.apache.hadoop.hive.ql.optimizer.optiq.RelOptHiveTable; import org.apache.hadoop.hive.ql.optimizer.optiq.TraitsUtil; @@ -9627,8 +9628,12 @@ public void analyzeInternal(ASTNode ast) throws SemanticException { */ } catch (Exception e) { LOG.error("CBO failed, skipping CBO. ", e); - if (!conf.getBoolVar(ConfVars.HIVE_IN_TEST) || (optiqPlanner.noColsMissingStats.get() > 0)) { + if (!conf.getBoolVar(ConfVars.HIVE_IN_TEST) || + (optiqPlanner.noColsMissingStats.get() > 0) || + e instanceof OptiqSemanticException) { reAnalyzeAST = true; + } else { + throw e instanceof SemanticException ? (SemanticException) e : new SemanticException(e); } } finally { runCBO = false; @@ -12327,11 +12332,22 @@ private RelNode genJoinLogicalPlan(ASTNode joinParseTree, Map a return genJoinRelNode(leftRel, rightRel, hiveJoinType, joinCond); } - private RelNode genTableLogicalPlan(String tableAlias, QB qb) { + private RelNode genTableLogicalPlan(String tableAlias, QB qb) throws SemanticException { RowResolver rr = new RowResolver(); HiveTableScanRel tableRel = null; try { + + // 0. If the table has a Sample specified, bail from Optiq path. + if ( qb.getParseInfo().getTabSample(tableAlias) != null || + SemanticAnalyzer.this.nameToSplitSample.containsKey(tableAlias)) { + String msg = String.format("Table Sample specified for %s." + + " Currently we don't support Table Sample clauses in CBO," + + " turn off cbo for queries on tableSamples.", tableAlias); + LOG.debug(msg); + throw new OptiqSemanticException(msg); + } + // 1. Get Table Alias String alias_id = getAliasId(tableAlias, qb); @@ -12399,7 +12415,11 @@ private RelNode genTableLogicalPlan(String tableAlias, QB qb) { m_relToHiveRR.put(tableRel, rr); m_relToHiveColNameOptiqPosMap.put(tableRel, hiveToOptiqColMap); } catch (Exception e) { - throw (new RuntimeException(e)); + if ( e instanceof SemanticException) { + throw (SemanticException) e; + } else { + throw (new RuntimeException(e)); + } } return tableRel; @@ -13311,7 +13331,15 @@ private RelNode genSelectLogicalPlan(QB qb, RelNode srcRel) throws SemanticExcep int posn = 0; boolean hintPresent = (selExprList.getChild(0).getType() == HiveParser.TOK_HINTLIST); if (hintPresent) { - posn++; + String hint = SemanticAnalyzer.this.ctx.getTokenRewriteStream(). + toString( + selExprList.getChild(0).getTokenStartIndex(), + selExprList.getChild(0).getTokenStopIndex()); + String msg = String.format("Hint specified for %s." + + " Currently we don't support hints in CBO," + + " turn off cbo to use hints.", hint); + LOG.debug(msg); + throw new OptiqSemanticException(msg); } // 4. Determine if select corresponds to a subquery