/** Equivalence to {@link org.apache.calcite.plan.RelOptUtil#createCastRel} * for {@link MutableRel}. */ public static MutableRel createCastRel(MutableRel rel, RelDataType castRowType, boolean rename) { RelDataType rowType = rel.getRowType(); if (RelOptUtil.areRowTypesEqual(rowType, castRowType, rename)) { // nothing to do return rel; } List<RexNode> castExps = RexUtil.generateCastExpressions(rel.cluster.getRexBuilder(), castRowType, rowType); final List<String> fieldNames = rename ? castRowType.getFieldNames() : rowType.getFieldNames(); return MutableProject.of(rel, castExps, fieldNames); } }
b: if (allColumnsInAggregate && newAggCalls.isEmpty() && RelOptUtil.areRowTypesEqual(r.getRowType(), aggregate.getRowType(), false)) {
@Deprecated // to be removed before 2.0 public static RelNode renameIfNecessary( RelNode rel, RelDataType desiredRowType) { final RelDataType rowType = rel.getRowType(); if (rowType == desiredRowType) { // Nothing to do. return rel; } assert !rowType.equals(desiredRowType); if (!areRowTypesEqual(rowType, desiredRowType, false)) { // The row types are different ignoring names. Nothing we can do. return rel; } rel = createRename( rel, desiredRowType.getFieldNames()); return rel; }
@Deprecated // to be removed before 2.0 public static RelNode renameIfNecessary( RelNode rel, RelDataType desiredRowType) { final RelDataType rowType = rel.getRowType(); if (rowType == desiredRowType) { // Nothing to do. return rel; } assert !rowType.equals(desiredRowType); if (!areRowTypesEqual(rowType, desiredRowType, false)) { // The row types are different ignoring names. Nothing we can do. return rel; } rel = createRename( rel, desiredRowType.getFieldNames()); return rel; }
/** * Verifies that a row type being added to an equivalence class matches the * existing type, raising an assertion if this is not the case. * * @param originalRel canonical rel for equivalence class * @param newRel rel being added to equivalence class * @param equivalenceClass object representing equivalence class */ public static void verifyTypeEquivalence( RelNode originalRel, RelNode newRel, Object equivalenceClass) { RelDataType expectedRowType = originalRel.getRowType(); RelDataType actualRowType = newRel.getRowType(); // Row types must be the same, except for field names. if (areRowTypesEqual(expectedRowType, actualRowType, false)) { return; } String s = "Cannot add expression of different type to set:\n" + "set type is " + expectedRowType.getFullTypeString() + "\nexpression type is " + actualRowType.getFullTypeString() + "\nset is " + equivalenceClass.toString() + "\nexpression is " + newRel.toString(); throw new AssertionError(s); }
/** * Verifies that a row type being added to an equivalence class matches the * existing type, raising an assertion if this is not the case. * * @param originalRel canonical rel for equivalence class * @param newRel rel being added to equivalence class * @param equivalenceClass object representing equivalence class */ public static void verifyTypeEquivalence( RelNode originalRel, RelNode newRel, Object equivalenceClass) { RelDataType expectedRowType = originalRel.getRowType(); RelDataType actualRowType = newRel.getRowType(); // Row types must be the same, except for field names. if (areRowTypesEqual(expectedRowType, actualRowType, false)) { return; } String s = "Cannot add expression of different type to set:\n" + "set type is " + expectedRowType.getFullTypeString() + "\nexpression type is " + actualRowType.getFullTypeString() + "\nset is " + equivalenceClass.toString() + "\nexpression is " + newRel.toString(); throw new AssertionError(s); }
private Prel renameAsNecessary(RelDataType expectedRowType, Prel initialInput) { if(RelOptUtil.areRowTypesEqual(initialInput.getRowType(), expectedRowType, false) && !RelOptUtil.areRowTypesEqual(initialInput.getRowType(), expectedRowType, true)) { final List<RexNode> refs = new ArrayList<>(); final List<RelDataTypeField> fields = expectedRowType.getFieldList(); final RexBuilder rb = initialInput.getCluster().getRexBuilder(); for(int i = 0; i < expectedRowType.getFieldCount(); i++) { refs.add(rb.makeInputRef(fields.get(i).getType(), i)); } return new ProjectPrel(initialInput.getCluster(), initialInput.getTraitSet(), initialInput, refs, expectedRowType); } else { return initialInput; } }
/** * Returns whether all the inputs of this set operator have the same row * type as its output row. * * @param compareNames Whether column names are important in the * homogeneity comparison * @return Whether all the inputs of this set operator have the same row * type as its output row */ public boolean isHomogeneous(boolean compareNames) { RelDataType unionType = getRowType(); for (RelNode input : getInputs()) { if (!RelOptUtil.areRowTypesEqual( input.getRowType(), unionType, compareNames)) { return false; } } return true; } }
/** * Returns whether all the inputs of this set operator have the same row * type as its output row. * * @param compareNames Whether column names are important in the * homogeneity comparison * @return Whether all the inputs of this set operator have the same row * type as its output row */ public boolean isHomogeneous(boolean compareNames) { RelDataType unionType = getRowType(); for (RelNode input : getInputs()) { if (!RelOptUtil.areRowTypesEqual( input.getRowType(), unionType, compareNames)) { return false; } } return true; } }
coerce = true; assert RelOptUtil.areRowTypesEqual( newInputs.get(i).getRowType(), expectedType,
coerce = true; assert RelOptUtil.areRowTypesEqual( newInputs.get(i).getRowType(), expectedType,
/** * 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(); }
/** * 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(); }
/** Equivalence to {@link org.apache.calcite.plan.RelOptUtil#createCastRel} * for {@link MutableRel}. */ public static MutableRel createCastRel(MutableRel rel, RelDataType castRowType, boolean rename) { RelDataType rowType = rel.rowType; if (RelOptUtil.areRowTypesEqual(rowType, castRowType, rename)) { // nothing to do return rel; } List<RexNode> castExps = RexUtil.generateCastExpressions(rel.cluster.getRexBuilder(), castRowType, rowType); final List<String> fieldNames = rename ? castRowType.getFieldNames() : rowType.getFieldNames(); return MutableProject.of(rel, castExps, fieldNames); }
/** Equivalence to {@link org.apache.calcite.plan.RelOptUtil#createCastRel} * for {@link MutableRel}. */ public static MutableRel createCastRel(MutableRel rel, RelDataType castRowType, boolean rename) { RelDataType rowType = rel.rowType; if (RelOptUtil.areRowTypesEqual(rowType, castRowType, rename)) { // nothing to do return rel; } List<RexNode> castExps = RexUtil.generateCastExpressions(rel.cluster.getRexBuilder(), castRowType, rowType); final List<String> fieldNames = rename ? castRowType.getFieldNames() : rowType.getFieldNames(); return MutableProject.of(rel, castExps, fieldNames); }
protected void apply(RelOptRuleCall call, Filter filter, TableScan scan) { final RelOptPlanner planner = call.getPlanner(); final List<RelOptMaterialization> materializations = planner.getMaterializations(); if (!materializations.isEmpty()) { RelNode root = filter.copy(filter.getTraitSet(), Collections.singletonList((RelNode) scan)); List<RelOptMaterialization> applicableMaterializations = RelOptMaterializations.getApplicableMaterializations(root, materializations); for (RelOptMaterialization materialization : applicableMaterializations) { if (RelOptUtil.areRowTypesEqual(scan.getRowType(), materialization.queryRel.getRowType(), false)) { RelNode target = materialization.queryRel; final HepPlanner hepPlanner = new HepPlanner(program, planner.getContext()); hepPlanner.setRoot(target); target = hepPlanner.findBestExp(); List<RelNode> subs = new MaterializedViewSubstitutionVisitor(target, root) .go(materialization.tableRel); for (RelNode s : subs) { call.transformTo(s); } } } } } }
protected void apply(RelOptRuleCall call, Filter filter, TableScan scan) { final RelOptPlanner planner = call.getPlanner(); final List<RelOptMaterialization> materializations = planner.getMaterializations(); if (!materializations.isEmpty()) { RelNode root = filter.copy(filter.getTraitSet(), Collections.singletonList((RelNode) scan)); List<RelOptMaterialization> applicableMaterializations = RelOptMaterializations.getApplicableMaterializations(root, materializations); for (RelOptMaterialization materialization : applicableMaterializations) { if (RelOptUtil.areRowTypesEqual(scan.getRowType(), materialization.queryRel.getRowType(), false)) { RelNode target = materialization.queryRel; final HepPlanner hepPlanner = new HepPlanner(program, planner.getContext()); hepPlanner.setRoot(target); target = hepPlanner.findBestExp(); List<RelNode> subs = new MaterializedViewSubstitutionVisitor(target, root) .go(materialization.tableRel); for (RelNode s : subs) { call.transformTo(s); } } } } } }
assert projectFactory != null; RelDataType rowType = rel.getRowType(); if (areRowTypesEqual(rowType, castRowType, rename)) {
assert projectFactory != null; RelDataType rowType = rel.getRowType(); if (areRowTypesEqual(rowType, castRowType, rename)) {