Skip to content

Commit

Permalink
Merge pull request #36 from shaunsales/feature/aggregation
Browse files Browse the repository at this point in the history
Implemented new aggregation type.
  • Loading branch information
DvirDukhan authored Sep 6, 2020
2 parents 5b4ac9b + e84b2f5 commit b05b45d
Show file tree
Hide file tree
Showing 25 changed files with 166 additions and 177 deletions.
8 changes: 4 additions & 4 deletions NRedisTimeSeries.Example/MRangeExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class MRangeExample
/// In this case, the strings are implicitly casted into TimeStamp objects.
/// The TimeSeriesMRange command returns an IReadOnlyList<(string key, IReadOnlyList<TimeSeriesLabel> labels, IReadOnlyList<TimeSeriesTuple> values)>collection.
/// </summary>
public static void BasicMRangeExample()
public static void BasicMRangeExample()
{
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
Expand All @@ -43,7 +43,7 @@ public static void CountMRangeExample()
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
var filter = new List<string> { "MRANGEkey=MRANGEvalue" };
var results = db.TimeSeriesMRange("-", "+", filter, count:50);
var results = db.TimeSeriesMRange("-", "+", filter, count: 50);
// Values extraction example. No lables in this case.
foreach (var result in results)
{
Expand All @@ -64,7 +64,7 @@ public static void MRangeAggregationExample()
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
var filter = new List<string> { "MRANGEkey=MRANGEvalue" };
var results = db.TimeSeriesMRange("-", "+", filter, aggregation:Aggregation.MIN, timeBucket:50);
var results = db.TimeSeriesMRange("-", "+", filter, aggregation: TsAggregation.Min, timeBucket: 50);
// Values extraction example. No lables in this case.
foreach (var result in results)
{
Expand All @@ -85,7 +85,7 @@ public static void MRangeWithLabelsExample()
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
var filter = new List<string> { "MRANGEkey=MRANGEvalue" };
var results = db.TimeSeriesMRange("-", "+", filter,withLabels:true);
var results = db.TimeSeriesMRange("-", "+", filter, withLabels: true);
// Values extraction example.
foreach (var result in results)
{
Expand Down
2 changes: 1 addition & 1 deletion NRedisTimeSeries.Example/MRangeExampleAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static async Task MRangeAggregationAsyncExample()
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
var filter = new List<string> { "MRANGEkey=MRANGEvalue" };
var results = await db.TimeSeriesMRangeAsync("-", "+", filter, aggregation: Aggregation.MIN, timeBucket: 50);
var results = await db.TimeSeriesMRangeAsync("-", "+", filter, aggregation: TsAggregation.Min, timeBucket: 50);
// Values extraction example. No lables in this case.
foreach (var result in results)
{
Expand Down
2 changes: 1 addition & 1 deletion NRedisTimeSeries.Example/RangeExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static void RangeAggregationExample()
{
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
db.TimeSeriesRange("my_ts", "-", "+", aggregation: Aggregation.MIN, timeBucket: 50);
db.TimeSeriesRange("my_ts", "-", "+", aggregation: TsAggregation.Min, timeBucket: 50);
redis.Close();
}
}
Expand Down
2 changes: 1 addition & 1 deletion NRedisTimeSeries.Example/RangeExampleAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static async Task RangeAggregationAsyncExample()
{
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
await db.TimeSeriesRangeAsync("my_ts", "-", "+", aggregation: Aggregation.MIN, timeBucket: 50);
await db.TimeSeriesRangeAsync("my_ts", "-", "+", aggregation: TsAggregation.Min, timeBucket: 50);
redis.Close();
}
}
Expand Down
2 changes: 1 addition & 1 deletion NRedisTimeSeries.Example/RulesExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void RulesCreateDeleteExample()
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
// Create you rule with destination key, time bucket and aggregation type.
TimeSeriesRule rule = new TimeSeriesRule("dest_ts", 50, Aggregation.AVG);
TimeSeriesRule rule = new TimeSeriesRule("dest_ts", 50, TsAggregation.Avg);
db.TimeSeriesCreateRule("my_ts", rule);
db.TimeSeriesDeleteRule("my_ts", "dest");
redis.Close();
Expand Down
2 changes: 1 addition & 1 deletion NRedisTimeSeries.Example/RulesExampleAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static async Task RulesCreateDeleteAsyncExample()
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
// Create your rule with destination key, time bucket and aggregation type.
TimeSeriesRule rule = new TimeSeriesRule("dest_ts", 50, Aggregation.AVG);
TimeSeriesRule rule = new TimeSeriesRule("dest_ts", 50, TsAggregation.Avg);
await db.TimeSeriesCreateRuleAsync("my_ts", rule);
await db.TimeSeriesDeleteRuleAsync("my_ts", "dest");
redis.Close();
Expand Down
4 changes: 2 additions & 2 deletions NRedisTimeSeries.Test/TestAPI/TestMRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void TestMRangeAggregation()
}

var tuples = CreateData(db, 50);
var results = db.TimeSeriesMRange("-", "+", new List<string> { "key=MRangeAggregation" }, aggregation: Aggregation.MIN, timeBucket: 50);
var results = db.TimeSeriesMRange("-", "+", new List<string> { "key=MRangeAggregation" }, aggregation: TsAggregation.Min, timeBucket: 50);
Assert.Equal(keys.Length, results.Count);
for (int i = 0; i < results.Count; i++)
{
Expand Down Expand Up @@ -171,7 +171,7 @@ public void TestMissingTimeBucket()
}

var tuples = CreateData(db, 50);
var ex = Assert.Throws<ArgumentException>(() => db.TimeSeriesMRange("-", "+", new List<string> { "key=MissingTimeBucket" }, aggregation: Aggregation.AVG));
var ex = Assert.Throws<ArgumentException>(() => db.TimeSeriesMRange("-", "+", new List<string> { "key=MissingTimeBucket" }, aggregation: TsAggregation.Avg));
Assert.Equal("RANGE Aggregation should have timeBucket value", ex.Message);

}
Expand Down
4 changes: 2 additions & 2 deletions NRedisTimeSeries.Test/TestAPI/TestMRangeAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public async Task TestMRangeAggregation()
}

var tuples = await CreateData(db, keys, 50);
var results = await db.TimeSeriesMRangeAsync("-", "+", new List<string> { $"{keys[0]}=value" }, aggregation: Aggregation.MIN, timeBucket: 50);
var results = await db.TimeSeriesMRangeAsync("-", "+", new List<string> { $"{keys[0]}=value" }, aggregation: TsAggregation.Min, timeBucket: 50);
Assert.Equal(keys.Length, results.Count);
for (var i = 0; i < results.Count; i++)
{
Expand Down Expand Up @@ -172,7 +172,7 @@ public async Task TestMissingTimeBucket()
{
await db.TimeSeriesMRangeAsync("-", "+",
filter: new List<string>() { $"key=value" },
aggregation: Aggregation.AVG);
aggregation: TsAggregation.Avg);
});
Assert.Equal("RANGE Aggregation should have timeBucket value", ex.Message);
}
Expand Down
4 changes: 2 additions & 2 deletions NRedisTimeSeries.Test/TestAPI/TestMRevRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void TestMRevRangeAggregation()
}

var tuples = CreateData(db, keys, 50);
var results = db.TimeSeriesMRevRange("-", "+", new List<string> { $"{keys[0]}=value" }, aggregation: Aggregation.MIN, timeBucket: 50);
var results = db.TimeSeriesMRevRange("-", "+", new List<string> { $"{keys[0]}=value" }, aggregation: TsAggregation.Min, timeBucket: 50);
Assert.Equal(keys.Length, results.Count);
for (var i = 0; i < results.Count; i++)
{
Expand Down Expand Up @@ -168,7 +168,7 @@ public void TestMissingTimeBucket()
}

var tuples = CreateData(db, keys, 50);
var ex = Assert.Throws<ArgumentException>(() => db.TimeSeriesMRevRange("-", "+", new List<string> { "key=MissingTimeBucket" }, aggregation: Aggregation.AVG));
var ex = Assert.Throws<ArgumentException>(() => db.TimeSeriesMRevRange("-", "+", new List<string> { "key=MissingTimeBucket" }, aggregation: TsAggregation.Avg));
Assert.Equal("RANGE Aggregation should have timeBucket value", ex.Message);

}
Expand Down
4 changes: 2 additions & 2 deletions NRedisTimeSeries.Test/TestAPI/TestMRevRangeAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public async Task TestMRangeAggregation()
}

var tuples = await CreateData(db, keys, 50);
var results = await db.TimeSeriesMRevRangeAsync("-", "+", new List<string> { $"{keys[0]}=value" }, aggregation: Aggregation.MIN, timeBucket: 50);
var results = await db.TimeSeriesMRevRangeAsync("-", "+", new List<string> { $"{keys[0]}=value" }, aggregation: TsAggregation.Min, timeBucket: 50);
Assert.Equal(keys.Length, results.Count);
for (var i = 0; i < results.Count; i++)
{
Expand Down Expand Up @@ -172,7 +172,7 @@ public async Task TestMissingTimeBucket()
{
await db.TimeSeriesMRevRangeAsync("-", "+",
filter: new List<string>() { $"key=value" },
aggregation: Aggregation.AVG);
aggregation: TsAggregation.Avg);
});
Assert.Equal("RANGE Aggregation should have timeBucket value", ex.Message);
}
Expand Down
4 changes: 2 additions & 2 deletions NRedisTimeSeries.Test/TestAPI/TestRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ public void TestRangeAggregation()
{
IDatabase db = redisFixture.Redis.GetDatabase();
var tuples = CreateData(db, 50);
Assert.Equal(tuples, db.TimeSeriesRange(key, "-", "+", aggregation: Aggregation.MIN, timeBucket: 50));
Assert.Equal(tuples, db.TimeSeriesRange(key, "-", "+", aggregation: TsAggregation.Min, timeBucket: 50));
}

[Fact]
public void TestMissingTimeBucket()
{
IDatabase db = redisFixture.Redis.GetDatabase();
var tuples = CreateData(db, 50);
var ex = Assert.Throws<ArgumentException>(() => db.TimeSeriesRange(key, "-", "+", aggregation: Aggregation.AVG));
var ex = Assert.Throws<ArgumentException>(() => db.TimeSeriesRange(key, "-", "+", aggregation: TsAggregation.Avg));
Assert.Equal("RANGE Aggregation should have timeBucket value", ex.Message);

}
Expand Down
4 changes: 2 additions & 2 deletions NRedisTimeSeries.Test/TestAPI/TestRangeAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task TestRangeAggregation()
var key = CreateKeyName();
var db = redisFixture.Redis.GetDatabase();
var tuples = await CreateData(db, key, 50);
Assert.Equal(tuples, await db.TimeSeriesRangeAsync(key, "-", "+", aggregation: Aggregation.MIN, timeBucket: 50));
Assert.Equal(tuples, await db.TimeSeriesRangeAsync(key, "-", "+", aggregation: TsAggregation.Min, timeBucket: 50));
}

[Fact]
Expand All @@ -56,7 +56,7 @@ public async Task TestMissingTimeBucket()
var key = CreateKeyName();
var db = redisFixture.Redis.GetDatabase();
var tuples = await CreateData(db, key, 50);
var ex = await Assert.ThrowsAsync<ArgumentException>(async () => await db.TimeSeriesRangeAsync(key, "-", "+", aggregation: Aggregation.AVG));
var ex = await Assert.ThrowsAsync<ArgumentException>(async () => await db.TimeSeriesRangeAsync(key, "-", "+", aggregation: TsAggregation.Avg));
Assert.Equal("RANGE Aggregation should have timeBucket value", ex.Message);
}
}
Expand Down
4 changes: 2 additions & 2 deletions NRedisTimeSeries.Test/TestAPI/TestRevRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void TestRevRangeAggregation()
var key = CreateKeyName();
var db = redisFixture.Redis.GetDatabase();
var tuples = CreateData(db, key, 50);
Assert.Equal(ReverseData(tuples), db.TimeSeriesRevRange(key, "-", "+", aggregation: Aggregation.MIN, timeBucket: 50));
Assert.Equal(ReverseData(tuples), db.TimeSeriesRevRange(key, "-", "+", aggregation: TsAggregation.Min, timeBucket: 50));
}

[Fact]
Expand All @@ -55,7 +55,7 @@ public void TestMissingTimeBucket()
var key = CreateKeyName();
var db = redisFixture.Redis.GetDatabase();
var tuples = CreateData(db, key, 50);
var ex = Assert.Throws<ArgumentException>(() => db.TimeSeriesRevRange(key, "-", "+", aggregation: Aggregation.AVG));
var ex = Assert.Throws<ArgumentException>(() => db.TimeSeriesRevRange(key, "-", "+", aggregation: TsAggregation.Avg));
Assert.Equal("RANGE Aggregation should have timeBucket value", ex.Message);

}
Expand Down
4 changes: 2 additions & 2 deletions NRedisTimeSeries.Test/TestAPI/TestRevRangeAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task TestRevRangeAggregation()
var key = CreateKeyName();
var db = redisFixture.Redis.GetDatabase();
var tuples = await CreateData(db, key, 50);
Assert.Equal(ReverseData(tuples), await db.TimeSeriesRevRangeAsync(key, "-", "+", aggregation: Aggregation.MIN, timeBucket: 50));
Assert.Equal(ReverseData(tuples), await db.TimeSeriesRevRangeAsync(key, "-", "+", aggregation: TsAggregation.Min, timeBucket: 50));
}

[Fact]
Expand All @@ -56,7 +56,7 @@ public async Task TestMissingTimeBucket()
var key = CreateKeyName();
var db = redisFixture.Redis.GetDatabase();
var tuples = await CreateData(db, key, 50);
var ex = await Assert.ThrowsAsync<ArgumentException>(async () => await db.TimeSeriesRevRangeAsync(key, "-", "+", aggregation: Aggregation.AVG));
var ex = await Assert.ThrowsAsync<ArgumentException>(async () => await db.TimeSeriesRevRangeAsync(key, "-", "+", aggregation: TsAggregation.Avg));
Assert.Equal("RANGE Aggregation should have timeBucket value", ex.Message);
}
}
Expand Down
38 changes: 19 additions & 19 deletions NRedisTimeSeries.Test/TestAPI/TestRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ public class TestRules : AbstractTimeSeriesTest, IDisposable
{
private string srcKey = "RULES_TEST_SRC";

private Dictionary<Aggregation, string> destKeys;
private Dictionary<TsAggregation, string> destKeys;

public TestRules(RedisFixture redisFixture) : base(redisFixture)
{

destKeys = new Dictionary<Aggregation, string>
destKeys = new Dictionary<TsAggregation, string>
{
{ Aggregation.AVG, "RULES_DEST_" + Aggregation.AVG },
{ Aggregation.COUNT, "RULES_DEST_" + Aggregation.COUNT },
{ Aggregation.FIRST, "RULES_DEST_" + Aggregation.FIRST },
{ Aggregation.LAST, "RULES_DEST_" + Aggregation.LAST },
{ Aggregation.MAX, "RULES_DEST_" + Aggregation.MAX },
{ Aggregation.MIN, "RULES_DEST_" + Aggregation.MIN },
{ Aggregation.RANGE, "RULES_DEST_" + Aggregation.RANGE },
{ Aggregation.STDP, "RULES_DEST_" + Aggregation.STDP },
{ Aggregation.STDS, "RULES_DEST_" + Aggregation.STDS },
{ Aggregation.SUM, "RULES_DEST_" + Aggregation.SUM },
{ Aggregation.VARP, "RULES_DEST_" + Aggregation.VARP },
{ Aggregation.VARS, "RULES_DEST_" + Aggregation.VARS }
{ TsAggregation.Avg, "RULES_DEST_" + TsAggregation.Avg },
{ TsAggregation.Count, "RULES_DEST_" + TsAggregation.Count },
{ TsAggregation.First, "RULES_DEST_" + TsAggregation.First },
{ TsAggregation.Last, "RULES_DEST_" + TsAggregation.Last },
{ TsAggregation.Max, "RULES_DEST_" + TsAggregation.Max },
{ TsAggregation.Min, "RULES_DEST_" + TsAggregation.Min },
{ TsAggregation.Range, "RULES_DEST_" + TsAggregation.Range },
{ TsAggregation.StdP, "RULES_DEST_" + TsAggregation.StdP },
{ TsAggregation.StdS, "RULES_DEST_" + TsAggregation.StdS },
{ TsAggregation.Sum, "RULES_DEST_" + TsAggregation.Sum },
{ TsAggregation.VarP, "RULES_DEST_" + TsAggregation.VarP },
{ TsAggregation.VarS, "RULES_DEST_" + TsAggregation.VarS }
};
}

Expand All @@ -53,7 +53,7 @@ public void TestRulesAdditionDeletion()
}
long timeBucket = 50;
var rules = new List<TimeSeriesRule>();
var rulesMap = new Dictionary<Aggregation, TimeSeriesRule>();
var rulesMap = new Dictionary<TsAggregation, TimeSeriesRule>();
foreach(var aggregation in destKeys.Keys)
{
var rule = new TimeSeriesRule(destKeys[aggregation], timeBucket, aggregation);
Expand All @@ -77,9 +77,9 @@ public void TestRulesAdditionDeletion()
public void TestNonExistingSrc()
{
IDatabase db = redisFixture.Redis.GetDatabase();
string destKey = "RULES_DEST_" + Aggregation.AVG;
string destKey = "RULES_DEST_" + TsAggregation.Avg;
db.TimeSeriesCreate(destKey);
TimeSeriesRule rule = new TimeSeriesRule(destKey, 50, Aggregation.AVG);
TimeSeriesRule rule = new TimeSeriesRule(destKey, 50, TsAggregation.Avg);
var ex = Assert.Throws<RedisServerException>(() => db.TimeSeriesCreateRule(srcKey, rule));
Assert.Equal("ERR TSDB: the key does not exist", ex.Message);
ex = Assert.Throws<RedisServerException>(() => db.TimeSeriesDeleteRule(srcKey, destKey));
Expand All @@ -90,9 +90,9 @@ public void TestNonExistingSrc()
public void TestNonExisitingDestinaion()
{
IDatabase db = redisFixture.Redis.GetDatabase();
string destKey = "RULES_DEST_" + Aggregation.AVG;
string destKey = "RULES_DEST_" + TsAggregation.Avg;
db.TimeSeriesCreate(srcKey);
TimeSeriesRule rule = new TimeSeriesRule(destKey, 50, Aggregation.AVG);
TimeSeriesRule rule = new TimeSeriesRule(destKey, 50, TsAggregation.Avg);
var ex = Assert.Throws<RedisServerException>(() => db.TimeSeriesCreateRule(srcKey, rule));
Assert.Equal("ERR TSDB: the key does not exist", ex.Message);
ex = Assert.Throws<RedisServerException>(() => db.TimeSeriesDeleteRule(srcKey, destKey));
Expand Down
Loading

0 comments on commit b05b45d

Please sign in to comment.