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

Fix failing transform tests and support dates_as_epoch_millis #5209

Merged
merged 1 commit into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions src/Nest/XPack/Transform/TransformSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public interface ITransformSettings

[DataMember(Name = "max_page_search_size")]
public int? MaxPageSearchSize { get; set; }

[DataMember(Name = "dates_as_epoch_millis")]
public bool? DatesAsEpochMilliseconds { get; set; }
}

/// <inheritdoc />
Expand All @@ -31,12 +34,16 @@ public class TransformSettings : ITransformSettings

/// <inheritdoc />
public int? MaxPageSearchSize { get; set; }

/// <inheritdoc />
public bool? DatesAsEpochMilliseconds { get; set; }
}

public class TransformSettingsDescriptor : DescriptorBase<TransformSettingsDescriptor, ITransformSettings>, ITransformSettings
{
float? ITransformSettings.DocsPerSecond { get; set; }
int? ITransformSettings.MaxPageSearchSize { get; set; }
bool? ITransformSettings.DatesAsEpochMilliseconds { get; set; }

/// <inheritdoc cref="ITransformSettings.DocsPerSecond"/>
public TransformSettingsDescriptor DocsPerSecond(float? docsPerSecond) =>
Expand All @@ -45,5 +52,9 @@ public TransformSettingsDescriptor DocsPerSecond(float? docsPerSecond) =>
/// <inheritdoc cref="ITransformSettings.MaxPageSearchSize"/>
public TransformSettingsDescriptor MaxPageSearchSize(int? maxPageSearchSize) =>
Assign(maxPageSearchSize, (a, v) => a.MaxPageSearchSize = v);

/// <inheritdoc cref="ITransformSettings.DatesAsEpochMilliseconds"/>
public TransformSettingsDescriptor DatesAsEpochMilliseconds(bool? datesAsEpochMillis = true) =>
Assign(datesAsEpochMillis, (a, v) => a.DatesAsEpochMilliseconds = v);
}
}
4 changes: 3 additions & 1 deletion tests/Tests.Domain/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,10 @@ public class Metadata
public class ProjectTransform
{
public double? AverageCommits { get; set; }

public long WeekStartedOnMillis { get; set; }

public long WeekStartedOn { get; set; }
public DateTime WeekStartedOnDate { get; set; }

public long SumIntoMaster { get; set; }
}
Expand Down
11 changes: 9 additions & 2 deletions tests/Tests/XPack/Transform/TransformApiTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
using FluentAssertions;
using Nest;
using Tests.Core.Client;
using Tests.Core.Extensions;
using Tests.Core.ManagedElasticsearch.Clusters;
using Tests.Domain;
Expand Down Expand Up @@ -171,7 +173,7 @@ public TransformApiTests(WritableCluster cluster, EndpointUsage usage) : base(ne
},
GroupBy = new Dictionary<string, ISingleGroupSource>
{
{ "weekStartedOn", new DateHistogramGroupSource()
{ TestClient.Configuration.InRange("<7.11.0") ? "weekStartedOnMillis" : "weekStartedOnDate", new DateHistogramGroupSource
{
Field = Field<Project>(f => f.StartedOn),
CalendarInterval = DateInterval.Week
Expand Down Expand Up @@ -207,7 +209,7 @@ public TransformApiTests(WritableCluster cluster, EndpointUsage usage) : base(ne
)
)
.GroupBy(g => g
.DateHistogram("weekStartedOn", dh => dh
.DateHistogram(TestClient.Configuration.InRange("<7.11.0") ? "weekStartedOnMillis" : "weekStartedOnDate", dh => dh
.Field(f => f.StartedOn)
.CalendarInterval(DateInterval.Week)
)
Expand Down Expand Up @@ -317,6 +319,11 @@ [I] public async Task PreviewTransformResponse() => await Assert<PreviewTransfor
r.GeneratedDestinationIndex.Mappings.Should().NotBeNull();
r.GeneratedDestinationIndex.Settings.Should().NotBeNull();
r.GeneratedDestinationIndex.Aliases.Should().NotBeNull();

if (TestClient.Configuration.InRange("<7.11.0"))
r.Preview.First().WeekStartedOnMillis.Should().BeGreaterOrEqualTo(1);
else
r.Preview.First().WeekStartedOnDate.Should().NotBe(DateTime.MinValue);
});

[I] public async Task UpdateTransformResponse() => await Assert<UpdateTransformResponse>(UpdateTransformStep, (v, r) =>
Expand Down
Loading