[ https://issues.apache.org/jira/browse/CALCITE-2146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16334696#comment-16334696 ]
Julian Hyde commented on CALCITE-2146: -------------------------------------- It was not designed to be thread-safe. A cluster is the state for preparing a query. We assume that only one thread is preparing a particular query at a time. The solution to your problem, probably, is to copy a template into its own cluster when you start working on it as a mutable query. > Errant CyclicMetadataException in multithreaded context > ------------------------------------------------------- > > Key: CALCITE-2146 > URL: https://issues.apache.org/jira/browse/CALCITE-2146 > Project: Calcite > Issue Type: Bug > Components: core > Affects Versions: 1.15.0 > Reporter: Paul Jackson > Assignee: Julian Hyde > Priority: Major > > The code that protects against cyclic metadata is not thread-safe. A typical > stack trace looks like: > {{Caused by: org.apache.calcite.rel.metadata.CyclicMetadataException}} > {{ at > org.apache.calcite.rel.metadata.CyclicMetadataException.<clinit>(CyclicMetadataException.java:28)}} > {{ at GeneratedMetadataHandler_Collation.collations(Unknown Source)}} > {{ at GeneratedMetadataHandler_Collation.collations_$(Unknown Source)}} > {{ at GeneratedMetadataHandler_Collation.collations(Unknown Source)}} > {{ at > org.apache.calcite.rel.metadata.RelMetadataQuery.collations(RelMetadataQuery.java:563)}} > {{ at > org.apache.calcite.rel.metadata.RelMdCollation.collations(RelMdCollation.java:117)}} > {{ at GeneratedMetadataHandler_Collation.collations_$(Unknown Source)}} > {{ at GeneratedMetadataHandler_Collation.collations(Unknown Source)}} > {{ at GeneratedMetadataHandler_Collation.collations_$(Unknown Source)}} > {{ at GeneratedMetadataHandler_Collation.collations(Unknown Source)}} > {{ at > org.apache.calcite.rel.metadata.RelMetadataQuery.collations(RelMetadataQuery.java:563)}} > {{ at > org.apache.calcite.rel.metadata.RelMdCollation.project(RelMdCollation.java:207)}} > {{ at > org.apache.calcite.rel.logical.LogicalProject$1.get(LogicalProject.java:117)}} > {{ at > org.apache.calcite.rel.logical.LogicalProject$1.get(LogicalProject.java:115)}} > {{ at org.apache.calcite.plan.RelTraitSet.replaceIfs(RelTraitSet.java:238)}} > {{ at > org.apache.calcite.rel.logical.LogicalProject.create(LogicalProject.java:113)}} > {{ at > org.apache.calcite.rel.logical.LogicalProject.create(LogicalProject.java:103)}} > {{ at > org.apache.calcite.rel.core.RelFactories$ProjectFactoryImpl.createProject(RelFactories.java:127)}} > {{ at org.apache.calcite.tools.RelBuilder.project(RelBuilder.java:1064)}} > Generally, the use case that causes this is one where we have a set of SQL > templates represented as RelNodes, which we use as a starting point for > queries. If different threads operate on the same RelNode, they may work on > the same cluster, and therefore the same RelMetadataQuery instance, which > contains a map instance that is used to detect Cyclic Metadata. -- This message was sent by Atlassian JIRA (v7.6.3#76005)