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 BuiltInFunctionInfo(Class<? extends FunctionExpression> f, BuiltInFunction d) { this.name = SchemaUtil.normalizeIdentifier(d.name()); this.func = f; this.funcCtor = d.nodeClass() == FunctionParseNode.class ? getExpressionCtor(f, null) : null; this.nodeCtor = d.nodeClass() == FunctionParseNode.class ? null : getParseNodeCtor(d.nodeClass()); this.args = new BuiltInFunctionArgInfo[d.args().length]; int requiredArgCount = 0; for (int i = 0; i < args.length; i++) { this.args[i] = new BuiltInFunctionArgInfo(d.args()[i]); if (this.args[i].getDefaultValue() == null) { requiredArgCount = i + 1; } } this.requiredArgCount = requiredArgCount; this.isAggregate = AggregateFunction.class.isAssignableFrom(f); this.classType = d.classType(); this.derivedFunctions = d.derivedFunctions(); }
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 BuiltInFunctionInfo(Class<? extends FunctionExpression> f, BuiltInFunction d) { this.name = SchemaUtil.normalizeIdentifier(d.name()); this.func = f; this.funcCtor = d.nodeClass() == FunctionParseNode.class ? getExpressionCtor(f, null) : null; this.nodeCtor = d.nodeClass() == FunctionParseNode.class ? null : getParseNodeCtor(d.nodeClass()); this.args = new BuiltInFunctionArgInfo[d.args().length]; int requiredArgCount = 0; for (int i = 0; i < args.length; i++) { this.args[i] = new BuiltInFunctionArgInfo(d.args()[i]); if (this.args[i].getDefaultValue() == null) { requiredArgCount = i + 1; } } this.requiredArgCount = requiredArgCount; this.isAggregate = AggregateFunction.class.isAssignableFrom(f); this.classType = d.classType(); this.derivedFunctions = d.derivedFunctions(); }
@BuiltInFunction(name = FloorFunction.NAME, args = { @Argument(allowedTypes={PTimestamp.class}),
@BuiltInFunction(name=SumAggregateFunction.NAME, nodeClass=SumAggregateParseNode.class, args= {@Argument(allowedTypes={PDecimal.class})} ) public class SumAggregateFunction extends DelegateConstantToCountAggregateFunction { public static final String NAME = "SUM";
@FunctionParseNode.BuiltInFunction(name=RegexpSplitFunction.NAME, nodeClass = RegexpSplitParseNode.class, args= { @FunctionParseNode.Argument(allowedTypes={PVarchar.class}),
@BuiltInFunction(name=CoalesceFunction.NAME, args= { @Argument(), @Argument()} )
@BuiltInFunction(name = CeilFunction.NAME, args = { @Argument(allowedTypes={PTimestamp.class}),
@FunctionParseNode.BuiltInFunction(name = DecodeFunction.NAME, args = { @FunctionParseNode.Argument(allowedTypes = { PVarchar.class }), @FunctionParseNode.Argument(enumeration = "EncodeFormat")})
@BuiltInFunction(name=DistinctCountAggregateFunction.NAME, nodeClass=DistinctCountParseNode.class, args= {@Argument()} ) public class DistinctCountAggregateFunction extends DelegateConstantToCountAggregateFunction { public static final String NAME = "DISTINCT_COUNT";
@BuiltInFunction(name=InstrFunction.NAME, args={ @Argument(allowedTypes={ PVarchar.class }), @Argument(allowedTypes={ PVarchar.class })})
@BuiltInFunction(name = FloorFunction.NAME, args = { @Argument(allowedTypes={PDecimal.class}),
@BuiltInFunction(name = CeilFunction.NAME, args = { @Argument(allowedTypes={PDate.class}),
@BuiltInFunction(name = RoundFunction.NAME, args = { @Argument(allowedTypes={PTimestamp.class}),
@BuiltInFunction(name = CeilFunction.NAME, args = { @Argument(allowedTypes={PDecimal.class}),
@BuiltInFunction(name=AvgAggregateFunction.NAME, nodeClass=AvgAggregateParseNode.class, args= {@Argument(allowedTypes={PDecimal.class})} ) public class AvgAggregateFunction extends CompositeAggregateFunction { public static final String NAME = "AVG";
@BuiltInFunction(name = EncodeFunction.NAME, args = { @Argument(allowedTypes = { PLong.class }), @Argument(enumeration = "EncodeFormat") }) public class EncodeFunction extends ScalarFunction {
@BuiltInFunction(name=CountAggregateFunction.NAME, args= {@Argument()} ) public class CountAggregateFunction extends SingleAggregateFunction { public static final String NAME = "COUNT";
@BuiltInFunction(name=LTrimFunction.NAME, args={ @Argument(allowedTypes={PVarchar.class})}) public class LTrimFunction extends ScalarFunction {