use of org.apache.calcite.rel.type.RelDataTypeField in project drill by apache.
the class DrillValuesRel method verifyRowType.
private static void verifyRowType(final ImmutableList<ImmutableList<RexLiteral>> tuples, RelDataType rowType) {
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();
if ((!(RexLiteral.isNullLiteral(literal))) && (!(SqlTypeUtil.canAssignFrom(fieldType, literal.getType())))) {
throw new AssertionError("to " + fieldType + " from " + literal);
}
}
}
}
use of org.apache.calcite.rel.type.RelDataTypeField in project drill by apache.
the class DrillProjectRel method convert.
public static DrillProjectRel convert(Project project, ConversionContext context) throws InvalidRelException {
RelNode input = context.toRel(project.getInput());
List<RelDataTypeField> fields = Lists.newArrayList();
List<RexNode> exps = Lists.newArrayList();
for (NamedExpression expr : project.getSelections()) {
fields.add(new RelDataTypeFieldImpl(expr.getRef().getRootSegment().getPath(), fields.size(), context.getTypeFactory().createSqlType(SqlTypeName.ANY)));
exps.add(context.toRex(expr.getExpr()));
}
return new DrillProjectRel(context.getCluster(), context.getLogicalTraits(), input, exps, new RelRecordType(fields));
}
use of org.apache.calcite.rel.type.RelDataTypeField in project drill by apache.
the class DrillWriterRel method resolvePartitionKeys.
private List<Integer> resolvePartitionKeys() {
final List<Integer> keys = Lists.newArrayList();
final RelDataType inputRowType = getInput().getRowType();
final List<String> partitionCol = getCreateTableEntry().getPartitionColumns();
for (final String col : partitionCol) {
final RelDataTypeField field = inputRowType.getField(col, false, false);
Preconditions.checkArgument(field != null, String.format("partition col %s could not be resolved in table's column lists!", col));
keys.add(field.getIndex());
}
return keys;
}
use of org.apache.calcite.rel.type.RelDataTypeField in project drill by apache.
the class ConvertCountToDirectScan method getCountDirectScanRowType.
private RelDataType getCountDirectScanRowType(RelDataTypeFactory typeFactory) {
List<RelDataTypeField> fields = Lists.newArrayList();
fields.add(new RelDataTypeFieldImpl("count", 0, typeFactory.createSqlType(SqlTypeName.BIGINT)));
return new RelRecordType(fields);
}
use of org.apache.calcite.rel.type.RelDataTypeField in project drill by apache.
the class JoinPrel method rename.
private RelNode rename(RelNode input, List<RelDataTypeField> inputFields, List<String> outputFieldNames) {
List<RexNode> exprs = Lists.newArrayList();
for (RelDataTypeField field : inputFields) {
RexNode expr = input.getCluster().getRexBuilder().makeInputRef(field.getType(), field.getIndex());
exprs.add(expr);
}
RelDataType rowType = RexUtil.createStructType(input.getCluster().getTypeFactory(), exprs, outputFieldNames);
ProjectPrel proj = new ProjectPrel(input.getCluster(), input.getTraitSet(), input, exprs, rowType);
return proj;
}
Aggregations