Skip to content

Commit

Permalink
NestedLoopNode implements DQLPlanNode interface
Browse files Browse the repository at this point in the history
now to support projections
  • Loading branch information
Philipp Bogensberger committed Jun 9, 2015
1 parent 9b64e8d commit 43f8ac3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import io.crate.planner.node.ExecutionNode;
import io.crate.planner.node.ExecutionNodeVisitor;
import io.crate.planner.node.PlanNode;
import io.crate.planner.node.PlanNodeVisitor;
import io.crate.planner.node.dql.AbstractDQLPlanNode;
import io.crate.types.DataType;
import io.crate.types.DataTypes;
import org.elasticsearch.common.io.stream.StreamInput;
Expand All @@ -36,7 +35,7 @@
import java.io.IOException;
import java.util.*;

public class NestedLoopNode implements PlanNode, ExecutionNode {
public class NestedLoopNode extends AbstractDQLPlanNode {

public static final ExecutionNodeFactory<NestedLoopNode> FACTORY = new ExecutionNodeFactory<NestedLoopNode>() {
@Override
Expand All @@ -45,10 +44,6 @@ public NestedLoopNode create() {
}
};

private UUID jobId;
private int executionNodeId;
private String name;
private List<DataType> outputTypes = ImmutableList.of();
private int downstreamExecutionNodeId = NO_EXECUTION_NODE;
private Set<String> executionNodes;
private List<String> downstreamNodes = ImmutableList.of();
Expand All @@ -59,26 +54,14 @@ public NestedLoopNode create() {
public NestedLoopNode() {}

public NestedLoopNode(int executionNodeId, String name) {
this.name = name;
this.executionNodeId = executionNodeId;
super(executionNodeId, name);
}


@Override
public Type type() {
return Type.NESTED_LOOP;
}

@Override
public String name() {
return name;
}

@Override
public int executionNodeId() {
return executionNodeId;
}

@Override
public Set<String> executionNodes() {
if (executionNodes == null) {
Expand Down Expand Up @@ -127,13 +110,15 @@ public void rightInputTypes(List<DataType> rightInputTypes) {
}

@Override
public UUID jobId() {
return jobId;
public List<DataType> inputTypes() {
throw new UnsupportedOperationException("inputsTypes not supported. " +
"Use leftInputTypes() or rightInputTypes()");
}

@Override
public void jobId(UUID jobId) {
this.jobId = jobId;
public void inputTypes(List<DataType> inputTypes) {
throw new UnsupportedOperationException("inputsTypes not supported. " +
"Use leftInputTypes() or rightInputTypes()");
}

@Override
Expand All @@ -147,29 +132,9 @@ public <C, R> R accept(PlanNodeVisitor<C, R> visitor, C context) {
return visitor.visitNestedLoopNode(this, context);
}

@Override
public List<DataType> outputTypes() {
return outputTypes;
}

@Override
public void outputTypes(List<DataType> outputTypes) {
this.outputTypes = outputTypes;
}

@Override
public void readFrom(StreamInput in) throws IOException {
name = in.readString();
jobId = new UUID(in.readLong(), in.readLong());
executionNodeId = in.readVInt();

int numCols = in.readVInt();
if (numCols > 0) {
outputTypes = new ArrayList<>(numCols);
for (int i = 0; i < numCols; i++) {
outputTypes.add(DataTypes.fromStream(in));
}
}
super.readFrom(in);
downstreamExecutionNodeId = in.readVInt();

int numDownstreamNodes = in.readVInt();
Expand Down Expand Up @@ -204,17 +169,7 @@ public void readFrom(StreamInput in) throws IOException {

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(name);
assert jobId != null : "jobId must not be null";
out.writeLong(jobId.getMostSignificantBits());
out.writeLong(jobId.getLeastSignificantBits());
out.writeVInt(executionNodeId);

int numCols = outputTypes.size();
out.writeVInt(numCols);
for (int i = 0; i < numCols; i++) {
DataTypes.toStream(outputTypes.get(i), out);
}
super.writeTo(out);
out.writeVInt(downstreamExecutionNodeId);
out.writeVInt(downstreamNodes.size());
for (String downstreamNode : downstreamNodes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@

package io.crate.planner.node.dql;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
import io.crate.planner.node.dql.join.NestedLoopNode;
import io.crate.planner.projection.Projection;
import io.crate.planner.projection.TopNProjection;
import io.crate.test.integration.CrateUnitTest;
import io.crate.types.DataType;
import io.crate.types.DataTypes;
Expand All @@ -49,6 +52,10 @@ public void testSerialization() throws Exception {
node.downstreamNodes(Sets.newHashSet("node3", "node4"));
node.downstreamExecutionNodeId(5);

TopNProjection topNProjection = new TopNProjection(10, 0);

node.projections(ImmutableList.<Projection>of(topNProjection));

BytesStreamOutput output = new BytesStreamOutput();
node.writeTo(output);

Expand Down

0 comments on commit 43f8ac3

Please sign in to comment.