Java Code Examples for org.apache.calcite.plan.RelOptUtil#eq()

The following examples show how to use org.apache.calcite.plan.RelOptUtil#eq() . 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 Bats with Apache License 2.0 6 votes vote down vote up
/**
 * 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 2
Source File: RexProgram.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Overrides {@link RexChecker} method, because {@link RexLocalRef} is
 * is illegal in most rex expressions, but legal in a program. */
@Override public Boolean visitLocalRef(RexLocalRef localRef) {
  final int index = localRef.getIndex();
  if ((index < 0) || (index >= internalExprTypeList.size())) {
    ++failCount;
    return litmus.fail(null);
  }
  if (!RelOptUtil.eq(
      "type1",
      localRef.getType(),
      "type2",
      internalExprTypeList.get(index), litmus)) {
    ++failCount;
    return litmus.fail(null);
  }
  return litmus.succeed();
}
 
Example 3
Source File: RexUtil.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Returns whether the type of an array of expressions is compatible with a
 * struct type.
 *
 * @param exprs Array of expressions
 * @param type  Type
 * @param litmus What to do if an error is detected (there is a mismatch)
 *
 * @return Whether every expression has the same type as the corresponding
 * member of the struct type
 *
 * @see RelOptUtil#eq(String, RelDataType, String, RelDataType, org.apache.calcite.util.Litmus)
 */
public static boolean compatibleTypes(
    List<RexNode> exprs,
    RelDataType type,
    Litmus litmus) {
  final List<RelDataTypeField> fields = type.getFieldList();
  if (exprs.size() != fields.size()) {
    return litmus.fail("rowtype mismatches expressions");
  }
  for (int i = 0; i < fields.size(); i++) {
    final RelDataType exprType = exprs.get(i).getType();
    final RelDataType fieldType = fields.get(i).getType();
    if (!RelOptUtil.eq("type1", exprType, "type2", fieldType, litmus)) {
      return litmus.fail(null);
    }
  }
  return litmus.succeed();
}
 
Example 4
Source File: RexUtil.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * 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: Aggregate.java    From Bats with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the inferred type of an {@link AggregateCall} matches the
 * type it was given when it was created.
 *
 * @param aggCall Aggregate call
 * @param litmus What to do if an error is detected (types do not match)
 * @return Whether the inferred and declared types match
 */
private boolean typeMatchesInferred(
    final AggregateCall aggCall,
    final Litmus litmus) {
  SqlAggFunction aggFunction = aggCall.getAggregation();
  AggCallBinding callBinding = aggCall.createBinding(this);
  RelDataType type = aggFunction.inferReturnType(callBinding);
  RelDataType expectedType = aggCall.type;
  return RelOptUtil.eq("aggCall type",
      expectedType,
      "inferred type",
      type,
      litmus);
}
 
Example 6
Source File: RexChecker.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override public Boolean visitInputRef(RexInputRef ref) {
  final int index = ref.getIndex();
  if ((index < 0) || (index >= inputTypeList.size())) {
    ++failCount;
    return litmus.fail("RexInputRef index {} out of range 0..{}",
        index, inputTypeList.size() - 1);
  }
  if (!ref.getType().isStruct()
      && !RelOptUtil.eq("ref", ref.getType(), "input",
          inputTypeList.get(index), litmus)) {
    ++failCount;
    return litmus.fail(null);
  }
  return litmus.succeed();
}
 
Example 7
Source File: RexProgram.java    From Bats with Apache License 2.0 5 votes vote down vote up
/** Overrides {@link RexChecker} method, because {@link RexLocalRef} is
 * is illegal in most rex expressions, but legal in a program. */
@Override
public Boolean visitLocalRef(RexLocalRef localRef) {
    final int index = localRef.getIndex();
    if ((index < 0) || (index >= internalExprTypeList.size())) {
        ++failCount;
        return litmus.fail(null);
    }
    if (!RelOptUtil.eq("type1", localRef.getType(), "type2", internalExprTypeList.get(index), litmus)) {
        ++failCount;
        return litmus.fail(null);
    }
    return litmus.succeed();
}
 
Example 8
Source File: RexUtil.java    From Bats with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the type of an array of expressions is compatible with a
 * struct type.
 *
 * @param exprs Array of expressions
 * @param type  Type
 * @param litmus What to do if an error is detected (there is a mismatch)
 *
 * @return Whether every expression has the same type as the corresponding
 * member of the struct type
 *
 * @see RelOptUtil#eq(String, RelDataType, String, RelDataType, org.apache.calcite.util.Litmus)
 */
public static boolean compatibleTypes(List<RexNode> exprs, RelDataType type, Litmus litmus) {
    final List<RelDataTypeField> fields = type.getFieldList();
    if (exprs.size() != fields.size()) {
        return litmus.fail("rowtype mismatches expressions");
    }
    for (int i = 0; i < fields.size(); i++) {
        final RelDataType exprType = exprs.get(i).getType();
        final RelDataType fieldType = fields.get(i).getType();
        if (!RelOptUtil.eq("type1", exprType, "type2", fieldType, litmus)) {
            return litmus.fail(null);
        }
    }
    return litmus.succeed();
}
 
Example 9
Source File: Aggregate.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the inferred type of an {@link AggregateCall} matches the
 * type it was given when it was created.
 *
 * @param aggCall Aggregate call
 * @param litmus What to do if an error is detected (types do not match)
 * @return Whether the inferred and declared types match
 */
private boolean typeMatchesInferred(
    final AggregateCall aggCall,
    final Litmus litmus) {
  SqlAggFunction aggFunction = aggCall.getAggregation();
  AggCallBinding callBinding = aggCall.createBinding(this);
  RelDataType type = aggFunction.inferReturnType(callBinding);
  RelDataType expectedType = aggCall.type;
  return RelOptUtil.eq("aggCall type",
      expectedType,
      "inferred type",
      type,
      litmus);
}
 
Example 10
Source File: RexChecker.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public Boolean visitInputRef(RexInputRef ref) {
  final int index = ref.getIndex();
  if ((index < 0) || (index >= inputTypeList.size())) {
    ++failCount;
    return litmus.fail("RexInputRef index {} out of range 0..{}",
        index, inputTypeList.size() - 1);
  }
  if (!ref.getType().isStruct()
      && !RelOptUtil.eq("ref", ref.getType(), "input",
          inputTypeList.get(index), litmus)) {
    ++failCount;
    return litmus.fail(null);
  }
  return litmus.succeed();
}