Skip to content

Commit

Permalink
Don't allow '__time' as a GroupBy output field name (apache#3967)
Browse files Browse the repository at this point in the history
* Don't allow '__time' as a GroupBy column field name

* Tweak exception message
  • Loading branch information
jon-wei authored and gianm committed Feb 23, 2017
1 parent 02fc625 commit 58b704c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import io.druid.query.spec.QuerySegmentSpec;
import io.druid.segment.VirtualColumn;
import io.druid.segment.VirtualColumns;
import io.druid.segment.column.Column;
import org.joda.time.Interval;

import java.util.Arrays;
Expand Down Expand Up @@ -572,6 +573,13 @@ private static void verifyOutputNames(
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import io.druid.granularity.PeriodGranularity;
import io.druid.granularity.QueryGranularities;
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.guava.MergeSequence;
import io.druid.java.util.common.guava.Sequence;
Expand Down Expand Up @@ -4237,6 +4238,11 @@ public void testDifferentIntervalSubquery()
@Test
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
.builder()
.setDataSource(QueryRunnerTestHelper.dataSource)
Expand Down Expand Up @@ -4269,28 +4275,16 @@ public void testGroupByTimeExtractionNamedUnderUnderTime()
)
.setLimitSpec(new DefaultLimitSpec(ImmutableList.<OrderByColumnSpec>of(), 1))
.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
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
.builder()
.setDataSource(QueryRunnerTestHelper.dataSource)
Expand Down Expand Up @@ -4318,16 +4312,6 @@ public void testGroupByWithUnderUnderTimeAsDimensionNameWithHavingAndLimit()
)
)
.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
Expand Down

0 comments on commit 58b704c

Please sign in to comment.