siddhi icon indicating copy to clipboard operation
siddhi copied to clipboard

Is it possible to partition by two keys?

Open szjiajin opened this issue 6 years ago • 2 comments

Description: I want to partition a stream by multiple keys but I am not sure how to implement this. I tried

define stream TestDataStream(projectName string, partName string, personName string, value double);
partition with (projectName of TestDataStream, personName of TestDataStream)
begin
     ....
end;

and

partition with (projectName and personName and partName of TestDataStream)
begin
     ....
end;

Both of them shows error so I assume I wrote it in the wrong way? Or should I write partition within partition?

Thank you for any advice in advance!

Suggested Labels:

Suggested Assignees:

Affected Product Version:

OS, DB, other environment details and versions:
IntelliJ IDEA 2017.3.5 (Community Edition) Build #IC-173.4674.33, built on March 6, 2018 JRE: 1.8.0_152-release-1024-b15 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Windows 10 10.0 Steps to reproduce: see description Related Issues:

szjiajin avatar Jun 12 '18 10:06 szjiajin

Please refer this[1] testcase which partition a stream by multiple keys.

[1] https://github.com/wso2/siddhi/blob/master/modules/siddhi-core/src/test/java/org/wso2/siddhi/core/query/partition/PartitionTestCase1.java#L144

tishan89 avatar Jun 12 '18 16:06 tishan89

Unfortunately partitioning by multiple attributes of the same stream is not possible with Siddhi right now. As a workaround please create a composite key using a query and then partition the resulting steam based on the newly generated key.

You can use str:concat(projectName , '-', personName) to create a composite key at the select of your the previous query.

We'll work on adding this feature in future releases.

suhothayan avatar Jun 13 '18 03:06 suhothayan