use of com.facebook.presto.spi.function.FunctionHandle in project presto by prestodb.
the class StatsUtil method toStatsRepresentation.
static OptionalDouble toStatsRepresentation(FunctionAndTypeManager functionAndTypeManager, ConnectorSession session, Type type, Object value) {
requireNonNull(value, "value is null");
if (convertibleToDoubleWithCast(type)) {
InterpretedFunctionInvoker functionInvoker = new InterpretedFunctionInvoker(functionAndTypeManager);
FunctionHandle cast = functionAndTypeManager.lookupCast(CAST, type.getTypeSignature(), DoubleType.DOUBLE.getTypeSignature());
return OptionalDouble.of((double) functionInvoker.invoke(cast, session.getSqlFunctionProperties(), singletonList(value)));
}
if (DateType.DATE.equals(type)) {
return OptionalDouble.of(((Long) value).doubleValue());
}
return OptionalDouble.empty();
}
use of com.facebook.presto.spi.function.FunctionHandle in project presto by prestodb.
the class TestFunctionAndTypeManager method testIdentityCast.
@Test
public void testIdentityCast() {
FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
FunctionHandle exactOperator = functionAndTypeManager.lookupCast(CastType.CAST, HYPER_LOG_LOG.getTypeSignature(), HYPER_LOG_LOG.getTypeSignature());
assertEquals(exactOperator, new BuiltInFunctionHandle(new Signature(CAST.getFunctionName(), SCALAR, HYPER_LOG_LOG.getTypeSignature(), HYPER_LOG_LOG.getTypeSignature())));
}
use of com.facebook.presto.spi.function.FunctionHandle in project presto by prestodb.
the class TestRowExpressionDomainTranslator method testExpressionConstantFolding.
@Test
public void testExpressionConstantFolding() {
FunctionHandle hex = metadata.getFunctionAndTypeManager().lookupFunction("from_hex", fromTypes(VARCHAR));
RowExpression originalExpression = greaterThan(C_VARBINARY, call("from_hex", hex, VARBINARY, stringLiteral("123456")));
ExtractionResult result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_CONSTANT);
Slice value = Slices.wrappedBuffer(BaseEncoding.base16().decode("123456"));
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_VARBINARY, Domain.create(ValueSet.ofRanges(Range.greaterThan(VARBINARY, value)), false))));
RowExpression expression = toPredicate(result.getTupleDomain());
assertEquals(expression, greaterThan(C_VARBINARY, varbinaryLiteral(value)));
}
use of com.facebook.presto.spi.function.FunctionHandle in project presto by prestodb.
the class TestTypeValidator method testInvalidWindowFunctionCall.
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of variable 'sum(_[0-9]+)?' is expected to be double, but the actual type is bigint")
public void testInvalidWindowFunctionCall() {
VariableReferenceExpression windowVariable = variableAllocator.newVariable("sum", DOUBLE);
FunctionHandle functionHandle = FUNCTION_MANAGER.lookupFunction("sum", fromTypes(DOUBLE));
WindowNode.Frame frame = new WindowNode.Frame(RANGE, UNBOUNDED_PRECEDING, Optional.empty(), UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty(), Optional.empty());
WindowNode.Function function = new WindowNode.Function(call("sum", functionHandle, BIGINT, variableA), frame, false);
WindowNode.Specification specification = new WindowNode.Specification(ImmutableList.of(), Optional.empty());
PlanNode node = new WindowNode(Optional.empty(), newId(), baseTableScan, specification, ImmutableMap.of(windowVariable, function), Optional.empty(), ImmutableSet.of(), 0);
assertTypesValid(node);
}
use of com.facebook.presto.spi.function.FunctionHandle in project presto by prestodb.
the class TestTypeValidator method testValidWindow.
@Test
public void testValidWindow() {
VariableReferenceExpression windowVariable = variableAllocator.newVariable("sum", DOUBLE);
FunctionHandle functionHandle = FUNCTION_MANAGER.lookupFunction("sum", fromTypes(DOUBLE));
WindowNode.Frame frame = new WindowNode.Frame(RANGE, UNBOUNDED_PRECEDING, Optional.empty(), UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty(), Optional.empty());
WindowNode.Function function = new WindowNode.Function(call("sum", functionHandle, DOUBLE, variableC), frame, false);
WindowNode.Specification specification = new WindowNode.Specification(ImmutableList.of(), Optional.empty());
PlanNode node = new WindowNode(Optional.empty(), newId(), baseTableScan, specification, ImmutableMap.of(windowVariable, function), Optional.empty(), ImmutableSet.of(), 0);
assertTypesValid(node);
}
Aggregations