Package org.apache.calcite.sql.test
Class SqlTests
- java.lang.Object
-
- org.apache.calcite.sql.test.SqlTests
-
public abstract class SqlTests extends java.lang.Object
Utility methods.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SqlTests.ApproximateResultChecker
Result checker that checks a result against an expected value.static class
SqlTests.PatternResultChecker
Result checker that checks a result against a regular expression.static class
SqlTests.RefSetResultChecker
Result checker that checks a result against a list of expected strings.private static class
SqlTests.SqlTypeChecker
Checks that a type matches a given SQL type.static class
SqlTests.Stage
Stage of query processingstatic class
SqlTests.StringTypeChecker
Type checker which compares types to a specified string.
-
Field Summary
Fields Modifier and Type Field Description static SqlTester.ParameterChecker
ANY_PARAMETER_CHECKER
Checker that allows any number or type of parameters.static SqlTester.ResultChecker
ANY_RESULT_CHECKER
Checker that allows any result.static SqlTester.TypeChecker
ANY_TYPE_CHECKER
Checker which allows any type.static SqlTester.TypeChecker
BOOLEAN_TYPE_CHECKER
static SqlTester.TypeChecker
INTEGER_TYPE_CHECKER
private static java.util.regex.Pattern
LINE_COL_PATTERN
private static java.util.regex.Pattern
LINE_COL_TWICE_PATTERN
-
Constructor Summary
Constructors Constructor Description SqlTests()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
checkEx(java.lang.Throwable ex, java.lang.String expectedMsgPattern, org.apache.calcite.sql.parser.SqlParserUtil.StringAndPos sap, SqlTests.Stage stage)
Checks whether an exception matches the expected pattern.static void
compareResultSet(java.sql.ResultSet resultSet, java.util.Set<java.lang.String> refSet)
Compares the first column of a result set against a String-valued reference set, disregarding order entirely.static void
compareResultSetWithDelta(java.sql.ResultSet resultSet, double expected, double delta)
Compares the first column of a result set against a numeric result, within a given tolerance.static void
compareResultSetWithPattern(java.sql.ResultSet resultSet, java.util.regex.Pattern pattern)
Compares the first column of a result set against a pattern.static SqlTester.ResultChecker
createChecker(java.lang.Object result, double delta)
static java.lang.String
generateAggQuery(java.lang.String expr, java.lang.String[] inputValues)
static java.lang.String
generateAggQueryWithMultipleArgs(java.lang.String expr, java.lang.String[][] inputValues)
static java.lang.String
generateWinAggQuery(java.lang.String expr, java.lang.String windowSpec, java.lang.String[] inputValues)
static java.lang.String
getTypeString(org.apache.calcite.rel.type.RelDataType sqlType)
Helper function to get the string representation of a RelDataType (include precision/scale but no charset or collation)private static org.apache.calcite.avatica.ColumnMetaData.Rep
rep(int columnType)
-
-
-
Field Detail
-
INTEGER_TYPE_CHECKER
public static final SqlTester.TypeChecker INTEGER_TYPE_CHECKER
-
BOOLEAN_TYPE_CHECKER
public static final SqlTester.TypeChecker BOOLEAN_TYPE_CHECKER
-
ANY_TYPE_CHECKER
public static final SqlTester.TypeChecker ANY_TYPE_CHECKER
Checker which allows any type.
-
ANY_PARAMETER_CHECKER
public static final SqlTester.ParameterChecker ANY_PARAMETER_CHECKER
Checker that allows any number or type of parameters.
-
ANY_RESULT_CHECKER
public static final SqlTester.ResultChecker ANY_RESULT_CHECKER
Checker that allows any result.
-
LINE_COL_PATTERN
private static final java.util.regex.Pattern LINE_COL_PATTERN
-
LINE_COL_TWICE_PATTERN
private static final java.util.regex.Pattern LINE_COL_TWICE_PATTERN
-
-
Method Detail
-
getTypeString
public static java.lang.String getTypeString(org.apache.calcite.rel.type.RelDataType sqlType)
Helper function to get the string representation of a RelDataType (include precision/scale but no charset or collation)- Parameters:
sqlType
- Type- Returns:
- String representation of type
-
generateAggQuery
public static java.lang.String generateAggQuery(java.lang.String expr, java.lang.String[] inputValues)
-
generateAggQueryWithMultipleArgs
public static java.lang.String generateAggQueryWithMultipleArgs(java.lang.String expr, java.lang.String[][] inputValues)
-
generateWinAggQuery
public static java.lang.String generateWinAggQuery(java.lang.String expr, java.lang.String windowSpec, java.lang.String[] inputValues)
-
compareResultSet
public static void compareResultSet(java.sql.ResultSet resultSet, java.util.Set<java.lang.String> refSet) throws java.lang.Exception
Compares the first column of a result set against a String-valued reference set, disregarding order entirely.- Parameters:
resultSet
- Result setrefSet
- Expected results- Throws:
java.lang.Exception
- .
-
rep
private static org.apache.calcite.avatica.ColumnMetaData.Rep rep(int columnType)
-
compareResultSetWithPattern
public static void compareResultSetWithPattern(java.sql.ResultSet resultSet, java.util.regex.Pattern pattern) throws java.lang.Exception
Compares the first column of a result set against a pattern. The result set must return exactly one row.- Parameters:
resultSet
- Result setpattern
- Expected pattern- Throws:
java.lang.Exception
-
compareResultSetWithDelta
public static void compareResultSetWithDelta(java.sql.ResultSet resultSet, double expected, double delta) throws java.lang.Exception
Compares the first column of a result set against a numeric result, within a given tolerance. The result set must return exactly one row.- Parameters:
resultSet
- Result setexpected
- Expected resultdelta
- Tolerance- Throws:
java.lang.Exception
-
checkEx
public static void checkEx(java.lang.Throwable ex, java.lang.String expectedMsgPattern, org.apache.calcite.sql.parser.SqlParserUtil.StringAndPos sap, SqlTests.Stage stage)
Checks whether an exception matches the expected pattern. Ifsap
contains an error location, checks this too.- Parameters:
ex
- Exception thrownexpectedMsgPattern
- Expected patternsap
- Query and (optional) position in querystage
- Query processing stage
-
createChecker
public static SqlTester.ResultChecker createChecker(java.lang.Object result, double delta)
-
-