use of org.apache.calcite.rel.type.RelRecordType in project calcite by apache.
the class JavaTypeFactoryExtImpl method createPdxType.
public RelDataType createPdxType(PdxInstance pdxInstance) {
final List<RelDataTypeField> list = new ArrayList<>();
for (String fieldName : pdxInstance.getFieldNames()) {
Object field = pdxInstance.getField(fieldName);
Type fieldType;
if (field == null) {
fieldType = String.class;
} else if (field instanceof PdxInstance) {
// Map Nested PDX structures as String. This relates with
// GeodeUtils.convert case when clazz is Null.
fieldType = Map.class;
// RelDataType boza = createPdxType((PdxInstance) field);
} else {
fieldType = field.getClass();
}
list.add(new RelDataTypeFieldImpl(fieldName, list.size(), createType(fieldType)));
}
return canonize(new RelRecordType(list));
}
use of org.apache.calcite.rel.type.RelRecordType 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.calcite.rel.type.RelRecordType 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.calcite.rel.type.RelRecordType in project drill by apache.
the class RewriteProjectToFlatten method visitProject.
@Override
public Prel visitProject(ProjectPrel project, Object unused) throws RelConversionException {
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) {
// TODO - figure out what is the right setting for the traits
Prel newChild = ((Prel) project.getInput(0)).accept(this, null);
ProjectPrel newProject = new ProjectPrel(project.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);
if (child == project.getInput() && exprList.equals(project.getChildExps())) {
return project;
}
return (Prel) project.copy(project.getTraitSet(), child, exprList, new RelRecordType(relDataTypes));
}
use of org.apache.calcite.rel.type.RelRecordType 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);
}
Aggregations