use of com.facebook.presto.metadata.Signature in project presto by prestodb.
the class ParametricScalar method specialize.
@Override
public ScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) {
Signature boundSignature = applyBoundVariables(getSignature(), boundVariables, arity);
if (implementations.getExactImplementations().containsKey(boundSignature)) {
ScalarImplementation implementation = implementations.getExactImplementations().get(boundSignature);
Optional<MethodHandleAndConstructor> methodHandleAndConstructor = implementation.specialize(boundSignature, boundVariables, typeManager, functionRegistry);
checkCondition(methodHandleAndConstructor.isPresent(), FUNCTION_IMPLEMENTATION_ERROR, String.format("Exact implementation of %s do not match expected java types.", boundSignature.getName()));
return new ScalarFunctionImplementation(implementation.isNullable(), implementation.getNullableArguments(), implementation.getNullFlags(), methodHandleAndConstructor.get().getMethodHandle(), methodHandleAndConstructor.get().getConstructor(), isDeterministic());
}
ScalarFunctionImplementation selectedImplementation = null;
for (ScalarImplementation implementation : implementations.getSpecializedImplementations()) {
Optional<MethodHandleAndConstructor> methodHandle = implementation.specialize(boundSignature, boundVariables, typeManager, functionRegistry);
if (methodHandle.isPresent()) {
checkCondition(selectedImplementation == null, AMBIGUOUS_FUNCTION_IMPLEMENTATION, "Ambiguous implementation for %s with bindings %s", getSignature(), boundVariables.getTypeVariables());
selectedImplementation = new ScalarFunctionImplementation(implementation.isNullable(), implementation.getNullableArguments(), implementation.getNullFlags(), methodHandle.get().getMethodHandle(), methodHandle.get().getConstructor(), isDeterministic());
}
}
if (selectedImplementation != null) {
return selectedImplementation;
}
for (ScalarImplementation implementation : implementations.getGenericImplementations()) {
Optional<MethodHandleAndConstructor> methodHandle = implementation.specialize(boundSignature, boundVariables, typeManager, functionRegistry);
if (methodHandle.isPresent()) {
checkCondition(selectedImplementation == null, AMBIGUOUS_FUNCTION_IMPLEMENTATION, "Ambiguous implementation for %s with bindings %s", getSignature(), boundVariables.getTypeVariables());
selectedImplementation = new ScalarFunctionImplementation(implementation.isNullable(), implementation.getNullableArguments(), implementation.getNullFlags(), methodHandle.get().getMethodHandle(), methodHandle.get().getConstructor(), isDeterministic());
}
}
if (selectedImplementation != null) {
return selectedImplementation;
}
throw new PrestoException(FUNCTION_IMPLEMENTATION_MISSING, format("Unsupported type parameters (%s) for %s", boundVariables, getSignature()));
}
use of com.facebook.presto.metadata.Signature in project presto by prestodb.
the class CountAggregationBenchmark method createOperatorFactories.
@Override
protected List<? extends OperatorFactory> createOperatorFactories() {
OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "orders", "orderkey");
InternalAggregationFunction countFunction = localQueryRunner.getMetadata().getFunctionRegistry().getAggregateFunctionImplementation(new Signature("count", AGGREGATE, BIGINT.getTypeSignature()));
AggregationOperatorFactory aggregationOperator = new AggregationOperatorFactory(1, new PlanNodeId("test"), Step.SINGLE, ImmutableList.of(countFunction.bind(ImmutableList.of(0), Optional.empty())));
return ImmutableList.of(tableScanOperator, aggregationOperator);
}
use of com.facebook.presto.metadata.Signature in project presto by prestodb.
the class TestInCodeGenerator method testBigint.
@Test
public void testBigint() {
List<RowExpression> values = new ArrayList<>();
values.add(new ConstantExpression(Integer.MAX_VALUE + 1L, BIGINT));
values.add(new ConstantExpression(Integer.MIN_VALUE - 1L, BIGINT));
values.add(new ConstantExpression(3L, BIGINT));
assertEquals(checkSwitchGenerationCase(BIGINT, values), HASH_SWITCH);
values.add(new ConstantExpression(null, BIGINT));
assertEquals(checkSwitchGenerationCase(BIGINT, values), HASH_SWITCH);
values.add(new CallExpression(new Signature(CAST, SCALAR, BIGINT.getTypeSignature(), DOUBLE.getTypeSignature()), BIGINT, Collections.singletonList(new ConstantExpression(12345678901234.0, DOUBLE))));
assertEquals(checkSwitchGenerationCase(BIGINT, values), HASH_SWITCH);
for (long i = 6; i <= 32; ++i) {
values.add(new ConstantExpression(i, BIGINT));
}
assertEquals(checkSwitchGenerationCase(BIGINT, values), HASH_SWITCH);
values.add(new ConstantExpression(33L, BIGINT));
assertEquals(checkSwitchGenerationCase(BIGINT, values), SET_CONTAINS);
}
use of com.facebook.presto.metadata.Signature in project presto by prestodb.
the class InCodeGeneratorBenchmark method setup.
@Setup
public void setup() {
Random random = new Random();
RowExpression[] arguments = new RowExpression[1 + inListCount];
switch(type) {
case StandardTypes.BIGINT:
prestoType = BIGINT;
for (int i = 1; i <= inListCount; i++) {
arguments[i] = constant((long) random.nextInt(), BIGINT);
}
break;
case StandardTypes.DOUBLE:
prestoType = DOUBLE;
for (int i = 1; i <= inListCount; i++) {
arguments[i] = constant(random.nextDouble(), DOUBLE);
}
break;
case StandardTypes.VARCHAR:
prestoType = VARCHAR;
for (int i = 1; i <= inListCount; i++) {
arguments[i] = constant(Slices.utf8Slice(Long.toString(random.nextLong())), VARCHAR);
}
break;
default:
throw new IllegalStateException();
}
arguments[0] = field(0, prestoType);
RowExpression project = field(0, prestoType);
PageBuilder pageBuilder = new PageBuilder(ImmutableList.of(prestoType));
for (int i = 0; i < 10_000; i++) {
pageBuilder.declarePosition();
switch(type) {
case StandardTypes.BIGINT:
BIGINT.writeLong(pageBuilder.getBlockBuilder(0), random.nextInt());
break;
case StandardTypes.DOUBLE:
DOUBLE.writeDouble(pageBuilder.getBlockBuilder(0), random.nextDouble());
break;
case StandardTypes.VARCHAR:
VARCHAR.writeSlice(pageBuilder.getBlockBuilder(0), Slices.utf8Slice(Long.toString(random.nextLong())));
break;
}
}
inputPage = pageBuilder.build();
RowExpression filter = call(new Signature(IN, SCALAR, parseTypeSignature(StandardTypes.BOOLEAN)), BOOLEAN, arguments);
processor = new ExpressionCompiler(MetadataManager.createTestMetadataManager()).compilePageProcessor(filter, ImmutableList.of(project)).get();
}
use of com.facebook.presto.metadata.Signature in project presto by prestodb.
the class TestTypeValidator method testInvalidWindowFunctionSignature.
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'sum(_[0-9]+)?' is expected to be double, but the actual type is bigint")
public void testInvalidWindowFunctionSignature() throws Exception {
Symbol windowSymbol = symbolAllocator.newSymbol("sum", DOUBLE);
Signature signature = new Signature("sum", FunctionKind.WINDOW, ImmutableList.of(), ImmutableList.of(), // should be DOUBLE
BIGINT.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature()), false);
FunctionCall functionCall = new FunctionCall(QualifiedName.of("sum"), ImmutableList.of(columnC.toSymbolReference()));
WindowNode.Frame frame = new WindowNode.Frame(WindowFrame.Type.RANGE, FrameBound.Type.UNBOUNDED_PRECEDING, Optional.empty(), FrameBound.Type.UNBOUNDED_FOLLOWING, Optional.empty());
WindowNode.Function function = new WindowNode.Function(functionCall, signature, frame);
WindowNode.Specification specification = new WindowNode.Specification(ImmutableList.of(), ImmutableList.of(), ImmutableMap.of());
PlanNode node = new WindowNode(newId(), baseTableScan, specification, ImmutableMap.of(windowSymbol, function), Optional.empty(), ImmutableSet.of(), 0);
assertTypesValid(node);
}
Aggregations