NobiGo commented on code in PR #4459:
URL: https://github.com/apache/calcite/pull/4459#discussion_r2188807792
##########
core/src/test/java/org/apache/calcite/test/RelMetadataTest.java:
##########
@@ -4463,6 +4463,41 @@ static <K, V> List<String> toSortedStringList(Map<K, V>
map) {
assertThat(ndv, is(100.0));
}
+ /** Test case of
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7083">[CALCITE-7083]
+ * RelMdDistinctRowCount aggregates implementation problems</a>. */
+ @Test void testAggregateDistinctRowcount() {
+ // test case of groupKey contains aggregated column
+ sql("select name, sum(sal) from (values ('b', 10), ('b', 20), ('b', 30))
as t(name, sal) "
+ + "group by name")
+ .assertThatDistinctRowCount(bitSetOf(1), is(1d));
+ sql("select name, sum(sal) from (values ('a', 10), ('b', 10), ('c', 10))
as t(name, sal) "
+ + "group by name")
+ .assertThatDistinctRowCount(bitSetOf(1), is(3d));
+ // test case of predicate is not null
+ // LogicalFilter(condition=[=($0, 2)])
+ // LogicalAggregate(group=[{1}], sumsal=[SUM($0)])
+ // LogicalValues(tuples=[[{ 10, 1 }, { 20, 2 }, { 30, 3 }]])
+ // since the selectivity of the predicate is guessed, this ndv does not
represent the actual
+ // value. This case is only to verify that the predicate will be correctly
pushed down
+ // to the Value
+ fixture()
+ .withRelFn(b -> {
+ b.values(new String[]{"sal", "id"}, 10, 1, 20, 2, 30, 3);
+ RelBuilder.GroupKey groupKey = b.groupKey(1);
+ AggregateCall sum =
+ AggregateCall.create(SqlStdOperatorTable.SUM, false, false,
false,
+ ImmutableList.of(), ImmutableList.of(0), -1, null,
RelCollations.EMPTY,
+ 1, b.peek(), null, "sumsal");
+ b.aggregate(groupKey, ImmutableList.of(sum));
Review Comment:
You can try use `a.aggregate(groupKey,b.sum(xxxx,xxx))` replace sum
**AggregateCall.**
##########
core/src/test/java/org/apache/calcite/test/RelMetadataTest.java:
##########
@@ -4463,6 +4463,41 @@ static <K, V> List<String> toSortedStringList(Map<K, V>
map) {
assertThat(ndv, is(100.0));
}
+ /** Test case of
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7083">[CALCITE-7083]
+ * RelMdDistinctRowCount aggregates implementation problems</a>. */
+ @Test void testAggregateDistinctRowcount() {
+ // test case of groupKey contains aggregated column
+ sql("select name, sum(sal) from (values ('b', 10), ('b', 20), ('b', 30))
as t(name, sal) "
+ + "group by name")
+ .assertThatDistinctRowCount(bitSetOf(1), is(1d));
+ sql("select name, sum(sal) from (values ('a', 10), ('b', 10), ('c', 10))
as t(name, sal) "
+ + "group by name")
+ .assertThatDistinctRowCount(bitSetOf(1), is(3d));
+ // test case of predicate is not null
+ // LogicalFilter(condition=[=($0, 2)])
+ // LogicalAggregate(group=[{1}], sumsal=[SUM($0)])
+ // LogicalValues(tuples=[[{ 10, 1 }, { 20, 2 }, { 30, 3 }]])
+ // since the selectivity of the predicate is guessed, this ndv does not
represent the actual
+ // value. This case is only to verify that the predicate will be correctly
pushed down
+ // to the Value
+ fixture()
+ .withRelFn(b -> {
+ b.values(new String[]{"sal", "id"}, 10, 1, 20, 2, 30, 3);
+ RelBuilder.GroupKey groupKey = b.groupKey(1);
+ AggregateCall sum =
+ AggregateCall.create(SqlStdOperatorTable.SUM, false, false,
false,
+ ImmutableList.of(), ImmutableList.of(0), -1, null,
RelCollations.EMPTY,
+ 1, b.peek(), null, "sumsal");
+ b.aggregate(groupKey, ImmutableList.of(sum));
+ RexNode predicate =
+ b.equals(RexInputRef.of(0, b.peek().getRowType()), b.literal(2));
Review Comment:
`b.field(0)` may be can replace `RexInputRef.of(0, b.peek().getRowType())`.
##########
core/src/test/java/org/apache/calcite/test/RelMetadataTest.java:
##########
@@ -4463,6 +4463,41 @@ static <K, V> List<String> toSortedStringList(Map<K, V>
map) {
assertThat(ndv, is(100.0));
}
+ /** Test case of
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7083">[CALCITE-7083]
+ * RelMdDistinctRowCount aggregates implementation problems</a>. */
+ @Test void testAggregateDistinctRowcount() {
+ // test case of groupKey contains aggregated column
+ sql("select name, sum(sal) from (values ('b', 10), ('b', 20), ('b', 30))
as t(name, sal) "
+ + "group by name")
+ .assertThatDistinctRowCount(bitSetOf(1), is(1d));
+ sql("select name, sum(sal) from (values ('a', 10), ('b', 10), ('c', 10))
as t(name, sal) "
+ + "group by name")
+ .assertThatDistinctRowCount(bitSetOf(1), is(3d));
+ // test case of predicate is not null
+ // LogicalFilter(condition=[=($0, 2)])
+ // LogicalAggregate(group=[{1}], sumsal=[SUM($0)])
+ // LogicalValues(tuples=[[{ 10, 1 }, { 20, 2 }, { 30, 3 }]])
+ // since the selectivity of the predicate is guessed, this ndv does not
represent the actual
Review Comment:
Here, NDV should be capitalized.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]