Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't allow '__time' as a GroupBy output field name #3967

Merged
merged 2 commits into from
Feb 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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