本文整理汇总了Java中org.apache.calcite.rel.type.RelDataType.getFieldCount方法的典型用法代码示例。如果您正苦于以下问题:Java RelDataType.getFieldCount方法的具体用法?Java RelDataType.getFieldCount怎么用?Java RelDataType.getFieldCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.rel.type.RelDataType
的用法示例。
在下文中一共展示了RelDataType.getFieldCount方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deriveCopiedRowTypeFromInput
import org.apache.calcite.rel.type.RelDataType; //导入方法依赖的package包/类
/**
* Derive rowType for the copied WindowPrel based on input.
* When copy() is called, the input might be different from the current one's input.
* We have to use the new input's field in the copied WindowPrel.
*/
private RelDataType deriveCopiedRowTypeFromInput(final RelNode input) {
final RelDataType inputRowType = input.getRowType();
final RelDataType windowRowType = this.getRowType();
final List<RelDataTypeField> fieldList = new ArrayList<>(inputRowType.getFieldList());
final int inputFieldCount = inputRowType.getFieldCount();
final int windowFieldCount = windowRowType.getFieldCount();
for (int i = inputFieldCount; i < windowFieldCount; i++) {
fieldList.add(windowRowType.getFieldList().get(i));
}
final RelDataType rowType = this.getCluster().getRexBuilder().getTypeFactory().createStructType(fieldList);
return rowType;
}
示例2: insertProjUnderScreenOrWriter
import org.apache.calcite.rel.type.RelDataType; //导入方法依赖的package包/类
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);
}
示例3: areRowTypesEqual
import org.apache.calcite.rel.type.RelDataType; //导入方法依赖的package包/类
/**
* Verifies that two row type names match.
* Does not compare nullability.
* Differs from RelOptUtil implementation by not defining types as equal if one is of type ANY.
*
* @param rowType1 row type for comparison
* @param rowType2 row type for comparison
*
* @return boolean indicating that rel data types are equivalent
*/
public static boolean areRowTypesEqual(
RelDataType rowType1,
RelDataType rowType2) {
if (rowType1 == rowType2) {
return true;
}
if (rowType2.getFieldCount() != rowType1.getFieldCount()) {
return false;
}
final List<RelDataTypeField> f1 = rowType1.getFieldList();
final List<RelDataTypeField> f2 = rowType2.getFieldList();
for (Pair<RelDataTypeField, RelDataTypeField> pair : Pair.zip(f1, f2)) {
final RelDataType type1 = pair.left.getType();
final RelDataType type2 = pair.right.getType();
// Compare row type names.
if (!type1.equals(type2)) {
return false;
}
}
return true;
}
示例4: getFieldOrigins
import org.apache.calcite.rel.type.RelDataType; //导入方法依赖的package包/类
/**
* extract origins of the fields
* @param graph the root node of the query
* @param rowType the rowType after validation
* @return the origins of the fields in the query. at the same index as the original rowType
*/
public static List<FieldOrigin> getFieldOrigins(RelNode graph, RelDataType rowType) {
if (graph.getRowType().getFieldCount() != rowType.getFieldCount()) {
throw new IllegalArgumentException(format(
"graph and rowType should have the same field count:\ngraph: %s\nrowType: %s",
graph, rowType));
}
List<FieldOrigin> definitions = new ArrayList<>();
RelMetadataQuery query = graph.getCluster().getMetadataQuery();
for (int i = 0; i < graph.getRowType().getFieldCount(); i++) {
Set<RelColumnOrigin> origins = query.getColumnOrigins(graph, i);
List<Origin> namedOrigins = new ArrayList<>();
for (RelColumnOrigin relColumnOrigin : origins) {
List<String> table = Origins.getTable(relColumnOrigin);
String colName = Origins.getColName(relColumnOrigin);
namedOrigins.add(new Origin(colName, relColumnOrigin.isDerived()).setTableList(table));
}
// we need the rowtype after validation and before planning
// graph.getRowType() may not have to be the user facing rowtype anymore
// (even if it often does)
String name = rowType.getFieldList().get(i).getName();
definitions.add(i, new FieldOrigin(name).setOriginsList(namedOrigins));
}
return definitions;
}
示例5: convertToDrel
import org.apache.calcite.rel.type.RelDataType; //导入方法依赖的package包/类
private DrillRel convertToDrel(RelNode relNode, AbstractSchema schema, String modelName, List<String> partitionColumns, RelDataType queryRowType)
throws RelConversionException, SqlUnsupportedException {
final DrillRel convertedRelNode = convertToDrel(relNode);
// Put a non-trivial topProject to ensure the final output field name is preserved, when necessary.
// Only insert project when the field count from the child is same as that of the queryRowType.
final DrillRel topPreservedNameProj = queryRowType.getFieldCount() == convertedRelNode.getRowType().getFieldCount() ?
addRenamedProject(convertedRelNode, queryRowType) : convertedRelNode;
final RelTraitSet traits = convertedRelNode.getCluster().traitSet().plus(DrillRel.DRILL_LOGICAL);
final DrillWriterRel writerRel = new DrillWriterRel(convertedRelNode.getCluster(),
traits, topPreservedNameProj, schema.trainNewModel(modelName, partitionColumns));
return new DrillScreenRel(writerRel.getCluster(), writerRel.getTraitSet(), writerRel);
}
示例6: convertToDrel
import org.apache.calcite.rel.type.RelDataType; //导入方法依赖的package包/类
private DrillRel convertToDrel(RelNode relNode, AbstractSchema schema, String tableName, List<String> partitionColumns, RelDataType queryRowType)
throws RelConversionException, SqlUnsupportedException {
final DrillRel convertedRelNode = convertToDrel(relNode);
// Put a non-trivial topProject to ensure the final output field name is preserved, when necessary.
// Only insert project when the field count from the child is same as that of the queryRowType.
final DrillRel topPreservedNameProj = queryRowType.getFieldCount() == convertedRelNode.getRowType().getFieldCount() ?
addRenamedProject(convertedRelNode, queryRowType) : convertedRelNode;
final RelTraitSet traits = convertedRelNode.getCluster().traitSet().plus(DrillRel.DRILL_LOGICAL);
final DrillWriterRel writerRel = new DrillWriterRel(convertedRelNode.getCluster(),
traits, topPreservedNameProj, schema.createNewTable(tableName, partitionColumns));
return new DrillScreenRel(writerRel.getCluster(), writerRel.getTraitSet(), writerRel);
}
示例7: renameAsNecessary
import org.apache.calcite.rel.type.RelDataType; //导入方法依赖的package包/类
private Prel renameAsNecessary(RelDataType expectedRowType, Prel initialInput) {
if(RelOptUtil.areRowTypesEqual(initialInput.getRowType(), expectedRowType, false) && !RelOptUtil.areRowTypesEqual(initialInput.getRowType(), expectedRowType, true)) {
final List<RexNode> refs = new ArrayList<>();
final List<RelDataTypeField> fields = expectedRowType.getFieldList();
final RexBuilder rb = initialInput.getCluster().getRexBuilder();
for(int i = 0; i < expectedRowType.getFieldCount(); i++) {
refs.add(rb.makeInputRef(fields.get(i).getType(), i));
}
return new ProjectPrel(initialInput.getCluster(), initialInput.getTraitSet(), initialInput, refs, expectedRowType);
} else {
return initialInput;
}
}
示例8: toCalciteRecordType
import org.apache.calcite.rel.type.RelDataType; //导入方法依赖的package包/类
public RelDataType toCalciteRecordType(RelDataTypeFactory factory, Set<String> fieldBlacklist){
FieldInfoBuilder builder = new FieldInfoBuilder(factory);
for(Field f : this) {
if(!fieldBlacklist.contains(f.getName())){
builder.add(f.getName(), CompleteType.toCalciteType(f, factory));
}
}
RelDataType rowType = builder.build();
if(rowType.getFieldCount() == 0){
throw UserException.dataReadError().message("Selected table has no columns.").build(logger);
}
return rowType;
}
示例9: areRowTypesCompatible
import org.apache.calcite.rel.type.RelDataType; //导入方法依赖的package包/类
public static boolean areRowTypesCompatible(
RelDataType rowType1,
RelDataType rowType2,
boolean compareNames,
boolean allowSubstring) {
if (rowType1 == rowType2) {
return true;
}
if (compareNames) {
// if types are not identity-equal, then either the names or
// the types must be different
return false;
}
if (rowType2.getFieldCount() != rowType1.getFieldCount()) {
return false;
}
final List<RelDataTypeField> f1 = rowType1.getFieldList();
final List<RelDataTypeField> f2 = rowType2.getFieldList();
for (Pair<RelDataTypeField, RelDataTypeField> pair : Pair.zip(f1, f2)) {
final RelDataType type1 = pair.left.getType();
final RelDataType type2 = pair.right.getType();
// If one of the types is ANY comparison should succeed
if (type1.getSqlTypeName() == SqlTypeName.ANY
|| type2.getSqlTypeName() == SqlTypeName.ANY) {
continue;
}
if (type1.getSqlTypeName() != type2.getSqlTypeName()) {
if (allowSubstring
&& (type1.getSqlTypeName() == SqlTypeName.CHAR && type2.getSqlTypeName() == SqlTypeName.CHAR)
&& (type1.getPrecision() <= type2.getPrecision())) {
return true;
}
// Check if Drill implicit casting can resolve the incompatibility
List<TypeProtos.MinorType> types = Lists.newArrayListWithCapacity(2);
types.add(Types.getMinorTypeFromName(type1.getSqlTypeName().getName()));
types.add(Types.getMinorTypeFromName(type2.getSqlTypeName().getName()));
if(TypeCastRules.getLeastRestrictiveType(types) != null) {
return true;
}
return false;
}
}
return true;
}
示例10: computeSelfCost
import org.apache.calcite.rel.type.RelDataType; //导入方法依赖的package包/类
/**
* Computes the cost honoring column pushdown and relative costs across {@link GroupScan group scans}.
*
* The cost model is a function of row count, column and scan factors. Row count may or may not be precise and is
* obtained from{@link GroupScan#getScanStats(PlannerSettings)}. Column factor is relative to number of columns to
* scan. Scan factor represents the relative cost of making the scan as compared to other scans kinds.
*
* An exact field contributes 1 whole points to column factor. A sub field scan contributes proportionately anywhere
* from (0, 1], weighting subsequent sub fields less through a logarithmic model.
*/
@Override
public RelOptCost computeSelfCost(final RelOptPlanner planner, final RelMetadataQuery mq) {
final List<SchemaPath> columns = getColumns();
final boolean isStarQuery = ColumnUtils.isStarQuery(columns);
final int allColumns = getTable().getRowType().getFieldCount();
final double columnFactor;
if (isStarQuery) {
columnFactor = allColumns;
} else {
double runningFactor = 0;
// Maintain map of root to child segments to determine what fraction of a whole field is projected.
final Multimap<NameSegment, SchemaPath> subFields = HashMultimap.create();
for (final SchemaPath column : columns) {
subFields.put(column.getRootSegment(), column);
}
for (Map.Entry<PathSegment.NameSegment, SchemaPath> entry : subFields.entries()) {
final PathSegment.NameSegment root = entry.getKey();
final SchemaPath field = entry.getValue();
final String rootPath = root.getPath();
final boolean entireColSelected = rootPath.equalsIgnoreCase(field.getAsUnescapedPath());
if (entireColSelected) {
runningFactor += 1;
} else {
final RelDataType dataType = getRowType().getField(rootPath, false, false).getType();
final int subFieldCount = dataType.isStruct() ? dataType.getFieldCount() : 1;
// sandwich impact of this projection between (0, 1]
final double impact = Math.log10(1 + (Math.min(1, subFieldCount/MAX_COLUMNS) * 9));
runningFactor += impact;
}
}
columnFactor = runningFactor;
}
final double estimatedCount = estimateRowCount(mq);
// If the estimatedCount is actually 0, then make it 1, so that at least, we choose the scan that
// has fewer columns pushed down since all the cost scales with rowCount.
final double rowCount = Math.max(1, estimatedCount);
final double scanFactor = getGroupScan().getScanCostFactor().getFactor();
final double cpuCost = rowCount * columnFactor * scanFactor;
final double ioCost = cpuCost;
if (PrelUtil.getSettings(getCluster()).useDefaultCosting()) {
return planner.getCostFactory().makeCost(estimatedCount, cpuCost, ioCost);
}
final double networkCost = ioCost;
// Even though scan is reading from disk, in the currently generated plans all plans will
// need to read the same amount of data, so keeping the disk io cost 0 is ok for now.
// In the future we might consider alternative scans that go against projections or
// different compression schemes etc that affect the amount of data read. Such alternatives
// would affect both cpu and io cost.
final DremioCost.Factory costFactory = (DremioCost.Factory)planner.getCostFactory();
return costFactory.makeCost(estimatedCount, cpuCost, ioCost, networkCost);
}
示例11: areRowTypesCompatible
import org.apache.calcite.rel.type.RelDataType; //导入方法依赖的package包/类
public static boolean areRowTypesCompatible(
RelDataType rowType1,
RelDataType rowType2,
boolean compareNames,
boolean allowSubstring) {
if (rowType1 == rowType2) {
return true;
}
if (compareNames) {
// if types are not identity-equal, then either the names or
// the types must be different
return false;
}
if (rowType2.getFieldCount() != rowType1.getFieldCount()) {
return false;
}
final List<RelDataTypeField> f1 = rowType1.getFieldList();
final List<RelDataTypeField> f2 = rowType2.getFieldList();
for (Pair<RelDataTypeField, RelDataTypeField> pair : Pair.zip(f1, f2)) {
final RelDataType type1 = pair.left.getType();
final RelDataType type2 = pair.right.getType();
// If one of the types is ANY comparison should succeed
if (type1.getSqlTypeName() == SqlTypeName.ANY
|| type2.getSqlTypeName() == SqlTypeName.ANY) {
continue;
}
if (type1.getSqlTypeName() != type2.getSqlTypeName()) {
if (allowSubstring
&& (type1.getSqlTypeName() == SqlTypeName.CHAR && type2.getSqlTypeName() == SqlTypeName.CHAR)
&& (type1.getPrecision() <= type2.getPrecision())) {
return true;
}
// Check if Dremio implicit casting can resolve the incompatibility
List<TypeProtos.MinorType> types = Lists.newArrayListWithCapacity(2);
types.add(Types.getMinorTypeFromName(type1.getSqlTypeName().getName()));
types.add(Types.getMinorTypeFromName(type2.getSqlTypeName().getName()));
if(TypeCastRules.getLeastRestrictiveType(types) != null) {
return true;
}
return false;
}
}
return true;
}