mirror of https://github.com/apache/druid.git
fix select for non existant dimensions and metrics
This commit is contained in:
parent
d3f04d4fbe
commit
9e0a2fd487
|
@ -115,24 +115,34 @@ public class SelectQueryEngine
|
||||||
for (Map.Entry<String, DimensionSelector> dimSelector : dimSelectors.entrySet()) {
|
for (Map.Entry<String, DimensionSelector> dimSelector : dimSelectors.entrySet()) {
|
||||||
final String dim = dimSelector.getKey();
|
final String dim = dimSelector.getKey();
|
||||||
final DimensionSelector selector = dimSelector.getValue();
|
final DimensionSelector selector = dimSelector.getValue();
|
||||||
final IndexedInts vals = selector.getRow();
|
|
||||||
|
|
||||||
if (vals.size() == 1) {
|
if (selector == null) {
|
||||||
final String dimVal = selector.lookupName(vals.get(0));
|
theEvent.put(dim, null);
|
||||||
theEvent.put(dim, dimVal);
|
|
||||||
} else {
|
} else {
|
||||||
List<String> dimVals = Lists.newArrayList();
|
final IndexedInts vals = selector.getRow();
|
||||||
for (int i = 0; i < vals.size(); ++i) {
|
|
||||||
dimVals.add(selector.lookupName(vals.get(i)));
|
if (vals.size() == 1) {
|
||||||
|
final String dimVal = selector.lookupName(vals.get(0));
|
||||||
|
theEvent.put(dim, dimVal);
|
||||||
|
} else {
|
||||||
|
List<String> dimVals = Lists.newArrayList();
|
||||||
|
for (int i = 0; i < vals.size(); ++i) {
|
||||||
|
dimVals.add(selector.lookupName(vals.get(i)));
|
||||||
|
}
|
||||||
|
theEvent.put(dim, dimVals);
|
||||||
}
|
}
|
||||||
theEvent.put(dim, dimVals);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<String, ObjectColumnSelector> metSelector : metSelectors.entrySet()) {
|
for (Map.Entry<String, ObjectColumnSelector> metSelector : metSelectors.entrySet()) {
|
||||||
final String metric = metSelector.getKey();
|
final String metric = metSelector.getKey();
|
||||||
final ObjectColumnSelector selector = metSelector.getValue();
|
final ObjectColumnSelector selector = metSelector.getValue();
|
||||||
theEvent.put(metric, selector.get());
|
|
||||||
|
if (selector == null) {
|
||||||
|
theEvent.put(metric, null);
|
||||||
|
} else {
|
||||||
|
theEvent.put(metric, selector.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.addEntry(
|
builder.addEntry(
|
||||||
|
|
|
@ -30,6 +30,8 @@ import io.druid.query.QueryRunner;
|
||||||
import io.druid.query.QueryRunnerTestHelper;
|
import io.druid.query.QueryRunnerTestHelper;
|
||||||
import io.druid.query.Result;
|
import io.druid.query.Result;
|
||||||
import io.druid.query.TableDataSource;
|
import io.druid.query.TableDataSource;
|
||||||
|
import io.druid.query.filter.AndDimFilter;
|
||||||
|
import io.druid.query.filter.DimFilter;
|
||||||
import io.druid.query.filter.SelectorDimFilter;
|
import io.druid.query.filter.SelectorDimFilter;
|
||||||
import io.druid.query.spec.LegacySegmentSpec;
|
import io.druid.query.spec.LegacySegmentSpec;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
@ -358,6 +360,103 @@ public class SelectQueryRunnerTest
|
||||||
verify(expectedResults, results);
|
verify(expectedResults, results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFullSelectNoResults()
|
||||||
|
{
|
||||||
|
SelectQuery query = new SelectQuery(
|
||||||
|
new TableDataSource(QueryRunnerTestHelper.dataSource),
|
||||||
|
new LegacySegmentSpec(new Interval("2011-01-12/2011-01-14")),
|
||||||
|
new AndDimFilter(
|
||||||
|
Arrays.<DimFilter>asList(
|
||||||
|
new SelectorDimFilter(QueryRunnerTestHelper.providerDimension, "spot"),
|
||||||
|
new SelectorDimFilter(QueryRunnerTestHelper.providerDimension, "foo")
|
||||||
|
)
|
||||||
|
),
|
||||||
|
QueryRunnerTestHelper.allGran,
|
||||||
|
Lists.<String>newArrayList(),
|
||||||
|
Lists.<String>newArrayList(),
|
||||||
|
new PagingSpec(null, 3),
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
Iterable<Result<SelectResultValue>> results = Sequences.toList(
|
||||||
|
runner.run(query),
|
||||||
|
Lists.<Result<SelectResultValue>>newArrayList()
|
||||||
|
);
|
||||||
|
|
||||||
|
List<Result<SelectResultValue>> expectedResults = Arrays.asList(
|
||||||
|
new Result<SelectResultValue>(
|
||||||
|
new DateTime("2011-01-12T00:00:00.000Z"),
|
||||||
|
new SelectResultValue(
|
||||||
|
ImmutableMap.<String, Integer>of(),
|
||||||
|
Lists.<EventHolder>newArrayList()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
verify(expectedResults, results);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFullSelectNoDimensionAndMetric()
|
||||||
|
{
|
||||||
|
SelectQuery query = new SelectQuery(
|
||||||
|
new TableDataSource(QueryRunnerTestHelper.dataSource),
|
||||||
|
new LegacySegmentSpec(new Interval("2011-01-12/2011-01-14")),
|
||||||
|
null,
|
||||||
|
QueryRunnerTestHelper.allGran,
|
||||||
|
Lists.<String>newArrayList("foo"),
|
||||||
|
Lists.<String>newArrayList("foo2"),
|
||||||
|
new PagingSpec(null, 3),
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
Iterable<Result<SelectResultValue>> results = Sequences.toList(
|
||||||
|
runner.run(query),
|
||||||
|
Lists.<Result<SelectResultValue>>newArrayList()
|
||||||
|
);
|
||||||
|
|
||||||
|
List<Result<SelectResultValue>> expectedResults = Arrays.asList(
|
||||||
|
new Result<SelectResultValue>(
|
||||||
|
new DateTime("2011-01-12T00:00:00.000Z"),
|
||||||
|
new SelectResultValue(
|
||||||
|
ImmutableMap.of(QueryRunnerTestHelper.segmentId, 2),
|
||||||
|
Arrays.asList(
|
||||||
|
new EventHolder(
|
||||||
|
QueryRunnerTestHelper.segmentId,
|
||||||
|
0,
|
||||||
|
new ImmutableMap.Builder<String, Object>()
|
||||||
|
.put(EventHolder.timestampKey, new DateTime("2011-01-12T00:00:00.000Z"))
|
||||||
|
.put("foo", null)
|
||||||
|
.put("foo2", null)
|
||||||
|
.build()
|
||||||
|
),
|
||||||
|
new EventHolder(
|
||||||
|
QueryRunnerTestHelper.segmentId,
|
||||||
|
1,
|
||||||
|
new ImmutableMap.Builder<String, Object>()
|
||||||
|
.put(EventHolder.timestampKey, new DateTime("2011-01-12T00:00:00.000Z"))
|
||||||
|
.put(providerLowercase, "spot")
|
||||||
|
.put(QueryRunnerTestHelper.indexMetric, 100.000000F)
|
||||||
|
.build()
|
||||||
|
),
|
||||||
|
new EventHolder(
|
||||||
|
QueryRunnerTestHelper.segmentId,
|
||||||
|
2,
|
||||||
|
new ImmutableMap.Builder<String, Object>()
|
||||||
|
.put(EventHolder.timestampKey, new DateTime("2011-01-12T00:00:00.000Z"))
|
||||||
|
.put(providerLowercase, "spot")
|
||||||
|
.put(QueryRunnerTestHelper.indexMetric, 100.000000F)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
verify(expectedResults, results);
|
||||||
|
}
|
||||||
|
|
||||||
private static void verify(
|
private static void verify(
|
||||||
Iterable<Result<SelectResultValue>> expectedResults,
|
Iterable<Result<SelectResultValue>> expectedResults,
|
||||||
Iterable<Result<SelectResultValue>> actualResults
|
Iterable<Result<SelectResultValue>> actualResults
|
||||||
|
|
Loading…
Reference in New Issue