use of org.apache.calcite.rel.type.RelDataTypeField in project drill by apache.
the class StarColumnConverter method visitScan.
@Override
public Prel visitScan(ScanPrel scanPrel, Void value) throws RuntimeException {
if (StarColumnHelper.containsStarColumn(scanPrel.getRowType()) && prefixedForStar) {
List<RexNode> exprs = Lists.newArrayList();
for (RelDataTypeField field : scanPrel.getRowType().getFieldList()) {
RexNode expr = scanPrel.getCluster().getRexBuilder().makeInputRef(field.getType(), field.getIndex());
exprs.add(expr);
}
List<String> fieldNames = Lists.newArrayList();
long tableId = tableNumber.getAndIncrement();
for (String name : scanPrel.getRowType().getFieldNames()) {
if (StarColumnHelper.isNonPrefixedStarColumn(name)) {
// Add prefix to * column.
fieldNames.add("T" + tableId + StarColumnHelper.PREFIX_DELIMITER + name);
} else {
// Keep regular column as it is.
fieldNames.add(name);
}
}
RelDataType rowType = RexUtil.createStructType(scanPrel.getCluster().getTypeFactory(), exprs, fieldNames);
// insert a PAS.
ProjectPrel proj = new ProjectPrel(scanPrel.getCluster(), scanPrel.getTraitSet(), scanPrel, exprs, rowType);
return proj;
} else {
return visitPrel(scanPrel, value);
}
}
use of org.apache.calcite.rel.type.RelDataTypeField in project drill by apache.
the class RewriteProjectToFlatten method visitProject.
@Override
public Prel visitProject(ProjectPrel node, Object unused) throws RelConversionException {
ProjectPrel project = node;
List<RexNode> exprList = new ArrayList<>();
boolean rewrite = false;
List<RelDataTypeField> relDataTypes = new ArrayList<>();
int i = 0;
RexNode flatttenExpr = null;
for (RexNode rex : project.getChildExps()) {
RexNode newExpr = rex;
if (rex instanceof RexCall) {
RexCall function = (RexCall) rex;
String functionName = function.getOperator().getName();
if (functionName.equalsIgnoreCase("flatten")) {
rewrite = true;
if (function.getOperands().size() != 1) {
throw new RelConversionException("Flatten expression expects a single input.");
}
newExpr = function.getOperands().get(0);
RexBuilder builder = new RexBuilder(factory);
flatttenExpr = builder.makeInputRef(new RelDataTypeDrillImpl(new RelDataTypeHolder(), factory), i);
}
}
relDataTypes.add(project.getRowType().getFieldList().get(i));
i++;
exprList.add(newExpr);
}
if (rewrite == true) {
// TODO - figure out what is the right setting for the traits
Prel newChild = ((Prel) project.getInput(0)).accept(this, null);
ProjectPrel newProject = new ProjectPrel(node.getCluster(), project.getTraitSet(), newChild, exprList, new RelRecordType(relDataTypes));
FlattenPrel flatten = new FlattenPrel(project.getCluster(), project.getTraitSet(), newProject, flatttenExpr);
return flatten;
}
Prel child = ((Prel) project.getInput()).accept(this, null);
return (Prel) project.copy(project.getTraitSet(), child, exprList, new RelRecordType(relDataTypes));
}
use of org.apache.calcite.rel.type.RelDataTypeField in project lucene-solr by apache.
the class SolrSort method implement.
public void implement(Implementor implementor) {
implementor.visitChild(0, getInput());
List<RelFieldCollation> sortCollations = collation.getFieldCollations();
if (!sortCollations.isEmpty()) {
// Construct a series of order clauses from the desired collation
final List<RelDataTypeField> fields = getRowType().getFieldList();
for (RelFieldCollation fieldCollation : sortCollations) {
final String name = fields.get(fieldCollation.getFieldIndex()).getName();
String direction = "asc";
if (fieldCollation.getDirection().equals(RelFieldCollation.Direction.DESCENDING)) {
direction = "desc";
}
implementor.addOrder(name, direction);
}
}
if (fetch != null) {
implementor.setLimit(((RexLiteral) fetch).getValue().toString());
}
}
Aggregations