use of org.apache.flink.table.planner.delegation.hive.copy.HiveParserWindowingSpec in project flink by apache.
the class HiveParserCalcitePlanner method genSelectForWindowing.
private RelNode genSelectForWindowing(HiveParserQB qb, RelNode srcRel, HashSet<ColumnInfo> newColumns) throws SemanticException {
HiveParserWindowingSpec wSpec = !qb.getAllWindowingSpecs().isEmpty() ? qb.getAllWindowingSpecs().values().iterator().next() : null;
if (wSpec == null) {
return null;
}
// 1. Get valid Window Function Spec
wSpec.validateAndMakeEffective();
List<HiveParserWindowingSpec.WindowExpressionSpec> windowExpressions = wSpec.getWindowExpressions();
if (windowExpressions == null || windowExpressions.isEmpty()) {
return null;
}
HiveParserRowResolver inputRR = relToRowResolver.get(srcRel);
// 2. Get RexNodes for original Projections from below
List<RexNode> projsForWindowSelOp = new ArrayList<>(HiveParserUtils.getProjsFromBelowAsInputRef(srcRel));
// 3. Construct new Row Resolver with everything from below.
HiveParserRowResolver outRR = new HiveParserRowResolver();
if (!HiveParserRowResolver.add(outRR, inputRR)) {
LOG.warn("Duplicates detected when adding columns to RR: see previous message");
}
// 4. Walk through Window Expressions & Construct RexNodes for those. Update out_rwsch
final HiveParserQBParseInfo qbp = qb.getParseInfo();
final String selClauseName = qbp.getClauseNames().iterator().next();
final boolean cubeRollupGrpSetPresent = (!qbp.getDestRollups().isEmpty() || !qbp.getDestGroupingSets().isEmpty() || !qbp.getDestCubes().isEmpty());
for (HiveParserWindowingSpec.WindowExpressionSpec winExprSpec : windowExpressions) {
if (!qbp.getDestToGroupBy().isEmpty()) {
// Special handling of grouping function
winExprSpec.setExpression(rewriteGroupingFunctionAST(getGroupByForClause(qbp, selClauseName), winExprSpec.getExpression(), !cubeRollupGrpSetPresent));
}
if (outRR.getExpression(winExprSpec.getExpression()) == null) {
Pair<RexNode, TypeInfo> rexAndType = getWindowRexAndType(winExprSpec, srcRel);
projsForWindowSelOp.add(rexAndType.getKey());
// 6.2.2 Update Output Row Schema
ColumnInfo oColInfo = new ColumnInfo(getColumnInternalName(projsForWindowSelOp.size()), rexAndType.getValue(), null, false);
outRR.putExpression(winExprSpec.getExpression(), oColInfo);
newColumns.add(oColInfo);
}
}
return genSelectRelNode(projsForWindowSelOp, outRR, srcRel, windowExpressions);
}
Aggregations