Skip to content

Commit

Permalink
fixup! fixup! add consumer for cross joins
Browse files Browse the repository at this point in the history
  • Loading branch information
mfussenegger committed Jan 20, 2015
1 parent 00c15e3 commit 5033fcd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import io.crate.Constants;
import io.crate.analyze.AnalysisMetaData;
import io.crate.analyze.SelectAnalyzedStatement;
import io.crate.analyze.WhereClause;
Expand All @@ -35,6 +34,7 @@
import io.crate.analyze.relations.TableRelation;
import io.crate.exceptions.ValidationException;
import io.crate.metadata.Routing;
import io.crate.operation.projectors.TopN;
import io.crate.planner.node.PlanNode;
import io.crate.planner.node.dql.QueryThenFetchNode;
import io.crate.planner.node.dql.join.NestedLoopNode;
Expand Down Expand Up @@ -142,8 +142,12 @@ public PlannedAnalyzedRelation visitSelectAnalyzedStatement(SelectAnalyzedStatem
return null;
}
TableRelation tableRelation = (TableRelation) analyzedRelation;
FilteringContext filteringContext = filterOutputForRelation(statement.outputSymbols(), tableRelation);
if (tableRelation.tableInfo().schemaInfo().systemSchema()) {
context.validationException(new ValidationException("CROSS JOIN on system tables is not supported"));
return null;
}

FilteringContext filteringContext = filterOutputForRelation(statement.outputSymbols(), tableRelation);
hasMixedOutputs = hasMixedOutputs || filteringContext.hasMixedOutputs;
relations.put(tableRelation, new RelationContext(Lists.newArrayList(filteringContext.allOutputs())));
}
Expand Down Expand Up @@ -173,7 +177,7 @@ public PlannedAnalyzedRelation visitSelectAnalyzedStatement(SelectAnalyzedStatem
);
queryThenFetchNodes.add(qtf);
}
int limit = MoreObjects.firstNonNull(statement.limit(), Constants.DEFAULT_SELECT_LIMIT);
int limit = MoreObjects.firstNonNull(statement.limit(), TopN.NO_LIMIT);
NestedLoopNode nestedLoopNode = toNestedLoop(queryThenFetchNodes, limit, statement.offset());

if (hasMixedOutputs || statement.isLimited()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.crate.operation.aggregation.impl.AggregationImplModule;
import io.crate.operation.operator.OperatorModule;
import io.crate.operation.predicate.PredicateModule;
import io.crate.operation.projectors.TopN;
import io.crate.operation.scalar.ScalarFunctionModule;
import io.crate.planner.*;
import io.crate.planner.node.PlanNode;
Expand All @@ -48,6 +49,7 @@
import java.util.List;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThat;

public class CrossJoinConsumerTest {
Expand Down Expand Up @@ -87,12 +89,21 @@ public void testExplicitCrossJoinWithoutLimitOrOrderBy() throws Exception {
assertThat(next, instanceOf(NestedLoopNode.class));

NestedLoopNode nestedLoopNode = (NestedLoopNode) next;
PlanNode left = nestedLoopNode.left();
assertThat(nestedLoopNode.projections().isEmpty(), is(true));
assertThat(nestedLoopNode.limit(), is(TopN.NO_LIMIT));
assertThat(nestedLoopNode.offset(), is(0));
assertThat(nestedLoopNode.outputTypes().size(), is(8));

PlanNode left = nestedLoopNode.left();
assertThat(left, instanceOf(QueryThenFetchNode.class));
QueryThenFetchNode leftQtf = (QueryThenFetchNode)left;

assertThat(leftQtf.outputs().isEmpty(), is(false));
PlanNode right = nestedLoopNode.right();
assertThat(right, instanceOf(QueryThenFetchNode.class));
QueryThenFetchNode rightQtf = (QueryThenFetchNode)right;

// what's left and right changes per test run... so just make sure the outputs are different
assertNotEquals(leftQtf.outputs().size(), rightQtf.outputs().size());
}

@Test
Expand Down

0 comments on commit 5033fcd

Please sign in to comment.