vlsi commented on a change in pull request #2154:
URL: https://github.com/apache/calcite/pull/2154#discussion_r504475521
##########
File path: core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
##########
@@ -3102,6 +3108,69 @@ private void checkNodeTypeCount(String sql, Map<Class<?
extends RelNode>, Intege
is("=($0, $1)"));
}
+ @Test void testColumnStatistics() {
+ final FrameworkConfig config = RelBuilderTest.config().build();
+ final RelBuilder builder = RelBuilder.create(config);
+ final RelOptCluster cluster = builder.getCluster();
+ final RelDataTypeFactory typeFactory = cluster.getTypeFactory();
+
+ final RelDataType stringType = typeFactory.createJavaType(String.class);
+ final RelDataType integerType = typeFactory.createJavaType(Integer.class);
+
+ final Map<String, ColStatistics> colStatistics = new HashMap<>();
+ final String col1 = "key";
+ final String col2 = "count";
+
+ final ColStatistics colStats = new ColStatistics() {
+ @Override public Long getCountDistinct() {
+ return 5L;
+ }
+
+ @Override public Double getAvgColLen() {
+ return 2D;
+ }
+
+ @Override public Long getNumNulls() {
+ return null;
+ }
+
+ @Override public <C> C unwrap(Class<C> aClass) {
+ return null;
+ }
+ };
+
+ colStatistics.put(col1, colStats);
+ final Table table = new AbstractTable() {
+ public RelDataType getRowType(RelDataTypeFactory typeFactory) {
+ return typeFactory.builder()
+ .add(col1, stringType)
+ .add(col2, integerType).build();
+ }
+
+ @Override public Statistic getStatistic() {
+ return Statistics.of(100d, colStatistics);
+ }
+ };
+
+ final RelOptAbstractTable t1 = new RelOptAbstractTable(null,
+ "t1", table.getRowType(typeFactory)) {
+ @Override public ColStatistics getColumnStatistics(String colName) {
+ return table.getStatistic().getColumnStats(colName);
+ }
+ };
+
+ final RelNode rel = LogicalTableScan.create(cluster, t1,
ImmutableList.of());
+ final RelMetadataQuery mq = rel.getCluster().getMetadataQuery();
+
+ ImmutableBitSet groupKey =
+ ImmutableBitSet.of(rel.getRowType().getFieldNames().indexOf(col1));
+ Double ndv = mq.getDistinctRowCount(rel, groupKey, null);
+ assertThat(ndv.intValue(), is(5));
+
+ Double size = mq.getAverageRowSize(rel);
+ assertThat(size.intValue(), is(6));
Review comment:
Please add the clarification messages. For instance:
`"getAverageRowSize(...), rowType=" + rel.getRowType()`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]