@SuppressWarnings({ "unchecked", "rawtypes" }) BuiltInFunctionArgInfo(Argument argument) { if (argument.enumeration().length() > 0) { this.isConstant = true; this.defaultValue = null; String packageName = FunctionExpression.class.getPackage().getName(); try { clazz = Class.forName(packageName + "." + argument.enumeration()); } catch (ClassNotFoundException e) { try { clazz = Class.forName(argument.enumeration()); } catch (ClassNotFoundException e1) { throw new IllegalStateException("The enumeration annotation '" + argument.enumeration() + "' does not resolve to a enumeration class"); } else { this.allowedValues = Collections.emptySet(); this.isConstant = argument.isConstant(); this.allowedTypes = argument.allowedTypes(); this.defaultValue = getExpFromConstant(argument.defaultValue()); this.minValue = getExpFromConstant(argument.minValue()); this.maxValue = getExpFromConstant(argument.maxValue());
@SuppressWarnings({ "unchecked", "rawtypes" }) BuiltInFunctionArgInfo(Argument argument) { if (argument.enumeration().length() > 0) { this.isConstant = true; this.defaultValue = null; String packageName = FunctionExpression.class.getPackage().getName(); try { clazz = Class.forName(packageName + "." + argument.enumeration()); } catch (ClassNotFoundException e) { try { clazz = Class.forName(argument.enumeration()); } catch (ClassNotFoundException e1) { throw new IllegalStateException("The enumeration annotation '" + argument.enumeration() + "' does not resolve to a enumeration class"); } else { this.allowedValues = Collections.emptySet(); this.isConstant = argument.isConstant(); this.allowedTypes = argument.allowedTypes(); this.defaultValue = getExpFromConstant(argument.defaultValue()); this.minValue = getExpFromConstant(argument.minValue()); this.maxValue = getExpFromConstant(argument.maxValue());
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"); } } } } /**
@BuiltInFunction(name=RegexpReplaceFunction.NAME, args= { @Argument(allowedTypes={PVarchar.class}), @Argument(allowedTypes={PVarchar.class}), @Argument(allowedTypes={PVarchar.class},defaultValue="null")}, classType = FunctionClassType.DERIVED ) public class ByteBasedRegexpReplaceFunction extends RegexpReplaceFunction { public ByteBasedRegexpReplaceFunction() { } public ByteBasedRegexpReplaceFunction(List<Expression> children) { super(children); } @Override protected AbstractBasePattern compilePatternSpec(String value) { return new JONIPattern(value, Option.MULTILINE); } }
@BuiltInFunction(name = PowerFunction.NAME, args = { @Argument(allowedTypes = { PDouble.class, PDecimal.class }), @Argument(allowedTypes = { PDouble.class, PDecimal.class }) }) public class PowerFunction extends JavaMathTwoArgumentFunction { public static final String NAME = "POWER"; public PowerFunction() { } public PowerFunction(List<Expression> children) throws SQLException { super(children); } @Override public String getName() { return NAME; } @Override protected double compute(double firstArg, double secondArg) { return Math.pow(firstArg, secondArg); } }
@BuiltInFunction(name=RegexpSubstrFunction.NAME, args= { @Argument(allowedTypes={PVarchar.class}), @Argument(allowedTypes={PVarchar.class}), @Argument(allowedTypes={PLong.class}, defaultValue="1")}, classType = FunctionClassType.DERIVED ) public class StringBasedRegexpSubstrFunction extends RegexpSubstrFunction { public StringBasedRegexpSubstrFunction() { } public StringBasedRegexpSubstrFunction(List<Expression> children) { super(children); } @Override protected AbstractBasePattern compilePatternSpec(String value) { return new JavaPattern(value, Pattern.DOTALL); } }
@BuiltInFunction(name=RegexpSubstrFunction.NAME, args= { @Argument(allowedTypes={PVarchar.class}), @Argument(allowedTypes={PVarchar.class}), @Argument(allowedTypes={PLong.class}, defaultValue="1")}, classType = FunctionClassType.DERIVED ) public class ByteBasedRegexpSubstrFunction extends RegexpSubstrFunction { public ByteBasedRegexpSubstrFunction() { } public ByteBasedRegexpSubstrFunction(List<Expression> children) { super(children); } @Override protected AbstractBasePattern compilePatternSpec(String value) { return new JONIPattern(value, Option.MULTILINE); } }
@BuiltInFunction(name=RegexpSplitFunction.NAME, args= { @Argument(allowedTypes={PVarchar.class}), @Argument(allowedTypes={PVarchar.class})}, classType = FunctionClassType.DERIVED ) public class StringBasedRegexpSplitFunction extends RegexpSplitFunction { public StringBasedRegexpSplitFunction() { } public StringBasedRegexpSplitFunction(List<Expression> children) { super(children); } @Override protected AbstractBaseSplitter compilePatternSpec(String value) { return new GuavaSplitter(value); } }
@BuiltInFunction(name=RegexpReplaceFunction.NAME, args= { @Argument(allowedTypes={PVarchar.class}), @Argument(allowedTypes={PVarchar.class}), @Argument(allowedTypes={PVarchar.class},defaultValue="null")}, classType = FunctionClassType.DERIVED ) public class ByteBasedRegexpReplaceFunction extends RegexpReplaceFunction { public ByteBasedRegexpReplaceFunction() { } public ByteBasedRegexpReplaceFunction(List<Expression> children) { super(children); } @Override protected AbstractBasePattern compilePatternSpec(String value) { return new JONIPattern(value, Option.MULTILINE); } }
@BuiltInFunction(name=RegexpSplitFunction.NAME, args= { @Argument(allowedTypes={PVarchar.class}), @Argument(allowedTypes={PVarchar.class})}, classType = FunctionClassType.DERIVED ) public class ByteBasedRegexpSplitFunction extends RegexpSplitFunction { public ByteBasedRegexpSplitFunction() { } public ByteBasedRegexpSplitFunction(List<Expression> children) { super(children); } @Override protected AbstractBaseSplitter compilePatternSpec(String value) { return new JONIPattern(value, Option.MULTILINE); } }
@BuiltInFunction(name=RegexpSplitFunction.NAME, args= { @Argument(allowedTypes={PVarchar.class}), @Argument(allowedTypes={PVarchar.class})}, classType = FunctionClassType.DERIVED ) public class ByteBasedRegexpSplitFunction extends RegexpSplitFunction { public ByteBasedRegexpSplitFunction() { } public ByteBasedRegexpSplitFunction(List<Expression> children) { super(children); } @Override protected AbstractBaseSplitter compilePatternSpec(String value) { return new JONIPattern(value, Option.MULTILINE); } }
@BuiltInFunction(name=RegexpSplitFunction.NAME, args= { @Argument(allowedTypes={PVarchar.class}), @Argument(allowedTypes={PVarchar.class})}, classType = FunctionClassType.DERIVED ) public class StringBasedRegexpSplitFunction extends RegexpSplitFunction { public StringBasedRegexpSplitFunction() { } public StringBasedRegexpSplitFunction(List<Expression> children) { super(children); } @Override protected AbstractBaseSplitter compilePatternSpec(String value) { return new GuavaSplitter(value); } }
args={@Argument(allowedTypes={PVarchar.class}), @Argument(allowedTypes={PVarchar.class},isConstant=true,defaultValue="null"), @Argument(allowedTypes={PVarchar.class}, isConstant=true, defaultValue = "null") } ) public class ToDateFunction extends ScalarFunction { public static final String NAME = "TO_DATE";
@BuiltInFunction(name = LpadFunction.NAME, args = { @Argument(allowedTypes = { PVarchar.class }), @Argument(allowedTypes = { PInteger.class }), @Argument(allowedTypes = { PVarchar.class }, defaultValue = "' '") }) public class LpadFunction extends ScalarFunction { public static final String NAME = "LPAD";