Skip to content

Commit

Permalink
[CALCITE-1725] Push project aggregate of time extract to druid
Browse files Browse the repository at this point in the history
* Fix 'testPushAggregateOnTime' test.
  • Loading branch information
jcamachor committed Apr 11, 2017
1 parent 35cd2ab commit e76d5ee
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,20 @@ private void parseField(List<String> fieldNames, List<ColumnMetaData.Rep> fieldT

// Move to next token, which is name's value
JsonToken token = parser.nextToken();
if (fieldName.equals(DEFAULT_RESPONSE_TIMESTAMP_COLUMN)) {

boolean isTimestampColumn = fieldName.equals(DEFAULT_RESPONSE_TIMESTAMP_COLUMN);
int i = fieldNames.indexOf(fieldName);
ColumnMetaData.Rep type = null;
if (i < 0) {
if (!isTimestampColumn) {
// Field not present
return;
}
} else {
type = fieldTypes.get(i);
}

if (isTimestampColumn || ColumnMetaData.Rep.JAVA_SQL_TIMESTAMP.equals(type)) {
try {
final Date parse;
// synchronized block to avoid race condition
Expand All @@ -285,11 +298,7 @@ private void parseField(List<String> fieldNames, List<ColumnMetaData.Rep> fieldT
}
return;
}
int i = fieldNames.indexOf(fieldName);
if (i < 0) {
return;
}
ColumnMetaData.Rep type = fieldTypes.get(i);

switch (token) {
case VALUE_NUMBER_INT:
if (type == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1081,10 +1081,9 @@ private static boolean containsLimit(QuerySpec querySpec) {
}

private ColumnMetaData.Rep getPrimitive(RelDataTypeField field) {
if (field.getName().equals(query.druidTable.timestampFieldName)) {
return ColumnMetaData.Rep.JAVA_SQL_TIMESTAMP;
}
switch (field.getType().getSqlTypeName()) {
case TIMESTAMP:
return ColumnMetaData.Rep.JAVA_SQL_TIMESTAMP;
case BIGINT:
return ColumnMetaData.Rep.LONG;
case INTEGER:
Expand Down
16 changes: 8 additions & 8 deletions druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -1506,18 +1506,18 @@ public Void apply(ResultSet resultSet) {
}

@Test public void testPushAggregateOnTime() {
String sql = "select \"product_id\", \"timestamp\" as \"time\" from \"foodmart\" where "
+ "\"product_id\" = 1016 and "
+ "\"timestamp\" < cast('1997-01-03' as timestamp) and \"timestamp\" > cast"
+ "('1990-01-01' as timestamp)" + " group by"
+ "\"timestamp\", \"product_id\" ";
String sql = "select \"product_id\", \"timestamp\" as \"time\" from \"foodmart\" "
+ "where \"product_id\" = 1016 "
+ "and \"timestamp\" < cast('1997-01-03' as timestamp) "
+ "and \"timestamp\" > cast('1990-01-01' as timestamp) "
+ "group by \"timestamp\", \"product_id\" ";
String druidQuery = "{'queryType':'groupBy','dataSource':'foodmart',"
+ "'granularity':'all','dimensions':[{'type':'extraction',"
+ "'dimension':'__time','outputName':'timestamp',"
+ "'dimension':'__time','outputName':'extract_0',"
+ "'extractionFn':{'type':'timeFormat','format':'yyyy-MM-dd";
sql(sql)
.returnsUnordered("product_id=1016; time=1997-01-02 00:00:00")
.queryContains(druidChecker(druidQuery));
.queryContains(druidChecker(druidQuery))
.returnsUnordered("product_id=1016; time=1997-01-02 00:00:00");
}

@Test public void testPushAggregateOnTimeWithExtractYear() {
Expand Down

0 comments on commit e76d5ee

Please sign in to comment.