Author: rhbutani
Date: Sat Sep  6 04:47:59 2014
New Revision: 1622826

URL: http://svn.apache.org/r1622826
Log:
HIVE-8006 CBO Trunk Merge: Test fail that includes Table Sample, rows(), query 
hints (Harish Butani via John Pullokkaran)

Added:
    
hive/branches/cbo/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/OptiqSemanticException.java
Modified:
    
hive/branches/cbo/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java

Added: 
hive/branches/cbo/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/OptiqSemanticException.java
URL: 
http://svn.apache.org/viewvc/hive/branches/cbo/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/OptiqSemanticException.java?rev=1622826&view=auto
==============================================================================
--- 
hive/branches/cbo/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/OptiqSemanticException.java
 (added)
+++ 
hive/branches/cbo/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/OptiqSemanticException.java
 Sat Sep  6 04:47:59 2014
@@ -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);
+  }
+}

Modified: 
hive/branches/cbo/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
URL: 
http://svn.apache.org/viewvc/hive/branches/cbo/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java?rev=1622826&r1=1622825&r2=1622826&view=diff
==============================================================================
--- 
hive/branches/cbo/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
 (original)
+++ 
hive/branches/cbo/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
 Sat Sep  6 04:47:59 2014
@@ -113,6 +113,7 @@ import org.apache.hadoop.hive.ql.optimiz
 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 class SemanticAnalyzer extends Ba
          */
       } 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 @@ public class SemanticAnalyzer extends Ba
       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 @@ public class SemanticAnalyzer extends Ba
         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 @@ public class SemanticAnalyzer extends Ba
       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


Reply via email to