private static MethodHandle resolveEqualOperator(Type type, FunctionRegistry functionRegistry) { Signature operator = functionRegistry.resolveOperator(EQUAL, ImmutableList.of(type, type)); ScalarFunctionImplementation implementation = functionRegistry.getScalarFunctionImplementation(operator); return implementation.getMethodHandle(); }
@Override public void addFunctions(List<? extends SqlFunction> functionInfos) { // TODO: transactional when FunctionRegistry is made transactional functions.addFunctions(functionInfos); }
private Optional<Signature> getSaturatedFloorCastOperator(Type fromType, Type toType) { if (metadata.getFunctionRegistry().canResolveOperator(SATURATED_FLOOR_CAST, toType, ImmutableList.of(fromType))) { return Optional.of(internalOperator(SATURATED_FLOOR_CAST, toType, ImmutableList.of(fromType))); } return Optional.empty(); }
@Override public Boolean visitCall(CallExpression call, Void context) { Signature signature = call.getSignature(); if (registry.isRegistered(signature) && !registry.getScalarFunctionImplementation(signature).isDeterministic()) { return false; } return call.getArguments().stream() .allMatch(expression -> expression.accept(this, context)); }
@Override public MethodHandle resolve(BoundVariables boundVariables, TypeManager typeManager, FunctionRegistry functionRegistry) { Signature signature = applyBoundVariables(this.signature, boundVariables, this.signature.getArgumentTypes().size()); if (invocationConvention.isPresent()) { return functionRegistry.getFunctionInvokerProvider().createFunctionInvoker(signature, invocationConvention).methodHandle(); } else { return functionRegistry.getScalarFunctionImplementation(signature).getMethodHandle(); } }
@Override protected List<? extends OperatorFactory> createOperatorFactories() { OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "orders", "totalprice"); InternalAggregationFunction doubleSum = MetadataManager.createTestMetadataManager().getFunctionRegistry().getAggregateFunctionImplementation( new Signature("sum", AGGREGATE, DOUBLE.getTypeSignature(), DOUBLE.getTypeSignature())); AggregationOperatorFactory aggregationOperator = new AggregationOperatorFactory(1, new PlanNodeId("test"), Step.SINGLE, ImmutableList.of(doubleSum.bind(ImmutableList.of(0), Optional.empty())), false); return ImmutableList.of(tableScanOperator, aggregationOperator); }
public TestingConnectorContext() { // associate typeManager with a function registry new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()); }
private Signature resolveSignature() { FunctionRegistry functionRegistry = new FunctionRegistry(typeRegistry, blockEncoding, new FeaturesConfig()); functionRegistry.addFunctions(createFunctionsFromSignatures()); return functionRegistry.resolveFunction(QualifiedName.of(TEST_FUNCTION_NAME), fromTypeSignatures(parameterTypes)); }
@Test public void testIdentityCast() { TypeRegistry typeManager = new TypeRegistry(); FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()); Signature exactOperator = registry.getCoercion(HYPER_LOG_LOG, HYPER_LOG_LOG); assertEquals(exactOperator.getName(), mangleOperatorName(OperatorType.CAST.name())); assertEquals(transform(exactOperator.getArgumentTypes(), Functions.toStringFunction()), ImmutableList.of(StandardTypes.HYPER_LOG_LOG)); assertEquals(exactOperator.getReturnType().getBase(), StandardTypes.HYPER_LOG_LOG); }
@Test public void testMagicLiteralFunction() { Signature signature = getMagicLiteralFunctionSignature(TIMESTAMP_WITH_TIME_ZONE); assertEquals(signature.getName(), "$literal$timestamp with time zone"); assertEquals(signature.getArgumentTypes(), ImmutableList.of(parseTypeSignature(StandardTypes.BIGINT))); assertEquals(signature.getReturnType().getBase(), StandardTypes.TIMESTAMP_WITH_TIME_ZONE); TypeRegistry typeManager = new TypeRegistry(); FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()); Signature function = registry.resolveFunction(QualifiedName.of(signature.getName()), fromTypeSignatures(signature.getArgumentTypes())); assertEquals(function.getArgumentTypes(), ImmutableList.of(parseTypeSignature(StandardTypes.BIGINT))); assertEquals(signature.getReturnType().getBase(), StandardTypes.TIMESTAMP_WITH_TIME_ZONE); }
@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "'sum' is both an aggregation and a scalar function") public void testConflictingScalarAggregation() { List<SqlFunction> functions = new FunctionListBuilder() .scalars(ScalarSum.class) .getFunctions(); TypeRegistry typeManager = new TypeRegistry(); FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()); registry.addFunctions(functions); }
@Test public void testListingHiddenFunctions() { TypeRegistry typeManager = new TypeRegistry(); FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()); List<SqlFunction> functions = registry.list(); List<String> names = transform(functions, input -> input.getSignature().getName()); assertTrue(names.contains("length"), "Expected function names " + names + " to contain 'length'"); assertTrue(names.contains("stddev"), "Expected function names " + names + " to contain 'stddev'"); assertTrue(names.contains("rank"), "Expected function names " + names + " to contain 'rank'"); assertFalse(names.contains("like"), "Expected function names " + names + " not to contain 'like'"); assertFalse(names.contains("$internal$sum_data_size_for_stats"), "Expected function names " + names + " not to contain '$internal$sum_data_size_for_stats'"); assertFalse(names.contains("$internal$max_data_size_for_stats"), "Expected function names " + names + " not to contain '$internal$max_data_size_for_stats'"); }
@Override public BytecodeNode generateExpression(Signature signature, BytecodeGeneratorContext generatorContext, Type returnType, List<RowExpression> arguments) { RowExpression argument = arguments.get(0); Signature function = generatorContext .getRegistry() .getCoercion(argument.getType(), returnType); return generatorContext.generateCall(function.getName(), generatorContext.getRegistry().getScalarFunctionImplementation(function), ImmutableList.of(generatorContext.generate(argument))); } }
public SignatureBuilder operatorType(OperatorType operatorType) { this.name = mangleOperatorName(requireNonNull(operatorType, "operatorType is null")); this.kind = SCALAR; return this; }
public Signature getCoercion(Type fromType, Type toType) { return getCoercion(fromType.getTypeSignature(), toType.getTypeSignature()); }
.collect(Collectors.toList()); Optional<Signature> match = matchFunctionExact(exactCandidates, parameterTypes); if (match.isPresent()) { return match.get(); .collect(Collectors.toList()); match = matchFunctionExact(genericCandidates, parameterTypes); if (match.isPresent()) { return match.get(); match = matchFunctionWithCoercion(allCandidates, parameterTypes); if (match.isPresent()) { return match.get(); Type parameterType = typeManager.getType(parameterTypes.get(0).getTypeSignature()); return getMagicLiteralFunctionSignature(type);
private Object invokeOperator(OperatorType operatorType, List<? extends Type> argumentTypes, List<Object> argumentValues) { Signature operatorSignature = metadata.getFunctionRegistry().resolveOperator(operatorType, argumentTypes); return functionInvoker.invoke(operatorSignature, session, argumentValues); }
Signature signature = FunctionRegistry.getMagicLiteralFunctionSignature(type); return new FunctionCall(QualifiedName.of(signature.getName()), ImmutableList.of(fromBase64)); Signature signature = FunctionRegistry.getMagicLiteralFunctionSignature(type); Expression rawLiteral = toExpression(object, FunctionRegistry.typeForMagicLiteral(type));
@Override public List<SqlFunction> listFunctions() { // TODO: transactional when FunctionRegistry is made transactional return functions.list(); }
private static FunctionCall colorLiteral(long value) { return new FunctionCall(QualifiedName.of(getMagicLiteralFunctionSignature(COLOR).getName()), ImmutableList.of(bigintLiteral(value))); }