Search in sources :

Example 1 with MetadataHandler

use of org.apache.calcite.rel.metadata.MetadataHandler 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));
    }
}
Also used : RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) RelNode(org.apache.calcite.rel.RelNode) BuiltInMetadata(org.apache.calcite.rel.metadata.BuiltInMetadata) Metadata(org.apache.calcite.rel.metadata.Metadata) UnboundMetadata(org.apache.calcite.rel.metadata.UnboundMetadata) JaninoRelMetadataProvider(org.apache.calcite.rel.metadata.JaninoRelMetadataProvider) DefaultRelMetadataProvider(org.apache.calcite.rel.metadata.DefaultRelMetadataProvider) ChainedRelMetadataProvider(org.apache.calcite.rel.metadata.ChainedRelMetadataProvider) ReflectiveRelMetadataProvider(org.apache.calcite.rel.metadata.ReflectiveRelMetadataProvider) RelMetadataProvider(org.apache.calcite.rel.metadata.RelMetadataProvider) MetadataDef(org.apache.calcite.rel.metadata.MetadataDef) Method(java.lang.reflect.Method) MetadataHandler(org.apache.calcite.rel.metadata.MetadataHandler) RelHint(org.apache.calcite.rel.hint.RelHint) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Aggregations

Method (java.lang.reflect.Method)1 RelNode (org.apache.calcite.rel.RelNode)1 RelHint (org.apache.calcite.rel.hint.RelHint)1 BuiltInMetadata (org.apache.calcite.rel.metadata.BuiltInMetadata)1 ChainedRelMetadataProvider (org.apache.calcite.rel.metadata.ChainedRelMetadataProvider)1 DefaultRelMetadataProvider (org.apache.calcite.rel.metadata.DefaultRelMetadataProvider)1 JaninoRelMetadataProvider (org.apache.calcite.rel.metadata.JaninoRelMetadataProvider)1 Metadata (org.apache.calcite.rel.metadata.Metadata)1 MetadataDef (org.apache.calcite.rel.metadata.MetadataDef)1 MetadataHandler (org.apache.calcite.rel.metadata.MetadataHandler)1 ReflectiveRelMetadataProvider (org.apache.calcite.rel.metadata.ReflectiveRelMetadataProvider)1 RelMetadataProvider (org.apache.calcite.rel.metadata.RelMetadataProvider)1 RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)1 UnboundMetadata (org.apache.calcite.rel.metadata.UnboundMetadata)1 Tag (org.junit.jupiter.api.Tag)1 Test (org.junit.jupiter.api.Test)1