use of org.apache.calcite.plan.RelOptCluster in project flink by apache.
the class LogicalDistribution method create.
public static LogicalDistribution create(RelNode input, RelCollation collation, List<Integer> distKeys) {
RelOptCluster cluster = input.getCluster();
collation = RelCollationTraitDef.INSTANCE.canonize(collation);
RelTraitSet traitSet = input.getTraitSet().replace(Convention.NONE).replace(collation);
return new LogicalDistribution(cluster, traitSet, input, collation, distKeys);
}
use of org.apache.calcite.plan.RelOptCluster in project flink by apache.
the class SubQueryDecorrelator method decorrelateQuery.
/**
* Decorrelates a subquery.
*
* <p>This is the main entry point to {@code SubQueryDecorrelator}.
*
* @param rootRel The node which has SubQuery.
* @return Decorrelate result.
*/
public static Result decorrelateQuery(RelNode rootRel) {
int maxCnfNodeCount = FlinkRelOptUtil.getMaxCnfNodeCount(rootRel);
final CorelMapBuilder builder = new CorelMapBuilder(maxCnfNodeCount);
final CorelMap corelMap = builder.build(rootRel);
if (builder.hasNestedCorScope || builder.hasUnsupportedCorCondition) {
return null;
}
if (!corelMap.hasCorrelation()) {
return Result.EMPTY;
}
RelOptCluster cluster = rootRel.getCluster();
RelBuilder relBuilder = new FlinkRelBuilder(cluster.getPlanner().getContext(), cluster, null);
RexBuilder rexBuilder = cluster.getRexBuilder();
final SubQueryDecorrelator decorrelator = new SubQueryDecorrelator(new SubQueryRelDecorrelator(corelMap, relBuilder, rexBuilder, maxCnfNodeCount), relBuilder);
rootRel.accept(decorrelator);
return new Result(decorrelator.subQueryMap);
}
use of org.apache.calcite.plan.RelOptCluster in project flink by apache.
the class StreamPhysicalPythonGroupWindowAggregateRule method convert.
@Override
public RelNode convert(RelNode rel) {
FlinkLogicalWindowAggregate agg = (FlinkLogicalWindowAggregate) rel;
LogicalWindow window = agg.getWindow();
List<AggregateCall> aggCalls = agg.getAggCallList();
boolean isPandasPythonUDAF = aggCalls.stream().anyMatch(x -> PythonUtil.isPythonAggregate(x, PythonFunctionKind.PANDAS));
if (isPandasPythonUDAF && window instanceof SessionGroupWindow) {
throw new TableException("Session Group Window is currently not supported for Pandas UDAF.");
}
RelNode input = agg.getInput();
RelOptCluster cluster = rel.getCluster();
FlinkRelDistribution requiredDistribution;
if (agg.getGroupCount() != 0) {
requiredDistribution = FlinkRelDistribution.hash(agg.getGroupSet().asList(), true);
} else {
requiredDistribution = FlinkRelDistribution.SINGLETON();
}
RelTraitSet requiredTraitSet = input.getTraitSet().replace(FlinkConventions.STREAM_PHYSICAL()).replace(requiredDistribution);
RelTraitSet providedTraitSet = rel.getTraitSet().replace(FlinkConventions.STREAM_PHYSICAL());
RelNode newInput = RelOptRule.convert(input, requiredTraitSet);
ReadableConfig config = ShortcutUtils.unwrapTableConfig(rel);
WindowEmitStrategy emitStrategy = WindowEmitStrategy.apply(config, agg.getWindow());
if (emitStrategy.produceUpdates()) {
throw new TableException("Python Group Window Aggregate Function is currently not supported for early fired or lately fired.");
}
return new StreamPhysicalPythonGroupWindowAggregate(cluster, providedTraitSet, newInput, rel.getRowType(), agg.getGroupSet().toArray(), JavaScalaConversionUtil.toScala(aggCalls), agg.getWindow(), agg.getNamedProperties(), emitStrategy);
}
use of org.apache.calcite.plan.RelOptCluster in project flink by apache.
the class ProjectWindowTableFunctionTransposeRule method createNewTableFunctionScan.
private LogicalTableFunctionScan createNewTableFunctionScan(RelBuilder relBuilder, LogicalTableFunctionScan oldScan, LogicalType timeAttributeType, RelNode newInput, Map<Integer, Integer> mapping) {
relBuilder.push(newInput);
RexNode newCall = rewriteWindowCall((RexCall) oldScan.getCall(), mapping, relBuilder);
RelOptCluster cluster = oldScan.getCluster();
FlinkTypeFactory typeFactory = (FlinkTypeFactory) cluster.getTypeFactory();
RelDataType newScanOutputType = SqlWindowTableFunction.inferRowType(typeFactory, newInput.getRowType(), typeFactory.createFieldTypeFromLogicalType(timeAttributeType));
return LogicalTableFunctionScan.create(cluster, new ArrayList<>(Collections.singleton(newInput)), newCall, oldScan.getElementType(), newScanOutputType, oldScan.getColumnMappings());
}
use of org.apache.calcite.plan.RelOptCluster in project hive by apache.
the class HiveRelMdRuntimeRowCount method getRuntimeRowCount.
public Optional<Long> getRuntimeRowCount(RelNode rel) {
RelOptCluster cluster = rel.getCluster();
Context context = cluster.getPlanner().getContext();
if (context instanceof HivePlannerContext) {
StatsSource ss = ((HivePlannerContext) context).unwrap(StatsSource.class);
if (ss.canProvideStatsFor(rel.getClass())) {
Optional<OperatorStats> os = ss.lookup(RelTreeSignature.of(rel));
if (os.isPresent()) {
long outputRecords = os.get().getOutputRecords();
return Optional.of(outputRecords);
}
}
}
return Optional.empty();
}
Aggregations