Search in sources :

Example 6 with TpchColumnHandle

use of com.facebook.presto.tpch.TpchColumnHandle in project presto by prestodb.

the class TestCostCalculator method tableScan.

private TableScanNode tableScan(String id, List<VariableReferenceExpression> variables) {
    ImmutableMap.Builder<VariableReferenceExpression, ColumnHandle> assignments = ImmutableMap.builder();
    for (VariableReferenceExpression variable : variables) {
        assignments.put(variable, new TpchColumnHandle("orderkey", BIGINT));
    }
    TpchTableHandle tableHandle = new TpchTableHandle("orders", 1.0);
    return new TableScanNode(Optional.empty(), new PlanNodeId(id), new TableHandle(new ConnectorId("tpch"), tableHandle, TpchTransactionHandle.INSTANCE, Optional.of(new TpchTableLayoutHandle(tableHandle, TupleDomain.all()))), variables, assignments.build(), TupleDomain.all(), TupleDomain.all());
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) TableHandle(com.facebook.presto.spi.TableHandle) TpchTableLayoutHandle(com.facebook.presto.tpch.TpchTableLayoutHandle) ImmutableMap(com.google.common.collect.ImmutableMap) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 7 with TpchColumnHandle

use of com.facebook.presto.tpch.TpchColumnHandle in project presto by prestodb.

the class TestValidateStreamingAggregations method testValidateSuccessful.

@Test
public void testValidateSuccessful() {
    validatePlan(p -> p.aggregation(a -> a.step(SINGLE).singleGroupingSet(p.variable("nationkey")).source(p.tableScan(nationTableHandle, ImmutableList.of(p.variable("nationkey", BIGINT)), ImmutableMap.of(p.variable("nationkey", BIGINT), new TpchColumnHandle("nationkey", BIGINT))))));
    validatePlan(p -> p.aggregation(a -> a.step(SINGLE).singleGroupingSet(p.variable("unique"), p.variable("nationkey")).preGroupedVariables(p.variable("unique"), p.variable("nationkey")).source(p.assignUniqueId(p.variable("unique"), p.tableScan(nationTableHandle, ImmutableList.of(p.variable("nationkey", BIGINT)), ImmutableMap.of(p.variable("nationkey", BIGINT), new TpchColumnHandle("nationkey", BIGINT)))))));
}
Also used : WarningCollector(com.facebook.presto.spi.WarningCollector) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test) SINGLE(com.facebook.presto.spi.plan.AggregationNode.Step.SINGLE) PrestoException(com.facebook.presto.spi.PrestoException) Function(java.util.function.Function) TpchTableLayoutHandle(com.facebook.presto.tpch.TpchTableLayoutHandle) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) ImmutableList(com.google.common.collect.ImmutableList) TypeProvider(com.facebook.presto.sql.planner.TypeProvider) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) TableHandle(com.facebook.presto.spi.TableHandle) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) TestingTransactionHandle(com.facebook.presto.testing.TestingTransactionHandle) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) SqlParser(com.facebook.presto.sql.parser.SqlParser) PlanNode(com.facebook.presto.spi.plan.PlanNode) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) Optional(java.util.Optional) ConnectorId(com.facebook.presto.spi.ConnectorId) Metadata(com.facebook.presto.metadata.Metadata) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 8 with TpchColumnHandle

use of com.facebook.presto.tpch.TpchColumnHandle in project presto by prestodb.

the class TestPickTableLayout method replaceWithExistsWhenNoLayoutExist.

@Test
public void replaceWithExistsWhenNoLayoutExist() {
    ColumnHandle columnHandle = new TpchColumnHandle("nationkey", BIGINT);
    tester().assertThat(pickTableLayout.pickTableLayoutForPredicate()).on(p -> {
        p.variable("nationkey", BIGINT);
        return p.filter(p.rowExpression("nationkey = BIGINT '44'"), p.tableScan(nationTableHandle, ImmutableList.of(p.variable("nationkey", BIGINT)), ImmutableMap.of(p.variable("nationkey", BIGINT), columnHandle), TupleDomain.none(), TupleDomain.none()));
    }).matches(values("A"));
    tester().assertThat(pickTableLayout.pickTableLayoutForPredicate()).on(p -> {
        p.variable("nationkey");
        return p.filter(p.rowExpression("nationkey = BIGINT '44'"), p.tableScan(nationTableHandle, ImmutableList.of(variable("nationkey", BIGINT)), ImmutableMap.of(variable("nationkey", BIGINT), columnHandle), TupleDomain.none(), TupleDomain.none()));
    }).matches(values("A"));
}
Also used : PlanMatchPattern.filter(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.filter) Test(org.testng.annotations.Test) VarcharType.createVarcharType(com.facebook.presto.common.type.VarcharType.createVarcharType) TpchTableLayoutHandle(com.facebook.presto.tpch.TpchTableLayoutHandle) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) TableHandle(com.facebook.presto.spi.TableHandle) Expressions.variable(com.facebook.presto.sql.relational.Expressions.variable) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Type(com.facebook.presto.common.type.Type) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) PlanMatchPattern.constrainedTableScanWithTableLayout(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.constrainedTableScanWithTableLayout) ImmutableMap(com.google.common.collect.ImmutableMap) Rule(com.facebook.presto.sql.planner.iterative.Rule) BeforeClass(org.testng.annotations.BeforeClass) Domain.singleValue(com.facebook.presto.common.predicate.Domain.singleValue) TestingTransactionHandle(com.facebook.presto.testing.TestingTransactionHandle) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) Optional(java.util.Optional) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) ConnectorId(com.facebook.presto.spi.ConnectorId) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) Test(org.testng.annotations.Test) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest)

Example 9 with TpchColumnHandle

use of com.facebook.presto.tpch.TpchColumnHandle in project presto by prestodb.

the class TestPickTableLayout method nonDeterministicPredicate.

@Test
public void nonDeterministicPredicate() {
    Type orderStatusType = createVarcharType(1);
    tester().assertThat(pickTableLayout.pickTableLayoutForPredicate()).on(p -> {
        p.variable("orderstatus", orderStatusType);
        return p.filter(p.rowExpression("orderstatus = 'O' AND rand() = 0"), p.tableScan(ordersTableHandle, ImmutableList.of(p.variable("orderstatus", orderStatusType)), ImmutableMap.of(p.variable("orderstatus", orderStatusType), new TpchColumnHandle("orderstatus", orderStatusType))));
    }).matches(filter("rand() = 0", constrainedTableScanWithTableLayout("orders", ImmutableMap.of("orderstatus", singleValue(orderStatusType, utf8Slice("O"))), ImmutableMap.of("orderstatus", "orderstatus"))));
    tester().assertThat(pickTableLayout.pickTableLayoutForPredicate()).on(p -> {
        p.variable("orderstatus", orderStatusType);
        return p.filter(p.rowExpression("orderstatus = 'O' AND rand() = 0"), p.tableScan(ordersTableHandle, ImmutableList.of(variable("orderstatus", orderStatusType)), ImmutableMap.of(variable("orderstatus", orderStatusType), new TpchColumnHandle("orderstatus", orderStatusType))));
    }).matches(filter("rand() = 0", constrainedTableScanWithTableLayout("orders", ImmutableMap.of("orderstatus", singleValue(orderStatusType, utf8Slice("O"))), ImmutableMap.of("orderstatus", "orderstatus"))));
}
Also used : PlanMatchPattern.filter(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.filter) Test(org.testng.annotations.Test) VarcharType.createVarcharType(com.facebook.presto.common.type.VarcharType.createVarcharType) TpchTableLayoutHandle(com.facebook.presto.tpch.TpchTableLayoutHandle) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) TableHandle(com.facebook.presto.spi.TableHandle) Expressions.variable(com.facebook.presto.sql.relational.Expressions.variable) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Type(com.facebook.presto.common.type.Type) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) PlanMatchPattern.constrainedTableScanWithTableLayout(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.constrainedTableScanWithTableLayout) ImmutableMap(com.google.common.collect.ImmutableMap) Rule(com.facebook.presto.sql.planner.iterative.Rule) BeforeClass(org.testng.annotations.BeforeClass) Domain.singleValue(com.facebook.presto.common.predicate.Domain.singleValue) TestingTransactionHandle(com.facebook.presto.testing.TestingTransactionHandle) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) Optional(java.util.Optional) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) ConnectorId(com.facebook.presto.spi.ConnectorId) VarcharType.createVarcharType(com.facebook.presto.common.type.VarcharType.createVarcharType) Type(com.facebook.presto.common.type.Type) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) Test(org.testng.annotations.Test) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest)

Example 10 with TpchColumnHandle

use of com.facebook.presto.tpch.TpchColumnHandle in project presto by prestodb.

the class TestPruneIndexSourceColumns method buildProjectedIndexSource.

private static PlanNode buildProjectedIndexSource(PlanBuilder p, Predicate<VariableReferenceExpression> projectionFilter) {
    VariableReferenceExpression orderkey = p.variable("orderkey", INTEGER);
    VariableReferenceExpression custkey = p.variable("custkey", INTEGER);
    VariableReferenceExpression totalprice = p.variable("totalprice", DOUBLE);
    ColumnHandle orderkeyHandle = new TpchColumnHandle(orderkey.getName(), INTEGER);
    ColumnHandle custkeyHandle = new TpchColumnHandle(custkey.getName(), INTEGER);
    ColumnHandle totalpriceHandle = new TpchColumnHandle(totalprice.getName(), DOUBLE);
    return p.project(identityAssignmentsAsSymbolReferences(ImmutableList.of(orderkey, custkey, totalprice).stream().filter(projectionFilter).collect(toImmutableList())), p.indexSource(new TableHandle(new ConnectorId("local"), new TpchTableHandle("orders", TINY_SCALE_FACTOR), TestingTransactionHandle.create(), Optional.empty()), ImmutableSet.of(orderkey, custkey), ImmutableList.of(orderkey, custkey, totalprice), ImmutableMap.of(orderkey, orderkeyHandle, custkey, custkeyHandle, totalprice, totalpriceHandle), TupleDomain.fromFixedValues(ImmutableMap.of(totalpriceHandle, asNull(DOUBLE)))));
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) TableHandle(com.facebook.presto.spi.TableHandle) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) ConnectorId(com.facebook.presto.spi.ConnectorId) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle)

Aggregations

TpchColumnHandle (com.facebook.presto.tpch.TpchColumnHandle)12 TableHandle (com.facebook.presto.spi.TableHandle)11 TpchTableHandle (com.facebook.presto.tpch.TpchTableHandle)11 ConnectorId (com.facebook.presto.spi.ConnectorId)10 BeforeClass (org.testng.annotations.BeforeClass)9 TpchTableLayoutHandle (com.facebook.presto.tpch.TpchTableLayoutHandle)8 ColumnHandle (com.facebook.presto.spi.ColumnHandle)6 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)5 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 Optional (java.util.Optional)5 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)4 Type (com.facebook.presto.common.type.Type)4 PlanNodeIdAllocator (com.facebook.presto.spi.plan.PlanNodeIdAllocator)4 PlanBuilder (com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)4 TestingTransactionHandle (com.facebook.presto.testing.TestingTransactionHandle)4 Map (java.util.Map)4 Domain (com.facebook.presto.common.predicate.Domain)3 Domain.singleValue (com.facebook.presto.common.predicate.Domain.singleValue)3 VarcharType.createVarcharType (com.facebook.presto.common.type.VarcharType.createVarcharType)3