use of org.apache.calcite.rel.type.RelDataType 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.RelDataType in project drill by apache.
the class StarColumnConverter method insertProjUnderScreenOrWriter.
// insert PUS or PUW: Project Under Screen/Writer, when necessary.
private Prel insertProjUnderScreenOrWriter(Prel prel, RelDataType origRowType, Prel child) {
ProjectPrel proj = null;
List<RelNode> children = Lists.newArrayList();
List<RexNode> exprs = Lists.newArrayList();
for (int i = 0; i < origRowType.getFieldCount(); i++) {
RexNode expr = child.getCluster().getRexBuilder().makeInputRef(origRowType.getFieldList().get(i).getType(), i);
exprs.add(expr);
}
RelDataType newRowType = RexUtil.createStructType(child.getCluster().getTypeFactory(), exprs, origRowType.getFieldNames());
int fieldCount = prel.getRowType().isStruct() ? prel.getRowType().getFieldCount() : 1;
// Insert PUS/PUW : remove the prefix and keep the original field name.
if (fieldCount > 1) {
// // no point in allowing duplicates if we only have one column
proj = new ProjectAllowDupPrel(child.getCluster(), child.getTraitSet(), child, exprs, newRowType);
} else {
proj = new ProjectPrel(child.getCluster(), child.getTraitSet(), child, exprs, newRowType);
}
children.add(proj);
return (Prel) prel.copy(prel.getTraitSet(), children);
}
use of org.apache.calcite.rel.type.RelDataType in project lucene-solr by apache.
the class SolrToEnumerableConverter method implement.
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
// Generates a call to "query" with the appropriate fields
final BlockBuilder list = new BlockBuilder();
final SolrRel.Implementor solrImplementor = new SolrRel.Implementor();
solrImplementor.visitChild(0, getInput());
final RelDataType rowType = getRowType();
final PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), rowType, pref.prefer(JavaRowFormat.ARRAY));
final Expression table = list.append("table", solrImplementor.table.getExpression(SolrTable.SolrQueryable.class));
final Expression fields = list.append("fields", constantArrayList(Pair.zip(generateFields(SolrRules.solrFieldNames(rowType), solrImplementor.fieldMappings), new AbstractList<Class>() {
@Override
public Class get(int index) {
return physType.fieldClass(index);
}
@Override
public int size() {
return rowType.getFieldCount();
}
}), Pair.class));
final Expression query = list.append("query", Expressions.constant(solrImplementor.query, String.class));
final Expression orders = list.append("orders", constantArrayList(solrImplementor.orders, Pair.class));
final Expression buckets = list.append("buckets", constantArrayList(solrImplementor.buckets, String.class));
final Expression metricPairs = list.append("metricPairs", constantArrayList(solrImplementor.metricPairs, Pair.class));
final Expression limit = list.append("limit", Expressions.constant(solrImplementor.limitValue));
final Expression negativeQuery = list.append("negativeQuery", Expressions.constant(Boolean.toString(solrImplementor.negativeQuery), String.class));
final Expression havingPredicate = list.append("havingTest", Expressions.constant(solrImplementor.havingPredicate, String.class));
Expression enumerable = list.append("enumerable", Expressions.call(table, SolrMethod.SOLR_QUERYABLE_QUERY.method, fields, query, orders, buckets, metricPairs, limit, negativeQuery, havingPredicate));
Hook.QUERY_PLAN.run(query);
list.add(Expressions.return_(null, enumerable));
return implementor.result(physType, list.toBlock());
}
Aggregations