Skip to content

Commit

Permalink
Merge pull request #39 from MindscapeHQ/issue-21/bound-filter-strings
Browse files Browse the repository at this point in the history
Support BoundFilter with string values
  • Loading branch information
Jeremy Norman authored Jul 6, 2021
2 parents d22d871 + 7e30207 commit fb1be76
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;

namespace Raygun.Druid4Net.IntegrationTests.Queries.Scan
{
[TestFixture]
public class BoundFilterOnMetric : TestQueryBase
{
private IList<QueryResult> _results;

[SetUp]
public void Execute()
{
var response = DruidClient.Scan<QueryResult>(q => q
.DataSource(Wikipedia.DataSource)
.Interval(FromDate, ToDate)
.Filter(new BoundFilter<int?>(Wikipedia.Metrics.Added, 10_000, null, lowerStrict: true, ordering: SortingOrder.numeric))
.Columns(Wikipedia.Metrics.Added)
);

_results = response.Data.SelectMany(x => x.Events).ToList();
}

[Test]
public void AllResultsHaveAddedGreaterThanTenThousand()
{
foreach (var result in _results)
{
Assert.That(result.Added, Is.GreaterThan(10_000));
}
}

private class QueryResult
{
public string Page { get; set; }

public int Added { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<AssemblyName>Raygun.Druid4Net.IntegrationTests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<LangVersion>9</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -60,6 +61,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Queries\GroupBy\CountriesWithLimitAndOrderBy.cs" />
<Compile Include="Queries\GroupBy\PagesGroupedByCity.cs" />
<Compile Include="Queries\Scan\BoundFilterOnMetric.cs" />
<Compile Include="Queries\Scan\ScanFilteredData.cs" />
<Compile Include="Queries\Scan\ScanVirtualColumns.cs" />
<Compile Include="Queries\Search\BasicSearch5Pages.cs" />
Expand Down
14 changes: 12 additions & 2 deletions Raygun.Druid4Net.Tests/Fluent/Filters/BoundFilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ public class BoundFilterTests
[Test]
public void Constructor_TypeIsCorrect()
{
var filter = new BoundFilter<int>("test_dimension", 10);
var filter = new BoundFilter<int?>("test_dimension", 10, null);
Assert.That(filter.Type, Is.EqualTo("bound"));
}

[Test]
public void Constructor_WithLowerValues_PropertiesAreSet()
{
var filter = new BoundFilter<int>("test_dimension", 10);
var filter = new BoundFilter<int?>("test_dimension", 10, null);
Assert.That(filter.Dimension, Is.EqualTo("test_dimension"));
Assert.That(filter.Lower, Is.EqualTo(10));
Assert.That(filter.Upper, Is.Null);
Expand Down Expand Up @@ -45,5 +45,15 @@ public void Constructor_WithAlternateTypeValues_PropertiesAreSet()
Assert.That(filter.Lower, Is.EqualTo(0.1));
Assert.That(filter.Upper, Is.EqualTo(0.2));
}

[Test]
public void Constructor_WithStringTypeValues_PropertiesAreSet()
{
var filter = new BoundFilter<string>("test_dimension", "1", "2", ordering: SortingOrder.alphanumeric);
Assert.That(filter.Dimension, Is.EqualTo("test_dimension"));
Assert.That(filter.Lower, Is.EqualTo("1"));
Assert.That(filter.Upper, Is.EqualTo("2"));
Assert.That(filter.Ordering, Is.EqualTo(SortingOrder.alphanumeric));
}
}
}
1 change: 1 addition & 0 deletions Raygun.Druid4Net.Tests/Raygun.Druid4Net.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<LangVersion>9</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
8 changes: 4 additions & 4 deletions Raygun.Druid4Net/Fluent/Filters/BoundFilter.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@

namespace Raygun.Druid4Net
{
public class BoundFilter<T> : IFilterSpec where T : struct
public class BoundFilter<T> : IFilterSpec
{
public string Type => "bound";

public string Dimension { get; }

public T? Lower { get; }
public T Lower { get; }

public T? Upper { get; }
public T Upper { get; }

public bool LowerStrict { get; }

public bool UpperStrict { get; }

public SortingOrder Ordering { get; }

public BoundFilter(string dimension, T? lower, T? upper = null, bool lowerStrict = false, bool upperStrict = false, SortingOrder ordering = SortingOrder.lexicographic)
public BoundFilter(string dimension, T lower, T upper, bool lowerStrict = false, bool upperStrict = false, SortingOrder ordering = SortingOrder.lexicographic)
{
Dimension = dimension;
Lower = lower;
Expand Down
1 change: 1 addition & 0 deletions Raygun.Druid4Net/Raygun.Druid4Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<TargetFrameworks>net45;netstandard1.6;netstandard2.0</TargetFrameworks>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<PackageVersion>3.0.0</PackageVersion>
<LangVersion>9</LangVersion>
</PropertyGroup>
<!-- NuGet Options -->
<PropertyGroup>
Expand Down

0 comments on commit fb1be76

Please sign in to comment.