Skip to content
Permalink
Browse files
Method to specify eternity in the scan query builder (#12223)
* Method to specify eternity in the scan query builder

* Fix checkstyle issue

* Renamed eterity() to eternityInterval()

* Minor fixes
  • Loading branch information
paul-rogers committed Apr 4, 2022
1 parent 9068054 commit 2cc2088720e82339ecbe1a510b6312f3aa9d4c23
Showing 5 changed files with 32 additions and 47 deletions.
@@ -25,6 +25,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import org.apache.druid.java.util.common.Intervals;
import org.apache.druid.java.util.common.granularity.Granularities;
import org.apache.druid.java.util.common.granularity.Granularity;
import org.apache.druid.query.aggregation.AggregatorFactory;
@@ -45,6 +46,7 @@
import org.apache.druid.query.search.SearchQuerySpec;
import org.apache.druid.query.search.SearchSortSpec;
import org.apache.druid.query.spec.LegacySegmentSpec;
import org.apache.druid.query.spec.MultipleIntervalSegmentSpec;
import org.apache.druid.query.spec.QuerySegmentSpec;
import org.apache.druid.query.timeboundary.TimeBoundaryQuery;
import org.apache.druid.query.timeseries.TimeseriesQuery;
@@ -775,9 +777,9 @@ public static SegmentMetadataQueryBuilder newSegmentMetadataQueryBuilder()
* Usage example:
* <pre><code>
* ScanQuery query = new ScanQueryBuilder()
* .dataSource("Example")
* .interval("2010/2013")
* .build();
* .dataSource("Example")
* .eternityInterval()
* .build();
* </code></pre>
*
* @see ScanQuery
@@ -793,28 +795,11 @@ public static SegmentMetadataQueryBuilder newSegmentMetadataQueryBuilder()
private long offset;
private long limit;
private DimFilter dimFilter;
private List<String> columns;
private List<String> columns = new ArrayList<>();
private Boolean legacy;
private ScanQuery.Order order;
private List<ScanQuery.OrderBy> orderBy;

public ScanQueryBuilder()
{
dataSource = null;
querySegmentSpec = null;
virtualColumns = null;
context = null;
resultFormat = null;
batchSize = 0;
offset = 0;
limit = 0;
dimFilter = null;
columns = new ArrayList<>();
legacy = null;
order = null;
orderBy = null;
}

public ScanQuery build()
{
return new ScanQuery(
@@ -869,6 +854,16 @@ public ScanQueryBuilder intervals(QuerySegmentSpec q)
return this;
}

/**
* Convenience method for an interval over all time.
*/
public ScanQueryBuilder eternityInterval()
{
return intervals(
new MultipleIntervalSegmentSpec(
ImmutableList.of(Intervals.ETERNITY)));
}

public ScanQueryBuilder virtualColumns(VirtualColumns virtualColumns)
{
this.virtualColumns = virtualColumns;
@@ -197,7 +197,7 @@ private Druids.ScanQueryBuilder newTestQuery()
return Druids.newScanQueryBuilder()
.dataSource(new TableDataSource(QueryRunnerTestHelper.DATA_SOURCE))
.columns(Collections.emptyList())
.intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC)
.eternityInterval()
.limit(3)
.legacy(legacy);
}
@@ -59,7 +59,6 @@
import org.apache.druid.query.groupby.GroupByQueryHelper;
import org.apache.druid.query.groupby.strategy.GroupByStrategyV2;
import org.apache.druid.query.scan.ScanQuery;
import org.apache.druid.query.spec.MultipleIntervalSegmentSpec;
import org.apache.druid.query.timeseries.TimeseriesQuery;
import org.apache.druid.query.topn.TopNQuery;
import org.apache.druid.query.topn.TopNQueryBuilder;
@@ -638,11 +637,7 @@ public void testGroupByOnScanMultiValue()
{
ScanQuery subquery = new Druids.ScanQueryBuilder().dataSource(MULTI)
.columns("s", "n")
.intervals(
new MultipleIntervalSegmentSpec(
ImmutableList.of(Intervals.ETERNITY)
)
)
.eternityInterval()
.legacy(false)
.resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
.build();
@@ -693,11 +688,7 @@ public void testTopNScanMultiValue()
{
ScanQuery subquery = new Druids.ScanQueryBuilder().dataSource(MULTI)
.columns("s", "n")
.intervals(
new MultipleIntervalSegmentSpec(
ImmutableList.of(Intervals.ETERNITY)
)
)
.eternityInterval()
.legacy(false)
.resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
.build();
@@ -1024,7 +1015,6 @@ public void testGroupByOnArraysStringsasString()
);
}


@Test
public void testGroupByOnArraysUnknownStrings()
{
@@ -1469,12 +1459,12 @@ private <T> void testQuery(
this.how = how;
}

static ExpectedQuery local(final Query query)
static ExpectedQuery local(final Query<?> query)
{
return new ExpectedQuery(query, ClusterOrLocal.LOCAL);
}

static ExpectedQuery cluster(final Query query)
static ExpectedQuery cluster(final Query<?> query)
{
return new ExpectedQuery(query, ClusterOrLocal.CLUSTER);
}
@@ -2924,7 +2924,7 @@ public void testInnerJoinOnTwoInlineDataSourcesWithOuterWhere(Map<String, Object
new QueryDataSource(
newScanQueryBuilder()
.dataSource(CalciteTests.DATASOURCE1)
.intervals(querySegmentSpec(Filtration.eternity()))
.eternityInterval()
.filters(new SelectorDimFilter("dim1", "10.1", null))
.virtualColumns(expressionVirtualColumn("v0", "\'10.1\'", ColumnType.STRING))
.columns(ImmutableList.of("__time", "v0"))
@@ -2935,7 +2935,7 @@ public void testInnerJoinOnTwoInlineDataSourcesWithOuterWhere(Map<String, Object
new QueryDataSource(
newScanQueryBuilder()
.dataSource(CalciteTests.DATASOURCE1)
.intervals(querySegmentSpec(Filtration.eternity()))
.eternityInterval()
.filters(new SelectorDimFilter("dim1", "10.1", null))
.columns(ImmutableList.of("dim1"))
.resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
@@ -182,7 +182,7 @@ public void testMultiValueStringWorksLikeStringScan() throws Exception
ImmutableList.of(
new Druids.ScanQueryBuilder()
.dataSource(CalciteTests.DATASOURCE3)
.intervals(querySegmentSpec(Filtration.eternity()))
.eternityInterval()
.virtualColumns(expressionVirtualColumn("v0", "concat(\"dim3\",'foo')", ColumnType.STRING))
.columns(ImmutableList.of("v0"))
.context(QUERY_CONTEXT_DEFAULT)
@@ -210,7 +210,7 @@ public void testMultiValueStringWorksLikeStringSelfConcatScan() throws Exception
ImmutableList.of(
new Druids.ScanQueryBuilder()
.dataSource(CalciteTests.DATASOURCE3)
.intervals(querySegmentSpec(Filtration.eternity()))
.eternityInterval()
.virtualColumns(expressionVirtualColumn("v0", "concat(\"dim3\",'-lol-',\"dim3\")", ColumnType.STRING))
.columns(ImmutableList.of("v0"))
.context(QUERY_CONTEXT_DEFAULT)
@@ -237,7 +237,7 @@ public void testMultiValueStringWorksLikeStringScanWithFilter() throws Exception
ImmutableList.of(
new Druids.ScanQueryBuilder()
.dataSource(CalciteTests.DATASOURCE3)
.intervals(querySegmentSpec(Filtration.eternity()))
.eternityInterval()
.virtualColumns(expressionVirtualColumn("v0", "concat(\"dim3\",'foo')", ColumnType.STRING))
.filters(selector("v0", "bfoo", null))
.columns(ImmutableList.of("v0"))
@@ -262,7 +262,7 @@ public void testMultiValueStringOverlapFilter() throws Exception
ImmutableList.of(
newScanQueryBuilder()
.dataSource(CalciteTests.DATASOURCE3)
.intervals(querySegmentSpec(Filtration.eternity()))
.eternityInterval()
.filters(new InDimFilter("dim3", ImmutableList.of("a", "b"), null))
.columns("dim3")
.resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
@@ -285,7 +285,7 @@ public void testMultiValueStringOverlapFilterNonLiteral() throws Exception
ImmutableList.of(
newScanQueryBuilder()
.dataSource(CalciteTests.DATASOURCE3)
.intervals(querySegmentSpec(Filtration.eternity()))
.eternityInterval()
.filters(expressionFilter("array_overlap(\"dim3\",array(\"dim2\"))"))
.columns("dim3")
.resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
@@ -305,7 +305,7 @@ public void testMultiValueStringContainsFilter() throws Exception
ImmutableList.of(
newScanQueryBuilder()
.dataSource(CalciteTests.DATASOURCE3)
.intervals(querySegmentSpec(Filtration.eternity()))
.eternityInterval()
.filters(
new AndDimFilter(
new SelectorDimFilter("dim3", "a", null),
@@ -332,7 +332,7 @@ public void testMultiValueStringContainsArrayOfOneElement() throws Exception
ImmutableList.of(
newScanQueryBuilder()
.dataSource(CalciteTests.DATASOURCE3)
.intervals(querySegmentSpec(Filtration.eternity()))
.eternityInterval()
.filters(new SelectorDimFilter("dim3", "a", null))
.columns("dim3")
.resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
@@ -354,7 +354,7 @@ public void testMultiValueStringContainsArrayOfNonLiteral() throws Exception
ImmutableList.of(
newScanQueryBuilder()
.dataSource(CalciteTests.DATASOURCE3)
.intervals(querySegmentSpec(Filtration.eternity()))
.eternityInterval()
.filters(expressionFilter("array_contains(\"dim3\",array(\"dim2\"))"))
.columns("dim3")
.resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
@@ -376,7 +376,7 @@ public void testMultiValueStringSlice() throws Exception
ImmutableList.of(
new Druids.ScanQueryBuilder()
.dataSource(CalciteTests.DATASOURCE3)
.intervals(querySegmentSpec(Filtration.eternity()))
.eternityInterval()
.virtualColumns(expressionVirtualColumn("v0", "array_slice(\"dim3\",1)", ColumnType.STRING))
.columns(ImmutableList.of("v0"))
.context(QUERY_CONTEXT_DEFAULT)

0 comments on commit 2cc2088

Please sign in to comment.