mirror of
https://github.com/apache/druid.git
synced 2025-02-17 15:35:56 +00:00
Don't allow '__time' as a GroupBy output field name (#3967)
* Don't allow '__time' as a GroupBy column field name * Tweak exception message
This commit is contained in:
parent
02fc625b5f
commit
58b704c3b4
@ -58,6 +58,7 @@ import io.druid.query.spec.LegacySegmentSpec;
|
|||||||
import io.druid.query.spec.QuerySegmentSpec;
|
import io.druid.query.spec.QuerySegmentSpec;
|
||||||
import io.druid.segment.VirtualColumn;
|
import io.druid.segment.VirtualColumn;
|
||||||
import io.druid.segment.VirtualColumns;
|
import io.druid.segment.VirtualColumns;
|
||||||
|
import io.druid.segment.column.Column;
|
||||||
import org.joda.time.Interval;
|
import org.joda.time.Interval;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -572,6 +573,13 @@ public class GroupByQuery extends BaseQuery<Row>
|
|||||||
throw new IAE("Duplicate output name[%s]", postAggregator.getName());
|
throw new IAE("Duplicate output name[%s]", postAggregator.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (outputNames.contains(Column.TIME_COLUMN_NAME)) {
|
||||||
|
throw new IAE(
|
||||||
|
"'%s' cannot be used as an output name for dimensions, aggregators, or post-aggregators.",
|
||||||
|
Column.TIME_COLUMN_NAME
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder
|
public static class Builder
|
||||||
|
@ -38,6 +38,7 @@ import io.druid.data.input.Row;
|
|||||||
import io.druid.granularity.PeriodGranularity;
|
import io.druid.granularity.PeriodGranularity;
|
||||||
import io.druid.granularity.QueryGranularities;
|
import io.druid.granularity.QueryGranularities;
|
||||||
import io.druid.jackson.DefaultObjectMapper;
|
import io.druid.jackson.DefaultObjectMapper;
|
||||||
|
import io.druid.java.util.common.IAE;
|
||||||
import io.druid.java.util.common.ISE;
|
import io.druid.java.util.common.ISE;
|
||||||
import io.druid.java.util.common.guava.MergeSequence;
|
import io.druid.java.util.common.guava.MergeSequence;
|
||||||
import io.druid.java.util.common.guava.Sequence;
|
import io.druid.java.util.common.guava.Sequence;
|
||||||
@ -4237,6 +4238,11 @@ public class GroupByQueryRunnerTest
|
|||||||
@Test
|
@Test
|
||||||
public void testGroupByTimeExtractionNamedUnderUnderTime()
|
public void testGroupByTimeExtractionNamedUnderUnderTime()
|
||||||
{
|
{
|
||||||
|
expectedException.expect(IAE.class);
|
||||||
|
expectedException.expectMessage(
|
||||||
|
"'__time' cannot be used as an output name for dimensions, aggregators, or post-aggregators."
|
||||||
|
);
|
||||||
|
|
||||||
GroupByQuery query = GroupByQuery
|
GroupByQuery query = GroupByQuery
|
||||||
.builder()
|
.builder()
|
||||||
.setDataSource(QueryRunnerTestHelper.dataSource)
|
.setDataSource(QueryRunnerTestHelper.dataSource)
|
||||||
@ -4269,28 +4275,16 @@ public class GroupByQueryRunnerTest
|
|||||||
)
|
)
|
||||||
.setLimitSpec(new DefaultLimitSpec(ImmutableList.<OrderByColumnSpec>of(), 1))
|
.setLimitSpec(new DefaultLimitSpec(ImmutableList.<OrderByColumnSpec>of(), 1))
|
||||||
.build();
|
.build();
|
||||||
List<Row> expectedResults = Arrays.asList(
|
|
||||||
GroupByQueryRunnerTestHelper.createExpectedRow(
|
|
||||||
"1970-01-01",
|
|
||||||
"__time",
|
|
||||||
"Friday",
|
|
||||||
"market",
|
|
||||||
"spot",
|
|
||||||
"index",
|
|
||||||
13219.574157714844,
|
|
||||||
"rows",
|
|
||||||
117L,
|
|
||||||
"addRowsIndexConstant",
|
|
||||||
13337.574157714844
|
|
||||||
)
|
|
||||||
);
|
|
||||||
Iterable<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
|
|
||||||
TestHelper.assertExpectedObjects(expectedResults, results, "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGroupByWithUnderUnderTimeAsDimensionNameWithHavingAndLimit()
|
public void testGroupByWithUnderUnderTimeAsDimensionNameWithHavingAndLimit()
|
||||||
{
|
{
|
||||||
|
expectedException.expect(IAE.class);
|
||||||
|
expectedException.expectMessage(
|
||||||
|
"'__time' cannot be used as an output name for dimensions, aggregators, or post-aggregators."
|
||||||
|
);
|
||||||
|
|
||||||
GroupByQuery query = GroupByQuery
|
GroupByQuery query = GroupByQuery
|
||||||
.builder()
|
.builder()
|
||||||
.setDataSource(QueryRunnerTestHelper.dataSource)
|
.setDataSource(QueryRunnerTestHelper.dataSource)
|
||||||
@ -4318,16 +4312,6 @@ public class GroupByQueryRunnerTest
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
List<Row> expectedResults = Arrays.asList(
|
|
||||||
GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "__time", "business", "rows", 1L, "idx", 118L),
|
|
||||||
GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "__time", "automotive", "rows", 1L, "idx", 135L),
|
|
||||||
GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "__time", "business", "rows", 1L, "idx", 112L),
|
|
||||||
GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "__time", "automotive", "rows", 1L, "idx", 147L)
|
|
||||||
);
|
|
||||||
|
|
||||||
Iterable<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
|
|
||||||
TestHelper.assertExpectedObjects(expectedResults, results, "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user