private static void addBuiltInFunction(Class<? extends FunctionExpression> f) throws Exception { BuiltInFunction d = f.getAnnotation(BuiltInFunction.class); if (d == null) { return; } int nArgs = d.args().length; BuiltInFunctionInfo value = new BuiltInFunctionInfo(f, d); if (d.classType() != FunctionParseNode.FunctionClassType.ABSTRACT) { BUILT_IN_FUNCTION_MULTIMAP.put(value.getName(), value); } if (d.classType() != FunctionParseNode.FunctionClassType.DERIVED) { do { // Add function to function map, throwing if conflicts found // Add entry for each possible version of function based on arguments that are not required to be present (i.e. arg with default value) BuiltInFunctionKey key = new BuiltInFunctionKey(value.getName(), nArgs); if (BUILT_IN_FUNCTION_MAP.put(key, value) != null) { throw new IllegalStateException("Multiple " + value.getName() + " functions with " + nArgs + " arguments"); } } while (--nArgs >= 0 && d.args()[nArgs].defaultValue().length() > 0); // Look for default values that aren't at the end and throw while (--nArgs >= 0) { if (d.args()[nArgs].defaultValue().length() > 0) { throw new IllegalStateException("Function " + value.getName() + " has non trailing default value of '" + d.args()[nArgs].defaultValue() + "'. Only trailing arguments may have default values"); } } } } /**
public List<Expression> validate(List<Expression> children, StatementContext context) throws SQLException { BuiltInFunctionInfo info = this.getInfo(); BuiltInFunctionArgInfo[] args = info.getArgs(); if (args.length < children.size() || info.getRequiredArgCount() > children.size()) { throw new FunctionNotFoundException(this.name); for (int i = children.size(); i < info.getArgs().length; i++) { moreChildren.add(LiteralExpression.newConstant(null, args[i].allowedTypes.length == 0 ? null : PDataTypeFactory.getInstance().instanceFromClass(args[i].allowedTypes[0]), Determinism.ALWAYS));
Constructor<? extends FunctionExpression> fCtor = info.getFuncCtor(); if (fCtor == null) { fCtor = getExpressionCtor(info.func, null);
public List<Expression> validate(List<Expression> children, StatementContext context) throws SQLException { BuiltInFunctionInfo info = this.getInfo(); BuiltInFunctionArgInfo[] args = info.getArgs(); if (args.length < children.size() || info.getRequiredArgCount() > children.size()) { throw new FunctionNotFoundException(this.name); for (int i = children.size(); i < info.getArgs().length; i++) { moreChildren.add(LiteralExpression.newConstant(null, args[i].allowedTypes.length == 0 ? null : PDataTypeFactory.getInstance().instanceFromClass(args[i].allowedTypes[0]), Determinism.ALWAYS));
public List<Expression> validate(List<Expression> children, StatementContext context) throws SQLException { BuiltInFunctionInfo info = this.getInfo(); BuiltInFunctionArgInfo[] args = info.getArgs(); if (args.length < children.size() || info.getRequiredArgCount() > children.size()) { throw new FunctionNotFoundException(this.name); for (int i = children.size(); i < info.getArgs().length; i++) { moreChildren.add(LiteralExpression.newConstant(null, args[i].allowedTypes.length == 0 ? null : PDataTypeFactory.getInstance().instanceFromClass(args[i].allowedTypes[0]), Determinism.ALWAYS));
if(node instanceof UDFParseNode) { function = context.getResolver().resolveFunction(node.getName()); BuiltInFunctionInfo info = new BuiltInFunctionInfo(function); node = new UDFParseNode(node.getName(), node.getChildren(), info); for (int i = 0; i < info.getRequiredArgCount(); i++) {
public static void validateFunctionArguement(BuiltInFunctionInfo info, int childIndex, Expression child) throws ArgumentTypeMismatchException, ValueRangeExcpetion { BuiltInFunctionArgInfo arg = info.getArgs()[childIndex]; if (arg.getAllowedTypes().length > 0) { boolean isCoercible = false; child.getDataType(), info.getName() + " argument " + (childIndex + 1)); LiteralExpression maxValue = arg.getMaxValue(); if (minValue != null && minValue.getDataType().compareTo(minValue.getValue(), valueExp.getValue(), valueExp.getDataType()) > 0) { throw new ValueRangeExcpetion(minValue, maxValue == null ? "" : maxValue, valueExp.getValue(), info.getName() + " argument " + (childIndex + 1)); throw new ValueRangeExcpetion(minValue == null ? "" : minValue, maxValue, valueExp.getValue(), info.getName() + " argument " + (childIndex + 1)); throw new ArgumentTypeMismatchException("constant", child.toString(), info.getName() + " argument " + (childIndex + 1)); if (!arg.getAllowedValues().contains(value.toString().toUpperCase())) { throw new ArgumentTypeMismatchException(Arrays.toString(arg.getAllowedValues().toArray(new String[0])), value.toString(), info.getName() + " argument " + (childIndex + 1));
if(node instanceof UDFParseNode) { function = context.getResolver().resolveFunction(node.getName()); BuiltInFunctionInfo info = new BuiltInFunctionInfo(function); node = new UDFParseNode(node.getName(), node.getChildren(), info); for (int i = 0; i < info.getRequiredArgCount(); i++) {
public static void validateFunctionArguement(BuiltInFunctionInfo info, int childIndex, Expression child) throws ArgumentTypeMismatchException, ValueRangeExcpetion { BuiltInFunctionArgInfo arg = info.getArgs()[childIndex]; if (arg.getAllowedTypes().length > 0) { boolean isCoercible = false; child.getDataType(), info.getName() + " argument " + (childIndex + 1)); LiteralExpression maxValue = arg.getMaxValue(); if (minValue != null && minValue.getDataType().compareTo(minValue.getValue(), valueExp.getValue(), valueExp.getDataType()) > 0) { throw new ValueRangeExcpetion(minValue, maxValue == null ? "" : maxValue, valueExp.getValue(), info.getName() + " argument " + (childIndex + 1)); throw new ValueRangeExcpetion(minValue == null ? "" : minValue, maxValue, valueExp.getValue(), info.getName() + " argument " + (childIndex + 1)); throw new ArgumentTypeMismatchException("constant", child.toString(), info.getName() + " argument " + (childIndex + 1)); if (!arg.getAllowedValues().contains(value.toString().toUpperCase())) { throw new ArgumentTypeMismatchException(Arrays.toString(arg.getAllowedValues().toArray(new String[0])), value.toString(), info.getName() + " argument " + (childIndex + 1));
Constructor<? extends FunctionExpression> fCtor = info.getFuncCtor(); if (fCtor == null) { fCtor = getExpressionCtor(info.func, null);
Constructor<? extends FunctionExpression> fCtor = info.getFuncCtor(); if (fCtor == null) { fCtor = getExpressionCtor(info.func, null);
private static void addBuiltInFunction(Class<? extends FunctionExpression> f) throws Exception { BuiltInFunction d = f.getAnnotation(BuiltInFunction.class); if (d == null) { return; } int nArgs = d.args().length; BuiltInFunctionInfo value = new BuiltInFunctionInfo(f, d); if (d.classType() != FunctionParseNode.FunctionClassType.ABSTRACT) { BUILT_IN_FUNCTION_MULTIMAP.put(value.getName(), value); } if (d.classType() != FunctionParseNode.FunctionClassType.DERIVED) { do { // Add function to function map, throwing if conflicts found // Add entry for each possible version of function based on arguments that are not required to be present (i.e. arg with default value) BuiltInFunctionKey key = new BuiltInFunctionKey(value.getName(), nArgs); if (BUILT_IN_FUNCTION_MAP.put(key, value) != null) { throw new IllegalStateException("Multiple " + value.getName() + " functions with " + nArgs + " arguments"); } } while (--nArgs >= 0 && d.args()[nArgs].defaultValue().length() > 0); // Look for default values that aren't at the end and throw while (--nArgs >= 0) { if (d.args()[nArgs].defaultValue().length() > 0) { throw new IllegalStateException("Function " + value.getName() + " has non trailing default value of '" + d.args()[nArgs].defaultValue() + "'. Only trailing arguments may have default values"); } } } } /**
private static void addBuiltInFunction(Class<? extends FunctionExpression> f) throws Exception { BuiltInFunction d = f.getAnnotation(BuiltInFunction.class); if (d == null) { return; } int nArgs = d.args().length; BuiltInFunctionInfo value = new BuiltInFunctionInfo(f, d); if (d.classType() != FunctionParseNode.FunctionClassType.ABSTRACT) { BUILT_IN_FUNCTION_MULTIMAP.put(value.getName(), value); } if (d.classType() != FunctionParseNode.FunctionClassType.DERIVED) { do { // Add function to function map, throwing if conflicts found // Add entry for each possible version of function based on arguments that are not required to be present (i.e. arg with default value) BuiltInFunctionKey key = new BuiltInFunctionKey(value.getName(), nArgs); if (BUILT_IN_FUNCTION_MAP.put(key, value) != null) { throw new IllegalStateException("Multiple " + value.getName() + " functions with " + nArgs + " arguments"); } } while (--nArgs >= 0 && d.args()[nArgs].defaultValue().length() > 0); // Look for default values that aren't at the end and throw while (--nArgs >= 0) { if (d.args()[nArgs].defaultValue().length() > 0) { throw new IllegalStateException("Function " + value.getName() + " has non trailing default value of '" + d.args()[nArgs].defaultValue() + "'. Only trailing arguments may have default values"); } } } } /**
public FunctionParseNode function(String name, List<ParseNode> valueNodes, List<ParseNode> columnNodes, boolean isAscending) { List<ParseNode> args = Lists.newArrayListWithExpectedSize(columnNodes.size() + valueNodes.size() + 1); args.addAll(columnNodes); args.add(new LiteralParseNode(Boolean.valueOf(isAscending))); args.addAll(valueNodes); BuiltInFunctionInfo info = getInfo(name, args); if(info==null) { return new UDFParseNode(name,args,info); } Constructor<? extends FunctionParseNode> ctor = info.getNodeCtor(); if (ctor == null) { return new AggregateFunctionWithinGroupParseNode(name, args, info); } else { try { return ctor.newInstance(name, args, info); } catch (Exception e) { throw new RuntimeException(e); } } }
public FunctionParseNode function(String name, List<ParseNode> valueNodes, List<ParseNode> columnNodes, boolean isAscending) { List<ParseNode> args = Lists.newArrayListWithExpectedSize(columnNodes.size() + valueNodes.size() + 1); args.addAll(columnNodes); args.add(new LiteralParseNode(Boolean.valueOf(isAscending))); args.addAll(valueNodes); BuiltInFunctionInfo info = getInfo(name, args); if(info==null) { return new UDFParseNode(name,args,info); } Constructor<? extends FunctionParseNode> ctor = info.getNodeCtor(); if (ctor == null) { return new AggregateFunctionWithinGroupParseNode(name, args, info); } else { try { return ctor.newInstance(name, args, info); } catch (Exception e) { throw new RuntimeException(e); } } }
public FunctionParseNode function(String name, List<ParseNode> args) { BuiltInFunctionInfo info = getInfo(name, args); if (info == null) { return new UDFParseNode(name, args, info); } Constructor<? extends FunctionParseNode> ctor = info.getNodeCtor(); if (ctor == null) { return info.isAggregate() ? new AggregateFunctionParseNode(name, args, info) : new FunctionParseNode(name, args, info); } else { try { return ctor.newInstance(name, args, info); } catch (Exception e) { throw new RuntimeException(e); } } }
public FunctionParseNode function(String name, List<ParseNode> args) { BuiltInFunctionInfo info = getInfo(name, args); if (info == null) { return new UDFParseNode(name, args, info); } Constructor<? extends FunctionParseNode> ctor = info.getNodeCtor(); if (ctor == null) { return info.isAggregate() ? new AggregateFunctionParseNode(name, args, info) : new FunctionParseNode(name, args, info); } else { try { return ctor.newInstance(name, args, info); } catch (Exception e) { throw new RuntimeException(e); } } }
public boolean isAggregate() { if(getInfo()==null) return false; return getInfo().isAggregate(); }
public boolean isAggregate() { if(getInfo()==null) return false; return getInfo().isAggregate(); }
if(node instanceof UDFParseNode) { function = context.getResolver().resolveFunction(node.getName()); BuiltInFunctionInfo info = new BuiltInFunctionInfo(function); node = new UDFParseNode(node.getName(), node.getChildren(), info); for (int i = 0; i < info.getRequiredArgCount(); i++) {