This is an automated email from the ASF dual-hosted git repository.

laurent pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/master by this push:
     new 00f8b5f  RelOptUtilTest concurrency fixup
00f8b5f is described below

commit 00f8b5f5ca1d45ce5029a474c42e674bec31634f
Author: Laurent Goujon <laur...@apache.org>
AuthorDate: Wed May 29 14:04:46 2019 -0700

    RelOptUtilTest concurrency fixup
    
    RelOptUtilTest was creating a static RelOptCluster which could be used
    during tests running in parallel to acces the associated RelMetadataQuery
    instance.  Alas the object is not safe to access from multiple threads
    and in some occasions tests would fail with CyclicMetadataException.
    
    Fixing the test class by creating a new RelOptCluster/RelBuilder
    instance for each test, and removing the static instances.
---
 .../org/apache/calcite/plan/RelOptUtilTest.java    | 143 +++++++++++----------
 1 file changed, 73 insertions(+), 70 deletions(-)

diff --git a/core/src/test/java/org/apache/calcite/plan/RelOptUtilTest.java 
b/core/src/test/java/org/apache/calcite/plan/RelOptUtilTest.java
index a72df31..a284e10 100644
--- a/core/src/test/java/org/apache/calcite/plan/RelOptUtilTest.java
+++ b/core/src/test/java/org/apache/calcite/plan/RelOptUtilTest.java
@@ -65,21 +65,15 @@ public class RelOptUtilTest {
         .defaultSchema(CalciteAssert.addSchema(rootSchema, 
CalciteAssert.SchemaSpec.SCOTT));
   }
 
-  private static final RelNode EMP_SCAN;
-  private static final RelNode DEPT_SCAN;
-  static {
-    final RelBuilder builder = RelBuilder.create(config().build());
-    EMP_SCAN = builder.scan("EMP").build();
-    DEPT_SCAN = builder.scan("DEPT").build();
-  }
+  private RelBuilder relBuilder;
 
-  private static final RelDataType EMP_ROW = EMP_SCAN.getRowType();
-  private static final RelDataType DEPT_ROW = DEPT_SCAN.getRowType();
+  private RelNode empScan;
+  private RelNode deptScan;
 
-  private static final List<RelDataTypeField> EMP_DEPT_JOIN_REL_FIELDS =
-      Lists.newArrayList(Iterables.concat(EMP_ROW.getFieldList(), 
DEPT_ROW.getFieldList()));
+  private RelDataType empRow;
+  private RelDataType deptRow;
 
-  private RelBuilder relBuilder;
+  private List<RelDataTypeField> empDeptJoinRelFields;
 
   //~ Constructors -----------------------------------------------------------
 
@@ -90,6 +84,15 @@ public class RelOptUtilTest {
 
   @Before public void setUp() {
     relBuilder = RelBuilder.create(config().build());
+
+    empScan = relBuilder.scan("EMP").build();
+    deptScan = relBuilder.scan("DEPT").build();
+
+    empRow = empScan.getRowType();
+    deptRow = deptScan.getRowType();
+
+    empDeptJoinRelFields =
+        Lists.newArrayList(Iterables.concat(empRow.getFieldList(), 
deptRow.getFieldList()));
   }
 
   @Test public void testTypeDump() {
@@ -145,12 +148,12 @@ public class RelOptUtilTest {
    * where the join condition contains just one which is a EQUAL operator.
    */
   @Test public void testSplitJoinConditionEquals() {
-    int leftJoinIndex = 
EMP_SCAN.getRowType().getFieldNames().indexOf("DEPTNO");
-    int rightJoinIndex = DEPT_ROW.getFieldNames().indexOf("DEPTNO");
+    int leftJoinIndex = empScan.getRowType().getFieldNames().indexOf("DEPTNO");
+    int rightJoinIndex = deptRow.getFieldNames().indexOf("DEPTNO");
 
     RexNode joinCond = relBuilder.call(SqlStdOperatorTable.EQUALS,
-        RexInputRef.of(leftJoinIndex, EMP_DEPT_JOIN_REL_FIELDS),
-        RexInputRef.of(EMP_ROW.getFieldCount() + rightJoinIndex, 
EMP_DEPT_JOIN_REL_FIELDS));
+        RexInputRef.of(leftJoinIndex, empDeptJoinRelFields),
+        RexInputRef.of(empRow.getFieldCount() + rightJoinIndex, 
empDeptJoinRelFields));
 
     splitJoinConditionHelper(
         joinCond,
@@ -165,12 +168,12 @@ public class RelOptUtilTest {
    * where the join condition contains just one which is a IS NOT DISTINCT 
operator.
    */
   @Test public void testSplitJoinConditionIsNotDistinctFrom() {
-    int leftJoinIndex = 
EMP_SCAN.getRowType().getFieldNames().indexOf("DEPTNO");
-    int rightJoinIndex = DEPT_ROW.getFieldNames().indexOf("DEPTNO");
+    int leftJoinIndex = empScan.getRowType().getFieldNames().indexOf("DEPTNO");
+    int rightJoinIndex = deptRow.getFieldNames().indexOf("DEPTNO");
 
     RexNode joinCond = 
relBuilder.call(SqlStdOperatorTable.IS_NOT_DISTINCT_FROM,
-        RexInputRef.of(leftJoinIndex, EMP_DEPT_JOIN_REL_FIELDS),
-        RexInputRef.of(EMP_ROW.getFieldCount() + rightJoinIndex, 
EMP_DEPT_JOIN_REL_FIELDS));
+        RexInputRef.of(leftJoinIndex, empDeptJoinRelFields),
+        RexInputRef.of(empRow.getFieldCount() + rightJoinIndex, 
empDeptJoinRelFields));
 
     splitJoinConditionHelper(
         joinCond,
@@ -185,12 +188,12 @@ public class RelOptUtilTest {
    * where the join condition contains an expanded version of IS NOT DISTINCT
    */
   @Test public void testSplitJoinConditionExpandedIsNotDistinctFrom() {
-    int leftJoinIndex = 
EMP_SCAN.getRowType().getFieldNames().indexOf("DEPTNO");
-    int rightJoinIndex = DEPT_ROW.getFieldNames().indexOf("DEPTNO");
+    int leftJoinIndex = empScan.getRowType().getFieldNames().indexOf("DEPTNO");
+    int rightJoinIndex = deptRow.getFieldNames().indexOf("DEPTNO");
 
-    RexInputRef leftKeyInputRef = RexInputRef.of(leftJoinIndex, 
EMP_DEPT_JOIN_REL_FIELDS);
+    RexInputRef leftKeyInputRef = RexInputRef.of(leftJoinIndex, 
empDeptJoinRelFields);
     RexInputRef rightKeyInputRef =
-        RexInputRef.of(EMP_ROW.getFieldCount() + rightJoinIndex, 
EMP_DEPT_JOIN_REL_FIELDS);
+        RexInputRef.of(empRow.getFieldCount() + rightJoinIndex, 
empDeptJoinRelFields);
     RexNode joinCond = relBuilder.call(SqlStdOperatorTable.OR,
         relBuilder.call(SqlStdOperatorTable.EQUALS, leftKeyInputRef, 
rightKeyInputRef),
         relBuilder.call(SqlStdOperatorTable.AND,
@@ -210,12 +213,12 @@ public class RelOptUtilTest {
    * where the join condition contains an expanded version of IS NOT DISTINCT 
using CASE
    */
   @Test public void testSplitJoinConditionExpandedIsNotDistinctFromUsingCase() 
{
-    int leftJoinIndex = 
EMP_SCAN.getRowType().getFieldNames().indexOf("DEPTNO");
-    int rightJoinIndex = DEPT_ROW.getFieldNames().indexOf("DEPTNO");
+    int leftJoinIndex = empScan.getRowType().getFieldNames().indexOf("DEPTNO");
+    int rightJoinIndex = deptRow.getFieldNames().indexOf("DEPTNO");
 
-    RexInputRef leftKeyInputRef = RexInputRef.of(leftJoinIndex, 
EMP_DEPT_JOIN_REL_FIELDS);
+    RexInputRef leftKeyInputRef = RexInputRef.of(leftJoinIndex, 
empDeptJoinRelFields);
     RexInputRef rightKeyInputRef =
-        RexInputRef.of(EMP_ROW.getFieldCount() + rightJoinIndex, 
EMP_DEPT_JOIN_REL_FIELDS);
+        RexInputRef.of(empRow.getFieldCount() + rightJoinIndex, 
empDeptJoinRelFields);
     RexNode joinCond = RelOptUtil.isDistinctFrom(
         relBuilder.getRexBuilder(),
         leftKeyInputRef,
@@ -236,12 +239,12 @@ public class RelOptUtilTest {
    * where the join condition contains an expanded version of IS NOT DISTINCT 
using CASE
    */
   @Test public void 
testSplitJoinConditionExpandedIsNotDistinctFromUsingCase2() {
-    int leftJoinIndex = 
EMP_SCAN.getRowType().getFieldNames().indexOf("DEPTNO");
-    int rightJoinIndex = DEPT_ROW.getFieldNames().indexOf("DEPTNO");
+    int leftJoinIndex = empScan.getRowType().getFieldNames().indexOf("DEPTNO");
+    int rightJoinIndex = deptRow.getFieldNames().indexOf("DEPTNO");
 
-    RexInputRef leftKeyInputRef = RexInputRef.of(leftJoinIndex, 
EMP_DEPT_JOIN_REL_FIELDS);
+    RexInputRef leftKeyInputRef = RexInputRef.of(leftJoinIndex, 
empDeptJoinRelFields);
     RexInputRef rightKeyInputRef =
-        RexInputRef.of(EMP_ROW.getFieldCount() + rightJoinIndex, 
EMP_DEPT_JOIN_REL_FIELDS);
+        RexInputRef.of(empRow.getFieldCount() + rightJoinIndex, 
empDeptJoinRelFields);
     RexNode joinCond = relBuilder.call(SqlStdOperatorTable.CASE,
         relBuilder.call(SqlStdOperatorTable.IS_NULL, leftKeyInputRef),
         relBuilder.call(SqlStdOperatorTable.IS_NULL, rightKeyInputRef),
@@ -257,13 +260,13 @@ public class RelOptUtilTest {
         relBuilder.literal(true));
   }
 
-  private static void splitJoinConditionHelper(RexNode joinCond, List<Integer> 
expLeftKeys,
+  private void splitJoinConditionHelper(RexNode joinCond, List<Integer> 
expLeftKeys,
       List<Integer> expRightKeys, List<Boolean> expFilterNulls, RexNode 
expRemaining) {
     List<Integer> actLeftKeys = new ArrayList<>();
     List<Integer> actRightKeys = new ArrayList<>();
     List<Boolean> actFilterNulls = new ArrayList<>();
 
-    RexNode actRemaining = RelOptUtil.splitJoinCondition(EMP_SCAN, DEPT_SCAN, 
joinCond, actLeftKeys,
+    RexNode actRemaining = RelOptUtil.splitJoinCondition(empScan, deptScan, 
joinCond, actLeftKeys,
         actRightKeys, actFilterNulls);
 
     assertEquals(expRemaining, actRemaining);
@@ -277,20 +280,20 @@ public class RelOptUtilTest {
    * where the join condition contains a complex expression
    */
   @Test public void testPushDownJoinConditions() {
-    int leftJoinIndex = 
EMP_SCAN.getRowType().getFieldNames().indexOf("DEPTNO");
-    int rightJoinIndex = DEPT_ROW.getFieldNames().indexOf("DEPTNO");
+    int leftJoinIndex = empScan.getRowType().getFieldNames().indexOf("DEPTNO");
+    int rightJoinIndex = deptRow.getFieldNames().indexOf("DEPTNO");
 
-    RexInputRef leftKeyInputRef = RexInputRef.of(leftJoinIndex, 
EMP_DEPT_JOIN_REL_FIELDS);
+    RexInputRef leftKeyInputRef = RexInputRef.of(leftJoinIndex, 
empDeptJoinRelFields);
     RexInputRef rightKeyInputRef =
-        RexInputRef.of(EMP_ROW.getFieldCount() + rightJoinIndex, 
EMP_DEPT_JOIN_REL_FIELDS);
+        RexInputRef.of(empRow.getFieldCount() + rightJoinIndex, 
empDeptJoinRelFields);
     RexNode joinCond = relBuilder.call(SqlStdOperatorTable.EQUALS,
         relBuilder.call(SqlStdOperatorTable.PLUS, leftKeyInputRef, 
relBuilder.literal(1)),
         rightKeyInputRef);
 
 
     // Build the join operator and push down join conditions
-    relBuilder.push(EMP_SCAN);
-    relBuilder.push(DEPT_SCAN);
+    relBuilder.push(empScan);
+    relBuilder.push(deptScan);
     relBuilder.join(JoinRelType.INNER, joinCond);
     Join join = (Join) relBuilder.build();
     RelNode transformed = RelOptUtil.pushDownJoinConditions(join, relBuilder);
@@ -306,13 +309,13 @@ public class RelOptUtilTest {
             relBuilder.call(
                 SqlStdOperatorTable.EQUALS,
                 // Computed field is added at the end (and index start at 0)
-                RexInputRef.of(EMP_ROW.getFieldCount(), join.getRowType()),
+                RexInputRef.of(empRow.getFieldCount(), join.getRowType()),
                 // Right side is shifted by 1
-                RexInputRef.of(EMP_ROW.getFieldCount() + 1 + rightJoinIndex, 
join.getRowType()))
+                RexInputRef.of(empRow.getFieldCount() + 1 + rightJoinIndex, 
join.getRowType()))
             .toString()));
     assertThat(newJoin.getLeft(), is(instanceOf(Project.class)));
     Project leftInput = (Project) newJoin.getLeft();
-    
assertThat(leftInput.getChildExps().get(EMP_ROW.getFieldCount()).toString(),
+    assertThat(leftInput.getChildExps().get(empRow.getFieldCount()).toString(),
         is(relBuilder.call(SqlStdOperatorTable.PLUS, leftKeyInputRef, 
relBuilder.literal(1))
             .toString()));
   }
@@ -322,20 +325,20 @@ public class RelOptUtilTest {
    * where the join condition contains a complex expression
    */
   @Test public void testPushDownJoinConditionsWithIsNotDistinct() {
-    int leftJoinIndex = 
EMP_SCAN.getRowType().getFieldNames().indexOf("DEPTNO");
-    int rightJoinIndex = DEPT_ROW.getFieldNames().indexOf("DEPTNO");
+    int leftJoinIndex = empScan.getRowType().getFieldNames().indexOf("DEPTNO");
+    int rightJoinIndex = deptRow.getFieldNames().indexOf("DEPTNO");
 
-    RexInputRef leftKeyInputRef = RexInputRef.of(leftJoinIndex, 
EMP_DEPT_JOIN_REL_FIELDS);
+    RexInputRef leftKeyInputRef = RexInputRef.of(leftJoinIndex, 
empDeptJoinRelFields);
     RexInputRef rightKeyInputRef =
-        RexInputRef.of(EMP_ROW.getFieldCount() + rightJoinIndex, 
EMP_DEPT_JOIN_REL_FIELDS);
+        RexInputRef.of(empRow.getFieldCount() + rightJoinIndex, 
empDeptJoinRelFields);
     RexNode joinCond = 
relBuilder.call(SqlStdOperatorTable.IS_NOT_DISTINCT_FROM,
         relBuilder.call(SqlStdOperatorTable.PLUS, leftKeyInputRef, 
relBuilder.literal(1)),
         rightKeyInputRef);
 
 
     // Build the join operator and push down join conditions
-    relBuilder.push(EMP_SCAN);
-    relBuilder.push(DEPT_SCAN);
+    relBuilder.push(empScan);
+    relBuilder.push(deptScan);
     relBuilder.join(JoinRelType.INNER, joinCond);
     Join join = (Join) relBuilder.build();
     RelNode transformed = RelOptUtil.pushDownJoinConditions(join, relBuilder);
@@ -351,13 +354,13 @@ public class RelOptUtilTest {
             relBuilder.call(
                 SqlStdOperatorTable.IS_NOT_DISTINCT_FROM,
                 // Computed field is added at the end (and index start at 0)
-                RexInputRef.of(EMP_ROW.getFieldCount(), join.getRowType()),
+                RexInputRef.of(empRow.getFieldCount(), join.getRowType()),
                 // Right side is shifted by 1
-                RexInputRef.of(EMP_ROW.getFieldCount() + 1 + rightJoinIndex, 
join.getRowType()))
+                RexInputRef.of(empRow.getFieldCount() + 1 + rightJoinIndex, 
join.getRowType()))
             .toString()));
     assertThat(newJoin.getLeft(), is(instanceOf(Project.class)));
     Project leftInput = (Project) newJoin.getLeft();
-    
assertThat(leftInput.getChildExps().get(EMP_ROW.getFieldCount()).toString(),
+    assertThat(leftInput.getChildExps().get(empRow.getFieldCount()).toString(),
         is(relBuilder.call(SqlStdOperatorTable.PLUS, leftKeyInputRef, 
relBuilder.literal(1))
             .toString()));
 
@@ -368,12 +371,12 @@ public class RelOptUtilTest {
    * where the join condition contains a complex expression
    */
   @Test public void testPushDownJoinConditionsWithExpandedIsNotDistinct() {
-    int leftJoinIndex = 
EMP_SCAN.getRowType().getFieldNames().indexOf("DEPTNO");
-    int rightJoinIndex = DEPT_ROW.getFieldNames().indexOf("DEPTNO");
+    int leftJoinIndex = empScan.getRowType().getFieldNames().indexOf("DEPTNO");
+    int rightJoinIndex = deptRow.getFieldNames().indexOf("DEPTNO");
 
-    RexInputRef leftKeyInputRef = RexInputRef.of(leftJoinIndex, 
EMP_DEPT_JOIN_REL_FIELDS);
+    RexInputRef leftKeyInputRef = RexInputRef.of(leftJoinIndex, 
empDeptJoinRelFields);
     RexInputRef rightKeyInputRef =
-        RexInputRef.of(EMP_ROW.getFieldCount() + rightJoinIndex, 
EMP_DEPT_JOIN_REL_FIELDS);
+        RexInputRef.of(empRow.getFieldCount() + rightJoinIndex, 
empDeptJoinRelFields);
     RexNode joinCond = relBuilder.call(SqlStdOperatorTable.OR,
         relBuilder.call(SqlStdOperatorTable.EQUALS,
             relBuilder.call(SqlStdOperatorTable.PLUS, leftKeyInputRef, 
relBuilder.literal(1)),
@@ -386,8 +389,8 @@ public class RelOptUtilTest {
 
 
     // Build the join operator and push down join conditions
-    relBuilder.push(EMP_SCAN);
-    relBuilder.push(DEPT_SCAN);
+    relBuilder.push(empScan);
+    relBuilder.push(deptScan);
     relBuilder.join(JoinRelType.INNER, joinCond);
     Join join = (Join) relBuilder.build();
     RelNode transformed = RelOptUtil.pushDownJoinConditions(join, relBuilder);
@@ -403,13 +406,13 @@ public class RelOptUtilTest {
             relBuilder.call(
                 SqlStdOperatorTable.IS_NOT_DISTINCT_FROM,
                 // Computed field is added at the end (and index start at 0)
-                RexInputRef.of(EMP_ROW.getFieldCount(), join.getRowType()),
+                RexInputRef.of(empRow.getFieldCount(), join.getRowType()),
                 // Right side is shifted by 1
-                RexInputRef.of(EMP_ROW.getFieldCount() + 1 + rightJoinIndex, 
join.getRowType()))
+                RexInputRef.of(empRow.getFieldCount() + 1 + rightJoinIndex, 
join.getRowType()))
                 .toString()));
     assertThat(newJoin.getLeft(), is(instanceOf(Project.class)));
     Project leftInput = (Project) newJoin.getLeft();
-    
assertThat(leftInput.getChildExps().get(EMP_ROW.getFieldCount()).toString(),
+    assertThat(leftInput.getChildExps().get(empRow.getFieldCount()).toString(),
         is(relBuilder.call(SqlStdOperatorTable.PLUS, leftKeyInputRef, 
relBuilder.literal(1))
             .toString()));
   }
@@ -419,12 +422,12 @@ public class RelOptUtilTest {
    * where the join condition contains a complex expression
    */
   @Test public void 
testPushDownJoinConditionsWithExpandedIsNotDistinctUsingCase() {
-    int leftJoinIndex = 
EMP_SCAN.getRowType().getFieldNames().indexOf("DEPTNO");
-    int rightJoinIndex = DEPT_ROW.getFieldNames().indexOf("DEPTNO");
+    int leftJoinIndex = empScan.getRowType().getFieldNames().indexOf("DEPTNO");
+    int rightJoinIndex = deptRow.getFieldNames().indexOf("DEPTNO");
 
-    RexInputRef leftKeyInputRef = RexInputRef.of(leftJoinIndex, 
EMP_DEPT_JOIN_REL_FIELDS);
+    RexInputRef leftKeyInputRef = RexInputRef.of(leftJoinIndex, 
empDeptJoinRelFields);
     RexInputRef rightKeyInputRef =
-        RexInputRef.of(EMP_ROW.getFieldCount() + rightJoinIndex, 
EMP_DEPT_JOIN_REL_FIELDS);
+        RexInputRef.of(empRow.getFieldCount() + rightJoinIndex, 
empDeptJoinRelFields);
     RexNode joinCond = relBuilder.call(SqlStdOperatorTable.CASE,
         relBuilder.call(SqlStdOperatorTable.IS_NULL,
             relBuilder.call(SqlStdOperatorTable.PLUS, leftKeyInputRef, 
relBuilder.literal(1))),
@@ -438,8 +441,8 @@ public class RelOptUtilTest {
 
 
     // Build the join operator and push down join conditions
-    relBuilder.push(EMP_SCAN);
-    relBuilder.push(DEPT_SCAN);
+    relBuilder.push(empScan);
+    relBuilder.push(deptScan);
     relBuilder.join(JoinRelType.INNER, joinCond);
     Join join = (Join) relBuilder.build();
     RelNode transformed = RelOptUtil.pushDownJoinConditions(join, relBuilder);
@@ -455,13 +458,13 @@ public class RelOptUtilTest {
             relBuilder.call(
                 SqlStdOperatorTable.IS_NOT_DISTINCT_FROM,
                 // Computed field is added at the end (and index start at 0)
-                RexInputRef.of(EMP_ROW.getFieldCount(), join.getRowType()),
+                RexInputRef.of(empRow.getFieldCount(), join.getRowType()),
                 // Right side is shifted by 1
-                RexInputRef.of(EMP_ROW.getFieldCount() + 1 + rightJoinIndex, 
join.getRowType()))
+                RexInputRef.of(empRow.getFieldCount() + 1 + rightJoinIndex, 
join.getRowType()))
               .toString()));
     assertThat(newJoin.getLeft(), is(instanceOf(Project.class)));
     Project leftInput = (Project) newJoin.getLeft();
-    
assertThat(leftInput.getChildExps().get(EMP_ROW.getFieldCount()).toString(),
+    assertThat(leftInput.getChildExps().get(empRow.getFieldCount()).toString(),
         is(relBuilder.call(SqlStdOperatorTable.PLUS, leftKeyInputRef, 
relBuilder.literal(1))
             .toString()));
   }

Reply via email to