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

SegmentMetadataQuery: Fix default interval handling. #5489

Merged
merged 2 commits into from
Mar 15, 2018
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: 10 additions & 1 deletion processing/src/main/java/io/druid/query/Druids.java
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ public static class SegmentMetadataQueryBuilder
private EnumSet<SegmentMetadataQuery.AnalysisType> analysisTypes;
private Boolean merge;
private Boolean lenientAggregatorMerge;
private Boolean usingDefaultInterval;
private Map<String, Object> context;

public SegmentMetadataQueryBuilder()
Expand All @@ -601,6 +602,7 @@ public SegmentMetadataQueryBuilder()
analysisTypes = null;
merge = null;
lenientAggregatorMerge = null;
usingDefaultInterval = null;
context = null;
}

Expand All @@ -613,7 +615,7 @@ public SegmentMetadataQuery build()
merge,
context,
analysisTypes,
false,
usingDefaultInterval,
lenientAggregatorMerge
);
}
Expand All @@ -627,6 +629,7 @@ public static SegmentMetadataQueryBuilder copy(SegmentMetadataQuery query)
.analysisTypes(query.getAnalysisTypes())
.merge(query.isMerge())
.lenientAggregatorMerge(query.isLenientAggregatorMerge())
.usingDefaultInterval(query.isUsingDefaultInterval())
.context(query.getContext());
}

Expand Down Expand Up @@ -696,6 +699,12 @@ public SegmentMetadataQueryBuilder lenientAggregatorMerge(boolean lenientAggrega
return this;
}

public SegmentMetadataQueryBuilder usingDefaultInterval(boolean usingDefaultInterval)
{
this.usingDefaultInterval = usingDefaultInterval;
return this;
}

public SegmentMetadataQueryBuilder context(Map<String, Object> c)
{
context = c;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.druid.jackson.DefaultObjectMapper;
import io.druid.java.util.common.Intervals;
import io.druid.query.CacheStrategy;
import io.druid.query.Druids;
import io.druid.query.TableDataSource;
import io.druid.query.aggregation.AggregatorFactory;
import io.druid.query.aggregation.DoubleMaxAggregatorFactory;
Expand All @@ -38,10 +39,14 @@
import io.druid.query.metadata.metadata.SegmentMetadataQuery;
import io.druid.query.spec.LegacySegmentSpec;
import io.druid.segment.column.ValueType;
import io.druid.timeline.LogicalSegment;
import org.joda.time.Period;
import org.junit.Assert;
import org.junit.Test;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class SegmentMetadataQueryQueryToolChestTest
{
Expand Down Expand Up @@ -271,6 +276,37 @@ public void testMergeAggregatorsConflict()
);
}

@Test
public void testFilterSegments()
{
final SegmentMetadataQueryConfig config = new SegmentMetadataQueryConfig();
final SegmentMetadataQueryQueryToolChest toolChest = new SegmentMetadataQueryQueryToolChest(config);

final List<LogicalSegment> filteredSegments = toolChest.filterSegments(
Druids.newSegmentMetadataQueryBuilder().dataSource("foo").merge(true).build(),
ImmutableList
.of(
"2000-01-01/P1D",
"2000-01-04/P1D",
"2000-01-09/P1D",
"2000-01-09/P1D"
)
.stream()
.map(interval -> (LogicalSegment) () -> Intervals.of(interval))
.collect(Collectors.toList())
);

Assert.assertEquals(Period.weeks(1), config.getDefaultHistory());
Assert.assertEquals(
ImmutableList.of(
Intervals.of("2000-01-04/P1D"),
Intervals.of("2000-01-09/P1D"),
Intervals.of("2000-01-09/P1D")
),
filteredSegments.stream().map(LogicalSegment::getInterval).collect(Collectors.toList())
);
}

@SuppressWarnings("ArgumentParameterSwap")
@Test
public void testMergeRollup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,9 @@ public void testSerdeWithDefaultInterval() throws Exception

// test serialize and deserialize
Assert.assertEquals(query, MAPPER.readValue(MAPPER.writeValueAsString(query), Query.class));

// test copy
Assert.assertEquals(query, Druids.SegmentMetadataQueryBuilder.copy((SegmentMetadataQuery) query).build());
}

@Test
Expand Down