Package org.apache.calcite.test
Class RexProgramTest
- java.lang.Object
-
- org.apache.calcite.test.RexProgramBuilderBase
-
- org.apache.calcite.test.RexProgramTest
-
public class RexProgramTest extends RexProgramBuilderBase
Unit tests forRexProgram
andRexProgramBuilder
.
-
-
Field Summary
-
Fields inherited from class org.apache.calcite.test.RexProgramBuilderBase
executor, falseLiteral, MAX_FIELDS, nullBool, nullInt, nullVarchar, rexBuilder, simplify, trueLiteral, typeFactory
-
-
Constructor Summary
Constructors Constructor Description RexProgramTest()
Creates a RexProgramTest.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
assertNode(java.lang.String message, java.lang.String expected, org.apache.calcite.rex.RexNode node)
Asserts that given node has expected string representation with account of node typeprivate void
assertTypeAndToString(org.apache.calcite.rex.RexNode rexNode, java.lang.String representation, java.lang.String type)
private void
checkCnf(org.apache.calcite.rex.RexNode node, java.lang.String expected)
private void
checkExponentialCnf(int n)
private void
checkIs(org.apache.calcite.rex.RexNode e, boolean expected)
Checks thatRexNode.isAlwaysTrue()
,RexNode.isAlwaysTrue()
andRexSimplify
agree that an expression reduces to true or false.private void
checkPullFactors(org.apache.calcite.rex.RexNode node, java.lang.String expected)
private void
checkPullFactorsUnchanged(org.apache.calcite.rex.RexNode node)
private void
checkSimplify(org.apache.calcite.rex.RexNode node, java.lang.String expected)
Simplifies an expression and checks that the result is as expected.private void
checkSimplify2(org.apache.calcite.rex.RexNode node, java.lang.String expected, java.lang.String expectedFalse)
Simplifies an expression and checks the result if unknowns remain unknown, or if unknown becomes false.private void
checkSimplify3(org.apache.calcite.rex.RexNode node, java.lang.String expected, java.lang.String expectedFalse, java.lang.String expectedTrue)
private void
checkSimplify3_(org.apache.calcite.rex.RexNode node, java.lang.String expected, java.lang.String expectedFalse, java.lang.String expectedTrue)
void
checkSimplifyDynamicParam()
private void
checkSimplifyFilter(org.apache.calcite.rex.RexNode node, java.lang.String expected)
private void
checkSimplifyFilter(org.apache.calcite.rex.RexNode node, org.apache.calcite.plan.RelOptPredicateList predicates, java.lang.String expected)
private void
checkSimplifyUnchanged(org.apache.calcite.rex.RexNode node)
Simplifies an expression and checks that the result is unchanged.private void
checkThresholdCnf(org.apache.calcite.rex.RexNode node, int threshold, java.lang.String expected)
private org.apache.calcite.rex.RexProgramBuilder
createProg(int variant)
Creates a program, depending on variant:select (x + y) + (x + 1) as a, (x + x) as b from t(x, y)
select (x + y) + (x + 1) as a, (x + (x + 1)) as b from t(x, y)
select (x + y) + (x + 1) as a, (x + x) as b from t(x, y) where ((x + y) > 1) and ((x + y) > 1)
select (x + y) + (x + 1) as a, (x + x) as b from t(x, y) where not case when x + 1 > 5 then true when y is null then null else false end
private java.lang.Comparable
eval(org.apache.calcite.rex.RexNode e)
void
fieldAccessEqualsHashCode()
private static java.lang.String
getString(com.google.common.collect.ImmutableMap<org.apache.calcite.rex.RexNode,org.apache.calcite.rex.RexNode> map)
Converts a map to a string, sorting on the string representation of its keys.private static int
nodeCount(org.apache.calcite.rex.RexNode node)
Returns the number of nodes (including leaves) in a Rex tree.void
notDistinct()
void
removeRedundantCast()
void
setUp()
private org.apache.calcite.rex.RexNode
simplify(org.apache.calcite.rex.RexNode e)
void
simplifyNull()
void
simplifyStrong()
void
testBuildProgram()
Tests construction of a RexProgram.void
testCastLiteral()
void
testCnf()
Unit test forRexUtil.toCnf(org.apache.calcite.rex.RexBuilder, org.apache.calcite.rex.RexNode)
.void
testCnf2()
void
testCnfExponential()
Tests formulas of various sizes whose size is exponential when converted to CNF.void
testCompareTimestampWithTimeZone()
void
testConstantMap()
void
testDuplicateAnd()
Checks translation of AND(x, x).void
testElimDups()
Tests construction and normalization of a RexProgram.void
testInterpreter()
void
testIsAlwaysTrueAndFalseNotXisNullisNotNullisFalse()
void
testIsAlwaysTrueAndFalseNotXisNullisNotNullisNotTrue()
void
testIsAlwaysTrueAndFalseNotXisNullisNotNullisTrue()
void
testIsAlwaysTrueAndFalseXisNotNullisNotNull()
void
testIsAlwaysTrueAndFalseXisNotNullisNull()
void
testIsAlwaysTrueAndFalseXisNullisNotNull()
void
testIsAlwaysTrueAndFalseXisNullisNotNullisFalse()
Unit tests for [CALCITE-2438] RexCall#isAlwaysTrue returns incorrect result.void
testIsAlwaysTrueAndFalseXisNullisNotNullisNotFalse()
void
testIsAlwaysTrueAndFalseXisNullisNotNullisNotTrue()
void
testIsAlwaysTrueAndFalseXisNullisNotNullisTrue()
void
testIsAlwaysTrueAndFalseXisNullisNull()
void
testIsDeterministic()
void
testLosslessCast()
Unit test forRexUtil.isLosslessCast(RexNode)
.void
testNoCommonReturnTypeFails()
void
testNormalize()
Tests construction and normalization of a RexProgram.void
testPullFactors()
Unit test forRexUtil.pullFactors(org.apache.calcite.rex.RexBuilder, org.apache.calcite.rex.RexNode)
.void
testRemovalOfNullabilityWideningCast()
void
testSimpleDynamicVars()
void
testSimplify()
void
testSimplifyAnd()
void
testSimplifyAnd3()
void
testSimplifyAndNot()
void
testSimplifyAndPush()
void
testSimplifyCaseAndNotSimplicationIsInAction()
void
testSimplifyCaseBranchesCollapse()
void
testSimplifyCaseBranchesCollapse2()
void
testSimplifyCaseBranchRemovalStrengthensType()
void
testSimplifyCaseCasting()
void
testSimplifyCaseCompaction()
void
testSimplifyCaseCompaction2()
void
testSimplifyCaseCompactionDiv()
void
testSimplifyCaseDiv1()
Tests a CASE value branch that contains division.void
testSimplifyCaseDiv2()
Tests a CASE condition that contains division,void
testSimplifyCaseNotNullableBoolean()
void
testSimplifyCaseNullableBoolean()
void
testSimplifyCaseNullableVarChar()
void
testSimplifyCastLiteral()
void
testSimplifyCastLiteral2()
void
testSimplifyCastLiteral3()
void
testSimplifyCoalesce()
void
testSimplifyCondition()
Tests how the condition is simplified.void
testSimplifyCondition2()
Tests how the condition is simplified.void
testSimplifyDynamicParam()
void
testSimplifyFalse()
void
testSimplifyFilter()
void
testSimplifyIsNotNull()
void
testSimplifyLiterals()
void
testSimplifyNot()
void
testSimplifyNotAnd()
void
testSimplifyOrNot()
void
testSimplifyOrTerms()
void
testSimplifyUnknown()
void
testStrong()
Unit test forStrong
.void
testThresholdCnf()
void
xAndNotX()
-
Methods inherited from class org.apache.calcite.test.RexProgramBuilderBase
abstractCast, add, and, and, case_, case_, cast, coalesce, div, divInt, eq, ge, gt, in, input, isDistinctFrom, isFalse, isNotDistinctFrom, isNotFalse, isNotNull, isNotTrue, isNull, isTrue, isUnknown, le, literal, literal, literal, literal, literal, literal, literal, lt, mul, ne, not, null_, nullable, nullIf, or, or, plus, sub, tBoolean, tBoolean, tInt, tInt, tVarchar, tVarchar, unaryMinus, unaryPlus, vBool, vBool, vBoolNotNull, vBoolNotNull, vInt, vInt, vIntNotNull, vIntNotNull, vVarchar, vVarchar, vVarcharNotNull, vVarcharNotNull
-
-
-
-
Method Detail
-
setUp
public void setUp()
- Overrides:
setUp
in classRexProgramBuilderBase
-
checkCnf
private void checkCnf(org.apache.calcite.rex.RexNode node, java.lang.String expected)
-
checkThresholdCnf
private void checkThresholdCnf(org.apache.calcite.rex.RexNode node, int threshold, java.lang.String expected)
-
checkPullFactorsUnchanged
private void checkPullFactorsUnchanged(org.apache.calcite.rex.RexNode node)
-
checkPullFactors
private void checkPullFactors(org.apache.calcite.rex.RexNode node, java.lang.String expected)
-
assertNode
private void assertNode(java.lang.String message, java.lang.String expected, org.apache.calcite.rex.RexNode node)
Asserts that given node has expected string representation with account of node type- Parameters:
message
- extra message that clarifies where the node came fromexpected
- expected string representation of the nodenode
- node to check
-
checkSimplify
private void checkSimplify(org.apache.calcite.rex.RexNode node, java.lang.String expected)
Simplifies an expression and checks that the result is as expected.
-
checkSimplifyUnchanged
private void checkSimplifyUnchanged(org.apache.calcite.rex.RexNode node)
Simplifies an expression and checks that the result is unchanged.
-
checkSimplify2
private void checkSimplify2(org.apache.calcite.rex.RexNode node, java.lang.String expected, java.lang.String expectedFalse)
Simplifies an expression and checks the result if unknowns remain unknown, or if unknown becomes false. If the result is the same, usecheckSimplify(RexNode, String)
.- Parameters:
node
- Expression to simplifyexpected
- Expected simplificationexpectedFalse
- Expected simplification, if unknown is to be treated as false
-
checkSimplify3
private void checkSimplify3(org.apache.calcite.rex.RexNode node, java.lang.String expected, java.lang.String expectedFalse, java.lang.String expectedTrue)
-
checkSimplify3_
private void checkSimplify3_(org.apache.calcite.rex.RexNode node, java.lang.String expected, java.lang.String expectedFalse, java.lang.String expectedTrue)
-
checkSimplifyFilter
private void checkSimplifyFilter(org.apache.calcite.rex.RexNode node, java.lang.String expected)
-
checkSimplifyFilter
private void checkSimplifyFilter(org.apache.calcite.rex.RexNode node, org.apache.calcite.plan.RelOptPredicateList predicates, java.lang.String expected)
-
nodeCount
private static int nodeCount(org.apache.calcite.rex.RexNode node)
Returns the number of nodes (including leaves) in a Rex tree.
-
testBuildProgram
public void testBuildProgram()
Tests construction of a RexProgram.
-
testNormalize
public void testNormalize()
Tests construction and normalization of a RexProgram.
-
testElimDups
public void testElimDups()
Tests construction and normalization of a RexProgram.
-
testSimplifyCondition
public void testSimplifyCondition()
Tests how the condition is simplified.
-
testSimplifyCondition2
public void testSimplifyCondition2()
Tests how the condition is simplified.
-
testDuplicateAnd
public void testDuplicateAnd()
Checks translation of AND(x, x).
-
createProg
private org.apache.calcite.rex.RexProgramBuilder createProg(int variant)
Creates a program, depending on variant:select (x + y) + (x + 1) as a, (x + x) as b from t(x, y)
select (x + y) + (x + 1) as a, (x + (x + 1)) as b from t(x, y)
select (x + y) + (x + 1) as a, (x + x) as b from t(x, y) where ((x + y) > 1) and ((x + y) > 1)
select (x + y) + (x + 1) as a, (x + x) as b from t(x, y) where not case when x + 1 > 5 then true when y is null then null else false end
-
testStrong
public void testStrong()
Unit test forStrong
.
-
xAndNotX
public void xAndNotX()
-
testLosslessCast
public void testLosslessCast()
Unit test forRexUtil.isLosslessCast(RexNode)
.
-
removeRedundantCast
public void removeRedundantCast()
-
testNoCommonReturnTypeFails
public void testNoCommonReturnTypeFails()
-
testCnf
public void testCnf()
Unit test forRexUtil.toCnf(org.apache.calcite.rex.RexBuilder, org.apache.calcite.rex.RexNode)
.
-
testCnf2
public void testCnf2()
-
testThresholdCnf
public void testThresholdCnf()
-
testCnfExponential
public void testCnfExponential()
Tests formulas of various sizes whose size is exponential when converted to CNF.
-
checkExponentialCnf
private void checkExponentialCnf(int n)
-
testPullFactors
public void testPullFactors()
Unit test forRexUtil.pullFactors(org.apache.calcite.rex.RexBuilder, org.apache.calcite.rex.RexNode)
.
-
testSimplify
public void testSimplify()
-
simplifyStrong
public void simplifyStrong()
-
testSimplifyFilter
public void testSimplifyFilter()
-
testSimplifyAndPush
public void testSimplifyAndPush()
-
testSimplifyOrTerms
public void testSimplifyOrTerms()
-
testSimplifyNotAnd
public void testSimplifyNotAnd()
-
testSimplifyUnknown
public void testSimplifyUnknown()
-
testSimplifyAnd3
public void testSimplifyAnd3()
-
fieldAccessEqualsHashCode
public void fieldAccessEqualsHashCode()
-
testSimplifyDynamicParam
public void testSimplifyDynamicParam()
-
testSimplifyCaseNotNullableBoolean
public void testSimplifyCaseNotNullableBoolean()
-
testSimplifyCaseNullableBoolean
public void testSimplifyCaseNullableBoolean()
-
testSimplifyCaseBranchesCollapse
public void testSimplifyCaseBranchesCollapse()
-
testSimplifyCaseBranchesCollapse2
public void testSimplifyCaseBranchesCollapse2()
-
testSimplifyCaseNullableVarChar
public void testSimplifyCaseNullableVarChar()
-
testSimplifyCaseCasting
public void testSimplifyCaseCasting()
-
testSimplifyCaseAndNotSimplicationIsInAction
public void testSimplifyCaseAndNotSimplicationIsInAction()
-
testSimplifyCaseBranchRemovalStrengthensType
public void testSimplifyCaseBranchRemovalStrengthensType()
-
testSimplifyCaseCompaction
public void testSimplifyCaseCompaction()
-
testSimplifyCaseCompaction2
public void testSimplifyCaseCompaction2()
-
testSimplifyCaseCompactionDiv
public void testSimplifyCaseCompactionDiv()
-
testSimplifyCaseDiv1
public void testSimplifyCaseDiv1()
Tests a CASE value branch that contains division.
-
testSimplifyCaseDiv2
public void testSimplifyCaseDiv2()
Tests a CASE condition that contains division,
-
testSimplifyAnd
public void testSimplifyAnd()
-
testSimplifyIsNotNull
public void testSimplifyIsNotNull()
-
checkSimplifyDynamicParam
public void checkSimplifyDynamicParam()
-
testSimplifyCastLiteral
public void testSimplifyCastLiteral()
-
testCastLiteral
public void testCastLiteral()
-
testSimplifyCastLiteral2
public void testSimplifyCastLiteral2()
-
testSimplifyCastLiteral3
public void testSimplifyCastLiteral3()
-
testRemovalOfNullabilityWideningCast
public void testRemovalOfNullabilityWideningCast()
-
testCompareTimestampWithTimeZone
public void testCompareTimestampWithTimeZone()
-
testSimplifyLiterals
public void testSimplifyLiterals()
-
testSimpleDynamicVars
public void testSimpleDynamicVars()
-
assertTypeAndToString
private void assertTypeAndToString(org.apache.calcite.rex.RexNode rexNode, java.lang.String representation, java.lang.String type)
-
testIsDeterministic
public void testIsDeterministic()
-
testConstantMap
public void testConstantMap()
-
notDistinct
public void notDistinct()
-
testSimplifyCoalesce
public void testSimplifyCoalesce()
-
simplifyNull
public void simplifyNull()
-
getString
private static java.lang.String getString(com.google.common.collect.ImmutableMap<org.apache.calcite.rex.RexNode,org.apache.calcite.rex.RexNode> map)
Converts a map to a string, sorting on the string representation of its keys.
-
testSimplifyFalse
public void testSimplifyFalse()
-
testSimplifyNot
public void testSimplifyNot()
-
testSimplifyAndNot
public void testSimplifyAndNot()
-
testSimplifyOrNot
public void testSimplifyOrNot()
-
simplify
private org.apache.calcite.rex.RexNode simplify(org.apache.calcite.rex.RexNode e)
-
testInterpreter
public void testInterpreter()
-
testIsAlwaysTrueAndFalseXisNullisNotNullisFalse
public void testIsAlwaysTrueAndFalseXisNullisNotNullisFalse()
Unit tests for [CALCITE-2438] RexCall#isAlwaysTrue returns incorrect result.
-
testIsAlwaysTrueAndFalseNotXisNullisNotNullisFalse
public void testIsAlwaysTrueAndFalseNotXisNullisNotNullisFalse()
-
testIsAlwaysTrueAndFalseXisNullisNotNullisTrue
public void testIsAlwaysTrueAndFalseXisNullisNotNullisTrue()
-
testIsAlwaysTrueAndFalseNotXisNullisNotNullisTrue
public void testIsAlwaysTrueAndFalseNotXisNullisNotNullisTrue()
-
testIsAlwaysTrueAndFalseNotXisNullisNotNullisNotTrue
public void testIsAlwaysTrueAndFalseNotXisNullisNotNullisNotTrue()
-
testIsAlwaysTrueAndFalseXisNullisNotNull
public void testIsAlwaysTrueAndFalseXisNullisNotNull()
-
testIsAlwaysTrueAndFalseXisNotNullisNotNull
public void testIsAlwaysTrueAndFalseXisNotNullisNotNull()
-
testIsAlwaysTrueAndFalseXisNullisNull
public void testIsAlwaysTrueAndFalseXisNullisNull()
-
testIsAlwaysTrueAndFalseXisNotNullisNull
public void testIsAlwaysTrueAndFalseXisNotNullisNull()
-
testIsAlwaysTrueAndFalseXisNullisNotNullisNotFalse
public void testIsAlwaysTrueAndFalseXisNullisNotNullisNotFalse()
-
testIsAlwaysTrueAndFalseXisNullisNotNullisNotTrue
public void testIsAlwaysTrueAndFalseXisNullisNotNullisNotTrue()
-
checkIs
private void checkIs(org.apache.calcite.rex.RexNode e, boolean expected)
Checks thatRexNode.isAlwaysTrue()
,RexNode.isAlwaysTrue()
andRexSimplify
agree that an expression reduces to true or false.
-
eval
private java.lang.Comparable eval(org.apache.calcite.rex.RexNode e)
-
-