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

ALIGN option #69

Merged
merged 6 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion src/main/java/com/redislabs/redistimeseries/Keyword.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public enum Keyword implements ProtocolCommand {
UNCOMPRESSED,
CHUNK_SIZE,
DUPLICATE_POLICY,
ON_DUPLICATE;
ON_DUPLICATE,
ALIGN;

private final byte[] raw;

Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/redislabs/redistimeseries/RangeParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class RangeParams {

private Integer count;

private byte[] align;

private Aggregation aggregationType;
private long timeBucket;

Expand All @@ -21,6 +23,23 @@ public RangeParams count(int count) {
return this;
}

private RangeParams align(byte[] raw) {
this.align = raw;
return this;
}

public RangeParams align(long timestamp) {
return align(Protocol.toByteArray(timestamp));
}

public RangeParams alignStart() {
return align("start".getBytes());
sazzad16 marked this conversation as resolved.
Show resolved Hide resolved
}

public RangeParams alignEnd() {
return align("end".getBytes());
sazzad16 marked this conversation as resolved.
Show resolved Hide resolved
}

public RangeParams aggregation(Aggregation aggregation, long timeBucket) {
this.aggregationType = aggregation;
this.timeBucket = timeBucket;
Expand Down Expand Up @@ -48,6 +67,11 @@ public byte[][] getByteParams(String key, Long from, Long to) {
params.add(Protocol.toByteArray(count));
}

if (align != null) {
params.add(Keyword.ALIGN.getRaw());
params.add(align);
}

if (aggregationType != null) {
params.add(Keyword.AGGREGATION.getRaw());
params.add(aggregationType.getRaw());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,43 @@ public void testIncrByDecrBy() throws InterruptedException {
}
}

@Test
public void align() {
client.add("align", 1, 10d);
client.add("align", 3, 5d);
client.add("align", 11, 10d);
client.add("align", 25, 11d);

Value[] values =
client.range(
"align", 1L, 30L, RangeParams.rangeParams().aggregation(Aggregation.COUNT, 10));
assertArrayEquals(new Value[] {new Value(1, 2), new Value(11, 1), new Value(21, 1)}, values);

values =
client.range(
"align",
1L,
30L,
RangeParams.rangeParams().alignStart().aggregation(Aggregation.COUNT, 10));
assertArrayEquals(new Value[] {new Value(1, 2), new Value(11, 1), new Value(21, 1)}, values);

values =
client.range(
"align",
1L,
30L,
RangeParams.rangeParams().alignEnd().aggregation(Aggregation.COUNT, 10));
assertArrayEquals(new Value[] {new Value(1, 2), new Value(11, 1), new Value(21, 1)}, values);

values =
client.range(
"align",
1L,
30L,
RangeParams.rangeParams().align(5).aggregation(Aggregation.COUNT, 10));
assertArrayEquals(new Value[] {new Value(1, 2), new Value(11, 1), new Value(21, 1)}, values);
}

@Test
public void testGet() {

Expand Down