org.apache.calcite.util.Litmus Java Examples
The following examples show how to use
org.apache.calcite.util.Litmus.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RexUtil.java From calcite with Apache License 2.0 | 6 votes |
/** * Returns whether an array of exp contains no aggregate function calls whose * arguments are not {@link RexInputRef}s. * * @param exprs Expressions * @param litmus Whether to assert if there is such a function call */ static boolean containNoNonTrivialAggs(List<RexNode> exprs, Litmus litmus) { for (RexNode expr : exprs) { if (expr instanceof RexCall) { RexCall rexCall = (RexCall) expr; if (rexCall.getOperator() instanceof SqlAggFunction) { for (RexNode operand : rexCall.operands) { if (!(operand instanceof RexLocalRef) && !(operand instanceof RexLiteral)) { return litmus.fail("contains non trivial agg: {}", operand); } } } } } return litmus.succeed(); }
Example #2
Source File: OverScope.java From Bats with Apache License 2.0 | 6 votes |
public SqlMonotonicity getMonotonicity(SqlNode expr) { SqlMonotonicity monotonicity = expr.getMonotonicity(this); if (monotonicity != SqlMonotonicity.NOT_MONOTONIC) { return monotonicity; } if (children.size() == 1) { final SqlValidatorNamespace child = children.get(0).namespace; final List<Pair<SqlNode, SqlMonotonicity>> monotonicExprs = child.getMonotonicExprs(); for (Pair<SqlNode, SqlMonotonicity> pair : monotonicExprs) { if (expr.equalsDeep(pair.left, Litmus.IGNORE)) { return pair.right; } } } return super.getMonotonicity(expr); }
Example #3
Source File: RexUtil.java From Bats with Apache License 2.0 | 6 votes |
/** * Returns whether the leading edge of a given array of expressions is * wholly {@link RexInputRef} objects with types corresponding to the * underlying datatype. */ public static boolean containIdentity(List<? extends RexNode> exprs, RelDataType rowType, Litmus litmus) { final List<RelDataTypeField> fields = rowType.getFieldList(); if (exprs.size() < fields.size()) { return litmus.fail("exprs/rowType length mismatch"); } for (int i = 0; i < fields.size(); i++) { if (!(exprs.get(i) instanceof RexInputRef)) { return litmus.fail("expr[{}] is not a RexInputRef", i); } RexInputRef inputRef = (RexInputRef) exprs.get(i); if (inputRef.getIndex() != i) { return litmus.fail("expr[{}] has ordinal {}", i, inputRef.getIndex()); } if (!RelOptUtil.eq("type1", exprs.get(i).getType(), "type2", fields.get(i).getType(), litmus)) { return litmus.fail(null); } } return litmus.succeed(); }
Example #4
Source File: RexUtil.java From calcite with Apache License 2.0 | 6 votes |
/** * Returns whether the leading edge of a given array of expressions is * wholly {@link RexInputRef} objects with types corresponding to the * underlying datatype. */ public static boolean containIdentity( List<? extends RexNode> exprs, RelDataType rowType, Litmus litmus) { final List<RelDataTypeField> fields = rowType.getFieldList(); if (exprs.size() < fields.size()) { return litmus.fail("exprs/rowType length mismatch"); } for (int i = 0; i < fields.size(); i++) { if (!(exprs.get(i) instanceof RexInputRef)) { return litmus.fail("expr[{}] is not a RexInputRef", i); } RexInputRef inputRef = (RexInputRef) exprs.get(i); if (inputRef.getIndex() != i) { return litmus.fail("expr[{}] has ordinal {}", i, inputRef.getIndex()); } if (!RelOptUtil.eq("type1", exprs.get(i).getType(), "type2", fields.get(i).getType(), litmus)) { return litmus.fail(null); } } return litmus.succeed(); }
Example #5
Source File: RelOptUtil.java From calcite with Apache License 2.0 | 6 votes |
/** * Returns whether two types are equal using 'equals'. * * @param desc1 Description of first type * @param type1 First type * @param desc2 Description of second type * @param type2 Second type * @param litmus What to do if an error is detected (types are not equal) * @return Whether the types are equal */ public static boolean eq( final String desc1, RelDataType type1, final String desc2, RelDataType type2, Litmus litmus) { // if any one of the types is ANY return true if (type1.getSqlTypeName() == SqlTypeName.ANY || type2.getSqlTypeName() == SqlTypeName.ANY) { return litmus.succeed(); } if (!type1.equals(type2)) { return litmus.fail("type mismatch:\n{}:\n{}\n{}:\n{}", desc1, type1.getFullTypeString(), desc2, type2.getFullTypeString()); } return litmus.succeed(); }
Example #6
Source File: Calc.java From calcite with Apache License 2.0 | 6 votes |
public boolean isValid(Litmus litmus, Context context) { if (!RelOptUtil.equal( "program's input type", program.getInputRowType(), "child's output type", getInput().getRowType(), litmus)) { return litmus.fail(null); } if (!program.isValid(litmus, context)) { return litmus.fail(null); } if (!program.isNormalized(litmus, getCluster().getRexBuilder())) { return litmus.fail(null); } return litmus.succeed(); }
Example #7
Source File: RexUtil.java From Bats with Apache License 2.0 | 6 votes |
/** * Returns whether an array of exp contains no aggregate function calls whose * arguments are not {@link RexInputRef}s. * * @param exprs Expressions * @param litmus Whether to assert if there is such a function call */ static boolean containNoNonTrivialAggs(List<RexNode> exprs, Litmus litmus) { for (RexNode expr : exprs) { if (expr instanceof RexCall) { RexCall rexCall = (RexCall) expr; if (rexCall.getOperator() instanceof SqlAggFunction) { for (RexNode operand : rexCall.getOperands()) { if (!(operand instanceof RexLocalRef) && !(operand instanceof RexLiteral)) { return litmus.fail("contains non trivial agg: {}", operand); } } } } } return litmus.succeed(); }
Example #8
Source File: SqlRowTypeNameSpec.java From calcite with Apache License 2.0 | 6 votes |
@Override public boolean equalsDeep(SqlTypeNameSpec node, Litmus litmus) { if (!(node instanceof SqlRowTypeNameSpec)) { return litmus.fail("{} != {}", this, node); } SqlRowTypeNameSpec that = (SqlRowTypeNameSpec) node; if (this.fieldNames.size() != that.fieldNames.size()) { return litmus.fail("{} != {}", this, node); } for (int i = 0; i < fieldNames.size(); i++) { if (!this.fieldNames.get(i).equalsDeep(that.fieldNames.get(i), litmus)) { return litmus.fail("{} != {}", this, node); } } if (this.fieldTypes.size() != that.fieldTypes.size()) { return litmus.fail("{} != {}", this, node); } for (int i = 0; i < fieldTypes.size(); i++) { if (!this.fieldTypes.get(i).equals(that.fieldTypes.get(i))) { return litmus.fail("{} != {}", this, node); } } return litmus.succeed(); }
Example #9
Source File: JoinRel.java From dremio-oss with Apache License 2.0 | 6 votes |
@Override public boolean isValid(Litmus litmus, Context context) { if (condition != null) { if (condition.getType().getSqlTypeName() != SqlTypeName.BOOLEAN) { return litmus.fail("condition must be boolean: {}", condition.getType()); } RexChecker checker = new RexChecker( getCluster().getTypeFactory().builder() .addAll(getSystemFieldList()) .addAll(getLeft().getRowType().getFieldList()) .addAll(getRight().getRowType().getFieldList()) .build(), context, litmus); condition.accept(checker); if (checker.getFailureCount() > 0) { return litmus.fail(checker.getFailureCount() + " failures in condition " + condition); } } return litmus.succeed(); }
Example #10
Source File: JoinRelBase.java From dremio-oss with Apache License 2.0 | 6 votes |
@Override public boolean isValid(Litmus litmus, Context context) { if (condition != null) { if (condition.getType().getSqlTypeName() != SqlTypeName.BOOLEAN) { return litmus.fail("condition must be boolean: {}", condition.getType()); } // The input to the condition is a row type consisting of system // fields, left fields, and right fields. Very similar to the // output row type, except that fields have not yet been made due // due to outer joins. RexChecker checker = new RexChecker( getCluster().getTypeFactory().builder() .addAll(getSystemFieldList()) .addAll(getLeft().getRowType().getFieldList()) .addAll(getRight().getRowType().getFieldList()) .build(), context, litmus); condition.accept(checker); if (checker.getFailureCount() > 0) { return litmus.fail(checker.getFailureCount() + " failures in condition " + condition); } } return litmus.succeed(); }
Example #11
Source File: SqlBasicTypeNameSpec.java From calcite with Apache License 2.0 | 6 votes |
@Override public boolean equalsDeep(SqlTypeNameSpec node, Litmus litmus) { if (!(node instanceof SqlBasicTypeNameSpec)) { return litmus.fail("{} != {}", this, node); } SqlBasicTypeNameSpec that = (SqlBasicTypeNameSpec) node; if (this.sqlTypeName != that.sqlTypeName) { return litmus.fail("{} != {}", this, node); } if (this.precision != that.precision) { return litmus.fail("{} != {}", this, node); } if (this.scale != that.scale) { return litmus.fail("{} != {}", this, node); } if (!Objects.equals(this.charSetName, that.charSetName)) { return litmus.fail("{} != {}", this, node); } return litmus.succeed(); }
Example #12
Source File: ExtendedSqlRowTypeNameSpec.java From flink with Apache License 2.0 | 6 votes |
@Override public boolean equalsDeep(SqlTypeNameSpec node, Litmus litmus) { if (!(node instanceof SqlRowTypeNameSpec)) { return litmus.fail("{} != {}", this, node); } ExtendedSqlRowTypeNameSpec that = (ExtendedSqlRowTypeNameSpec) node; if (this.fieldNames.size() != that.fieldNames.size()) { return litmus.fail("{} != {}", this, node); } for (int i = 0; i < fieldNames.size(); i++) { if (!this.fieldNames.get(i).equalsDeep(that.fieldNames.get(i), litmus)) { return litmus.fail("{} != {}", this, node); } } if (this.fieldTypes.size() != that.fieldTypes.size()) { return litmus.fail("{} != {}", this, node); } for (int i = 0; i < fieldTypes.size(); i++) { if (!this.fieldTypes.get(i).equals(that.fieldTypes.get(i))) { return litmus.fail("{} != {}", this, node); } } return litmus.succeed(); }
Example #13
Source File: SelectScope.java From calcite with Apache License 2.0 | 6 votes |
public SqlMonotonicity getMonotonicity(SqlNode expr) { SqlMonotonicity monotonicity = expr.getMonotonicity(this); if (monotonicity != SqlMonotonicity.NOT_MONOTONIC) { return monotonicity; } // TODO: compare fully qualified names final SqlNodeList orderList = getOrderList(); if (orderList.size() > 0) { SqlNode order0 = orderList.get(0); monotonicity = SqlMonotonicity.INCREASING; if ((order0 instanceof SqlCall) && (((SqlCall) order0).getOperator() == SqlStdOperatorTable.DESC)) { monotonicity = monotonicity.reverse(); order0 = ((SqlCall) order0).operand(0); } if (expr.equalsDeep(order0, Litmus.IGNORE)) { return monotonicity; } } return SqlMonotonicity.NOT_MONOTONIC; }
Example #14
Source File: Calc.java From Bats with Apache License 2.0 | 6 votes |
public boolean isValid(Litmus litmus, Context context) { if (!RelOptUtil.equal( "program's input type", program.getInputRowType(), "child's output type", getInput().getRowType(), litmus)) { return litmus.fail(null); } if (!program.isValid(litmus, context)) { return litmus.fail(null); } if (!program.isNormalized(litmus, getCluster().getRexBuilder())) { return litmus.fail(null); } return litmus.succeed(); }
Example #15
Source File: VolcanoPlanner.java From Bats with Apache License 2.0 | 6 votes |
/** * Checks internal consistency. */ protected boolean isValid(Litmus litmus) { for (RelSet set : allSets) { if (set.equivalentSet != null) { return litmus.fail("set [{}] has been merged: it should not be in the list", set); } for (RelSubset subset : set.subsets) { if (subset.set != set) { return litmus.fail("subset [{}] is in wrong set [{}]", subset.getDescription(), set); } for (RelNode rel : subset.getRels()) { RelOptCost relCost = getCost(rel, rel.getCluster().getMetadataQuery()); if (relCost.isLt(subset.bestCost)) { return litmus.fail("rel [{}] has lower cost {} than best cost {} of subset [{}]", rel.getDescription(), relCost, subset.bestCost, subset.getDescription()); } } } } return litmus.succeed(); }
Example #16
Source File: LatticeRootNode.java From calcite with Apache License 2.0 | 6 votes |
/** Validates that nodes form a tree; each node except the first references * a predecessor. */ boolean isValid(Litmus litmus) { for (int i = 0; i < descendants.size(); i++) { LatticeNode node = descendants.get(i); if (i == 0) { if (node != this) { return litmus.fail("node 0 should be root"); } } else { if (!(node instanceof LatticeChildNode)) { return litmus.fail("node after 0 should be child"); } final LatticeChildNode child = (LatticeChildNode) node; if (!descendants.subList(0, i).contains(child.parent)) { return litmus.fail("parent not in preceding list"); } } } return litmus.succeed(); }
Example #17
Source File: SqlDynamicParam.java From calcite with Apache License 2.0 | 5 votes |
public boolean equalsDeep(SqlNode node, Litmus litmus) { if (!(node instanceof SqlDynamicParam)) { return litmus.fail("{} != {}", this, node); } SqlDynamicParam that = (SqlDynamicParam) node; if (this.index != that.index) { return litmus.fail("{} != {}", this, node); } return litmus.succeed(); }
Example #18
Source File: SqlIntervalLiteral.java From calcite with Apache License 2.0 | 5 votes |
public boolean equals(Object obj) { if (!(obj instanceof IntervalValue)) { return false; } IntervalValue that = (IntervalValue) obj; return this.intervalStr.equals(that.intervalStr) && (this.sign == that.sign) && this.intervalQualifier.equalsDeep(that.intervalQualifier, Litmus.IGNORE); }
Example #19
Source File: ExtendedSqlCollectionTypeNameSpec.java From flink with Apache License 2.0 | 5 votes |
@Override public boolean equalsDeep(SqlTypeNameSpec spec, Litmus litmus) { if (!(spec instanceof ExtendedSqlCollectionTypeNameSpec)) { return litmus.fail("{} != {}", this, spec); } ExtendedSqlCollectionTypeNameSpec that = (ExtendedSqlCollectionTypeNameSpec) spec; if (this.elementNullable != that.elementNullable) { return litmus.fail("{} != {}", this, spec); } return super.equalsDeep(spec, litmus); }
Example #20
Source File: RexProgram.java From calcite with Apache License 2.0 | 5 votes |
/** * Returns whether this program is in canonical form. * * @param litmus What to do if an error is detected (program is not in * canonical form) * @param rexBuilder Rex builder * @return whether in canonical form */ public boolean isNormalized(Litmus litmus, RexBuilder rexBuilder) { final RexProgram normalizedProgram = normalize(rexBuilder, null); String normalized = normalizedProgram.toString(); String string = toString(); if (!normalized.equals(string)) { final String message = "Program is not normalized:\n" + "program: {}\n" + "normalized: {}\n"; return litmus.fail(message, string, normalized); } return litmus.succeed(); }
Example #21
Source File: SqlIdentifier.java From calcite with Apache License 2.0 | 5 votes |
public boolean equalsDeep(SqlNode node, Litmus litmus) { if (!(node instanceof SqlIdentifier)) { return litmus.fail("{} != {}", this, node); } SqlIdentifier that = (SqlIdentifier) node; if (this.names.size() != that.names.size()) { return litmus.fail("{} != {}", this, node); } for (int i = 0; i < names.size(); i++) { if (!this.names.get(i).equals(that.names.get(i))) { return litmus.fail("{} != {}", this, node); } } return litmus.succeed(); }
Example #22
Source File: RexUtil.java From Bats with Apache License 2.0 | 5 votes |
/** * Returns whether an array of expressions contains no forward references. * That is, if expression #i contains a {@link RexInputRef} referencing * field i or greater. * * @param exprs Array of expressions * @param inputRowType Input row type * @param litmus What to do if an error is detected (there is a * forward reference) * * @return Whether there is a forward reference */ public static boolean containNoForwardRefs(List<RexNode> exprs, RelDataType inputRowType, Litmus litmus) { final ForwardRefFinder visitor = new ForwardRefFinder(inputRowType); for (int i = 0; i < exprs.size(); i++) { RexNode expr = exprs.get(i); visitor.setLimit(i); // field cannot refer to self or later field try { expr.accept(visitor); } catch (ForwardRefFinder.IllegalForwardRefException e) { Util.swallow(e, null); return litmus.fail("illegal forward reference in {}", expr); } } return litmus.succeed(); }
Example #23
Source File: RexUtil.java From Bats with Apache License 2.0 | 5 votes |
/** * Returns whether an array of expressions has any common sub-expressions. */ public static boolean containNoCommonExprs(List<RexNode> exprs, Litmus litmus) { final ExpressionNormalizer visitor = new ExpressionNormalizer(false); for (RexNode expr : exprs) { try { expr.accept(visitor); } catch (ExpressionNormalizer.SubExprExistsException e) { Util.swallow(e, null); return litmus.fail(null); } } return litmus.succeed(); }
Example #24
Source File: SqlHintsConverterTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testInvalidQueryHint() { final String sql = "select /*+ weird_hint */ empno\n" + "from (select /*+ resource(mem='20Mb')*/ empno, ename\n" + "from emp left join dept on emp.deptno = dept.deptno)"; sql(sql).warns("Hint: WEIRD_HINT should be registered in the HintStrategyTable"); final String sql1 = "select /*+ resource(mem='20Mb')*/ empno\n" + "from (select /*+ weird_kv_hint(k1='v1') */ empno, ename\n" + "from emp left join dept on emp.deptno = dept.deptno)"; sql(sql1).warns("Hint: WEIRD_KV_HINT should be registered in the HintStrategyTable"); final String sql2 = "select /*+ AGG_STRATEGY(OPTION1) */\n" + "ename, avg(sal)\n" + "from emp group by ename"; final String error2 = "Hint AGG_STRATEGY only allows single option, " + "allowed options: [ONE_PHASE, TWO_PHASE]"; sql(sql2).warns(error2); // Change the error handler to validate again. sql(sql2).withTester( tester -> tester.withConfig( SqlToRelConverter.configBuilder() .withHintStrategyTable( HintTools.createHintStrategies( HintStrategyTable.builder().errorHandler(Litmus.THROW))) .build())) .fails(error2); }
Example #25
Source File: RexProgram.java From Bats with Apache License 2.0 | 5 votes |
/** * Returns whether this program is in canonical form. * * @param litmus What to do if an error is detected (program is not in * canonical form) * @param rexBuilder Rex builder * @return whether in canonical form */ public boolean isNormalized(Litmus litmus, RexBuilder rexBuilder) { final RexProgram normalizedProgram = normalize(rexBuilder, null); String normalized = normalizedProgram.toString(); String string = toString(); if (!normalized.equals(string)) { final String message = "Program is not normalized:\n" + "program: {}\n" + "normalized: {}\n"; return litmus.fail(message, string, normalized); } return litmus.succeed(); }
Example #26
Source File: SqlDataTypeSpec.java From calcite with Apache License 2.0 | 5 votes |
public boolean equalsDeep(SqlNode node, Litmus litmus) { if (!(node instanceof SqlDataTypeSpec)) { return litmus.fail("{} != {}", this, node); } SqlDataTypeSpec that = (SqlDataTypeSpec) node; if (!Objects.equals(this.timeZone, that.timeZone)) { return litmus.fail("{} != {}", this, node); } if (!this.typeNameSpec.equalsDeep(that.typeNameSpec, litmus)) { return litmus.fail(null); } return litmus.succeed(); }
Example #27
Source File: SqlAlienSystemTypeNameSpec.java From calcite with Apache License 2.0 | 5 votes |
@Override public boolean equalsDeep(SqlTypeNameSpec node, Litmus litmus) { if (!(node instanceof SqlAlienSystemTypeNameSpec)) { return litmus.fail("{} != {}", this, node); } SqlAlienSystemTypeNameSpec that = (SqlAlienSystemTypeNameSpec) node; if (!Objects.equals(this.typeAlias, that.typeAlias)) { return litmus.fail("{} != {}", this, node); } return super.equalsDeep(node, litmus); }
Example #28
Source File: RelOptUtil.java From Bats with Apache License 2.0 | 5 votes |
/** * Returns whether two types are equal using '='. * * @param desc1 Description of first type * @param type1 First type * @param desc2 Description of second type * @param type2 Second type * @param litmus What to do if an error is detected (types are not equal) * @return Whether the types are equal */ public static boolean eq(final String desc1, RelDataType type1, final String desc2, RelDataType type2, Litmus litmus) { // if any one of the types is ANY return true if (type1.getSqlTypeName() == SqlTypeName.ANY || type2.getSqlTypeName() == SqlTypeName.ANY) { return litmus.succeed(); } if (type1 != type2) { return litmus.fail("type mismatch:\n{}:\n{}\n{}:\n{}", desc1, type1.getFullTypeString(), desc2, type2.getFullTypeString()); } return litmus.succeed(); }
Example #29
Source File: Join.java From calcite with Apache License 2.0 | 5 votes |
@Override public boolean isValid(Litmus litmus, Context context) { if (!super.isValid(litmus, context)) { return false; } if (getRowType().getFieldCount() != getSystemFieldList().size() + left.getRowType().getFieldCount() + (joinType.projectsRight() ? right.getRowType().getFieldCount() : 0)) { return litmus.fail("field count mismatch"); } if (condition != null) { if (condition.getType().getSqlTypeName() != SqlTypeName.BOOLEAN) { return litmus.fail("condition must be boolean: {}", condition.getType()); } // The input to the condition is a row type consisting of system // fields, left fields, and right fields. Very similar to the // output row type, except that fields have not yet been made due // due to outer joins. RexChecker checker = new RexChecker( getCluster().getTypeFactory().builder() .addAll(getSystemFieldList()) .addAll(getLeft().getRowType().getFieldList()) .addAll(getRight().getRowType().getFieldList()) .build(), context, litmus); condition.accept(checker); if (checker.getFailureCount() > 0) { return litmus.fail(checker.getFailureCount() + " failures in condition " + condition); } } return litmus.succeed(); }
Example #30
Source File: SqlWindow.java From Bats with Apache License 2.0 | 5 votes |
/** * Overridden method to specifically check only the right subtree of a window * definition. * * @param node The SqlWindow to compare to "this" window * @param litmus What to do if an error is detected (nodes are not equal) * * @return boolean true if all nodes in the subtree are equal */ @Override public boolean equalsDeep(SqlNode node, Litmus litmus) { // This is the difference over super.equalsDeep. It skips // operands[0] the declared name fo this window. We only want // to check the window components. return node == this || node instanceof SqlWindow && SqlNode.equalDeep( Util.skip(getOperandList()), Util.skip(((SqlWindow) node).getOperandList()), litmus); }