/** * Convert the ColumnList to FieldSchema list. */ public static List<FieldSchema> getFieldSchemasFromColumnList( List<ExprNodeDesc> cols, String fieldPrefix) { List<FieldSchema> schemas = new ArrayList<FieldSchema>(cols.size()); for (int i = 0; i < cols.size(); i++) { schemas.add(HiveMetaStoreUtils.getFieldSchemaFromTypeInfo(fieldPrefix + i, cols.get(i).getTypeInfo())); } return schemas; }
private void addToGBExpr(RowResolver groupByOutputRowResolver, RowResolver groupByInputRowResolver, ASTNode grpbyExpr, ExprNodeDesc grpbyExprNDesc, List<ExprNodeDesc> gbExprNDescLst, List<String> outputColumnNames) { // TODO: Should we use grpbyExprNDesc.getTypeInfo()? what if expr is // UDF int i = gbExprNDescLst.size(); String field = SemanticAnalyzer.getColumnInternalName(i); outputColumnNames.add(field); gbExprNDescLst.add(grpbyExprNDesc); ColumnInfo oColInfo = new ColumnInfo(field, grpbyExprNDesc.getTypeInfo(), null, false); groupByOutputRowResolver.putExpression(grpbyExpr, oColInfo); addAlternateGByKeyMappings(grpbyExpr, oColInfo, groupByInputRowResolver, groupByOutputRowResolver); }
private static boolean isWideningCast(ExprNodeGenericFuncDesc engfd) { GenericUDF udf = engfd.getGenericUDF(); if (!FunctionRegistry.isOpCast(udf)) { // It is not a cast return false; } return TypeInfoUtils.implicitConvertible(engfd.getChildren().get(0).getTypeInfo(), engfd.getTypeInfo()); }
/** * Convert the ColumnList to FieldSchema list. */ public static List<FieldSchema> getFieldSchemasFromColumnList( List<ExprNodeDesc> cols, List<String> outputColumnNames, int start, String fieldPrefix) { List<FieldSchema> schemas = new ArrayList<FieldSchema>(cols.size()); for (int i = 0; i < cols.size(); i++) { schemas.add(HiveMetaStoreUtils.getFieldSchemaFromTypeInfo(fieldPrefix + outputColumnNames.get(i + start), cols.get(i).getTypeInfo())); } return schemas; }
TypeInfo tLeft = children.get(0).getTypeInfo(); TypeInfo tRight = children.get(1).getTypeInfo(); commonType = FunctionRegistry.getCommonClassForComparison(tLeft, tRight); if (commonType == null) { TypeInfo colTi = children.get(0).getTypeInfo(); if (colTi.getCategory() != Category.PRIMITIVE) { return colTi; // Handled later, only struct will be supported.
private void addToGBExpr(RowResolver groupByOutputRowResolver, RowResolver groupByInputRowResolver, ASTNode grpbyExpr, ExprNodeDesc grpbyExprNDesc, List<ExprNodeDesc> gbExprNDescLst, List<String> outputColumnNames) { // TODO: Should we use grpbyExprNDesc.getTypeInfo()? what if expr is // UDF int i = gbExprNDescLst.size(); String field = SemanticAnalyzer.getColumnInternalName(i); outputColumnNames.add(field); gbExprNDescLst.add(grpbyExprNDesc); ColumnInfo oColInfo = new ColumnInfo(field, grpbyExprNDesc.getTypeInfo(), null, false); groupByOutputRowResolver.putExpression(grpbyExpr, oColInfo); addAlternateGByKeyMappings(grpbyExpr, oColInfo, groupByInputRowResolver, groupByOutputRowResolver); }
/** * Convert the ColumnList to FieldSchema list. */ public static List<FieldSchema> getFieldSchemasFromColumnList( List<ExprNodeDesc> cols, String fieldPrefix) { List<FieldSchema> schemas = new ArrayList<FieldSchema>(cols.size()); for (int i = 0; i < cols.size(); i++) { schemas.add(MetaStoreUtils.getFieldSchemaFromTypeInfo(fieldPrefix + i, cols.get(i).getTypeInfo())); } return schemas; }
private static boolean isWideningCast(ExprNodeGenericFuncDesc engfd) { GenericUDF udf = engfd.getGenericUDF(); if (!FunctionRegistry.isOpCast(udf)) { // It is not a cast return false; } return TypeInfoUtils.implicitConvertible(engfd.getChildren().get(0).getTypeInfo(), engfd.getTypeInfo()); }
private static void addGrpSetCol(boolean createConstantExpr, String grpSetIDExprName, boolean addReducePrefixToColInfoName, List<ExprNodeDesc> exprLst, List<String> outputColumnNames, List<ColumnInfo> colInfoLst, Map<String, ExprNodeDesc> colExprMap) throws SemanticException { String outputColName = null; ExprNodeDesc grpSetColExpr = null; if (createConstantExpr) { grpSetColExpr = new ExprNodeConstantDesc("0L"); } else { grpSetColExpr = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, grpSetIDExprName, null, false); } exprLst.add(grpSetColExpr); outputColName = SemanticAnalyzer.getColumnInternalName(exprLst.size() - 1); outputColumnNames.add(outputColName); String internalColName = outputColName; if (addReducePrefixToColInfoName) { internalColName = Utilities.ReduceField.KEY.toString() + "." + outputColName; } colInfoLst.add(new ColumnInfo(internalColName, grpSetColExpr.getTypeInfo(), null, true)); colExprMap.put(internalColName, grpSetColExpr); }
/** * Convert the ColumnList to FieldSchema list. */ public static List<FieldSchema> getFieldSchemasFromColumnList( List<ExprNodeDesc> cols, List<String> outputColumnNames, int start, String fieldPrefix) { List<FieldSchema> schemas = new ArrayList<FieldSchema>(cols.size()); for (int i = 0; i < cols.size(); i++) { schemas.add(MetaStoreUtils.getFieldSchemaFromTypeInfo(fieldPrefix + outputColumnNames.get(i + start), cols.get(i).getTypeInfo())); } return schemas; }
TypeInfo tLeft = children.get(0).getTypeInfo(); TypeInfo tRight = children.get(1).getTypeInfo(); commonType = FunctionRegistry.getCommonClassForComparison(tLeft, tRight); if (commonType == null) { TypeInfo colTi = children.get(0).getTypeInfo(); if (colTi.getCategory() != Category.PRIMITIVE) { return colTi; // Handled later, only struct will be supported.
private static void addGrpSetCol(boolean createConstantExpr, String grpSetIDExprName, boolean addReducePrefixToColInfoName, List<ExprNodeDesc> exprLst, List<String> outputColumnNames, List<ColumnInfo> colInfoLst, Map<String, ExprNodeDesc> colExprMap) throws SemanticException { String outputColName = null; ExprNodeDesc grpSetColExpr = null; if (createConstantExpr) { grpSetColExpr = new ExprNodeConstantDesc("0"); } else { grpSetColExpr = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, grpSetIDExprName, null, false); } exprLst.add(grpSetColExpr); outputColName = SemanticAnalyzer.getColumnInternalName(exprLst.size() - 1); outputColumnNames.add(outputColName); String internalColName = outputColName; if (addReducePrefixToColInfoName) { internalColName = Utilities.ReduceField.KEY.toString() + "." + outputColName; } colInfoLst.add(new ColumnInfo(internalColName, grpSetColExpr.getTypeInfo(), null, true)); colExprMap.put(internalColName, grpSetColExpr); }
private static Pair<ArrayList<ColumnInfo>, Set<Integer>> createColInfos( List<RexNode> calciteExprs, List<ExprNodeDesc> hiveExprs, List<String> projNames, OpAttr inpOpAf) { if (hiveExprs.size() != projNames.size()) { throw new RuntimeException("Column expressions list doesn't match Column Names list"); } RexNode rexN; ExprNodeDesc pe; ArrayList<ColumnInfo> colInfos = new ArrayList<ColumnInfo>(); boolean vc; Set<Integer> newVColSet = new HashSet<Integer>(); for (int i = 0; i < hiveExprs.size(); i++) { pe = hiveExprs.get(i); rexN = calciteExprs.get(i); vc = false; if (rexN instanceof RexInputRef) { if (inpOpAf.vcolsInCalcite.contains(((RexInputRef) rexN).getIndex())) { newVColSet.add(i); vc = true; } } colInfos .add(new ColumnInfo(projNames.get(i), pe.getTypeInfo(), inpOpAf.tabAlias, vc)); } return new Pair<ArrayList<ColumnInfo>, Set<Integer>>(colInfos, newVColSet); }
private VectorExpression getCastToLongExpression(List<ExprNodeDesc> childExpr, PrimitiveCategory integerPrimitiveCategory) throws HiveException { ExprNodeDesc child = childExpr.get(0); String inputType = childExpr.get(0).getTypeString(); if (child instanceof ExprNodeConstantDesc) { // Return a constant vector expression Object constantValue = ((ExprNodeConstantDesc) child).getValue(); Long longValue = castConstantToLong(constantValue, child.getTypeInfo(), integerPrimitiveCategory); return getConstantVectorExpression(longValue, TypeInfoFactory.longTypeInfo, VectorExpressionDescriptor.Mode.PROJECTION); } // Float family, timestamp are handled via descriptor based lookup, int family needs // special handling. if (isIntFamily(inputType)) { // integer and boolean types require no conversion, so use a no-op return getIdentityExpression(childExpr); } return null; }
List<ColumnInfo> mapGBColInfoLst = inOp.getSchema().getSignature(); ArrayList<ExprNodeDesc> valueKeys = null; if (aggStartPos >= mapGBColInfoLst.size()) { valueKeys = new ArrayList<ExprNodeDesc>(); } else { valueKeys = ExprNodeDescUtils.genExprNodeDesc(inOp, aggStartPos, mapGBColInfoLst.size() - 1, true, setColToNonVirtual); for (int i = 0; i < valueKeys.size(); ++i) { + outputColName, valueKeys.get(i).getTypeInfo(), tabAlias, false); colInfoLst.add(colInfo); colExprMap.put(colInfo.getInternalName(), valueKeys.get(i));
for (int i = 0; i < length; i++) { schemas.add(HiveMetaStoreUtils.getFieldSchemaFromTypeInfo( fieldPrefix + outputColumnNames.get(i), cols.get(i).getTypeInfo())); for (int i : distinctCols) { names.add(HiveConf.getColumnInternalName(numExprs)); types.add(cols.get(i).getTypeInfo()); numExprs++; if (outputColumnNames.size() - length > 0) { schemas.add(HiveMetaStoreUtils.getFieldSchemaFromTypeInfo( fieldPrefix + outputColumnNames.get(length),
private VectorExpression getCastToBoolean(List<ExprNodeDesc> childExpr) throws HiveException { ExprNodeDesc child = childExpr.get(0); TypeInfo inputTypeInfo = child.getTypeInfo(); String inputType = inputTypeInfo.toString(); if (child instanceof ExprNodeConstantDesc) { if (null == ((ExprNodeConstantDesc)child).getValue()) { return getConstantVectorExpression(null, TypeInfoFactory.booleanTypeInfo, VectorExpressionDescriptor.Mode.PROJECTION); } // Don't do constant folding here. Wait until the optimizer is changed to do it. // Family of related JIRAs: HIVE-7421, HIVE-7422, and HIVE-7424. return null; } // Long and double are handled using descriptors, string needs to be specially handled. if (isStringFamily(inputType)) { return createVectorExpression(CastStringToBoolean.class, childExpr, VectorExpressionDescriptor.Mode.PROJECTION, TypeInfoFactory.booleanTypeInfo); } return null; }
List<ColumnInfo> mapGBColInfoLst = inOp.getSchema().getSignature(); ArrayList<ExprNodeDesc> valueKeys = null; if (aggStartPos >= mapGBColInfoLst.size()) { valueKeys = new ArrayList<ExprNodeDesc>(); } else { valueKeys = ExprNodeDescUtils.genExprNodeDesc(inOp, aggStartPos, mapGBColInfoLst.size() - 1, true, setColToNonVirtual); for (int i = 0; i < valueKeys.size(); ++i) { + outputColName, valueKeys.get(i).getTypeInfo(), tabAlias, false); colInfoLst.add(colInfo); colExprMap.put(colInfo.getInternalName(), valueKeys.get(i));
private static Pair<ArrayList<ColumnInfo>, Set<Integer>> createColInfos( List<RexNode> calciteExprs, List<ExprNodeDesc> hiveExprs, List<String> projNames, OpAttr inpOpAf) { if (hiveExprs.size() != projNames.size()) { throw new RuntimeException("Column expressions list doesn't match Column Names list"); } RexNode rexN; ExprNodeDesc pe; ArrayList<ColumnInfo> colInfos = new ArrayList<ColumnInfo>(); boolean vc; Set<Integer> newVColSet = new HashSet<Integer>(); for (int i = 0; i < hiveExprs.size(); i++) { pe = hiveExprs.get(i); rexN = calciteExprs.get(i); vc = false; if (rexN instanceof RexInputRef) { if (inpOpAf.vcolsInCalcite.contains(((RexInputRef) rexN).getIndex())) { newVColSet.add(i); vc = true; } } colInfos .add(new ColumnInfo(projNames.get(i), pe.getTypeInfo(), inpOpAf.tabAlias, vc)); } return new Pair<ArrayList<ColumnInfo>, Set<Integer>>(colInfos, newVColSet); }
private VectorExpression getCastToLongExpression(List<ExprNodeDesc> childExpr, PrimitiveCategory integerPrimitiveCategory) throws HiveException { ExprNodeDesc child = childExpr.get(0); String inputType = childExpr.get(0).getTypeString(); if (child instanceof ExprNodeConstantDesc) { // Return a constant vector expression Object constantValue = ((ExprNodeConstantDesc) child).getValue(); Long longValue = castConstantToLong(constantValue, child.getTypeInfo(), integerPrimitiveCategory); return getConstantVectorExpression(longValue, TypeInfoFactory.longTypeInfo, VectorExpressionDescriptor.Mode.PROJECTION); } // Float family, timestamp are handled via descriptor based lookup, int family needs // special handling. if (isIntFamily(inputType)) { // integer and boolean types require no conversion, so use a no-op return getIdentityExpression(childExpr); } return null; }