use of com.facebook.presto.sql.TestingRowExpressionTranslator in project presto by prestodb.
the class TestConnectorFilterStatsCalculatorService method setUp.
@BeforeClass
public void setUp() {
session = testSessionBuilder().build();
MetadataManager metadata = MetadataManager.createTestMetadataManager();
FilterStatsCalculator statsCalculator = new FilterStatsCalculator(metadata, new ScalarStatsCalculator(metadata), new StatsNormalizer());
statsCalculatorService = new ConnectorFilterStatsCalculatorService(statsCalculator);
xStats = ColumnStatistics.builder().setDistinctValuesCount(Estimate.of(40)).setRange(new DoubleRange(-10, 10)).setNullsFraction(Estimate.of(0.25)).build();
zeroTableStatistics = TableStatistics.builder().setRowCount(Estimate.zero()).setTotalSize(Estimate.zero()).build();
originalTableStatistics = TableStatistics.builder().setRowCount(Estimate.of(100)).setTotalSize(Estimate.of(800)).setColumnStatistics(xColumn, xStats).build();
originalTableStatisticsWithoutTotalSize = TableStatistics.builder().setRowCount(Estimate.of(100)).setColumnStatistics(xColumn, xStats).build();
standardTypes = TypeProvider.fromVariables(ImmutableList.<VariableReferenceExpression>builder().add(new VariableReferenceExpression(Optional.empty(), "x", DOUBLE)).build());
translator = new TestingRowExpressionTranslator(MetadataManager.createTestMetadataManager());
}
use of com.facebook.presto.sql.TestingRowExpressionTranslator in project presto by prestodb.
the class TestFilterStatsCalculator method setUp.
@BeforeClass
public void setUp() throws Exception {
xStats = VariableStatsEstimate.builder().setAverageRowSize(4.0).setDistinctValuesCount(40.0).setLowValue(-10.0).setHighValue(10.0).setNullsFraction(0.25).build();
yStats = VariableStatsEstimate.builder().setAverageRowSize(4.0).setDistinctValuesCount(20.0).setLowValue(0.0).setHighValue(5.0).setNullsFraction(0.5).build();
zStats = VariableStatsEstimate.builder().setAverageRowSize(4.0).setDistinctValuesCount(5.0).setLowValue(-100.0).setHighValue(100.0).setNullsFraction(0.1).build();
leftOpenStats = VariableStatsEstimate.builder().setAverageRowSize(4.0).setDistinctValuesCount(50.0).setLowValue(NEGATIVE_INFINITY).setHighValue(15.0).setNullsFraction(0.1).build();
rightOpenStats = VariableStatsEstimate.builder().setAverageRowSize(4.0).setDistinctValuesCount(50.0).setLowValue(-15.0).setHighValue(POSITIVE_INFINITY).setNullsFraction(0.1).build();
unknownRangeStats = VariableStatsEstimate.builder().setAverageRowSize(4.0).setDistinctValuesCount(50.0).setLowValue(NEGATIVE_INFINITY).setHighValue(POSITIVE_INFINITY).setNullsFraction(0.1).build();
emptyRangeStats = VariableStatsEstimate.builder().setAverageRowSize(0.0).setDistinctValuesCount(0.0).setLowValue(NaN).setHighValue(NaN).setNullsFraction(NaN).build();
mediumVarcharStats = VariableStatsEstimate.builder().setAverageRowSize(85.0).setDistinctValuesCount(165).setLowValue(NEGATIVE_INFINITY).setHighValue(POSITIVE_INFINITY).setNullsFraction(0.34).build();
standardInputStatistics = PlanNodeStatsEstimate.builder().addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "x", DOUBLE), xStats).addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "y", DOUBLE), yStats).addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "z", DOUBLE), zStats).addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "leftOpen", DOUBLE), leftOpenStats).addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "rightOpen", DOUBLE), rightOpenStats).addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "unknownRange", DOUBLE), unknownRangeStats).addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "emptyRange", DOUBLE), emptyRangeStats).addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "mediumVarchar", MEDIUM_VARCHAR_TYPE), mediumVarcharStats).setOutputRowCount(1000.0).build();
standardTypes = TypeProvider.fromVariables(ImmutableList.<VariableReferenceExpression>builder().add(new VariableReferenceExpression(Optional.empty(), "x", DOUBLE)).add(new VariableReferenceExpression(Optional.empty(), "y", DOUBLE)).add(new VariableReferenceExpression(Optional.empty(), "z", DOUBLE)).add(new VariableReferenceExpression(Optional.empty(), "leftOpen", DOUBLE)).add(new VariableReferenceExpression(Optional.empty(), "rightOpen", DOUBLE)).add(new VariableReferenceExpression(Optional.empty(), "unknownRange", DOUBLE)).add(new VariableReferenceExpression(Optional.empty(), "emptyRange", DOUBLE)).add(new VariableReferenceExpression(Optional.empty(), "mediumVarchar", MEDIUM_VARCHAR_TYPE)).build());
session = testSessionBuilder().build();
MetadataManager metadata = MetadataManager.createTestMetadataManager();
statsCalculator = new FilterStatsCalculator(metadata, new ScalarStatsCalculator(metadata), new StatsNormalizer());
translator = new TestingRowExpressionTranslator(MetadataManager.createTestMetadataManager());
}
use of com.facebook.presto.sql.TestingRowExpressionTranslator in project presto by prestodb.
the class TestScalarStatsCalculator method setUp.
@BeforeClass
public void setUp() {
calculator = new ScalarStatsCalculator(MetadataManager.createTestMetadataManager());
session = testSessionBuilder().build();
translator = new TestingRowExpressionTranslator(MetadataManager.createTestMetadataManager());
}
use of com.facebook.presto.sql.TestingRowExpressionTranslator 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);
}
Aggregations