hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From na...@apache.org
Subject svn commit: r1418012 - in /hive/trunk: common/src/java/org/apache/hadoop/hive/conf/ ql/src/java/org/apache/hadoop/hive/ql/exec/ ql/src/java/org/apache/hadoop/hive/ql/parse/ ql/src/java/org/apache/hadoop/hive/ql/plan/ ql/src/test/queries/clientpositive/...
Date Thu, 06 Dec 2012 17:47:12 GMT
Author: namit
Date: Thu Dec  6 17:47:11 2012
New Revision: 1418012

URL: http://svn.apache.org/viewvc?rev=1418012&view=rev
Log:
HIVE-2477 Use name of original expression for name of CAST output
(Navis via namit)


Added:
    hive/trunk/ql/src/test/queries/clientpositive/alias_casted_column.q
    hive/trunk/ql/src/test/results/clientpositive/alias_casted_column.q.out
Modified:
    hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/ExprNodeDescUtils.java

Modified: hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java?rev=1418012&r1=1418011&r2=1418012&view=diff
==============================================================================
--- hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java (original)
+++ hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java Thu Dec  6 17:47:11
2012
@@ -631,7 +631,7 @@ public class HiveConf extends Configurat
     HIVE_CONCATENATE_CHECK_INDEX ("hive.exec.concatenate.check.index", true),
     HIVE_IO_EXCEPTION_HANDLERS("hive.io.exception.handlers", ""),
 
-    //prefix used to auto generated column aliases
+    // prefix used to auto generated column aliases (this should be started with '_')
     HIVE_AUTOGEN_COLUMNALIAS_PREFIX_LABEL("hive.autogen.columnalias.prefix.label", "_c"),
     HIVE_AUTOGEN_COLUMNALIAS_PREFIX_INCLUDEFUNCNAME(
                                "hive.autogen.columnalias.prefix.includefuncname", false),

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java?rev=1418012&r1=1418011&r2=1418012&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java Thu Dec  6
17:47:11 2012
@@ -1180,6 +1180,34 @@ public final class FunctionRegistry {
   }
 
   /**
+   * Returns whether the exprNodeDesc is node of "cast".
+   */
+  private static boolean isOpCast(ExprNodeDesc desc) {
+    if (!(desc instanceof ExprNodeGenericFuncDesc)) {
+      return false;
+    }
+    GenericUDF genericUDF = ((ExprNodeGenericFuncDesc)desc).getGenericUDF();
+    Class udfClass;
+    if (genericUDF instanceof GenericUDFBridge) {
+      udfClass = ((GenericUDFBridge)genericUDF).getUdfClass();
+    } else {
+      udfClass = genericUDF.getClass();
+    }
+    return udfClass == UDFToBoolean.class || udfClass == UDFToByte.class ||
+        udfClass == UDFToDouble.class || udfClass == UDFToFloat.class ||
+        udfClass == UDFToInteger.class || udfClass == UDFToLong.class ||
+        udfClass == UDFToShort.class || udfClass == UDFToString.class ||
+        udfClass == GenericUDFTimestamp.class || udfClass == GenericUDFToBinary.class;
+  }
+
+  /**
+   * Returns whether the exprNodeDesc can recommend name for the expression
+   */
+  public static boolean isOpPreserveInputName(ExprNodeDesc desc) {
+    return isOpCast(desc);
+  }
+
+  /**
    * Registers the appropriate kind of temporary function based on a class's
    * type.
    *

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java?rev=1418012&r1=1418011&r2=1418012&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java Thu Dec 
6 17:47:11 2012
@@ -126,6 +126,7 @@ import org.apache.hadoop.hive.ql.plan.Dy
 import org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc;
 import org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc;
 import org.apache.hadoop.hive.ql.plan.ExprNodeDesc;
+import org.apache.hadoop.hive.ql.plan.ExprNodeDescUtils;
 import org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc;
 import org.apache.hadoop.hive.ql.plan.ExprNodeNullDesc;
 import org.apache.hadoop.hive.ql.plan.ExtractDesc;
@@ -2413,6 +2414,10 @@ public class SemanticAnalyzer extends Ba
         // We allow stateful functions in the SELECT list (but nowhere else)
         tcCtx.setAllowStatefulFunctions(true);
         ExprNodeDesc exp = genExprNodeDesc(expr, inputRR, tcCtx);
+        String recommended = recommendName(exp, colAlias);
+        if (recommended != null && out_rwsch.get(null, recommended) == null) {
+          colAlias = recommended;
+        }
         col_list.add(exp);
         if (subQuery) {
           out_rwsch.checkColumn(tabAlias, colAlias);
@@ -2461,6 +2466,17 @@ public class SemanticAnalyzer extends Ba
     return output;
   }
 
+  private String recommendName(ExprNodeDesc exp, String colAlias) {
+    if (!colAlias.startsWith(autogenColAliasPrfxLbl)) {
+      return null;
+    }
+    String column = ExprNodeDescUtils.recommendInputName(exp);
+    if (column != null && !column.startsWith(autogenColAliasPrfxLbl)) {
+      return column;
+    }
+    return null;
+  }
+
   /**
    * Class to store GenericUDAF related information.
    */

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/ExprNodeDescUtils.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/ExprNodeDescUtils.java?rev=1418012&r1=1418011&r2=1418012&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/ExprNodeDescUtils.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/ExprNodeDescUtils.java Thu Dec 
6 17:47:11 2012
@@ -98,4 +98,19 @@ public class ExprNodeDescUtils {
     return new ExprNodeGenericFuncDesc(TypeInfoFactory.booleanTypeInfo,
         FunctionRegistry.getGenericUDFForAnd(), children);
   }
+
+  /**
+   * Recommend name for the expression
+   */
+  public static String recommendInputName(ExprNodeDesc desc) {
+    if (desc instanceof ExprNodeColumnDesc) {
+      return ((ExprNodeColumnDesc)desc).getColumn();
+    }
+    List<ExprNodeDesc> children = desc.getChildren();
+    if (FunctionRegistry.isOpPreserveInputName(desc) && !children.isEmpty() &&
+      children.get(0) instanceof ExprNodeColumnDesc) {
+      return ((ExprNodeColumnDesc)children.get(0)).getColumn();
+    }
+    return null;
+  }
 }

Added: hive/trunk/ql/src/test/queries/clientpositive/alias_casted_column.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/alias_casted_column.q?rev=1418012&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/alias_casted_column.q (added)
+++ hive/trunk/ql/src/test/queries/clientpositive/alias_casted_column.q Thu Dec  6 17:47:11
2012
@@ -0,0 +1,5 @@
+-- HIVE-2477 Use name of original expression for name of CAST output
+explain select key from (select cast(key as int) from src )t;
+
+--backward
+explain select key2 from (select cast(key as int) key2 from src )t;

Added: hive/trunk/ql/src/test/results/clientpositive/alias_casted_column.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/alias_casted_column.q.out?rev=1418012&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/alias_casted_column.q.out (added)
+++ hive/trunk/ql/src/test/results/clientpositive/alias_casted_column.q.out Thu Dec  6 17:47:11
2012
@@ -0,0 +1,84 @@
+PREHOOK: query: -- HIVE-2477 Use name of original expression for name of CAST output
+explain select key from (select cast(key as int) from src )t
+PREHOOK: type: QUERY
+POSTHOOK: query: -- HIVE-2477 Use name of original expression for name of CAST output
+explain select key from (select cast(key as int) from src )t
+POSTHOOK: type: QUERY
+ABSTRACT SYNTAX TREE:
+  (TOK_QUERY (TOK_FROM (TOK_SUBQUERY (TOK_QUERY (TOK_FROM (TOK_TABREF (TOK_TABNAME src)))
(TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (TOK_FUNCTION
TOK_INT (TOK_TABLE_OR_COL key)))))) t)) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE))
(TOK_SELECT (TOK_SELEXPR (TOK_TABLE_OR_COL key)))))
+
+STAGE DEPENDENCIES:
+  Stage-1 is a root stage
+  Stage-0 is a root stage
+
+STAGE PLANS:
+  Stage: Stage-1
+    Map Reduce
+      Alias -> Map Operator Tree:
+        t:src 
+          TableScan
+            alias: src
+            Select Operator
+              expressions:
+                    expr: UDFToInteger(key)
+                    type: int
+              outputColumnNames: _col0
+              Select Operator
+                expressions:
+                      expr: _col0
+                      type: int
+                outputColumnNames: _col0
+                File Output Operator
+                  compressed: false
+                  GlobalTableId: 0
+                  table:
+                      input format: org.apache.hadoop.mapred.TextInputFormat
+                      output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
+
+  Stage: Stage-0
+    Fetch Operator
+      limit: -1
+
+
+PREHOOK: query: --backward
+explain select key2 from (select cast(key as int) key2 from src )t
+PREHOOK: type: QUERY
+POSTHOOK: query: --backward
+explain select key2 from (select cast(key as int) key2 from src )t
+POSTHOOK: type: QUERY
+ABSTRACT SYNTAX TREE:
+  (TOK_QUERY (TOK_FROM (TOK_SUBQUERY (TOK_QUERY (TOK_FROM (TOK_TABREF (TOK_TABNAME src)))
(TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (TOK_FUNCTION
TOK_INT (TOK_TABLE_OR_COL key)) key2)))) t)) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE))
(TOK_SELECT (TOK_SELEXPR (TOK_TABLE_OR_COL key2)))))
+
+STAGE DEPENDENCIES:
+  Stage-1 is a root stage
+  Stage-0 is a root stage
+
+STAGE PLANS:
+  Stage: Stage-1
+    Map Reduce
+      Alias -> Map Operator Tree:
+        t:src 
+          TableScan
+            alias: src
+            Select Operator
+              expressions:
+                    expr: UDFToInteger(key)
+                    type: int
+              outputColumnNames: _col0
+              Select Operator
+                expressions:
+                      expr: _col0
+                      type: int
+                outputColumnNames: _col0
+                File Output Operator
+                  compressed: false
+                  GlobalTableId: 0
+                  table:
+                      input format: org.apache.hadoop.mapred.TextInputFormat
+                      output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
+
+  Stage: Stage-0
+    Fetch Operator
+      limit: -1
+
+



Mime
View raw message