use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class Values method assertRowType.
/**
* Returns true if all tuples match rowType; otherwise, assert on
* mismatch.
*/
private boolean assertRowType() {
for (List<RexLiteral> tuple : tuples) {
assert tuple.size() == rowType.getFieldCount();
for (Pair<RexLiteral, RelDataTypeField> pair : Pair.zip(tuple, rowType.getFieldList())) {
RexLiteral literal = pair.left;
RelDataType fieldType = pair.right.getType();
// been dealt with.
if (!RexLiteral.isNullLiteral(literal)) {
assert SqlTypeUtil.canAssignFrom(fieldType, literal.getType()) : "to " + fieldType + " from " + literal;
}
}
}
return true;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class Window method isValid.
@Override
public boolean isValid(Litmus litmus, Context context) {
// In the window specifications, an aggregate call such as
// 'SUM(RexInputRef #10)' refers to expression #10 of inputProgram.
// (Not its projections.)
final RelDataType childRowType = getInput().getRowType();
final int childFieldCount = childRowType.getFieldCount();
final int inputSize = childFieldCount + constants.size();
final List<RelDataType> inputTypes = new AbstractList<RelDataType>() {
@Override
public RelDataType get(int index) {
return index < childFieldCount ? childRowType.getFieldList().get(index).getType() : constants.get(index - childFieldCount).getType();
}
@Override
public int size() {
return inputSize;
}
};
final RexChecker checker = new RexChecker(inputTypes, context, litmus);
int count = 0;
for (Group group : groups) {
for (RexWinAggCall over : group.aggCalls) {
++count;
if (!checker.isValid(over)) {
return litmus.fail(null);
}
}
}
if (count == 0) {
return litmus.fail("empty");
}
return litmus.succeed();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class ModifiableViewTable method extend.
/**
* Extends the underlying table and returns a new view with updated row-type
* and column-mapping.
*
* <p>The type factory is used to perform some scratch calculations, viz the
* type mapping, but the "real" row-type will be assigned later, when the
* table has been bound to the statement's type factory. The is important,
* because adding types to type factories that do not belong to a statement
* could potentially leak memory.
*
* @param extendedColumns Extended fields
* @param typeFactory Type factory
*/
public final ModifiableViewTable extend(List<RelDataTypeField> extendedColumns, RelDataTypeFactory typeFactory) {
final ExtensibleTable underlying = unwrap(ExtensibleTable.class);
assert underlying != null;
final RelDataTypeFactory.Builder builder = typeFactory.builder();
final RelDataType rowType = getRowType(typeFactory);
for (RelDataTypeField column : rowType.getFieldList()) {
builder.add(column);
}
for (RelDataTypeField column : extendedColumns) {
builder.add(column);
}
// The characteristics of the new view.
final RelDataType newRowType = builder.build();
final ImmutableIntList newColumnMapping = getNewColumnMapping(underlying, getColumnMapping(), extendedColumns, typeFactory);
// Extend the underlying table with only the fields that
// duplicate column names in neither the view nor the base table.
final List<RelDataTypeField> underlyingColumns = underlying.getRowType(typeFactory).getFieldList();
final List<RelDataTypeField> columnsOfExtendedBaseTable = RelOptUtil.deduplicateColumns(underlyingColumns, extendedColumns);
final List<RelDataTypeField> extendColumnsOfBaseTable = columnsOfExtendedBaseTable.subList(underlyingColumns.size(), columnsOfExtendedBaseTable.size());
final Table extendedTable = underlying.extend(extendColumnsOfBaseTable);
return extend(extendedTable, RelDataTypeImpl.proto(newRowType), newColumnMapping);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class Schemas method matches.
private static boolean matches(RelDataTypeFactory typeFactory, Function member, List<RelDataType> argumentTypes) {
List<FunctionParameter> parameters = member.getParameters();
if (parameters.size() != argumentTypes.size()) {
return false;
}
for (int i = 0; i < argumentTypes.size(); i++) {
RelDataType argumentType = argumentTypes.get(i);
FunctionParameter parameter = parameters.get(i);
if (!canConvert(argumentType, parameter.getType(typeFactory))) {
return false;
}
}
return true;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class RexUtil method generateCastExpressions.
/**
* Generates a cast for a row type.
*
* @param rexBuilder RexBuilder to use for constructing casts
* @param lhsRowType target row type
* @param rhsExps expressions to be cast
* @return cast expressions
*/
public static List<RexNode> generateCastExpressions(RexBuilder rexBuilder, RelDataType lhsRowType, List<RexNode> rhsExps) {
List<RelDataTypeField> lhsFields = lhsRowType.getFieldList();
List<RexNode> castExps = new ArrayList<>();
for (Pair<RelDataTypeField, RexNode> pair : Pair.zip(lhsFields, rhsExps, true)) {
RelDataTypeField lhsField = pair.left;
RelDataType lhsType = lhsField.getType();
final RexNode rhsExp = pair.right;
RelDataType rhsType = rhsExp.getType();
if (lhsType.equals(rhsType)) {
castExps.add(rhsExp);
} else {
castExps.add(rexBuilder.makeCast(lhsType, rhsExp));
}
}
return castExps;
}
Aggregations