@Override public String toString() { return indexExpr.getExprString(); } }
@Override public ExprNodeDesc clone() { List<ExprNodeDesc> cloneCh = new ArrayList<ExprNodeDesc>(chidren.size()); for (ExprNodeDesc ch : chidren) { cloneCh.add(ch.clone()); } ExprNodeGenericFuncDesc clone = new ExprNodeGenericFuncDesc(typeInfo, FunctionRegistry.cloneGenericUDF(genericUDF), funcText, cloneCh); return clone; }
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()); }
public static ExprNodeDesc foldExpr(ExprNodeGenericFuncDesc funcDesc) { GenericUDF udf = funcDesc.getGenericUDF(); if (!isConstantFoldableUdf(udf, funcDesc.getChildren())) { return funcDesc; } return evaluateFunction(funcDesc.getGenericUDF(),funcDesc.getChildren(), funcDesc.getChildren()); }
@Test public void testValidateNestedExpressions() { ExprNodeColumnDesc col1Expr = new ExprNodeColumnDesc(Integer.class, "col1", "table", false); ExprNodeConstantDesc constDesc = new ExprNodeConstantDesc(new Integer(10)); GenericUDFOPGreaterThan udf = new GenericUDFOPGreaterThan(); ExprNodeGenericFuncDesc greaterExprDesc = new ExprNodeGenericFuncDesc(); greaterExprDesc.setTypeInfo(TypeInfoFactory.booleanTypeInfo); greaterExprDesc.setGenericUDF(udf); List<ExprNodeDesc> children1 = new ArrayList<ExprNodeDesc>(2); children1.add(col1Expr); children1.add(constDesc); greaterExprDesc.setChildren(children1); FakeGenericUDF udf2 = new FakeGenericUDF(); ExprNodeGenericFuncDesc nonSupportedExpr = new ExprNodeGenericFuncDesc(); nonSupportedExpr.setTypeInfo(TypeInfoFactory.booleanTypeInfo); nonSupportedExpr.setGenericUDF(udf2); GenericUDFOPAnd andUdf = new GenericUDFOPAnd(); ExprNodeGenericFuncDesc andExprDesc = new ExprNodeGenericFuncDesc(); andExprDesc.setTypeInfo(TypeInfoFactory.booleanTypeInfo); andExprDesc.setGenericUDF(andUdf); List<ExprNodeDesc> children3 = new ArrayList<ExprNodeDesc>(2); children3.add(greaterExprDesc); children3.add(nonSupportedExpr); andExprDesc.setChildren(children3); Vectorizer v = new Vectorizer(); v.testSetCurrentBaseWork(new MapWork()); Assert.assertTrue(v.validateExprNodeDesc(andExprDesc, "test", VectorExpressionDescriptor.Mode.FILTER, false)); }
@Test public void testFilterWithNegativeScalar() throws HiveException { ExprNodeColumnDesc col1Expr = new ExprNodeColumnDesc(Integer.class, "col1", "table", false); ExprNodeConstantDesc constDesc = new ExprNodeConstantDesc(new Integer(-10)); GenericUDFOPGreaterThan udf = new GenericUDFOPGreaterThan(); ExprNodeGenericFuncDesc exprDesc = new ExprNodeGenericFuncDesc(); exprDesc.setGenericUDF(udf); List<ExprNodeDesc> children1 = new ArrayList<ExprNodeDesc>(2); children1.add(col1Expr); children1.add(constDesc); exprDesc.setChildren(children1); List<String> columns = new ArrayList<String>(); columns.add("col0"); columns.add("col1"); columns.add("col2"); VectorizationContext vc = new VectorizationContext("name", columns); VectorExpression ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.FILTER); assertTrue(ve instanceof FilterLongColGreaterLongScalar); }
private Timestamp getTimestampScalar(ExprNodeDesc expr) throws HiveException { if (expr instanceof ExprNodeGenericFuncDesc && ((ExprNodeGenericFuncDesc) expr).getGenericUDF() instanceof GenericUDFTimestamp) { return evaluateCastToTimestamp(expr); } if (!(expr instanceof ExprNodeConstantDesc)) { throw new HiveException("Constant timestamp value expected for expression argument. " + "Non-constant argument not supported for vectorization."); } ExprNodeConstantDesc constExpr = (ExprNodeConstantDesc) expr; String constTypeString = constExpr.getTypeString(); if (isStringFamily(constTypeString) || isDatetimeFamily(constTypeString)) { // create expression tree with type cast from string to timestamp ExprNodeGenericFuncDesc expr2 = new ExprNodeGenericFuncDesc(); GenericUDFTimestamp f = new GenericUDFTimestamp(); expr2.setGenericUDF(f); ArrayList<ExprNodeDesc> children = new ArrayList<>(); children.add(expr); expr2.setChildren(children); // initialize and evaluate return evaluateCastToTimestamp(expr2); } throw new HiveException("Udf: unhandled constant type for scalar argument. " + "Expecting string/date/timestamp."); }
} else if (!FunctionRegistry.isConsistentWithinQuery(fd.getGenericUDF())) { newfd = new ExprNodeConstantDesc(fd.getTypeInfo(), null); } else { newfd = new ExprNodeGenericFuncDesc(fd.getTypeInfo(), fd.getGenericUDF(), children);
ExprNodeGenericFuncDesc fd = (ExprNodeGenericFuncDesc) nd; if (LOG.isDebugEnabled()) { String err = "Processing " + fd.getExprString() + " " + fd.getGenericUDF().getUdfName() + " outputs "; for (Object child : nodeOutputs) { NodeInfoWrapper wrapper = (NodeInfoWrapper) child; return handleUdfOr(ctx, fd, nodeOutputs); } else if (FunctionRegistry.isIn(fd)) { List<ExprNodeDesc> children = fd.getChildren(); } else if (fd.getGenericUDF() instanceof GenericUDFStruct) { } else if (!FunctionRegistry.isConsistentWithinQuery(fd.getGenericUDF())) {
new ExprNodeGenericFuncDesc(outputTypeInfo, genericUdf, children); negativeTestMode, batchSource, exprDesc.getWritableObjectInspector(), outputTypeInfo, resultObjects);
@Test public void testSerializeTimestamp() { Timestamp ts = Timestamp.ofEpochMilli(1374554702000L, 123456); ExprNodeConstantDesc constant = new ExprNodeConstantDesc(ts); List<ExprNodeDesc> children = new ArrayList<ExprNodeDesc>(1); children.add(constant); ExprNodeGenericFuncDesc desc = new ExprNodeGenericFuncDesc(TypeInfoFactory.timestampTypeInfo, new GenericUDFFromUtcTimestamp(), children); assertEquals(desc.getExprString(), SerializationUtilities.deserializeExpression( SerializationUtilities.serializeExpression(desc)).getExprString()); }
ExprNodeGenericFuncDesc funcDesc = (ExprNodeGenericFuncDesc) desc; GenericUDF udf = funcDesc.getGenericUDF(); if (udf instanceof GenericUDFOPNot) { ExprNodeDesc child = funcDesc.getChildren().get(0); if (child instanceof ExprNodeGenericFuncDesc) { ExprNodeGenericFuncDesc childDesc = (ExprNodeGenericFuncDesc)child; GenericUDF childUDF = childDesc.getGenericUDF(); List<ExprNodeDesc> grandChildren = child.getChildren(); return ExprNodeGenericFuncDesc.newInstance( childUDF.negative(), newGrandChildren); for(ExprNodeDesc grandChild : grandChildren) { newGrandChildren.add(foldNegative( ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPNot(), Arrays.asList(grandChild)))); return ExprNodeGenericFuncDesc.newInstance( childUDF.negative(), newGrandChildren); newGrandChildren.add(foldNegative(grandChild)); childDesc.setChildren(newGrandChildren); return funcDesc;
new ExprNodeGenericFuncDesc( TypeInfoFactory.booleanTypeInfo, udf, children); nullTestMode, batchSource, exprDesc.getWritableObjectInspector(), outputTypeInfo, resultObjects)) { " does not match row-mode expected result is NULL which means false here" + " row values " + Arrays.toString(randomRows[i]) + " exprDesc " + exprDesc.toString()); (expectedResult == null ? "YES" : "NO result " + expectedResult.toString()) + " row values " + Arrays.toString(randomRows[i]) + " exprDesc " + exprDesc.toString()); " (" + expectedResult.getClass().getSimpleName() + ")" + " row values " + Arrays.toString(randomRows[i]) + " exprDesc " + exprDesc.toString());
FilterOperator filterOp = (FilterOperator) op; ExprNodeDesc filterExprNode = filterOp.getConf().getPredicate(); if (tableScanExprNode.isSame(filterExprNode)) { if (tableScanExprNode.getGenericUDF() instanceof GenericUDFOPOr) { for (ExprNodeDesc childExprNode : tableScanExprNode.getChildren()) { if (childExprNode.isSame(filterExprNode)) { ExprNodeGenericFuncDesc newPred = ExprNodeGenericFuncDesc.newInstance( new GenericUDFOPAnd(), Arrays.<ExprNodeDesc>asList(tableScanExprNode.clone(), filterExprNode)); filterOp.getConf().setPredicate(newPred); } else { Operator<FilterDesc> newOp = OperatorFactory.get(tsOp.getCompilationOpContext(), new FilterDesc(tableScanExprNode.clone(), false), new RowSchema(tsOp.getSchema().getSignature())); tsOp.replaceChild(op, newOp);
public static boolean isStructUDF(ExprNodeDesc columnDesc) { if (columnDesc instanceof ExprNodeGenericFuncDesc) { ExprNodeGenericFuncDesc exprNodeGenericFuncDesc = (ExprNodeGenericFuncDesc) columnDesc; return (exprNodeGenericFuncDesc.getGenericUDF() instanceof GenericUDFStruct); } return false; }
public static void replaceNullFiltersWithDefaultPartition(ExprNodeDesc origin, String defaultPartitionName) throws SemanticException { // Convert "ptn_col isnull" to "ptn_col = default_partition" and // "ptn_col isnotnull" to "ptn_col <> default_partition" String fnName = null; if (origin instanceof ExprNodeGenericFuncDesc) { if (((ExprNodeGenericFuncDesc) origin).getGenericUDF() instanceof GenericUDFOPNull) { fnName = "="; } else if (((ExprNodeGenericFuncDesc) origin).getGenericUDF() instanceof GenericUDFOPNotNull) { fnName = "<>"; } } // Found an expression for function "isnull" or "isnotnull" if (fnName != null) { List<ExprNodeDesc> children = origin.getChildren(); assert(children.size() == 1); ExprNodeConstantDesc defaultPartition = new ExprNodeConstantDesc(defaultPartitionName); children.add(defaultPartition); ((ExprNodeGenericFuncDesc) origin).setChildren(children); ((ExprNodeGenericFuncDesc) origin).setGenericUDF( FunctionRegistry.getFunctionInfo(fnName).getGenericUDF()); } else { if (origin.getChildren() != null) { for (ExprNodeDesc child : origin.getChildren()) { replaceNullFiltersWithDefaultPartition(child, defaultPartitionName); } } } }
private RexNode handleExplicitCast(ExprNodeGenericFuncDesc func, List<RexNode> childRexNodeLst) throws CalciteSemanticException { RexNode castExpr = null; if (childRexNodeLst != null && childRexNodeLst.size() == 1) { GenericUDF udf = func.getGenericUDF(); if ((udf instanceof GenericUDFToChar) || (udf instanceof GenericUDFToVarchar) || (udf instanceof GenericUDFToString) || (udf instanceof GenericUDFToDecimal) || (udf instanceof GenericUDFToDate) || (udf instanceof GenericUDFTimestamp) || (udf instanceof GenericUDFToTimestampLocalTZ) || (udf instanceof GenericUDFToBinary) || castExprUsingUDFBridge(udf)) { castExpr = cluster.getRexBuilder().makeAbstractCast( TypeConverter.convert(func.getTypeInfo(), cluster.getTypeFactory()), childRexNodeLst.get(0)); } } return castExpr; }
private void addChildren(ExprNodeGenericFuncDesc node) { for(ExprNodeDesc child: node.getChildren()) { parse(child); } }
public static ExprNodeGenericFuncDesc newInstance(GenericUDF genericUDF, List<ExprNodeDesc> children) throws UDFArgumentException { return newInstance(genericUDF, null, children); }
static NodeInfoWrapper getResultWrapFromResults(Boolean[] results, ExprNodeGenericFuncDesc fd, Object[] nodeOutputs) { Boolean ifAgree = ifResultsAgree(results); if (ifAgree == null) { return new NodeInfoWrapper(WalkState.DIVIDED, results, getOutExpr(fd, nodeOutputs)); } else if (ifAgree.booleanValue() == true) { return new NodeInfoWrapper(WalkState.TRUE, null, new ExprNodeConstantDesc(fd.getTypeInfo(), Boolean.TRUE)); } else { return new NodeInfoWrapper(WalkState.FALSE, null, new ExprNodeConstantDesc(fd.getTypeInfo(), Boolean.FALSE)); } }