Class CalciteAssert


  • public class CalciteAssert
    extends java.lang.Object
    Fluid DSL for testing Calcite connections and queries.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private CalciteAssert()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.apache.calcite.schema.SchemaPlus addSchema​(org.apache.calcite.schema.SchemaPlus rootSchema, CalciteAssert.SchemaSpec schema)  
      private static org.apache.calcite.schema.SchemaPlus addSchemaIfNotExists​(org.apache.calcite.schema.SchemaPlus rootSchema, CalciteAssert.SchemaSpec schemaSpec)  
      static void assertArrayEqual​(java.lang.String message, java.lang.Object[] expected, java.lang.Object[] actual)
      Asserts that two objects are equal.
      (package private) static void assertPrepare​(java.sql.Connection connection, java.lang.String sql, boolean materializationsEnabled, java.util.function.Function<org.apache.calcite.rel.RelNode,​java.lang.Void> convertChecker, java.util.function.Function<org.apache.calcite.rel.RelNode,​java.lang.Void> substitutionChecker)  
      private static void assertPrepare​(java.sql.Connection connection, java.lang.String sql, int limit, boolean materializationsEnabled, java.util.List<org.apache.calcite.util.Pair<org.apache.calcite.runtime.Hook,​java.util.function.Consumer>> hooks, java.util.function.Consumer<java.sql.ResultSet> resultChecker, java.util.function.Consumer<java.lang.Integer> updateChecker, java.util.function.Consumer<java.lang.Throwable> exceptionChecker, CalciteAssert.PreparedStatementConsumer consumer)  
      (package private) static void assertQuery​(java.sql.Connection connection, java.lang.String sql, int limit, boolean materializationsEnabled, java.util.List<org.apache.calcite.util.Pair<org.apache.calcite.runtime.Hook,​java.util.function.Consumer>> hooks, java.util.function.Consumer<java.sql.ResultSet> resultChecker, java.util.function.Consumer<java.lang.Integer> updateChecker, java.util.function.Consumer<java.lang.Throwable> exceptionChecker)  
      (package private) static java.lang.Object call​(java.lang.Object o, java.lang.String methodName, java.lang.Object... args)
      Calls a non-static method via reflection.
      (package private) static java.util.function.Consumer<java.lang.Throwable> checkException​(java.lang.String expected)  
      static java.util.function.Consumer<java.sql.ResultSet> checkMaskedResultContains​(java.lang.String expected)  
      (package private) static java.util.function.Function<org.apache.calcite.rel.RelNode,​java.lang.Void> checkRel​(java.lang.String expected, java.util.concurrent.atomic.AtomicInteger counter)  
      (package private) static java.util.function.Consumer<java.sql.ResultSet> checkResult​(boolean sort, boolean head, java.lang.String... lines)  
      (package private) static java.util.function.Consumer<java.sql.ResultSet> checkResult​(java.lang.String expected)  
      (package private) static java.util.function.Consumer<java.sql.ResultSet> checkResult​(java.lang.String expected, CalciteAssert.ResultSetFormatter resultSetFormatter)  
      static java.util.function.Consumer<java.sql.ResultSet> checkResultContains​(java.lang.String... expected)  
      static java.util.function.Consumer<java.sql.ResultSet> checkResultContains​(java.lang.String expected, int count)  
      static java.util.function.Consumer<java.sql.ResultSet> checkResultCount​(org.hamcrest.Matcher<java.lang.Integer> expected)  
      static java.util.function.Consumer<java.sql.ResultSet> checkResultType​(java.lang.String expected)  
      (package private) static java.util.function.Consumer<java.sql.ResultSet> checkResultUnordered​(java.lang.String... lines)  
      (package private) static java.util.function.Consumer<java.sql.ResultSet> checkResultValue​(java.lang.String expected)  
      static java.util.function.Consumer<java.lang.Integer> checkUpdateCount​(int expected)  
      (package private) static java.util.function.Consumer<java.lang.Throwable> checkValidationException​(java.lang.String expected)  
      (package private) static java.util.function.Consumer<java.sql.ResultSet> consistentResult​(boolean ordered)
      Checks that the result of the second and subsequent executions is the same as the first.
      (package private) static int countRows​(java.sql.ResultSet resultSet)  
      static CalciteAssert.AssertThat hr()
      Short-hand for CalciteAssert.that().with(Config.REGULAR).
      (package private) static java.lang.reflect.Method method​(java.lang.Object o, java.lang.String methodName, java.lang.Object[] args)
      Finds a non-static method based on its target, name and arguments.
      static CalciteAssert.AssertThat model​(java.lang.String model)
      Short-hand for CalciteAssert.that().with(Config.EMPTY).withModel(model).
      (package private) static java.lang.String newlineList​(java.util.Collection collection)  
      (package private) static CalciteAssert.PropBuilder propBuilder()
      private static java.lang.String str​(java.lang.Object[] objects)  
      static CalciteAssert.AssertThat that()
      Creates an instance of CalciteAssert with the empty configuration.
      static CalciteAssert.AssertThat that​(CalciteAssert.Config config)
      Creates an instance of CalciteAssert with a given configuration.
      (package private) static java.util.List<java.lang.String> toList​(java.sql.ResultSet resultSet)  
      (package private) static com.google.common.collect.ImmutableMultiset<java.lang.String> toSet​(java.sql.ResultSet resultSet)  
      (package private) static java.lang.String toString​(java.sql.ResultSet resultSet)
      Converts a ResultSet to a string.
      (package private) static java.util.Collection<java.lang.String> toStringList​(java.sql.ResultSet resultSet, java.util.Collection<java.lang.String> list)  
      private static java.lang.String typeString​(java.sql.ResultSetMetaData metaData)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DB

        public static final CalciteAssert.DatabaseInstance DB
        Which database to use for tests that require a JDBC data source.
        See Also:
        CalciteSystemProperty.TEST_DB
      • UTC_DATE_FORMAT

        private static final java.text.DateFormat UTC_DATE_FORMAT
      • UTC_TIME_FORMAT

        private static final java.text.DateFormat UTC_TIME_FORMAT
      • UTC_TIMESTAMP_FORMAT

        private static final java.text.DateFormat UTC_TIMESTAMP_FORMAT
    • Constructor Detail

      • CalciteAssert

        private CalciteAssert()
    • Method Detail

      • that

        public static CalciteAssert.AssertThat that()
        Creates an instance of CalciteAssert with the empty configuration.
      • model

        public static CalciteAssert.AssertThat model​(java.lang.String model)
        Short-hand for CalciteAssert.that().with(Config.EMPTY).withModel(model).
      • checkRel

        static java.util.function.Function<org.apache.calcite.rel.RelNode,​java.lang.Void> checkRel​(java.lang.String expected,
                                                                                                         java.util.concurrent.atomic.AtomicInteger counter)
      • checkException

        static java.util.function.Consumer<java.lang.Throwable> checkException​(java.lang.String expected)
      • checkValidationException

        static java.util.function.Consumer<java.lang.Throwable> checkValidationException​(java.lang.String expected)
      • checkResult

        static java.util.function.Consumer<java.sql.ResultSet> checkResult​(java.lang.String expected)
      • checkResult

        static java.util.function.Consumer<java.sql.ResultSet> checkResult​(java.lang.String expected,
                                                                           CalciteAssert.ResultSetFormatter resultSetFormatter)
      • checkResultValue

        static java.util.function.Consumer<java.sql.ResultSet> checkResultValue​(java.lang.String expected)
      • checkResultCount

        public static java.util.function.Consumer<java.sql.ResultSet> checkResultCount​(org.hamcrest.Matcher<java.lang.Integer> expected)
      • checkUpdateCount

        public static java.util.function.Consumer<java.lang.Integer> checkUpdateCount​(int expected)
      • consistentResult

        static java.util.function.Consumer<java.sql.ResultSet> consistentResult​(boolean ordered)
        Checks that the result of the second and subsequent executions is the same as the first.
        Parameters:
        ordered - Whether order should be the same both times
      • newlineList

        static java.lang.String newlineList​(java.util.Collection collection)
      • checkResult

        static java.util.function.Consumer<java.sql.ResultSet> checkResult​(boolean sort,
                                                                           boolean head,
                                                                           java.lang.String... lines)
        See Also:
        Matchers.returnsUnordered(String...)
      • checkResultContains

        public static java.util.function.Consumer<java.sql.ResultSet> checkResultContains​(java.lang.String... expected)
      • checkResultContains

        public static java.util.function.Consumer<java.sql.ResultSet> checkResultContains​(java.lang.String expected,
                                                                                          int count)
      • checkMaskedResultContains

        public static java.util.function.Consumer<java.sql.ResultSet> checkMaskedResultContains​(java.lang.String expected)
      • checkResultType

        public static java.util.function.Consumer<java.sql.ResultSet> checkResultType​(java.lang.String expected)
      • typeString

        private static java.lang.String typeString​(java.sql.ResultSetMetaData metaData)
                                            throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • assertQuery

        static void assertQuery​(java.sql.Connection connection,
                                java.lang.String sql,
                                int limit,
                                boolean materializationsEnabled,
                                java.util.List<org.apache.calcite.util.Pair<org.apache.calcite.runtime.Hook,​java.util.function.Consumer>> hooks,
                                java.util.function.Consumer<java.sql.ResultSet> resultChecker,
                                java.util.function.Consumer<java.lang.Integer> updateChecker,
                                java.util.function.Consumer<java.lang.Throwable> exceptionChecker)
      • assertPrepare

        private static void assertPrepare​(java.sql.Connection connection,
                                          java.lang.String sql,
                                          int limit,
                                          boolean materializationsEnabled,
                                          java.util.List<org.apache.calcite.util.Pair<org.apache.calcite.runtime.Hook,​java.util.function.Consumer>> hooks,
                                          java.util.function.Consumer<java.sql.ResultSet> resultChecker,
                                          java.util.function.Consumer<java.lang.Integer> updateChecker,
                                          java.util.function.Consumer<java.lang.Throwable> exceptionChecker,
                                          CalciteAssert.PreparedStatementConsumer consumer)
      • assertPrepare

        static void assertPrepare​(java.sql.Connection connection,
                                  java.lang.String sql,
                                  boolean materializationsEnabled,
                                  java.util.function.Function<org.apache.calcite.rel.RelNode,​java.lang.Void> convertChecker,
                                  java.util.function.Function<org.apache.calcite.rel.RelNode,​java.lang.Void> substitutionChecker)
      • toString

        static java.lang.String toString​(java.sql.ResultSet resultSet)
                                  throws java.sql.SQLException
        Converts a ResultSet to a string.
        Throws:
        java.sql.SQLException
      • countRows

        static int countRows​(java.sql.ResultSet resultSet)
                      throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • toStringList

        static java.util.Collection<java.lang.String> toStringList​(java.sql.ResultSet resultSet,
                                                                   java.util.Collection<java.lang.String> list)
                                                            throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • toList

        static java.util.List<java.lang.String> toList​(java.sql.ResultSet resultSet)
                                                throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • toSet

        static com.google.common.collect.ImmutableMultiset<java.lang.String> toSet​(java.sql.ResultSet resultSet)
                                                                            throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • call

        static java.lang.Object call​(java.lang.Object o,
                                     java.lang.String methodName,
                                     java.lang.Object... args)
                              throws java.lang.NoSuchMethodException,
                                     java.lang.reflect.InvocationTargetException,
                                     java.lang.IllegalAccessException
        Calls a non-static method via reflection. Useful for testing methods that don't exist in certain versions of the JDK.
        Throws:
        java.lang.NoSuchMethodException
        java.lang.reflect.InvocationTargetException
        java.lang.IllegalAccessException
      • method

        static java.lang.reflect.Method method​(java.lang.Object o,
                                               java.lang.String methodName,
                                               java.lang.Object[] args)
        Finds a non-static method based on its target, name and arguments. Throws if not found.
      • addSchema

        public static org.apache.calcite.schema.SchemaPlus addSchema​(org.apache.calcite.schema.SchemaPlus rootSchema,
                                                                     CalciteAssert.SchemaSpec schema)
      • addSchemaIfNotExists

        private static org.apache.calcite.schema.SchemaPlus addSchemaIfNotExists​(org.apache.calcite.schema.SchemaPlus rootSchema,
                                                                                 CalciteAssert.SchemaSpec schemaSpec)
      • assertArrayEqual

        public static void assertArrayEqual​(java.lang.String message,
                                            java.lang.Object[] expected,
                                            java.lang.Object[] actual)
        Asserts that two objects are equal. If they are not, an AssertionError is thrown with the given message. If expected and actual are null, they are considered equal.

        This method produces more user-friendly error messages than Assert.assertArrayEquals(String, Object[], Object[])

        Parameters:
        message - the identifying message for the AssertionError (null okay)
        expected - expected value
        actual - actual value
      • str

        private static java.lang.String str​(java.lang.Object[] objects)