use of org.apache.calcite.rel.metadata.Metadata in project calcite by apache.
the class RelMetadataTest method testMetadataHandlerCacheLimit.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1808">[CALCITE-1808]
* JaninoRelMetadataProvider loading cache might cause
* OutOfMemoryError</a>.
*
* <p>Too slow to run every day, and it does not reproduce the issue.
*/
@Tag("slow")
@Test
void testMetadataHandlerCacheLimit() {
assumeTrue(CalciteSystemProperty.METADATA_HANDLER_CACHE_MAXIMUM_SIZE.value() < 10_000, "If cache size is too large, this test may fail and the test won't be to blame");
final int iterationCount = 2_000;
final RelNode rel = sql("select * from emp").toRel();
final RelMetadataProvider metadataProvider = rel.getCluster().getMetadataProvider();
for (int i = 0; i < iterationCount; i++) {
RelMetadataProvider wrappedProvider = new RelMetadataProvider() {
// to be removed before 2.0
@Deprecated
@Override
@Nullable
public <M extends @Nullable Metadata> UnboundMetadata<M> apply(Class<? extends RelNode> relClass, Class<? extends M> metadataClass) {
return metadataProvider.apply(relClass, metadataClass);
}
// to be removed before 2.0
@Deprecated
@Override
public <M extends Metadata> Multimap<Method, MetadataHandler<M>> handlers(MetadataDef<M> def) {
return metadataProvider.handlers(def);
}
@Override
public List<MetadataHandler<?>> handlers(Class<? extends MetadataHandler<?>> handlerClass) {
return metadataProvider.handlers(handlerClass);
}
};
RelMetadataQuery.THREAD_PROVIDERS.set(JaninoRelMetadataProvider.of(wrappedProvider));
final RelMetadataQuery mq = rel.getCluster().getMetadataQuery();
final Double result = mq.getRowCount(rel);
assertThat(result, within(14d, 0.1d));
}
}
Aggregations