Skip to content

Commit

Permalink
Allocate new symbol for field reference
Browse files Browse the repository at this point in the history
This is to avoid duplicate key exceptions when building the assignments map. Any duplicates expressions are later removed by the optimizers
  • Loading branch information
martint committed Apr 27, 2013
1 parent ca9fe50 commit 4e140d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Expand Up @@ -9,6 +9,7 @@
import com.facebook.presto.metadata.TableHandle;
import com.facebook.presto.metadata.TableMetadata;
import com.facebook.presto.sql.analyzer.Analysis;
import com.facebook.presto.sql.analyzer.Field;
import com.facebook.presto.sql.analyzer.FieldOrExpression;
import com.facebook.presto.sql.analyzer.Session;
import com.facebook.presto.sql.analyzer.TupleDescriptor;
Expand Down Expand Up @@ -154,7 +155,8 @@ private PlanBuilder project(PlanBuilder subPlan, Iterable<FieldOrExpression> exp
Symbol symbol;

if (fieldOrExpression.isFieldReference()) {
symbol = subPlan.translate(fieldOrExpression);
Field field = subPlan.getRelationPlan().getDescriptor().getFields().get(fieldOrExpression.getFieldIndex());
symbol = symbolAllocator.newSymbol(field);
}
else {
Expression expression = fieldOrExpression.getExpression();
Expand Down
Expand Up @@ -1065,6 +1065,15 @@ public void testIfExpression()
"SELECT sum(CASE WHEN NULLIF(orderstatus, 'F') <> 'F' THEN totalprice ELSE 5.1 END) FROM orders");
}

@Test
public void testDuplicateFields()
throws Exception
{
assertQuery(
"SELECT * FROM (SELECT orderkey, orderkey FROM orders)",
"SELECT orderkey, orderkey FROM orders");
}

@Test
public void testCaseInsensitiveOutputAliasInOrderBy()
throws Exception
Expand Down

0 comments on commit 4e140d1

Please sign in to comment.