mirror of https://github.com/apache/druid.git
"all" type search query spec (#3300)
* "all" type search query spec * addressed comments * added unit test
This commit is contained in:
parent
2553997200
commit
884017d981
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* Licensed to Metamarkets Group Inc. (Metamarkets) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. Metamarkets licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.druid.query.search.search;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public class AllSearchQuerySpec implements SearchQuerySpec
|
||||||
|
{
|
||||||
|
private static final byte CACHE_TYPE_ID = 0x7f;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean accept(String dimVal)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] getCacheKey()
|
||||||
|
{
|
||||||
|
return new byte[]{CACHE_TYPE_ID};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object object)
|
||||||
|
{
|
||||||
|
return object instanceof AllSearchQuerySpec;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return CACHE_TYPE_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "AllSearchQuerySpec{}";
|
||||||
|
}
|
||||||
|
}
|
|
@ -66,10 +66,9 @@ public class SearchQuery extends BaseQuery<Result<SearchResultValue>>
|
||||||
this.granularity = granularity == null ? QueryGranularities.ALL : granularity;
|
this.granularity = granularity == null ? QueryGranularities.ALL : granularity;
|
||||||
this.limit = (limit == 0) ? 1000 : limit;
|
this.limit = (limit == 0) ? 1000 : limit;
|
||||||
this.dimensions = dimensions;
|
this.dimensions = dimensions;
|
||||||
this.querySpec = querySpec;
|
this.querySpec = querySpec == null ? new AllSearchQuerySpec() : querySpec;
|
||||||
|
|
||||||
Preconditions.checkNotNull(querySegmentSpec, "Must specify an interval");
|
Preconditions.checkNotNull(querySegmentSpec, "Must specify an interval");
|
||||||
Preconditions.checkNotNull(querySpec, "Must specify a query");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -29,7 +29,8 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
@JsonSubTypes.Type(name = "contains", value = ContainsSearchQuerySpec.class),
|
@JsonSubTypes.Type(name = "contains", value = ContainsSearchQuerySpec.class),
|
||||||
@JsonSubTypes.Type(name = "insensitive_contains", value = InsensitiveContainsSearchQuerySpec.class),
|
@JsonSubTypes.Type(name = "insensitive_contains", value = InsensitiveContainsSearchQuerySpec.class),
|
||||||
@JsonSubTypes.Type(name = "fragment", value = FragmentSearchQuerySpec.class),
|
@JsonSubTypes.Type(name = "fragment", value = FragmentSearchQuerySpec.class),
|
||||||
@JsonSubTypes.Type(name = "regex", value = RegexSearchQuerySpec.class)
|
@JsonSubTypes.Type(name = "regex", value = RegexSearchQuerySpec.class),
|
||||||
|
@JsonSubTypes.Type(name = "all", value = AllSearchQuerySpec.class)
|
||||||
})
|
})
|
||||||
public interface SearchQuerySpec
|
public interface SearchQuerySpec
|
||||||
{
|
{
|
||||||
|
|
|
@ -550,6 +550,35 @@ public class SearchQueryRunnerTest
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSearchAll()
|
||||||
|
{
|
||||||
|
List<SearchHit> expectedHits = Lists.newLinkedList();
|
||||||
|
expectedHits.add(new SearchHit(QueryRunnerTestHelper.marketDimension, "spot", 837));
|
||||||
|
expectedHits.add(new SearchHit(QueryRunnerTestHelper.marketDimension, "total_market", 186));
|
||||||
|
expectedHits.add(new SearchHit(QueryRunnerTestHelper.marketDimension, "upfront", 186));
|
||||||
|
|
||||||
|
checkSearchQuery(
|
||||||
|
Druids.newSearchQueryBuilder()
|
||||||
|
.dataSource(QueryRunnerTestHelper.dataSource)
|
||||||
|
.granularity(QueryRunnerTestHelper.allGran)
|
||||||
|
.intervals(QueryRunnerTestHelper.fullOnInterval)
|
||||||
|
.dimensions(QueryRunnerTestHelper.marketDimension)
|
||||||
|
.query("")
|
||||||
|
.build(),
|
||||||
|
expectedHits
|
||||||
|
);
|
||||||
|
checkSearchQuery(
|
||||||
|
Druids.newSearchQueryBuilder()
|
||||||
|
.dataSource(QueryRunnerTestHelper.dataSource)
|
||||||
|
.granularity(QueryRunnerTestHelper.allGran)
|
||||||
|
.intervals(QueryRunnerTestHelper.fullOnInterval)
|
||||||
|
.dimensions(QueryRunnerTestHelper.marketDimension)
|
||||||
|
.build(),
|
||||||
|
expectedHits
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private void checkSearchQuery(Query searchQuery, List<SearchHit> expectedResults)
|
private void checkSearchQuery(Query searchQuery, List<SearchHit> expectedResults)
|
||||||
{
|
{
|
||||||
checkSearchQuery(searchQuery, runner, expectedResults);
|
checkSearchQuery(searchQuery, runner, expectedResults);
|
||||||
|
|
Loading…
Reference in New Issue