use of com.facebook.presto.sql.planner.TypeProvider in project presto by prestodb.
the class TestValidateStreamingAggregations method validatePlan.
private void validatePlan(Function<PlanBuilder, PlanNode> planProvider) {
PlanBuilder builder = new PlanBuilder(TEST_SESSION, idAllocator, metadata);
PlanNode planNode = planProvider.apply(builder);
TypeProvider types = builder.getTypes();
getQueryRunner().inTransaction(session -> {
// metadata.getCatalogHandle() registers the catalog for the transaction
session.getCatalog().ifPresent(catalog -> metadata.getCatalogHandle(session, catalog));
new ValidateStreamingAggregations().validate(planNode, session, metadata, sqlParser, types, WarningCollector.NOOP);
return null;
});
}
use of com.facebook.presto.sql.planner.TypeProvider in project presto by prestodb.
the class TestValidateStreamingJoins method validatePlan.
private void validatePlan(Function<PlanBuilder, PlanNode> planProvider) {
PlanBuilder builder = new PlanBuilder(TEST_SESSION, idAllocator, metadata);
PlanNode planNode = planProvider.apply(builder);
TypeProvider types = builder.getTypes();
getQueryRunner().inTransaction(testSession, session -> {
session.getCatalog().ifPresent(catalog -> metadata.getCatalogHandle(session, catalog));
new ValidateStreamingJoins().validate(planNode, session, metadata, sqlParser, types, WarningCollector.NOOP);
return null;
});
}
use of com.facebook.presto.sql.planner.TypeProvider in project presto by prestodb.
the class TestRowExpressionTranslator method testMissingFunctionTranslator.
@Test
public void testMissingFunctionTranslator() {
String untranslated = "ABS(col1)";
TypeProvider typeProvider = TypeProvider.copyOf(ImmutableMap.of("col1", DOUBLE));
RowExpression specialForm = sqlToRowExpressionTranslator.translate(expression(untranslated), typeProvider);
TranslatedExpression translatedExpression = translateWith(specialForm, new TestFunctionTranslator(functionAndTypeManager, buildFunctionTranslator(ImmutableSet.of(TestFunctions.class))), emptyMap());
assertFalse(translatedExpression.getTranslated().isPresent());
}
use of com.facebook.presto.sql.planner.TypeProvider in project presto by prestodb.
the class ActualProperties method translateRowExpression.
public ActualProperties translateRowExpression(Map<VariableReferenceExpression, RowExpression> assignments, TypeProvider types) {
Map<VariableReferenceExpression, VariableReferenceExpression> inputToOutputVariables = new HashMap<>();
for (Map.Entry<VariableReferenceExpression, RowExpression> assignment : assignments.entrySet()) {
RowExpression expression = assignment.getValue();
if (isExpression(expression)) {
if (castToExpression(expression) instanceof SymbolReference) {
inputToOutputVariables.put(toVariableReference(castToExpression(expression), types), assignment.getKey());
}
} else {
if (expression instanceof VariableReferenceExpression) {
inputToOutputVariables.put((VariableReferenceExpression) expression, assignment.getKey());
}
}
}
Map<VariableReferenceExpression, ConstantExpression> translatedConstants = new HashMap<>();
for (Map.Entry<VariableReferenceExpression, ConstantExpression> entry : constants.entrySet()) {
if (inputToOutputVariables.containsKey(entry.getKey())) {
translatedConstants.put(inputToOutputVariables.get(entry.getKey()), entry.getValue());
}
}
ImmutableMap.Builder<VariableReferenceExpression, RowExpression> inputToOutputMappings = ImmutableMap.builder();
inputToOutputMappings.putAll(inputToOutputVariables);
constants.entrySet().stream().filter(entry -> !inputToOutputVariables.containsKey(entry.getKey())).forEach(inputToOutputMappings::put);
return builder().global(global.translateRowExpression(inputToOutputMappings.build(), assignments, types)).local(LocalProperties.translate(localProperties, variable -> Optional.ofNullable(inputToOutputVariables.get(variable)))).constants(translatedConstants).build();
}
use of com.facebook.presto.sql.planner.TypeProvider in project presto by prestodb.
the class RuleAssert method get.
public PlanNode get() {
RuleApplication ruleApplication = applyRule();
TypeProvider types = ruleApplication.types;
if (!ruleApplication.wasRuleApplied()) {
fail(String.format("%s did not fire for:\n%s", rule.getClass().getName(), formatPlan(plan, types)));
}
return ruleApplication.getTransformedPlan();
}
Aggregations