private void replaceExprNode(DynamicListContext ctx, FilterDesc desc, ExprNodeDesc node) { if (ctx.grandParent == null) { desc.setPredicate(node); } else { int i = ctx.grandParent.getChildren().indexOf(ctx.parent); ctx.grandParent.getChildren().remove(i); ctx.grandParent.getChildren().add(i, node); } }
private void replaceExprNode(DynamicListContext ctx, FilterDesc desc, ExprNodeDesc node) { if (ctx.grandParent == null) { desc.setPredicate(node); } else { int i = ctx.grandParent.getChildren().indexOf(ctx.parent); ctx.grandParent.getChildren().remove(i); ctx.grandParent.getChildren().add(i, node); } }
public static ExprNodeColumnDesc getColumnExpr(ExprNodeDesc expr) { while (FunctionRegistry.isOpCast(expr)) { expr = expr.getChildren().get(0); } return (expr instanceof ExprNodeColumnDesc) ? (ExprNodeColumnDesc)expr : null; }
public static ExprNodeColumnDesc getColumnExpr(ExprNodeDesc expr) { while (FunctionRegistry.isOpCast(expr)) { expr = expr.getChildren().get(0); } return (expr instanceof ExprNodeColumnDesc) ? (ExprNodeColumnDesc)expr : null; }
private boolean checkReferences(ExprNodeDesc expr, Set<String> funcOutputs, Set<String> ref) { if (expr instanceof ExprNodeColumnDesc) { String col = ((ExprNodeColumnDesc) expr).getColumn(); if (funcOutputs.contains(col) && !ref.add(col)) { return false; } } if (expr.getChildren() != null) { for (ExprNodeDesc child : expr.getChildren()) { if (!checkReferences(child, funcOutputs, ref)) { return false; } } } return true; }
private boolean checkExpression(ExprNodeDesc expr) { if (expr instanceof ExprNodeConstantDesc || expr instanceof ExprNodeColumnDesc) { return true; } if (expr instanceof ExprNodeGenericFuncDesc) { GenericUDF udf = ((ExprNodeGenericFuncDesc) expr).getGenericUDF(); if (udf instanceof GenericUDFToBinary || udf instanceof GenericUDFToChar || udf instanceof GenericUDFToDate || udf instanceof GenericUDFToDecimal || udf instanceof GenericUDFToUnixTimeStamp || udf instanceof GenericUDFToUtcTimestamp || udf instanceof GenericUDFToVarchar) { return expr.getChildren().size() == 1 && checkExpression(expr.getChildren().get(0)); } } return false; }
private static boolean isDefaultValueAllowed(ExprNodeDesc defaultValExpr) { while (FunctionRegistry.isOpCast(defaultValExpr)) { defaultValExpr = defaultValExpr.getChildren().get(0); } if(defaultValExpr instanceof ExprNodeConstantDesc) { return true; } if(defaultValExpr instanceof ExprNodeGenericFuncDesc){ for (ExprNodeDesc argument : defaultValExpr.getChildren()) { if (!isDefaultValueAllowed(argument)) { return false; } } return true; } return false; }
private static boolean checkForStatefulFunctions(List<ExprNodeDesc> list) { for (ExprNodeDesc node : list) { if (node instanceof ExprNodeGenericFuncDesc) { GenericUDF nodeUDF = ((ExprNodeGenericFuncDesc) node).getGenericUDF(); // Stateful? if (FunctionRegistry.isStateful(nodeUDF)) { return true; } if (node.getChildren() != null && !node.getChildren().isEmpty() && checkForStatefulFunctions(node.getChildren())) { return true; } } } return false; }
/** * Check if the expression node satisfies the following : * Has atleast one subexpression containing a partition/virtualcolumn and has * exactly refer to a single table alias. * @param en Expression Node Descriptor * @return true if there is atleast one subexpression with partition/virtual column * and has exactly refer to a single table alias. If not, return false. */ private boolean hasAtleastOneSubExprWithPartColOrVirtualColWithOneTableAlias(ExprNodeDesc en) { if (en == null || en.getChildren() == null) { return false; } for (ExprNodeDesc cn : en.getChildren()) { if (exprContainsOnlyPartitionColOrVirtualColOrConstants(cn) && getTableAlias(cn) != null) { return true; } } return false; }
private static boolean checkForStatefulFunctions(List<ExprNodeDesc> list) { for (ExprNodeDesc node : list) { if (node instanceof ExprNodeGenericFuncDesc) { GenericUDF nodeUDF = ((ExprNodeGenericFuncDesc) node).getGenericUDF(); // Stateful? if (FunctionRegistry.isStateful(nodeUDF)) { return true; } if (node.getChildren() != null && !node.getChildren().isEmpty() && checkForStatefulFunctions(node.getChildren())) { return true; } } } return false; }
/** * bind two predicates by AND op */ public static ExprNodeGenericFuncDesc mergePredicates(ExprNodeDesc prev, ExprNodeDesc next) { final List<ExprNodeDesc> children = new ArrayList<ExprNodeDesc>(2); if (FunctionRegistry.isOpAnd(prev)) { children.addAll(prev.getChildren()); } else { children.add(prev); } if (FunctionRegistry.isOpAnd(next)) { children.addAll(next.getChildren()); } else { children.add(next); } return new ExprNodeGenericFuncDesc(TypeInfoFactory.booleanTypeInfo, FunctionRegistry.getGenericUDFForAnd(), children); }
/** * return true if predicate is already included in source */ public static boolean containsPredicate(ExprNodeDesc source, ExprNodeDesc predicate) { if (source.isSame(predicate)) { return true; } if (FunctionRegistry.isOpAnd(source)) { if (containsPredicate(source.getChildren().get(0), predicate) || containsPredicate(source.getChildren().get(1), predicate)) { return true; } } return false; }
/** * Return false if the expression has any non deterministic function */ public static boolean isDeterministic(ExprNodeDesc desc) { if (desc instanceof ExprNodeGenericFuncDesc) { if (!FunctionRegistry.isDeterministic(((ExprNodeGenericFuncDesc)desc).getGenericUDF())) { return false; } } if (desc.getChildren() != null) { for (ExprNodeDesc child : desc.getChildren()) { if (!isDeterministic(child)) { return false; } } } return true; }
/** * 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; }
private void walkTreeAndTranslateColumnNames(ExprNodeDesc node, Map<String, String> columnMap) { if (node == null) { return; } if (node instanceof ExprNodeColumnDesc) { ExprNodeColumnDesc column = (ExprNodeColumnDesc) node; String hiveColumnName = column.getColumn().toLowerCase(); if (columnMap.containsKey(hiveColumnName)) { String dbColumnName = columnMap.get(hiveColumnName); String finalName = formatColumnName(dbColumnName); column.setColumn(finalName); } } else { if (node.getChildren() != null) { for (ExprNodeDesc childNode : node.getChildren()) { walkTreeAndTranslateColumnNames(childNode, columnMap); } } } }
/** * return true if predicate is already included in source */ public static boolean containsPredicate(ExprNodeDesc source, ExprNodeDesc predicate) { if (source.isSame(predicate)) { return true; } if (FunctionRegistry.isOpAnd(source)) { if (containsPredicate(source.getChildren().get(0), predicate) || containsPredicate(source.getChildren().get(1), predicate)) { return true; } } return false; }
/** * 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; }
/** * @param expr Expression. * @return True iff expr contains any non-native user-defined functions. */ static private boolean hasUserFunctions(ExprNodeDesc expr) { if (!(expr instanceof ExprNodeGenericFuncDesc)) { return false; } if (!FunctionRegistry.isBuiltInFuncExpr((ExprNodeGenericFuncDesc) expr)) { return true; } for (ExprNodeDesc child : expr.getChildren()) { if (hasUserFunctions(child)) { return true; } } return false; }
/** * split predicates by AND op */ public static List<ExprNodeDesc> split(ExprNodeDesc current, List<ExprNodeDesc> splitted) { if (FunctionRegistry.isOpAnd(current)) { for (ExprNodeDesc child : current.getChildren()) { split(child, splitted); } return splitted; } if (indexOf(current, splitted) < 0) { splitted.add(current); } return splitted; }
/** * split predicates by AND op */ public static List<ExprNodeDesc> split(ExprNodeDesc current, List<ExprNodeDesc> splitted) { if (FunctionRegistry.isOpAnd(current)) { for (ExprNodeDesc child : current.getChildren()) { split(child, splitted); } return splitted; } if (indexOf(current, splitted) < 0) { splitted.add(current); } return splitted; }