예제 #1
0
 public SelectStatement setProjection(List<ExpressionNode> p) {
   // so, we're going to remove any existing aliases used in the projection and add new ones
   AliasInformation info = getAliases();
   for (ExpressionNode en : projection.getMulti()) {
     if (en instanceof ExpressionAlias) {
       ExpressionAlias ea = (ExpressionAlias) en;
       info.removeAlias(ea.getAlias().get());
     }
   }
   for (ExpressionNode en : p) {
     if (en instanceof ExpressionAlias) {
       ExpressionAlias ea = (ExpressionAlias) en;
       info.addAlias(ea.getAlias().get());
     }
   }
   projection.set(p);
   return this;
 }
예제 #2
0
 private List<ExpressionNode> assignProjectionAliases(
     SchemaContext pc, List<ExpressionNode> in, AliasInformation ai) {
   ArrayList<ExpressionNode> np = new ArrayList<ExpressionNode>();
   for (ExpressionNode e : in) {
     if (e instanceof ExpressionAlias) {
       // already has an alias
       ExpressionAlias ea = (ExpressionAlias) e;
       if (ea.isSynthetic()) {
         // check for dup aliases
         UnqualifiedName unq = ea.getAlias().getNameAlias();
         if (ai.isDuplicateAlias(unq)) {
           NameAlias prefix = ea.getTarget().buildAlias(pc);
           ea.setAlias(ai.buildNewAlias(prefix.getNameAlias()));
         }
       } else if (ea.getAlias() instanceof StringLiteralAlias) {
         // mysql 5.5 docs state it is OK specify as a column alias as either a identifier or
         // string quoted literal in the projection
         // so here we convert the StringLiteralAlias 'foo' into NameAlias `foo`
         final StringLiteralAlias stringLit = (StringLiteralAlias) ea.getAlias();
         if (!stringLit.get().isEmpty()) {
           final UnqualifiedName unq = new UnqualifiedName(stringLit.get(), true);
           ea.setAlias(unq);
         } else {
           ea.setAlias(ai.buildNewAlias(null));
         }
       }
       np.add(e);
     } else {
       // see if we can build something reasonable
       NameAlias prefix = e.buildAlias(pc);
       np.add(
           new ExpressionAlias(e, new NameAlias(ai.buildNewAlias(prefix.getNameAlias())), true));
     }
   }
   return np;
 }