You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2020/11/03 13:29:04 UTC

[GitHub] [calcite] vlsi commented on a change in pull request #2236: [CALCITE-3913] Test correctness using formal verification (Qi Zhou)

vlsi commented on a change in pull request #2236:
URL: https://github.com/apache/calcite/pull/2236#discussion_r516285366



##########
File path: core/src/test/java/org/apache/calcite/test/SmtLibTest.java
##########
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.test;
+
+
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rel.logical.LogicalProject;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.test.verifier.RexToSymbolicColumn;
+import org.apache.calcite.test.verifier.SymbolicColumn;
+
+import com.microsoft.z3.BoolExpr;
+import com.microsoft.z3.Context;
+import com.microsoft.z3.Expr;
+import com.microsoft.z3.Solver;
+import com.microsoft.z3.Status;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Testing for integrating z3 with calcite to verify equivalence.
+ **/
+
+public class SmtLibTest {
+
+  static RelDataTypeFactory typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+
+  /**
+   * Check z3 dynamic library exits before run all other tests.
+   */
+  @BeforeAll static void testZ3Lib() throws Exception {
+    Context z3Context = new Context();
+    Expr x = z3Context.mkIntConst("x");
+    Expr one = z3Context.mkInt(1);
+    BoolExpr eq = z3Context.mkEq(x, one);
+    Solver solver = z3Context.mkSolver();
+    solver.add(eq);
+    assertEquals(solver.check(), Status.SATISFIABLE);
+  }
+
+  /** Converts a SQL string to a relational expression using mock schema. */
+  private static RelNode toRel(String sql) {
+    final SqlToRelTestBase test = new SqlToRelTestBase() {
+    };
+    return test.createTester().convertSqlToRel(sql).rel;
+  }
+
+  /** Converts a where condition string to a RexNode using mock schema on emp table. */
+  private static RexNode toRex(String cond) {
+    final String sql = "select *\n"
+        + "from emp where"
+        + cond;
+    final RelNode relNode = toRel(sql);
+    LogicalProject project = (LogicalProject) relNode;
+    LogicalFilter filter = (LogicalFilter) project.getInput();
+    return filter.getCondition();
+  }
+
+  private static boolean checkEqual(String cond1, String cond2) {
+    RexNode rexNode1 = toRex(cond1);
+    RexNode rexNode2 = toRex(cond2);
+    Context z3Context = new Context();
+    List<SymbolicColumn> inputSymbolicColumns = new ArrayList<>();
+    /** mock emp table, 8 columns with int type, since we only support numerical type for now **/
+    for (int i = 0; i < 8; i++) {
+      RelDataType intType = typeFactory.createJavaType(int.class);
+      SymbolicColumn inputColumn = SymbolicColumn.mkNewSymbolicColumn(z3Context, intType);
+      inputSymbolicColumns.add(inputColumn);

Review comment:
       Please use `RexProgramTestBase` so you could reuse all the helpers for types, etc, etc.

##########
File path: core/src/test/java/org/apache/calcite/test/SmtLibTest.java
##########
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.test;
+
+
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rel.logical.LogicalProject;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.test.verifier.RexToSymbolicColumn;
+import org.apache.calcite.test.verifier.SymbolicColumn;
+
+import com.microsoft.z3.BoolExpr;
+import com.microsoft.z3.Context;
+import com.microsoft.z3.Expr;
+import com.microsoft.z3.Solver;
+import com.microsoft.z3.Status;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Testing for integrating z3 with calcite to verify equivalence.
+ **/
+
+public class SmtLibTest {
+
+  static RelDataTypeFactory typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+
+  /**
+   * Check z3 dynamic library exits before run all other tests.
+   */
+  @BeforeAll static void testZ3Lib() throws Exception {
+    Context z3Context = new Context();
+    Expr x = z3Context.mkIntConst("x");
+    Expr one = z3Context.mkInt(1);
+    BoolExpr eq = z3Context.mkEq(x, one);
+    Solver solver = z3Context.mkSolver();
+    solver.add(eq);
+    assertEquals(solver.check(), Status.SATISFIABLE);
+  }
+
+  /** Converts a SQL string to a relational expression using mock schema. */
+  private static RelNode toRel(String sql) {
+    final SqlToRelTestBase test = new SqlToRelTestBase() {
+    };
+    return test.createTester().convertSqlToRel(sql).rel;
+  }
+
+  /** Converts a where condition string to a RexNode using mock schema on emp table. */
+  private static RexNode toRex(String cond) {
+    final String sql = "select *\n"
+        + "from emp where"
+        + cond;
+    final RelNode relNode = toRel(sql);
+    LogicalProject project = (LogicalProject) relNode;
+    LogicalFilter filter = (LogicalFilter) project.getInput();
+    return filter.getCondition();
+  }
+
+  private static boolean checkEqual(String cond1, String cond2) {
+    RexNode rexNode1 = toRex(cond1);
+    RexNode rexNode2 = toRex(cond2);
+    Context z3Context = new Context();
+    List<SymbolicColumn> inputSymbolicColumns = new ArrayList<>();
+    /** mock emp table, 8 columns with int type, since we only support numerical type for now **/
+    for (int i = 0; i < 8; i++) {
+      RelDataType intType = typeFactory.createJavaType(int.class);
+      SymbolicColumn inputColumn = SymbolicColumn.mkNewSymbolicColumn(z3Context, intType);
+      inputSymbolicColumns.add(inputColumn);

Review comment:
       Would you please move your classes to `org.apache.calcite.rex` package? Then `RexProgramTestBase` would be visible.

##########
File path: core/src/test/java/org/apache/calcite/test/SmtLibTest.java
##########
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.test;
+
+
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rel.logical.LogicalProject;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.test.verifier.RexToSymbolicColumn;
+import org.apache.calcite.test.verifier.SymbolicColumn;
+
+import com.microsoft.z3.BoolExpr;
+import com.microsoft.z3.Context;
+import com.microsoft.z3.Expr;
+import com.microsoft.z3.Solver;
+import com.microsoft.z3.Status;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Testing for integrating z3 with calcite to verify equivalence.
+ **/
+
+public class SmtLibTest {
+
+  static RelDataTypeFactory typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+
+  /**
+   * Check z3 dynamic library exits before run all other tests.
+   */
+  @BeforeAll static void testZ3Lib() throws Exception {
+    Context z3Context = new Context();
+    Expr x = z3Context.mkIntConst("x");
+    Expr one = z3Context.mkInt(1);
+    BoolExpr eq = z3Context.mkEq(x, one);
+    Solver solver = z3Context.mkSolver();
+    solver.add(eq);
+    assertEquals(solver.check(), Status.SATISFIABLE);
+  }
+
+  /** Converts a SQL string to a relational expression using mock schema. */
+  private static RelNode toRel(String sql) {
+    final SqlToRelTestBase test = new SqlToRelTestBase() {
+    };
+    return test.createTester().convertSqlToRel(sql).rel;
+  }
+
+  /** Converts a where condition string to a RexNode using mock schema on emp table. */
+  private static RexNode toRex(String cond) {
+    final String sql = "select *\n"
+        + "from emp where"
+        + cond;
+    final RelNode relNode = toRel(sql);
+    LogicalProject project = (LogicalProject) relNode;
+    LogicalFilter filter = (LogicalFilter) project.getInput();
+    return filter.getCondition();
+  }
+
+  private static boolean checkEqual(String cond1, String cond2) {
+    RexNode rexNode1 = toRex(cond1);
+    RexNode rexNode2 = toRex(cond2);
+    Context z3Context = new Context();
+    List<SymbolicColumn> inputSymbolicColumns = new ArrayList<>();
+    /** mock emp table, 8 columns with int type, since we only support numerical type for now **/
+    for (int i = 0; i < 8; i++) {
+      RelDataType intType = typeFactory.createJavaType(int.class);
+      SymbolicColumn inputColumn = SymbolicColumn.mkNewSymbolicColumn(z3Context, intType);
+      inputSymbolicColumns.add(inputColumn);

Review comment:
       > It seems even I throw errors in the BeforeAll methods, it still fail the test cases, which break the whole CI.
   
   You need to catch the exception and call `Assumptions.assume...`
   If the test fails with `assumption violated`, then it would be marked as skipped.
   
   See https://junit.org/junit5/docs/5.0.0/api/org/junit/jupiter/api/Assumptions.html#assumeTrue-boolean-
   
   For instance:
   
   ```java
   Assumptions.assumeTrue(verifyZ3Loads(), "z3 is required for the tests")
   ```

##########
File path: core/src/test/java/org/apache/calcite/test/SmtLibTest.java
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.test;
+
+
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rel.logical.LogicalProject;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexProgramBuilderBase;
+import org.apache.calcite.test.verifier.RexToSymbolicColumn;
+import org.apache.calcite.test.verifier.SymbolicColumn;
+
+import com.microsoft.z3.BoolExpr;
+import com.microsoft.z3.Context;
+import com.microsoft.z3.Expr;
+import com.microsoft.z3.Solver;
+import com.microsoft.z3.Status;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Testing for integrating z3 with calcite to verify equivalence.
+ **/
+
+public class SmtLibTest extends RexProgramBuilderBase {
+
+  /**
+   * Check z3 dynamic library exits before run all other tests.
+   */
+  @BeforeAll static void testZ3Lib() throws Error {
+    Context z3Context = new Context();
+    Expr x = z3Context.mkIntConst("x");
+    Expr one = z3Context.mkInt(1);
+    BoolExpr eq = z3Context.mkEq(x, one);
+    Solver solver = z3Context.mkSolver();
+    solver.add(eq);
+    assertEquals(solver.check(), Status.SATISFIABLE);
+  }
+
+  /** Converts a SQL string to a relational expression using mock schema. */
+  private RelNode toRel(String sql) {
+    final SqlToRelTestBase test = new SqlToRelTestBase() {
+    };
+    return test.createTester().convertSqlToRel(sql).rel;
+  }
+
+  /** Converts a where condition string to a RexNode using mock schema on emp table. */
+  private RexNode toRex(String cond) {
+    final String sql = "select *\n"
+        + "from emp where"
+        + cond;
+    final RelNode relNode = toRel(sql);
+    LogicalProject project = (LogicalProject) relNode;
+    LogicalFilter filter = (LogicalFilter) project.getInput();
+    return filter.getCondition();
+  }
+
+  private boolean checkEqual(String cond1, String cond2) {
+    RexNode rexNode1 = toRex(cond1);
+    RexNode rexNode2 = toRex(cond2);
+    Context z3Context = new Context();
+    List<SymbolicColumn> inputSymbolicColumns = new ArrayList<>();
+    /** mock emp table, 8 columns with int type, since we only support numerical type for now **/
+    for (int i = 0; i < 8; i++) {
+      SymbolicColumn inputColumn = SymbolicColumn.mkNewSymbolicColumn(z3Context, tInt());
+      inputSymbolicColumns.add(inputColumn);
+    }
+    List<BoolExpr> env = new ArrayList<>();
+    SymbolicColumn symbolicCond1 =
+        RexToSymbolicColumn.rexToColumn(rexNode1, inputSymbolicColumns, z3Context, env);
+    SymbolicColumn symbolicCond2 =
+        RexToSymbolicColumn.rexToColumn(rexNode2, inputSymbolicColumns, z3Context, env);
+
+    return SymbolicColumn.checkCondEq(symbolicCond1, symbolicCond2, env, z3Context);
+  }
+
+  @Test void rexNodeEq1() {
+    final String cond1 = " empno > 10 and deptno = 5";
+    final String cond2 = " empno + deptno > 15 and deptno = 5";

Review comment:
       This is nice. However, it might result in accidental "automatic simplification" during parsing.
   In other words, parser (or SQL to rex converter) might silently simplify the expression, so the actual tested node would be different from what is represented in the sources.
   
   On the other hand, `RexProgramBuilderBase` provides methods like `and`, `or`, etc. so `RexNode` can be created with fine details.

##########
File path: core/src/test/java/org/apache/calcite/test/SmtLibTest.java
##########
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.test;
+
+
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rel.logical.LogicalProject;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.test.verifier.RexToSymbolicColumn;
+import org.apache.calcite.test.verifier.SymbolicColumn;
+
+import com.microsoft.z3.BoolExpr;
+import com.microsoft.z3.Context;
+import com.microsoft.z3.Expr;
+import com.microsoft.z3.Solver;
+import com.microsoft.z3.Status;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Testing for integrating z3 with calcite to verify equivalence.
+ **/
+
+public class SmtLibTest {
+
+  static RelDataTypeFactory typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+
+  /**
+   * Check z3 dynamic library exits before run all other tests.
+   */
+  @BeforeAll static void testZ3Lib() throws Exception {
+    Context z3Context = new Context();
+    Expr x = z3Context.mkIntConst("x");
+    Expr one = z3Context.mkInt(1);
+    BoolExpr eq = z3Context.mkEq(x, one);
+    Solver solver = z3Context.mkSolver();
+    solver.add(eq);
+    assertEquals(solver.check(), Status.SATISFIABLE);
+  }
+
+  /** Converts a SQL string to a relational expression using mock schema. */
+  private static RelNode toRel(String sql) {
+    final SqlToRelTestBase test = new SqlToRelTestBase() {
+    };
+    return test.createTester().convertSqlToRel(sql).rel;
+  }
+
+  /** Converts a where condition string to a RexNode using mock schema on emp table. */
+  private static RexNode toRex(String cond) {
+    final String sql = "select *\n"
+        + "from emp where"
+        + cond;
+    final RelNode relNode = toRel(sql);
+    LogicalProject project = (LogicalProject) relNode;
+    LogicalFilter filter = (LogicalFilter) project.getInput();
+    return filter.getCondition();
+  }
+
+  private static boolean checkEqual(String cond1, String cond2) {
+    RexNode rexNode1 = toRex(cond1);
+    RexNode rexNode2 = toRex(cond2);
+    Context z3Context = new Context();
+    List<SymbolicColumn> inputSymbolicColumns = new ArrayList<>();
+    /** mock emp table, 8 columns with int type, since we only support numerical type for now **/
+    for (int i = 0; i < 8; i++) {
+      RelDataType intType = typeFactory.createJavaType(int.class);
+      SymbolicColumn inputColumn = SymbolicColumn.mkNewSymbolicColumn(z3Context, intType);
+      inputSymbolicColumns.add(inputColumn);

Review comment:
       Right you are. The proper base class is `RexProgramBuilderBase`

##########
File path: core/src/test/java/org/apache/calcite/test/SmtLibTest.java
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.test;
+
+
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rel.logical.LogicalProject;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexProgramBuilderBase;
+import org.apache.calcite.test.verifier.RexToSymbolicColumn;
+import org.apache.calcite.test.verifier.SymbolicColumn;
+
+import com.microsoft.z3.BoolExpr;
+import com.microsoft.z3.Context;
+import com.microsoft.z3.Expr;
+import com.microsoft.z3.Solver;
+import com.microsoft.z3.Status;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Testing for integrating z3 with calcite to verify equivalence.
+ **/
+
+public class SmtLibTest extends RexProgramBuilderBase {
+
+  /**
+   * Check z3 dynamic library exits before run all other tests.
+   */
+  @BeforeAll static void testZ3Lib() throws Error {
+    Context z3Context = new Context();
+    Expr x = z3Context.mkIntConst("x");
+    Expr one = z3Context.mkInt(1);
+    BoolExpr eq = z3Context.mkEq(x, one);
+    Solver solver = z3Context.mkSolver();
+    solver.add(eq);
+    assertEquals(solver.check(), Status.SATISFIABLE);
+  }
+
+  /** Converts a SQL string to a relational expression using mock schema. */
+  private RelNode toRel(String sql) {
+    final SqlToRelTestBase test = new SqlToRelTestBase() {
+    };
+    return test.createTester().convertSqlToRel(sql).rel;
+  }
+
+  /** Converts a where condition string to a RexNode using mock schema on emp table. */
+  private RexNode toRex(String cond) {
+    final String sql = "select *\n"
+        + "from emp where"
+        + cond;
+    final RelNode relNode = toRel(sql);
+    LogicalProject project = (LogicalProject) relNode;
+    LogicalFilter filter = (LogicalFilter) project.getInput();
+    return filter.getCondition();
+  }
+
+  private boolean checkEqual(String cond1, String cond2) {
+    RexNode rexNode1 = toRex(cond1);
+    RexNode rexNode2 = toRex(cond2);
+    Context z3Context = new Context();
+    List<SymbolicColumn> inputSymbolicColumns = new ArrayList<>();
+    /** mock emp table, 8 columns with int type, since we only support numerical type for now **/
+    for (int i = 0; i < 8; i++) {
+      SymbolicColumn inputColumn = SymbolicColumn.mkNewSymbolicColumn(z3Context, tInt());
+      inputSymbolicColumns.add(inputColumn);
+    }
+    List<BoolExpr> env = new ArrayList<>();
+    SymbolicColumn symbolicCond1 =
+        RexToSymbolicColumn.rexToColumn(rexNode1, inputSymbolicColumns, z3Context, env);
+    SymbolicColumn symbolicCond2 =
+        RexToSymbolicColumn.rexToColumn(rexNode2, inputSymbolicColumns, z3Context, env);
+
+    return SymbolicColumn.checkCondEq(symbolicCond1, symbolicCond2, env, z3Context);
+  }
+
+  @Test void rexNodeEq1() {
+    final String cond1 = " empno > 10 and deptno = 5";
+    final String cond2 = " empno + deptno > 15 and deptno = 5";

Review comment:
       This is nice. However, it might result in accidental "automatic simplification" during parsing.
   In other words, parser (or SQL to rex converter) might silently simplify the expression, so the actual tested node would be different from what is represented in the sources.
   
   `RexProgramBuilderBase` provides methods like `and`, `or`, etc. so `RexNode` can be created with fine details.

##########
File path: core/src/test/java/org/apache/calcite/test/SmtLibTest.java
##########
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.test;
+
+
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rel.logical.LogicalProject;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexProgramBuilderBase;
+import org.apache.calcite.test.verifier.RexToSymbolicColumn;
+import org.apache.calcite.test.verifier.SymbolicColumn;
+
+import com.microsoft.z3.BoolExpr;
+import com.microsoft.z3.Context;
+import com.microsoft.z3.Expr;
+import com.microsoft.z3.Solver;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+/**
+ * Testing for integrating z3 with calcite to verify equivalence.
+ **/
+
+public class SmtLibTest extends RexProgramBuilderBase {
+  static boolean z3Loads;
+  /**
+   * Check z3 dynamic library exits before run all other tests.
+   */
+  @BeforeAll static void testZ3Lib() {
+    try {
+      Context z3Context = new Context();
+      Expr x = z3Context.mkIntConst("x");
+      Expr one = z3Context.mkInt(1);
+      BoolExpr eq = z3Context.mkEq(x, one);
+      Solver solver = z3Context.mkSolver();
+      solver.add(eq);
+      solver.check();
+      z3Loads = true;
+    } catch (Error e) {
+      z3Loads = false;

Review comment:
       Does `assume` work here, so it is not duplicated across all the tests?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org