zabetak commented on code in PR #4089:
URL: https://github.com/apache/calcite/pull/4089#discussion_r1882541046
##########
core/src/test/java/org/apache/calcite/test/RelMetadataTest.java:
##########
@@ -1633,6 +1647,242 @@ private void
checkColumnUniquenessForFilterWithConstantColumns(String sql) {
.assertThatUniqueKeysAre(bitSetOf(0, 1));
}
+ @Test void testUniqueKeysWithLimitOnSortOneRow() {
+ sql("select ename, empno from emp order by ename limit 1")
+ .withCatalogReaderFactory(COMPOSITE_FACTORY)
+ .assertThatRel(is(instanceOf(Sort.class)))
+ .withMetadataConfig(uniqueKeyConfig(0))
+ .assertThatUniqueKeysAre()
+ .withMetadataConfig(uniqueKeyConfig(2))
+ .assertThatUniqueKeysAre(bitSetOf());
+ }
+
+ @Test void testUniqueKeysWithLimitOnFilter() {
+ sql("select * from s.passenger t1 where t1.age > 35")
+ .withCatalogReaderFactory(COMPOSITE_FACTORY)
+ .withRelTransform(project -> project.getInput(0))
+ .assertThatRel(is(instanceOf(Filter.class)))
+ .withMetadataConfig(uniqueKeyConfig(2))
+ .assertThatUniqueKeysAre(bitSetOf(0), bitSetOf(1));
+ }
+
+ @Test void
testUniqueKeysWithLimitOnProjectOverInputWithCompositeKeyAndRepeatedColumns() {
+ String cols = IntStream.range(0, 32).mapToObj(i -> "k" +
i).collect(Collectors.joining(","));
+ sql("select " + cols + ", " + cols + " from s.composite_keys_32_table")
+ .withCatalogReaderFactory(COMPOSITE_FACTORY)
+ .assertThatRel(is(instanceOf(Project.class)))
+ .withMetadataConfig(uniqueKeyConfig(2))
+ .assertThatUniqueKeysAre(ImmutableBitSet.range(0, 32),
+ ImmutableBitSet.range(0, 31).set(63));
Review Comment:
In various cases when there are changes in the compiler the plans change and
we have to update the golden files. I guess these tests would fall in the same
bucket they may need to be updated at some point in time.
The main purpose of the test is to show that the limit (2) is respected and
the query does not crash with OOM, which is the case without the changes.
Regarding the correctness of the output there should be already many other
tests that do this kind of verification.
In fact having the column names here, would make the result even more
confusing since each column appears twice in the project.
Admittedly, the results from the UniqueKeys API are difficult to digest at
first sight but it becomes easier after seeing a few simple examples.
--
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]