Skip to content

Commit

Permalink
Fix build warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ejsmith committed Mar 19, 2024
1 parent aa8e0f6 commit ab61b30
Show file tree
Hide file tree
Showing 3 changed files with 320 additions and 321 deletions.
121 changes: 60 additions & 61 deletions tests/Foundatio.Parsers.ElasticQueries.Tests/AggregationParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Foundatio.Parsers.ElasticQueries.Visitors;
using Foundatio.Parsers.LuceneQueries;
using Foundatio.Parsers.LuceneQueries.Extensions;
using Foundatio.Parsers.LuceneQueries.Nodes;
using Foundatio.Parsers.LuceneQueries.Visitors;
using Foundatio.Utility;
using Microsoft.Extensions.Logging;
Expand All @@ -24,13 +23,13 @@ public AggregationParserTests(ITestOutputHelper output, ElasticsearchFixture fix
public async Task ProcessSingleAggregationAsync()
{
var index = CreateRandomIndex<MyType>(d => d.Dynamic().Properties(p => p.GeoPoint(g => g.Name(f => f.Field3))));
Client.IndexMany(new[] {
new MyType { Field1 = "value1", Field4 = 1, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(5)), Field2 = "field2" },
new MyType { Field1 = "value2", Field4 = 2, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(4)) },
new MyType { Field1 = "value3", Field4 = 3, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(3)) },
new MyType { Field1 = "value4", Field4 = 4, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(2)) },
new MyType { Field1 = "value5", Field4 = 5, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(1)) }
}, index);
await Client.IndexManyAsync(new[] {
new MyType { Field1 = "value1", Field4 = 1, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(5)), Field2 = "field2" },
new MyType { Field1 = "value2", Field4 = 2, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(4)) },
new MyType { Field1 = "value3", Field4 = 3, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(3)) },
new MyType { Field1 = "value4", Field4 = 4, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(2)) },
new MyType { Field1 = "value5", Field4 = 5, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(1)) }
}, index);
await Client.Indices.RefreshAsync(index);

var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index).UseGeo(l => "51.5032520,-0.1278990"));
Expand All @@ -55,13 +54,13 @@ public async Task ProcessSingleAggregationAsync()
public async Task ProcessSingleAggregationWithAliasAsync()
{
var index = CreateRandomIndex<MyType>(d => d.Dynamic().Properties(p => p.GeoPoint(g => g.Name(f => f.Field3))));
Client.IndexMany(new[] {
new MyType { Field1 = "value1", Field4 = 1, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(5)), Field2 = "field2" },
new MyType { Field1 = "value2", Field4 = 2, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(4)) },
new MyType { Field1 = "value3", Field4 = 3, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(3)) },
new MyType { Field1 = "value4", Field4 = 4, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(2)) },
new MyType { Field1 = "value5", Field4 = 5, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(1)) }
}, index);
await Client.IndexManyAsync(new[] {
new MyType { Field1 = "value1", Field4 = 1, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(5)), Field2 = "field2" },
new MyType { Field1 = "value2", Field4 = 2, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(4)) },
new MyType { Field1 = "value3", Field4 = 3, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(3)) },
new MyType { Field1 = "value4", Field4 = 4, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(2)) },
new MyType { Field1 = "value5", Field4 = 5, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(1)) }
}, index);
await Client.Indices.RefreshAsync(index);

var fieldMap = new FieldMap { { "heynow", "field4" } };
Expand Down Expand Up @@ -91,13 +90,13 @@ public async Task ProcessAnalyzedAggregationWithAliasAsync()
.Fields(k => k.Keyword(m => m.Name("keyword"))))
.FieldAlias(f => f.Name("heynow").Path(k => k.Field1))
.GeoPoint(g => g.Name(f => f.Field3))));
Client.IndexMany(new[] {
new MyType { Field1 = "value1", Field4 = 1, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(5)), Field2 = "field2" },
new MyType { Field1 = "value2", Field4 = 2, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(4)) },
new MyType { Field1 = "value3", Field4 = 3, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(3)) },
new MyType { Field1 = "value4", Field4 = 4, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(2)) },
new MyType { Field1 = "value5", Field4 = 5, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(1)) }
}, index);
await Client.IndexManyAsync(new[] {
new MyType { Field1 = "value1", Field4 = 1, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(5)), Field2 = "field2" },
new MyType { Field1 = "value2", Field4 = 2, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(4)) },
new MyType { Field1 = "value3", Field4 = 3, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(3)) },
new MyType { Field1 = "value4", Field4 = 4, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(2)) },
new MyType { Field1 = "value5", Field4 = 5, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(1)) }
}, index);
await Client.Indices.RefreshAsync(index);

var fieldMap = new FieldMap { { "heynow2", "field1" } };
Expand All @@ -123,13 +122,13 @@ public async Task ProcessAnalyzedAggregationWithAliasAsync()
public async Task ProcessAggregationsAsync()
{
var index = CreateRandomIndex<MyType>(d => d.Dynamic().Properties(p => p.GeoPoint(g => g.Name(f => f.Field3))));
Client.IndexMany(new[] {
new MyType { Field1 = "value1", Field4 = 1, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(5)), Field2 = "field2" },
new MyType { Field1 = "value2", Field4 = 2, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(4)) },
new MyType { Field1 = "value3", Field4 = 3, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(3)) },
new MyType { Field1 = "value4", Field4 = 4, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(2)) },
new MyType { Field1 = "value5", Field4 = 5, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(1)) }
}, index);
await Client.IndexManyAsync(new[] {
new MyType { Field1 = "value1", Field4 = 1, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(5)), Field2 = "field2" },
new MyType { Field1 = "value2", Field4 = 2, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(4)) },
new MyType { Field1 = "value3", Field4 = 3, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(3)) },
new MyType { Field1 = "value4", Field4 = 4, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(2)) },
new MyType { Field1 = "value5", Field4 = 5, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(1)) }
}, index);
await Client.Indices.RefreshAsync(index);

var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index).UseGeo(l => "51.5032520,-0.1278990"));
Expand Down Expand Up @@ -171,7 +170,7 @@ public async Task ProcessNestedAggregationsWithAliasesAsync()
.Text(f3 => f3.Name("identity")
.Fields(f => f.Keyword(k => k.Name("keyword").IgnoreAbove(256))))))))));

Client.IndexMany(new[] { new MyType { Field1 = "value1" } }, index);
await Client.IndexManyAsync(new[] { new MyType { Field1 = "value1" } }, index);
await Client.Indices.RefreshAsync(index);

var aliasMap = new FieldMap { { "user", "data.@user.identity" }, { "alias1", "field1" } };
Expand Down Expand Up @@ -199,9 +198,9 @@ public async Task ProcessSingleAggregationWithAlias()
{
var index = CreateRandomIndex<MyType>();

Client.IndexMany(new[] {
new MyType { Field2 = "field2" }
}, index);
await Client.IndexManyAsync(new[] {
new MyType { Field2 = "field2" }
}, index);
await Client.Indices.RefreshAsync(index);

var aliasMap = new FieldMap { { "alias2", "field2" } };
Expand Down Expand Up @@ -233,9 +232,9 @@ public async Task ProcessAggregationsWithAliasesAsync()
.Object<object>(o2 => o2.Name("@user").Properties(p2 => p2
.Text(f3 => f3.Name("identity").Fields(f => f.Keyword(k => k.Name("keyword").IgnoreAbove(256))))))))));

Client.IndexMany(new[] {
new MyType { Field1 = "value1", Field4 = 1, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(5)), Field2 = "field2" }
}, index);
await Client.IndexManyAsync(new[] {
new MyType { Field1 = "value1", Field4 = 1, Field3 = "51.5032520,-0.1278990", Field5 = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(5)), Field2 = "field2" }
}, index);
await Client.Indices.RefreshAsync(index);

var aliasMap = new FieldMap { { "user", "data.@user.identity" }, { "alias1", "field1" }, { "alias2", "field2" }, { "alias3", "field3" }, { "alias4", "field4" }, { "alias5", "field5" } };
Expand Down Expand Up @@ -269,14 +268,14 @@ public async Task ProcessAggregationsWithAliasesAsync()
}

[Fact]
public void ProcessTermAggregations()
public async Task ProcessTermAggregations()
{
var index = CreateRandomIndex<MyType>();
Client.IndexMany(new[] { new MyType { Field1 = "value1" } }, index);
Client.Indices.Refresh(index);
await Client.IndexManyAsync(new[] { new MyType { Field1 = "value1" } }, index);
await Client.Indices.RefreshAsync(index);

var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index));
var aggregations = processor.BuildAggregationsAsync("terms:(field1 @exclude:myexclude @include:myinclude @include:otherinclude @missing:mymissing @exclude:otherexclude @min:1)").Result;
var aggregations = await processor.BuildAggregationsAsync("terms:(field1 @exclude:myexclude @include:myinclude @include:otherinclude @missing:mymissing @exclude:otherexclude @min:1)");

var actualResponse = Client.Search<MyType>(d => d.Index(index).Aggregations(aggregations));
string actualRequest = actualResponse.GetRequest();
Expand All @@ -298,14 +297,14 @@ public void ProcessTermAggregations()
}

[Fact]
public void ProcessHistogramIntervalAggregations()
public async Task ProcessHistogramIntervalAggregations()
{
var index = CreateRandomIndex<MyType>();
Client.IndexMany(new[] { new MyType { Field1 = "value1" } }, index);
Client.Indices.Refresh(index);
await Client.IndexManyAsync(new[] { new MyType { Field1 = "value1" } }, index);
await Client.Indices.RefreshAsync(index);

var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index));
var aggregations = processor.BuildAggregationsAsync("histogram:(field1~0.1)").Result;
var aggregations = await processor.BuildAggregationsAsync("histogram:(field1~0.1)");

var actualResponse = Client.Search<MyType>(d => d.Index(index).Aggregations(aggregations));
string actualRequest = actualResponse.GetRequest();
Expand All @@ -325,14 +324,14 @@ public void ProcessHistogramIntervalAggregations()
}

[Fact]
public void ProcessTermTopHitsAggregations()
public async Task ProcessTermTopHitsAggregations()
{
var index = CreateRandomIndex<MyType>();
Client.IndexMany(new[] { new MyType { Field1 = "value1" } }, index);
Client.Indices.Refresh(index);
await Client.IndexManyAsync(new[] { new MyType { Field1 = "value1" } }, index);
await Client.Indices.RefreshAsync(index);

var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index));
var aggregations = processor.BuildAggregationsAsync("terms:(field1~1000^2 tophits:(_~1000 @include:myinclude))").Result;
var aggregations = await processor.BuildAggregationsAsync("terms:(field1~1000^2 tophits:(_~1000 @include:myinclude))");

var actualResponse = Client.Search<MyType>(d => d.Index(index).Aggregations(aggregations));
string actualRequest = actualResponse.GetRequest();
Expand All @@ -353,14 +352,14 @@ public void ProcessTermTopHitsAggregations()
}

[Fact]
public void ProcessSortedTermAggregations()
public async Task ProcessSortedTermAggregations()
{
var index = CreateRandomIndex<MyType>();
Client.IndexMany(new[] { new MyType { Field1 = "value1" } }, index);
Client.Indices.Refresh(index);
await Client.IndexManyAsync(new[] { new MyType { Field1 = "value1" } }, index);
await Client.Indices.RefreshAsync(index);

var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index));
var aggregations = processor.BuildAggregationsAsync("terms:(field1 -cardinality:field4)").Result;
var aggregations = await processor.BuildAggregationsAsync("terms:(field1 -cardinality:field4)");

var actualResponse = Client.Search<MyType>(d => d.Index(index).Aggregations(aggregations));
string actualRequest = actualResponse.GetRequest();
Expand All @@ -383,14 +382,14 @@ public void ProcessSortedTermAggregations()
}

[Fact]
public void ProcessDateHistogramAggregations()
public async Task ProcessDateHistogramAggregations()
{
var index = CreateRandomIndex<MyType>();
Client.IndexMany(new[] { new MyType { Field5 = SystemClock.UtcNow } }, index);
Client.Indices.Refresh(index);
await Client.IndexManyAsync(new[] { new MyType { Field5 = SystemClock.UtcNow } }, index);
await Client.Indices.RefreshAsync(index);

var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index));
var aggregations = processor.BuildAggregationsAsync("date:(field5^1h @missing:\"0001-01-01T00:00:00\" min:field5^1h max:field5^1h)").Result;
var aggregations = await processor.BuildAggregationsAsync("date:(field5^1h @missing:\"0001-01-01T00:00:00\" min:field5^1h max:field5^1h)");

var actualResponse = Client.Search<MyType>(d => d.Index(index).Aggregations(aggregations));
string actualRequest = actualResponse.GetRequest();
Expand All @@ -417,14 +416,14 @@ public void ProcessDateHistogramAggregations()
}

[Fact]
public void CanSpecifyDefaultValuesAggregations()
public async Task CanSpecifyDefaultValuesAggregations()
{
var index = CreateRandomIndex<MyType>();
Client.IndexMany(new[] { new MyType { Field1 = "test" }, new MyType { Field4 = 1 } }, index);
Client.Indices.Refresh(index);
await Client.IndexManyAsync(new[] { new MyType { Field1 = "test" }, new MyType { Field4 = 1 } }, index);
await Client.Indices.RefreshAsync(index);

var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index));
var aggregations = processor.BuildAggregationsAsync("min:field4~0 max:field4~0 avg:field4~0 sum:field4~0 cardinality:field4~0").Result;
var aggregations = await processor.BuildAggregationsAsync("min:field4~0 max:field4~0 avg:field4~0 sum:field4~0 cardinality:field4~0");

var actualResponse = Client.Search<MyType>(d => d.Index(index).Aggregations(aggregations));
string actualRequest = actualResponse.GetRequest();
Expand Down Expand Up @@ -526,7 +525,7 @@ private async Task GetAggregationQueryInfoAsync(IQueryParser parser, string quer
if (maxNodeDepth >= 0)
Assert.Equal(maxNodeDepth, result.MaxNodeDepth);
if (fields != null)
Assert.Equal(fields, result.ReferencedFields);
Assert.Equal(fields, (HashSet<string>)result.ReferencedFields);

if (operations != null)
Assert.Equal(operations, result.Operations.ToDictionary(pair => pair.Key, pair => pair.Value));
Expand Down
Loading

0 comments on commit ab61b30

Please sign in to comment.