public void Limit_the_number_of_points_returned() { var query = InfluxQuery.From(h2o_feet) .Select((f, t) => new { f.water_level, t.location }) .Limit(3); query.Statement.Text.ShouldBe("SELECT water_level, location FROM h2o_feet LIMIT 3"); }
public void Group_query_results_by_a_single_tag() { var query = InfluxQuery.From(h2o_feet) .Select(fields => new { mean = MEAN(fields.water_level) }) .GroupBy(tags => new { tags.location }); query.Statement.Text.ShouldBe("SELECT MEAN(water_level) AS mean FROM h2o_feet GROUP BY location"); }
public void Selected_entire_field_set() { var testMeasurement = new Measurement <Fields>("test"); var select = InfluxQuery.From(testMeasurement).Select(fields => fields).Statement; select.Columns.ShouldNotBeEmpty(); select.ColumnNames().ShouldBe(new[] { nameof(Fields.weight), nameof(Fields.height) }); }
public void Select_all_fields_from_a_single_measurement() { // The example of this is "SELECT *::field FROM h2o_feet"; // Instead we know which fields we require so identify them explicitly. var query = InfluxQuery.From(h2o_feet).Select(fields => fields); query.Statement.Text.ShouldBe("SELECT \"level description\" AS level_description, water_level FROM h2o_feet"); }
public void Return_the_newest_points_first() { var query = InfluxQuery.From(h2o_feet) .Select(f => new { f.water_level }) .Where("location = 'santa_monica'") .OrderByTimeDesc(); query.Statement.Text.ShouldBe("SELECT water_level FROM h2o_feet WHERE location = 'santa_monica' ORDER BY time DESC"); }
public void Paginate_points() { var query = InfluxQuery.From(h2o_feet) .Select((f, t) => new { f.water_level, t.location }) .Limit(3) .Offset(3); query.Statement.Text.ShouldBe("SELECT water_level, location FROM h2o_feet LIMIT 3 OFFSET 3"); }
public void Group_query_results_into_12_minute_intervals() { var query = InfluxQuery.From(h2o_feet) .Select(fields => new { count = COUNT(fields.water_level) }) .Where("location='coyote_creek' AND time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:30:00Z'") .GroupBy(TimeSpan.FromMinutes(12)); query.Statement.Text.ShouldBe("SELECT COUNT(water_level) AS count FROM h2o_feet WHERE location='coyote_creek' AND time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:30:00Z' GROUP BY time(12m)"); }
public void Select_specific_field_and_tag() { var testMeasurement = new TaggedMeasurement <Fields, Tags>("test"); var select = InfluxQuery.From(testMeasurement).Select((fields, tags) => new { fields.height, tags.size }).Statement; select.Columns.ShouldNotBeEmpty(); select.ColumnNames().ShouldBe(new[] { nameof(Fields.height), nameof(Tags.size) }); }
public void Group_query_results_into_12_minutes_intervals_and_by_a_tag_key() { var query = InfluxQuery.From(h2o_feet) .Select(fields => new { count = COUNT(fields.water_level) }) .Where("time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:30:00Z'") .GroupBy(TimeSpan.FromMinutes(12), tags => new { tags.location }); query.Statement.Text.ShouldBe("SELECT COUNT(water_level) AS count FROM h2o_feet WHERE time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:30:00Z' GROUP BY time(12m),location"); }
public void Limit_the_number_of_points_and_series_returned() { var query = InfluxQuery.From(h2o_feet) .Select(f => new { f.water_level }) .GroupBy(t => t) .Limit(3) .SLimit(1); query.Statement.Text.ShouldBe("SELECT water_level FROM h2o_feet GROUP BY location LIMIT 3 SLIMIT 1"); }
public void Return_the_newest_points_first_and_include_a_GROUP_BY_time_clause() { var query = InfluxQuery.From(h2o_feet) .Select(f => new { mean = Aggregations.MEAN(f.water_level) }) .Where("time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:42:00Z'") .GroupBy(TimeSpan.FromMinutes(12)) .OrderByTimeDesc(); query.Statement.Text.ShouldBe("SELECT MEAN(water_level) AS mean FROM h2o_feet WHERE time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:42:00Z' GROUP BY time(12m) ORDER BY time DESC"); }
public void Limit_the_number_points_returned_and_include_a_GROUP_BY_clause() { var query = InfluxQuery.From(h2o_feet) .Select((f, t) => new { mean = Aggregations.MEAN(f.water_level) }) .Where("time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:42:00Z'") .GroupBy(TimeSpan.FromMinutes(12), t => t) .Limit(2); query.Statement.Text.ShouldBe("SELECT MEAN(water_level) AS mean FROM h2o_feet WHERE time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:42:00Z' GROUP BY time(12m),location LIMIT 2"); }
public void Paginate_series() { var query = InfluxQuery.From(h2o_feet) .Select(f => new { f.water_level }) .GroupBy(t => t) .SLimit(1) .SOffset(1); query.Statement.Text.ShouldBe("SELECT water_level FROM h2o_feet GROUP BY location SLIMIT 1 SOFFSET 1"); }
public void Select_data_that_have_specific_field_key_value() { // SELECT * FROM "h2o_feet" WHERE "water_level" > 8 var query = InfluxQuery.From(h2o_feet) .Select((fields, tags) => new { fields.water_level, fields.level_description, tags.location }) .Where("water_level > 8"); query.Statement.Text.ShouldBe("SELECT water_level, \"level description\" AS level_description, location FROM h2o_feet WHERE water_level > 8"); }
public void Select_data_that_have_a_specific_tag_key_value() { // SELECT "water_level" FROM "h2o_feet" WHERE "location" = 'santa_monica' var query = InfluxQuery.From(h2o_feet) .Select(fields => new { fields.water_level }) .Where("location = 'santa_monica'"); query.Statement.Text.ShouldBe("SELECT water_level FROM h2o_feet WHERE location = 'santa_monica'"); }
public async Task Single_series_field_projection_to_anonymous_type() { var h2o_feet = new WaterDepth(); var query = InfluxQuery.From(h2o_feet) .Select(fields => new { fields.water_level }) .Where("location = 'santa_monica'"); var results = await fixture.Client.Query(query.Statement); var expectedFirstTwoPoints = new[]
public void Alias_field() { var testMeasurement = new TaggedMeasurement <Fields, Tags>("test"); var select = InfluxQuery.From(testMeasurement).Select(fields => new { HowHigh = fields.height }).Statement; select.ColumnNames().ShouldBe(new[] { nameof(Fields.height) }); select.Columns.Select(x => x.Alias).ShouldBe(new[] { "HowHigh" }); select.ToString().ShouldBe("SELECT height AS HowHigh FROM test"); }
public void Select_all_fields_and_tags_from_a_single_measurement() { // The example of this is "SELECT * FROM h2o_feet"; // This would project tags and fields into one obejct. We cannot support this in C# without createing a new type. // Instead query using group by (which is more effiecten on the wire) then flatten in the results when we itterate. var query = InfluxQuery.From(h2o_feet) .Select(fields => fields) .GroupBy(tags => tags); query.Statement.Text.ShouldBe("SELECT \"level description\" AS level_description, water_level FROM h2o_feet GROUP BY location"); }
public void Count() { var testMeasurement = new Measurement <Fields>("test"); var select = InfluxQuery.From(testMeasurement).Select(fields => new { count = Aggregations.COUNT(fields.value) }).Statement; var column = select.Columns.Single() as FieldSelectionExpression; column.FieldName.ShouldBe(nameof(Fields.value)); column.Aggregation.Name.ShouldBe("COUNT"); select.ToString().ShouldBe("SELECT COUNT(value) AS count FROM test"); }
public void Paginate_points_and_include_several_clauses() { var query = InfluxQuery.From(h2o_feet) .Select(f => new { mean = Aggregations.MEAN(f.water_level) }) .Where("time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:42:00Z'") .GroupBy(TimeSpan.FromMinutes(12), t => t) .OrderByTimeDesc() .Limit(2) .Offset(2) .SLimit(1); query.Statement.Text.ShouldBe("SELECT MEAN(water_level) AS mean FROM h2o_feet WHERE time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:42:00Z' GROUP BY time(12m),location ORDER BY time DESC LIMIT 2 OFFSET 2 SLIMIT 1"); }
public void Select_specific_tags_and_fields_from_a_single_measurement() { var query = InfluxQuery.From(h2o_feet).Select((fields, tags) => new { fields.level_description, tags.location, fields.water_level }); query.Statement.Text.ShouldBe("SELECT \"level description\" AS level_description, location, water_level FROM h2o_feet"); }