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
* Adding additional comments.
  • Loading branch information
jcamachor committed Apr 10, 2017
1 parent 22fdd88 commit 2eebca8
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
import java.io.IOException;

/**
* Default implementation of Dimension spec
* Default implementation of DimensionSpec.
*
* <p>The default implementation returns dimension values as is and optionally
* renames the dimension.
*/
public class DefaultDimensionSpec implements DimensionSpec {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package org.apache.calcite.adapter.druid;

/**
* Druid dimension spec interface
* Interface for Druid DimensionSpec.
*
* <p>DimensionSpecs define how dimension values get transformed prior to aggregation.
*/
public interface DimensionSpec extends DruidQuery.Json {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
import static org.apache.calcite.adapter.druid.DruidQuery.writeFieldIf;

/**
* Extraction function dimension spec implementation
* Implementation of extraction function DimensionSpec.
*
* <p>The extraction function implementation returns dimension values transformed
* using the given extraction function.
*/
public class ExtractionDimensionSpec implements DimensionSpec {
private final String dimension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package org.apache.calcite.adapter.druid;

/**
* Extraction Function interface
* Interface for Druid extraction functions.
*
* <p>Extraction functions define the transformation applied to each dimension value.
*/
public interface ExtractionFunction extends DruidQuery.Json {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.apache.calcite.adapter.druid;

/**
* Time extraction dimension spec implementation
* DimensionSpec implementation that uses a time format extraction function.
*/
public class TimeExtractionDimensionSpec extends ExtractionDimensionSpec {

Expand All @@ -26,11 +26,28 @@ public TimeExtractionDimensionSpec(
super(DruidTable.DEFAULT_TIMESTAMP_COLUMN, extractionFunction, outputName);
}

/**
* Creates a time extraction DimensionSpec that renames the '__time' column
* to the given name.
*
* @param outputName name of the output column
* @return the time extraction DimensionSpec instance
*/
public static TimeExtractionDimensionSpec makeFullTimeExtract(String outputName) {
return new TimeExtractionDimensionSpec(
TimeExtractionFunction.createDefault(), outputName);
}

/**
* Creates a time extraction DimensionSpec that formats the '__time' column
* according to the given granularity and outputs the column with the given
* name. Only YEAR, MONTH, and DAY granularity are supported.
*
* @param granularity granularity to apply to the column
* @param outputName name of the output column
* @return the time extraction DimensionSpec instance or null if granularity
* is not supported
*/
public static TimeExtractionDimensionSpec makeExtract(
Granularity granularity, String outputName) {
switch (granularity) {
Expand All @@ -43,6 +60,7 @@ public static TimeExtractionDimensionSpec makeExtract(
case DAY:
return new TimeExtractionDimensionSpec(
TimeExtractionFunction.createFromGranularity(granularity), outputName);
// TODO: Support other granularities
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@
import static org.apache.calcite.adapter.druid.DruidQuery.writeFieldIf;

/**
* Time extraction implementation
* Implementation of Druid time format extraction function.
*
* <p>These functions return the dimension value formatted according to the given format string,
* time zone, and locale.
*
* <p>For __time dimension values, this formats the time value bucketed by the aggregation
* granularity.
*/
public class TimeExtractionFunction implements ExtractionFunction {

Expand All @@ -49,10 +55,22 @@ public TimeExtractionFunction(String format, String granularity, String timeZone
generator.writeEndObject();
}

/**
* Creates the default time format extraction function.
*
* @return the time extraction function
*/
public static TimeExtractionFunction createDefault() {
return new TimeExtractionFunction("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", null, "UTC", null);
}

/**
* Creates the time format extraction function for the given granularity.
* Only YEAR, MONTH, DAY, and HOUR granularity are supported.
*
* @param granularity granularity to apply to the column
* @return the time extraction function or null if granularity is not supported
*/
public static TimeExtractionFunction createFromGranularity(Granularity granularity) {
switch (granularity) {
case DAY:
Expand Down

0 comments on commit 2eebca8

Please sign in to comment.