use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeFieldImpl in project drill by apache.
the class CountToDirectScanUtils method constructDataType.
/**
* For each aggregate call creates field based on its name with bigint type.
* Constructs record type for created fields.
*
* @param aggregateRel aggregate relation expression
* @param fieldNames field names
* @return record type
*/
public static RelDataType constructDataType(Aggregate aggregateRel, Collection<String> fieldNames) {
List<RelDataTypeField> fields = new ArrayList<>();
int fieldIndex = 0;
for (String name : fieldNames) {
RelDataTypeField field = new RelDataTypeFieldImpl(name, fieldIndex++, aggregateRel.getCluster().getTypeFactory().createSqlType(SqlTypeName.BIGINT));
fields.add(field);
}
return new RelRecordType(fields);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeFieldImpl in project drill by apache.
the class AbstractIndexPlanGenerator method convertRowType.
protected RelDataType convertRowType(RelDataType origRowType, RelDataTypeFactory typeFactory) {
if (getRowKeyIndex(origRowType, origScan) >= 0) {
// row key already present
return origRowType;
}
List<RelDataTypeField> fields = new ArrayList<>();
fields.addAll(origRowType.getFieldList());
fields.add(new RelDataTypeFieldImpl(((DbGroupScan) IndexPlanUtils.getGroupScan(origScan)).getRowKeyName(), fields.size(), typeFactory.createSqlType(SqlTypeName.ANY)));
return new RelRecordType(fields);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeFieldImpl in project drill by apache.
the class FunctionalIndexHelper method rewriteFunctionalRowType.
/**
* if a field in rowType serves only the to-be-replaced column(s), we should replace it with new name "$1",
* otherwise we should keep this dataTypeField and add a new one for "$1"
* @param origScan the original scan whose rowtype is to be rewritten
* @param indexContext the index plan context
* @param functionInfo functional index information that may impact rewrite
* @return
*/
public static RelDataType rewriteFunctionalRowType(RelNode origScan, IndexCallContext indexContext, FunctionalIndexInfo functionInfo, Collection<SchemaPath> addedPaths) {
RelDataType origRowType = origScan.getRowType();
if (!functionInfo.hasFunctional()) {
return origRowType;
}
List<RelDataTypeField> fields = Lists.newArrayList();
Set<String> leftOutFieldNames = Sets.newHashSet();
if (indexContext.getLeftOutPathsInFunctions() != null) {
for (LogicalExpression expr : indexContext.getLeftOutPathsInFunctions()) {
leftOutFieldNames.add(((SchemaPath) expr).getRootSegmentPath());
}
}
Set<String> fieldInFunctions = Sets.newHashSet();
for (SchemaPath path : functionInfo.allPathsInFunction()) {
fieldInFunctions.add(path.getRootSegmentPath());
}
RelDataTypeFactory typeFactory = origScan.getCluster().getTypeFactory();
for (RelDataTypeField field : origRowType.getFieldList()) {
final String fieldName = field.getName();
if (fieldInFunctions.contains(fieldName)) {
if (!leftOutFieldNames.contains(fieldName)) {
continue;
}
}
fields.add(new RelDataTypeFieldImpl(SchemaPath.parseFromString(fieldName).getRootSegmentPath(), fields.size(), typeFactory.createSqlType(SqlTypeName.ANY)));
}
final Collection<SchemaPath> toAddToRowType = (addedPaths == null) ? functionInfo.allNewSchemaPaths() : addedPaths;
for (SchemaPath dollarPath : toAddToRowType) {
fields.add(new RelDataTypeFieldImpl(dollarPath.getRootSegmentPath(), fields.size(), origScan.getCluster().getTypeFactory().createSqlType(SqlTypeName.ANY)));
}
return new RelRecordType(fields);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeFieldImpl in project drill by apache.
the class FunctionalIndexHelper method convertRowTypeForIndexScan.
/**
* For IndexScan in non-covering case, rowType to return contains only row_key('_id') of primary table.
* so the rowType for IndexScan should be converted from [Primary_table.row_key, primary_table.indexed_col]
* to [indexTable.row_key(primary_table.indexed_col), indexTable.<primary_key.row_key> (Primary_table.row_key)]
* This will impact the columns of scan, the rowType of ScanRel
*
* @param origScan
* @param idxMarker the IndexableExprMarker that has analyzed original index condition on top of index scan
* @param idxScan
* @return
*/
public static RelDataType convertRowTypeForIndexScan(DrillScanRelBase origScan, IndexableExprMarker idxMarker, IndexGroupScan idxScan, FunctionalIndexInfo functionInfo) {
RelDataTypeFactory typeFactory = origScan.getCluster().getTypeFactory();
List<RelDataTypeField> fields = new ArrayList<>();
Set<SchemaPath> rowPaths = new LinkedHashSet<>();
// row_key in the rowType of scan on primary table
RelDataTypeField rowkey_primary;
RelRecordType newRowType = null;
DbGroupScan scan = (DbGroupScan) IndexPlanUtils.getGroupScan(origScan);
// first add row_key of primary table,
rowkey_primary = new RelDataTypeFieldImpl(scan.getRowKeyName(), fields.size(), typeFactory.createSqlType(SqlTypeName.ANY));
fields.add(rowkey_primary);
Map<RexNode, LogicalExpression> idxExprMap = idxMarker.getIndexableExpression();
for (LogicalExpression indexedExpr : idxExprMap.values()) {
if (indexedExpr instanceof SchemaPath) {
rowPaths.add((SchemaPath) indexedExpr);
} else if (indexedExpr instanceof CastExpression) {
SchemaPath newPath = functionInfo.getNewPathFromExpr(indexedExpr);
if (newPath != null) {
rowPaths.add(newPath);
}
}
}
for (SchemaPath newPath : rowPaths) {
fields.add(new RelDataTypeFieldImpl(newPath.getRootSegmentPath(), fields.size(), typeFactory.createSqlType(SqlTypeName.ANY)));
}
// update columns of groupscan accordingly
Set<RelDataTypeField> rowfields = Sets.newLinkedHashSet();
final List<SchemaPath> columns = Lists.newArrayList();
for (RelDataTypeField f : fields) {
SchemaPath path = SchemaPath.parseFromString(f.getName());
rowfields.add(new RelDataTypeFieldImpl(path.getRootSegmentPath(), rowfields.size(), typeFactory.createSqlType(SqlTypeName.ANY)));
columns.add(path);
}
idxScan.setColumns(columns);
// rowtype does not take the whole path, but only the rootSegment of the SchemaPath
newRowType = new RelRecordType(Lists.newArrayList(rowfields));
return newRowType;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeFieldImpl 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));
}
Aggregations