private void normalizeSorts( SchemaContext pc, Map<RewriteKey, ExpressionNode> projMap, Edge<?, ?> in) { @SuppressWarnings("unchecked") MultiEdge<?, SortingSpecification> min = (MultiEdge<?, SortingSpecification>) in; for (SortingSpecification ss : min.getMulti()) { ExpressionNode target = ss.getTarget(); if (target instanceof AliasInstance) continue; else if (target instanceof LiteralExpression) { // i.e. order by 1,2,3 LiteralExpression le = (LiteralExpression) target; Object value = le.getValue(pc); if (value instanceof Long) { Long index = (Long) value; if ((index.intValue() - 1) < projection.size()) { target = ExpressionUtils.getTarget(projection.get(index.intValue() - 1)); } } } ExpressionNode inProjection = projMap.get(target.getRewriteKey()); if (inProjection != null) { ExpressionAlias ea = (ExpressionAlias) inProjection.getParent(); AliasInstance ai = ea.buildAliasInstance(); ss.getTargetEdge().set(ai); } } }
public static SelectStatement filterEntryProjection(SelectStatement in, PartitionEntry jre) throws PEException { PartitionEntry actual = jre.getActualEntry(); SelectStatement expecting = null; if (actual instanceof OriginalPartitionEntry) expecting = ((OriginalPartitionEntry) actual).getChildCopy(); else expecting = actual.getJoinQuery(null); ListSet<ColumnKey> ec = new ListSet<ColumnKey>(); for (ExpressionNode en : expecting.getProjection()) { ExpressionNode targ = ExpressionUtils.getTarget(en); if (targ instanceof ColumnInstance) { ColumnKey was = ((ColumnInstance) targ).getColumnKey(); ColumnKey isnow = in.getMapper().copyColumnKeyForward(was); if (isnow == null) { throw new SchemaException(Pass.PLANNER, "Lost column during lookup table join"); } ec.add(isnow); } else if (targ instanceof FunctionCall) { ExpressionNode exn = targ; RewriteKey rk = in.getMapper().mapExpressionToColumn(exn); while (rk == null && (exn.getParent() instanceof ExpressionNode)) { exn = (ExpressionNode) exn.getParent(); rk = in.getMapper().mapExpressionToColumn(exn); } if (rk != null) { ec.add((ColumnKey) rk); } } } for (Iterator<ExpressionNode> iter = in.getProjectionEdge().iterator(); iter.hasNext(); ) { ExpressionNode en = ExpressionUtils.getTarget(iter.next()); if (en instanceof ColumnInstance) { ColumnKey ck = ((ColumnInstance) en).getColumnKey(); if (!ec.contains(ck)) iter.remove(); } } return in; }