Java Code Examples for org.apache.calcite.util.Litmus#fail()

The following examples show how to use org.apache.calcite.util.Litmus#fail() . 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 vote down vote up
/**
 * 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: RelOptUtil.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * 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 3
Source File: SqlNodeList.java    From Bats with Apache License 2.0 6 votes vote down vote up
public boolean equalsDeep(SqlNode node, Litmus litmus) {
  if (!(node instanceof SqlNodeList)) {
    return litmus.fail("{} != {}", this, node);
  }
  SqlNodeList that = (SqlNodeList) node;
  if (this.size() != that.size()) {
    return litmus.fail("{} != {}", this, node);
  }
  for (int i = 0; i < list.size(); i++) {
    SqlNode thisChild = list.get(i);
    final SqlNode thatChild = that.list.get(i);
    if (!thisChild.equalsDeep(thatChild, litmus)) {
      return litmus.fail(null);
    }
  }
  return litmus.succeed();
}
 
Example 4
Source File: SqlCall.java    From calcite with Apache License 2.0 6 votes vote down vote up
public boolean equalsDeep(SqlNode node, Litmus litmus) {
  if (node == this) {
    return true;
  }
  if (!(node instanceof SqlCall)) {
    return litmus.fail("{} != {}", this, node);
  }
  SqlCall that = (SqlCall) node;

  // Compare operators by name, not identity, because they may not
  // have been resolved yet. Use case insensitive comparison since
  // this may be a case insensitive system.
  if (!this.getOperator().getName().equalsIgnoreCase(that.getOperator().getName())) {
    return litmus.fail("{} != {}", this, node);
  }
  return equalDeep(this.getOperandList(), that.getOperandList(), litmus);
}
 
Example 5
Source File: ExtendedSqlRowTypeNameSpec.java    From flink with Apache License 2.0 6 votes vote down vote up
@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 6
Source File: RexUtil.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * 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 7
Source File: SqlCollectionTypeNameSpec.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public boolean equalsDeep(SqlTypeNameSpec spec, Litmus litmus) {
  if (!(spec instanceof SqlCollectionTypeNameSpec)) {
    return litmus.fail("{} != {}", this, spec);
  }
  SqlCollectionTypeNameSpec that = (SqlCollectionTypeNameSpec) spec;
  if (!this.elementTypeName.equalsDeep(that.elementTypeName, litmus)) {
    return litmus.fail("{} != {}", this, spec);
  }
  if (!Objects.equals(this.collectionTypeName, that.collectionTypeName)) {
    return litmus.fail("{} != {}", this, spec);
  }
  return litmus.succeed();
}
 
Example 8
Source File: RelDecorrelator.java    From calcite with Apache License 2.0 5 votes vote down vote up
static boolean allLessThan(Collection<Integer> integers, int limit,
    Litmus ret) {
  for (int value : integers) {
    if (value >= limit) {
      return ret.fail("out of range; value: {}, limit: {}", value, limit);
    }
  }
  return ret.succeed();
}
 
Example 9
Source File: SqlNode.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Returns whether two lists of operands are equal. */
public static boolean equalDeep(List<SqlNode> operands0,
    List<SqlNode> operands1, Litmus litmus) {
  if (operands0.size() != operands1.size()) {
    return litmus.fail(null);
  }
  for (int i = 0; i < operands0.size(); i++) {
    if (!SqlNode.equalDeep(operands0.get(i), operands1.get(i), litmus)) {
      return litmus.fail(null);
    }
  }
  return litmus.succeed();
}
 
Example 10
Source File: Snapshot.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public boolean isValid(Litmus litmus, Context context) {
  RelDataType dataType = period.getType();
  if (dataType.getSqlTypeName() != SqlTypeName.TIMESTAMP) {
    return litmus.fail("The system time period specification expects Timestamp type but is '"
        + dataType.getSqlTypeName() + "'");
  }
  return litmus.succeed();
}
 
Example 11
Source File: SqlIdentifier.java    From Bats with Apache License 2.0 5 votes vote down vote up
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 12
Source File: Filter.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override public boolean isValid(Litmus litmus, Context context) {
  if (RexUtil.isNullabilityCast(getCluster().getTypeFactory(), condition)) {
    return litmus.fail("Cast for just nullability not allowed");
  }
  final RexChecker checker =
      new RexChecker(getInput().getRowType(), context, litmus);
  condition.accept(checker);
  if (checker.getFailureCount() > 0) {
    return litmus.fail(null);
  }
  return litmus.succeed();
}
 
Example 13
Source File: RowKeyJoinRel.java    From Bats with Apache License 2.0 5 votes vote down vote up
/** The parent method relies the class being an instance of {@link org.apache.calcite.rel.core.SemiJoin}
 * in deciding row-type validity. We override this method to account for the RowKeyJoinRel logical rel
 * representing both regular and semi-joins */
@Override public boolean isValid(Litmus litmus, Context context) {
  if (getRowType().getFieldCount()
          != getSystemFieldList().size()
          + left.getRowType().getFieldCount()
          + ((this.isSemiJoin()) ? 0 : right.getRowType().getFieldCount())) {
    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 14
Source File: RexProgram.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * 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 15
Source File: RelOptUtil.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether two types are equal using
 * {@link #areRowTypesEqual(RelDataType, RelDataType, boolean)}. Both types
 * must not be null.
 *
 * @param desc1 Description of role of first type
 * @param type1 First type
 * @param desc2 Description of role of second type
 * @param type2 Second type
 * @param litmus Whether to assert if they are not equal
 * @return Whether the types are equal
 */
public static boolean equal(
    final String desc1,
    RelDataType type1,
    final String desc2,
    RelDataType type2,
    Litmus litmus) {
  if (!areRowTypesEqual(type1, type2, false)) {
    return litmus.fail("Type mismatch:\n{}:\n{}\n{}:\n{}",
        desc1, type1.getFullTypeString(),
        desc2, type2.getFullTypeString());
  }
  return litmus.succeed();
}
 
Example 16
Source File: SqlAlienSystemTypeNameSpec.java    From calcite with Apache License 2.0 5 votes vote down vote up
@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 17
Source File: SqlUserDefinedTypeNameSpec.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public boolean equalsDeep(SqlTypeNameSpec spec, Litmus litmus) {
  if (!(spec instanceof SqlUserDefinedTypeNameSpec)) {
    return litmus.fail("{} != {}", this, spec);
  }
  SqlUserDefinedTypeNameSpec that = (SqlUserDefinedTypeNameSpec) spec;
  if (!this.getTypeName().equalsDeep(that.getTypeName(), litmus)) {
    return litmus.fail("{} != {}", this, spec);
  }
  return litmus.succeed();
}
 
Example 18
Source File: SqlPostfixOperator.java    From Bats with Apache License 2.0 4 votes vote down vote up
@Override public boolean validRexOperands(int count, Litmus litmus) {
  if (count != 1) {
    return litmus.fail("wrong operand count {} for {}", count, this);
  }
  return litmus.succeed();
}
 
Example 19
Source File: SqlDotOperator.java    From Bats with Apache License 2.0 4 votes vote down vote up
@Override public boolean validRexOperands(final int count, final Litmus litmus) {
  return litmus.fail("DOT is valid only for SqlCall not for RexCall");
}
 
Example 20
Source File: RelOptUtil.java    From Bats with Apache License 2.0 3 votes vote down vote up
/**
 * Returns whether two types are equal using
 * {@link #areRowTypesEqual(RelDataType, RelDataType, boolean)}. Both types
 * must not be null.
 *
 * @param desc1 Description of role of first type
 * @param type1 First type
 * @param desc2 Description of role of second type
 * @param type2 Second type
 * @param litmus Whether to assert if they are not equal
 * @return Whether the types are equal
 */
public static boolean equal(final String desc1, RelDataType type1, final String desc2, RelDataType type2,
        Litmus litmus) {
    if (!areRowTypesEqual(type1, type2, false)) {
        return litmus.fail("Type mismatch:\n{}:\n{}\n{}:\n{}", desc1, type1.getFullTypeString(), desc2,
                type2.getFullTypeString());
    }
    return litmus.succeed();
}