use of com.facebook.presto.sql.planner.PlanVariableAllocator in project presto by prestodb.
the class TestSimplifyExpressions method assertSimplifies.
private static void assertSimplifies(String expression, String expected, String rowExpressionExpected) {
Expression actualExpression = rewriteIdentifiersToSymbolReferences(SQL_PARSER.createExpression(expression));
Expression expectedExpression = rewriteIdentifiersToSymbolReferences(SQL_PARSER.createExpression(expected));
Expression rewritten = rewrite(actualExpression, TEST_SESSION, new PlanVariableAllocator(booleanVariablesFor(actualExpression)), METADATA, LITERAL_ENCODER, SQL_PARSER);
assertEquals(normalize(rewritten), normalize(expectedExpression));
TestingRowExpressionTranslator translator = new TestingRowExpressionTranslator(METADATA);
RowExpression actualRowExpression = translator.translate(actualExpression, TypeProvider.viewOf(TYPES));
RowExpression simplifiedRowExpression = SimplifyRowExpressions.rewrite(actualRowExpression, METADATA, TEST_SESSION.toConnectorSession());
Expression expectedByRowExpression = Optional.ofNullable(rowExpressionExpected).map(expr -> rewriteIdentifiersToSymbolReferences(SQL_PARSER.createExpression(expr))).orElse(rewritten);
RowExpression simplifiedByExpression = translator.translate(expectedByRowExpression, TypeProvider.viewOf(TYPES));
assertEquals(simplifiedRowExpression, simplifiedByExpression);
}
use of com.facebook.presto.sql.planner.PlanVariableAllocator in project presto by prestodb.
the class TestStatisticsWriterNode method createTestDescriptor.
private static StatisticAggregationsDescriptor<VariableReferenceExpression> createTestDescriptor() {
StatisticAggregationsDescriptor.Builder<VariableReferenceExpression> builder = StatisticAggregationsDescriptor.builder();
PlanVariableAllocator variableAllocator = new PlanVariableAllocator();
for (String column : COLUMNS) {
for (ColumnStatisticType type : ColumnStatisticType.values()) {
builder.addColumnStatistic(new ColumnStatisticMetadata(column, type), testVariable(variableAllocator));
}
builder.addGrouping(column, testVariable(variableAllocator));
}
builder.addTableStatistic(ROW_COUNT, testVariable(variableAllocator));
return builder.build();
}
Aggregations