Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic partition #51

Merged
merged 8 commits into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,14 @@ private void handleExecutionPlan(String executionPlanId, String executionPlan) t
executionPlanIdToPartitionKeys.put(executionPlanId, new ArrayList<>());
}
inputStreamToExecutionPlans.get(inputStreamId).add(executionPlanId);
executionPlanIdToPartitionKeys.get(executionPlanId).addAll(
streamPartitions.get(inputStreamId).getGroupByList());

if(streamPartitions.get(inputStreamId).getPartitonWithList().isEmpty()){
executionPlanIdToPartitionKeys.get(executionPlanId).addAll(
streamPartitions.get(inputStreamId).getGroupByList());
}else{
executionPlanIdToPartitionKeys.get(executionPlanId).addAll(
streamPartitions.get(inputStreamId).getPartitonWithList());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import io.siddhi.query.api.definition.StreamDefinition;
import io.siddhi.query.api.execution.ExecutionElement;
import io.siddhi.query.api.execution.partition.Partition;
import io.siddhi.query.api.execution.partition.PartitionType;
import io.siddhi.query.api.execution.partition.ValuePartitionType;
import io.siddhi.query.api.execution.query.Query;
import io.siddhi.query.api.execution.query.input.handler.StreamHandler;
import io.siddhi.query.api.execution.query.input.handler.Window;
Expand All @@ -31,6 +33,7 @@
import io.siddhi.query.api.execution.query.output.stream.OutputStream;
import io.siddhi.query.api.execution.query.selection.OutputAttribute;
import io.siddhi.query.api.execution.query.selection.Selector;
import io.siddhi.query.api.expression.Expression;
import io.siddhi.query.api.expression.Variable;
import io.siddhi.query.compiler.SiddhiCompiler;
import org.apache.commons.collections.ListUtils;
Expand Down Expand Up @@ -82,7 +85,14 @@ private void parse() throws Exception {
if (executionElement instanceof Query) {
query = (Query) executionElement;
}else{
query = ((Partition) executionElement).getQueryList().get(0);
Partition partition = (Partition) executionElement;
Map<String, PartitionType> partitionTypeMap = partition.getPartitionTypeMap();
query = partition.getQueryList().get(0);
for(Map.Entry<String, PartitionType> partitionType : partitionTypeMap.entrySet()){
if(partitionType.getValue() instanceof ValuePartitionType){
retrievePartition(findStreamPartition(partitionType.getKey(),(ValuePartitionType) partitionType.getValue()));
}
}
}
//--FIX END
InputStream inputStream = query.getInputStream();
Expand Down Expand Up @@ -198,7 +208,7 @@ private void retrievePartition(StreamPartition partition) throws Exception {
StreamPartition existingPartition = streamPartitions.get(partition.getInputStreamId());
if (existingPartition.getType().equals(partition.getType())
&& ListUtils.isEqualList(existingPartition.getGroupByList(), partition.getGroupByList())
|| existingPartition.getType().equals(StreamPartition.Type.SHUFFLE)) {
|| existingPartition.getType().equals(StreamPartition.Type.SHUFFLE) || existingPartition.getType().equals(StreamPartition.Type.PARTITIONWITH)) {
streamPartitions.put(partition.getInputStreamId(), partition);
} else {
throw new Exception("You have incompatible partitions on stream " + partition.getInputStreamId()
Expand All @@ -225,6 +235,20 @@ private StreamPartition findStreamPartition(SingleInputStream inputStream, Selec
}
}

private StreamPartition findStreamPartition(String streamId, ValuePartitionType value){
StreamPartition partition = new StreamPartition(streamId);
if(value != null){
Expression expression = value.getExpression();
if(expression instanceof Variable){
String attributeName = ((Variable) expression).getAttributeName();
partition.setPartitionWithList(Collections.singletonList(attributeName));
partition.setType(StreamPartition.Type.PARTITIONWITH);
return partition;
}
}
return null;
}

private StreamPartition generatePartition(String streamId, List<Window> windows, List<Variable> groupBy) {
StreamPartition partition = new StreamPartition(streamId);

Expand Down Expand Up @@ -259,12 +283,14 @@ public Map<String, StreamPartition> getStreamPartitions() throws Exception {
public static class StreamPartition {
public enum Type {
GROUPBY,
SHUFFLE
SHUFFLE,
PARTITIONWITH,
}

private String inputStreamId;
private Type type;
private List<String> groupByList = new ArrayList<>();
private List<String> partitionWithList = new ArrayList<>();

public StreamPartition(String inputStreamId) {
this.inputStreamId = inputStreamId;
Expand All @@ -289,5 +315,11 @@ public List<String> getGroupByList() {
public void setGroupByList(List<String> groupByList) {
this.groupByList = groupByList;
}

public List<String> getPartitonWithList() {
return partitionWithList;
}

public void setPartitionWithList(List<String> partitionWithList){ this.partitionWithList = partitionWithList;}
}
}