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));
}
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);
}
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));
}
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));
}
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));
}
Aggregations