Search in sources :

Example 6 with FlinkRelMetadataQuery

use of org.apache.flink.table.planner.plan.metadata.FlinkRelMetadataQuery in project flink by apache.

the class CatalogConstraintTest method testWithPrimaryKey.

@Test
public void testWithPrimaryKey() throws Exception {
    TableSchema tableSchema = TableSchema.builder().fields(new String[] { "a", "b", "c" }, new DataType[] { DataTypes.STRING(), DataTypes.BIGINT().notNull(), DataTypes.INT() }).primaryKey("b").build();
    Map<String, String> properties = buildCatalogTableProperties(tableSchema);
    catalog.createTable(new ObjectPath(databaseName, "T1"), new CatalogTableImpl(tableSchema, properties, ""), false);
    RelNode t1 = TableTestUtil.toRelNode(tEnv.sqlQuery("select * from T1"));
    FlinkRelMetadataQuery mq = FlinkRelMetadataQuery.reuseOrCreate(t1.getCluster().getMetadataQuery());
    assertEquals(ImmutableSet.of(ImmutableBitSet.of(1)), mq.getUniqueKeys(t1));
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) TableSchema(org.apache.flink.table.api.TableSchema) RelNode(org.apache.calcite.rel.RelNode) CatalogTableImpl(org.apache.flink.table.catalog.CatalogTableImpl) FlinkRelMetadataQuery(org.apache.flink.table.planner.plan.metadata.FlinkRelMetadataQuery) Test(org.junit.Test)

Example 7 with FlinkRelMetadataQuery

use of org.apache.flink.table.planner.plan.metadata.FlinkRelMetadataQuery in project flink by apache.

the class CatalogStatisticsTest method assertTableStatisticsWithUnknownRowCount.

private void assertTableStatisticsWithUnknownRowCount(TableEnvironment tEnv, String tableName) {
    RelNode t1 = TableTestUtil.toRelNode(tEnv.sqlQuery("select * from " + tableName));
    FlinkRelMetadataQuery mq = FlinkRelMetadataQuery.reuseOrCreate(t1.getCluster().getMetadataQuery());
    // 1E8 is default value defined in FlinkPreparingTableBase
    assertEquals(1E8, mq.getRowCount(t1), 0.0);
    assertColumnStatistics(t1, mq);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) FlinkRelMetadataQuery(org.apache.flink.table.planner.plan.metadata.FlinkRelMetadataQuery)

Example 8 with FlinkRelMetadataQuery

use of org.apache.flink.table.planner.plan.metadata.FlinkRelMetadataQuery in project flink by apache.

the class CatalogStatisticsTest method testGetPartitionStatsWithSomeUnknownColumnStats.

@Test
public void testGetPartitionStatsWithSomeUnknownColumnStats() throws Exception {
    TestPartitionableSourceFactory.createTemporaryTable(tEnv, "PartT", true);
    createPartitionStats("A", 1);
    createPartitionColumnStats("A", 1, true);
    createPartitionStats("A", 2);
    createPartitionColumnStats("A", 2);
    RelNode t1 = ((PlannerBase) ((TableEnvironmentImpl) tEnv).getPlanner()).optimize(TableTestUtil.toRelNode(tEnv.sqlQuery("select id, name from PartT where part1 = 'A'")));
    FlinkRelMetadataQuery mq = FlinkRelMetadataQuery.reuseOrCreate(t1.getCluster().getMetadataQuery());
    assertEquals(200.0, mq.getRowCount(t1), 0.0);
    // long type
    assertNull(mq.getDistinctRowCount(t1, ImmutableBitSet.of(0), null));
    assertNull(mq.getColumnNullCount(t1, 0));
    assertNull(mq.getColumnInterval(t1, 0));
    // string type
    assertNull(mq.getDistinctRowCount(t1, ImmutableBitSet.of(1), null));
    assertNull(mq.getColumnNullCount(t1, 1));
}
Also used : RelNode(org.apache.calcite.rel.RelNode) PlannerBase(org.apache.flink.table.planner.delegation.PlannerBase) FlinkRelMetadataQuery(org.apache.flink.table.planner.plan.metadata.FlinkRelMetadataQuery) Test(org.junit.Test)

Example 9 with FlinkRelMetadataQuery

use of org.apache.flink.table.planner.plan.metadata.FlinkRelMetadataQuery in project flink by apache.

the class CatalogStatisticsTest method testGetPartitionStatsWithUnknownColumnStats.

@Test
public void testGetPartitionStatsWithUnknownColumnStats() throws Exception {
    TestPartitionableSourceFactory.createTemporaryTable(tEnv, "PartT", true);
    createPartitionStats("A", 1);
    createPartitionStats("A", 2);
    createPartitionColumnStats("A", 2);
    RelNode t1 = ((PlannerBase) ((TableEnvironmentImpl) tEnv).getPlanner()).optimize(TableTestUtil.toRelNode(tEnv.sqlQuery("select id, name from PartT where part1 = 'A'")));
    FlinkRelMetadataQuery mq = FlinkRelMetadataQuery.reuseOrCreate(t1.getCluster().getMetadataQuery());
    assertEquals(200.0, mq.getRowCount(t1), 0.0);
    // long type
    assertNull(mq.getDistinctRowCount(t1, ImmutableBitSet.of(0), null));
    assertNull(mq.getColumnNullCount(t1, 0));
    assertNull(mq.getColumnInterval(t1, 0));
    // string type
    assertNull(mq.getDistinctRowCount(t1, ImmutableBitSet.of(1), null));
    assertNull(mq.getColumnNullCount(t1, 1));
}
Also used : RelNode(org.apache.calcite.rel.RelNode) PlannerBase(org.apache.flink.table.planner.delegation.PlannerBase) FlinkRelMetadataQuery(org.apache.flink.table.planner.plan.metadata.FlinkRelMetadataQuery) Test(org.junit.Test)

Example 10 with FlinkRelMetadataQuery

use of org.apache.flink.table.planner.plan.metadata.FlinkRelMetadataQuery in project flink by apache.

the class CatalogStatisticsTest method testGetPartitionStatsWithUnknownRowCount.

@Test
public void testGetPartitionStatsWithUnknownRowCount() throws Exception {
    TestPartitionableSourceFactory.createTemporaryTable(tEnv, "PartT", true);
    createPartitionStats("A", 1, TableStats.UNKNOWN.getRowCount());
    createPartitionColumnStats("A", 1);
    createPartitionStats("A", 2);
    createPartitionColumnStats("A", 2);
    RelNode t1 = ((PlannerBase) ((TableEnvironmentImpl) tEnv).getPlanner()).optimize(TableTestUtil.toRelNode(tEnv.sqlQuery("select id, name from PartT where part1 = 'A'")));
    FlinkRelMetadataQuery mq = FlinkRelMetadataQuery.reuseOrCreate(t1.getCluster().getMetadataQuery());
    assertEquals(100_000_000, mq.getRowCount(t1), 0.0);
    assertEquals(Arrays.asList(8.0, 43.5), mq.getAverageColumnSizes(t1));
    // long type
    assertEquals(46.0, mq.getDistinctRowCount(t1, ImmutableBitSet.of(0), null), 0.0);
    assertEquals(154.0, mq.getColumnNullCount(t1, 0), 0.0);
    assertEquals(ValueInterval$.MODULE$.apply(BigDecimal.valueOf(-123L), BigDecimal.valueOf(763322L), true, true), mq.getColumnInterval(t1, 0));
    // string type
    assertEquals(40.0, mq.getDistinctRowCount(t1, ImmutableBitSet.of(1), null), 0.0);
    assertEquals(0.0, mq.getColumnNullCount(t1, 1), 0.0);
    assertNull(mq.getColumnInterval(t1, 1));
}
Also used : RelNode(org.apache.calcite.rel.RelNode) PlannerBase(org.apache.flink.table.planner.delegation.PlannerBase) FlinkRelMetadataQuery(org.apache.flink.table.planner.plan.metadata.FlinkRelMetadataQuery) Test(org.junit.Test)

Aggregations

RelNode (org.apache.calcite.rel.RelNode)10 FlinkRelMetadataQuery (org.apache.flink.table.planner.plan.metadata.FlinkRelMetadataQuery)10 Test (org.junit.Test)6 PlannerBase (org.apache.flink.table.planner.delegation.PlannerBase)4 Collections (java.util.Collections)2 List (java.util.List)2 Set (java.util.Set)2 TableSchema (org.apache.flink.table.api.TableSchema)2 CatalogTableImpl (org.apache.flink.table.catalog.CatalogTableImpl)2 ObjectPath (org.apache.flink.table.catalog.ObjectPath)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 RelOptUtil (org.apache.calcite.plan.RelOptUtil)1