Skip to content

Commit

Permalink
Fix up previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
julianhyde committed Sep 16, 2016
1 parent 962eac5 commit baaf256
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ public boolean apply(MetaTable v1) {

private ImmutableList<MetaTypeInfo> getAllDefaultType() {
final ImmutableList.Builder<MetaTypeInfo> allTypeList =
new ImmutableList.Builder<>();
ImmutableList.builder();
final CalciteConnectionImpl conn = (CalciteConnectionImpl) connection;
final RelDataTypeSystem typeSystem = conn.typeFactory.getTypeSystem();
for (SqlTypeName sqlTypeName : SqlTypeName.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,9 @@ private DruidDateTimeUtils() {
}

/**
* Given a list of predicates, it generates the equivalent Interval
* (if possible). It assumes that all the predicates in the input
* reference a single column : the timestamp column.
*
* @param conjs list of conditions to use for the transformation
* @return interval representing the conditions in the input list
* Generates a list of {@link Interval}s equivalent to a given
* expression. Assumes that all the predicates in the input
* reference a single column: the timestamp column.
*/
public static List<Interval> createInterval(RelDataType type, RexNode e) {
final List<Range> ranges = extractRanges(type, e, false);
Expand All @@ -90,9 +87,9 @@ protected static List<Interval> toInterval(List<Range> ranges) {
return DruidTable.DEFAULT_INTERVAL;
}
long start = range.hasLowerBound() ? toLong(range.lowerEndpoint())
: DruidTable.DEFAULT_INTERVAL.getStartMillis();
: DruidTable.DEFAULT_INTERVAL.getStartMillis();
long end = range.hasUpperBound() ? toLong(range.upperEndpoint())
: DruidTable.DEFAULT_INTERVAL.getEndMillis();
: DruidTable.DEFAULT_INTERVAL.getEndMillis();
if (range.hasLowerBound() && range.lowerBoundType() == BoundType.OPEN) {
start++;
}
Expand All @@ -109,7 +106,7 @@ protected static List<Interval> toInterval(List<Range> ranges) {
}

protected static List<Range> extractRanges(RelDataType type, RexNode node,
boolean withNot) {
boolean withNot) {
switch (node.getKind()) {
case EQUALS:
case LESS_THAN:
Expand Down Expand Up @@ -167,7 +164,7 @@ protected static List<Range> extractRanges(RelDataType type, RexNode node,
}

protected static List<Range> leafToRanges(RelDataType type, RexCall call,
boolean withNot) {
boolean withNot) {
switch (call.getKind()) {
case EQUALS:
case LESS_THAN:
Expand All @@ -177,16 +174,16 @@ protected static List<Range> leafToRanges(RelDataType type, RexCall call,
{
RexLiteral literal = null;
if (call.getOperands().get(0) instanceof RexInputRef
&& call.getOperands().get(1) instanceof RexLiteral) {
&& call.getOperands().get(1) instanceof RexLiteral) {
literal = extractLiteral(call.getOperands().get(1));
} else if (call.getOperands().get(0) instanceof RexInputRef
&& call.getOperands().get(1).getKind() == SqlKind.CAST) {
&& call.getOperands().get(1).getKind() == SqlKind.CAST) {
literal = extractLiteral(call.getOperands().get(1));
} else if (call.getOperands().get(1) instanceof RexInputRef
&& call.getOperands().get(0) instanceof RexLiteral) {
&& call.getOperands().get(0) instanceof RexLiteral) {
literal = extractLiteral(call.getOperands().get(0));
} else if (call.getOperands().get(1) instanceof RexInputRef
&& call.getOperands().get(0).getKind() == SqlKind.CAST) {
&& call.getOperands().get(0).getKind() == SqlKind.CAST) {
literal = extractLiteral(call.getOperands().get(0));
}
if (literal == null) {
Expand Down Expand Up @@ -230,10 +227,10 @@ protected static List<Range> leafToRanges(RelDataType type, RexCall call,
boolean inverted = value1.compareTo(value2) > 0;
if (!withNot) {
return Arrays.<Range>asList(
inverted ? Range.closed(value2, value1) : Range.closed(value1, value2));
inverted ? Range.closed(value2, value1) : Range.closed(value1, value2));
}
return Arrays.<Range>asList(Range.lessThan(inverted ? value2 : value1),
Range.greaterThan(inverted ? value1 : value2));
Range.greaterThan(inverted ? value1 : value2));
}
case IN:
{
Expand All @@ -249,7 +246,7 @@ protected static List<Range> leafToRanges(RelDataType type, RexCall call,
}
if (withNot) {
ranges.addAll(
Arrays.<Range>asList(Range.lessThan(element), Range.greaterThan(element)));
Arrays.<Range>asList(Range.lessThan(element), Range.greaterThan(element)));
} else {
ranges.add(Range.closed(element, element));
}
Expand Down Expand Up @@ -433,7 +430,7 @@ public static long extractTotalTime(List<Interval> intervals) {
}

/**
* Extract granularity from a call FLOOR(<time> TO <timeunit>).
* Extracts granularity from a call {@code FLOOR(<time> TO <timeunit>)}.
* Timeunit specifies the granularity. Returns null if it cannot
* be inferred.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class DruidQuery extends AbstractRelNode implements BindableRel {
* @param traitSet Traits
* @param table Table
* @param druidTable Druid table
* @param interval Interval for the query
* @param intervals Intervals for the query
* @param rels Internal relational expressions
*/
protected DruidQuery(RelOptCluster cluster, RelTraitSet traitSet,
Expand Down Expand Up @@ -127,10 +127,10 @@ String signature() {
for (RelNode rel : rels) {
b.append(rel instanceof TableScan ? 's'
: rel instanceof Project ? 'p'
: rel instanceof Filter ? 'f'
: rel instanceof Aggregate ? 'a'
: rel instanceof Sort ? 'l'
: '!');
: rel instanceof Filter ? 'f'
: rel instanceof Aggregate ? 'a'
: rel instanceof Sort ? 'l'
: '!');
}
return b.toString();
}
Expand Down Expand Up @@ -243,13 +243,13 @@ private static DruidQuery create(RelOptCluster cluster, RelTraitSet traitSet,
public static DruidQuery extendQuery(DruidQuery query, RelNode r) {
final ImmutableList.Builder<RelNode> builder = ImmutableList.builder();
return DruidQuery.create(query.getCluster(), r.getTraitSet(), query.getTable(),
query.druidTable, query.intervals, builder.addAll(query.rels).add(r).build());
query.druidTable, query.intervals, builder.addAll(query.rels).add(r).build());
}

/** Extends a DruidQuery. */
public static DruidQuery extendQuery(DruidQuery query, List<Interval> intervals) {
return DruidQuery.create(query.getCluster(), query.getTraitSet(), query.getTable(),
query.druidTable, intervals, query.rels);
query.druidTable, intervals, query.rels);
}

@Override public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) {
Expand All @@ -259,8 +259,8 @@ public static DruidQuery extendQuery(DruidQuery query, List<Interval> intervals)

@Override public RelDataType deriveRowType() {
return getCluster().getTypeFactory().createStructType(
Pair.right(Util.last(rels).getRowType().getFieldList()),
getQuerySpec().fieldNames);
Pair.right(Util.last(rels).getRowType().getFieldList()),
getQuerySpec().fieldNames);
}

public TableScan getTableScan() {
Expand Down Expand Up @@ -296,7 +296,7 @@ public DruidTable getDruidTable() {
} else if (rel instanceof Sort) {
final Sort sort = (Sort) rel;
for (Ord<RelFieldCollation> ord
: Ord.zip(sort.collation.getFieldCollations())) {
: Ord.zip(sort.collation.getFieldCollations())) {
pw.item("sort" + ord.i, ord.e.getFieldIndex());
}
for (Ord<RelFieldCollation> ord
Expand Down Expand Up @@ -392,7 +392,7 @@ protected QuerySpec deriveQuerySpec() {
}

return getQuery(rowType, filter, projects, groupSet, aggCalls, aggNames,
collationIndexes, collationDirections, fetch);
collationIndexes, collationDirections, fetch);
}

public QueryType getQueryType() {
Expand Down Expand Up @@ -451,7 +451,7 @@ protected QuerySpec getQuery(RelDataType rowType, RexNode filter, List<RexNode>
// Reference, it could be to the timestamp column or any other dimension
final RexInputRef ref = (RexInputRef) project;
final String origin = druidTable.getRowType(getCluster().getTypeFactory())
.getFieldList().get(ref.getIndex()).getName();
.getFieldList().get(ref.getIndex()).getName();
if (origin.equals(druidTable.timestampFieldName)) {
granularity = "none";
builder.add(s);
Expand All @@ -465,7 +465,7 @@ protected QuerySpec getQuery(RelDataType rowType, RexNode filter, List<RexNode>
// Call, check if we should infer granularity
final RexCall call = (RexCall) project;
final String funcGranularity =
DruidDateTimeUtils.extractGranularity(call);
DruidDateTimeUtils.extractGranularity(call);
if (funcGranularity != null) {
granularity = funcGranularity;
builder.add(s);
Expand Down Expand Up @@ -507,12 +507,12 @@ protected QuerySpec getQuery(RelDataType rowType, RexNode filter, List<RexNode>
boolean sortsMetric = false;
if (collationIndexes != null) {
assert collationDirections != null;
ImmutableList.Builder<JsonCollation> colBuilder
= new ImmutableList.Builder<JsonCollation>();
ImmutableList.Builder<JsonCollation> colBuilder =
ImmutableList.builder();
for (Pair<Integer, Direction> p : Pair.zip(collationIndexes, collationDirections)) {
colBuilder.add(
new JsonCollation(fieldNames.get(p.left),
p.right == Direction.DESCENDING ? "descending" : "ascending"));
new JsonCollation(fieldNames.get(p.left),
p.right == Direction.DESCENDING ? "descending" : "ascending"));
if (p.left >= groupSet.cardinality() && p.right == Direction.DESCENDING) {
// Currently only support for DESC in TopN
sortsMetric = true;
Expand Down Expand Up @@ -619,7 +619,7 @@ protected QuerySpec getQuery(RelDataType rowType, RexNode filter, List<RexNode>
generator.writeFieldName("pagingSpec");
generator.writeStartObject();
generator.writeNumberField("threshold", fetch != null ? fetch
: CalciteConnectionProperty.DRUID_FETCH.wrap(new Properties()).getInt());
: CalciteConnectionProperty.DRUID_FETCH.wrap(new Properties()).getInt());
generator.writeEndObject();

generator.writeFieldName("context");
Expand Down Expand Up @@ -789,7 +789,7 @@ private static class Translator {
if (druidTable.metricFieldNames.contains(fieldName)) {
metrics.add(fieldName);
} else if (!druidTable.timestampFieldName.equals(fieldName)
&& !DruidTable.DEFAULT_TIMESTAMP_COLUMN.equals(fieldName)) {
&& !DruidTable.DEFAULT_TIMESTAMP_COLUMN.equals(fieldName)) {
dimensions.add(fieldName);
}
}
Expand All @@ -805,7 +805,7 @@ String translate(RexNode e, boolean set) {
if (druidTable.metricFieldNames.contains(fieldName)) {
metrics.add(fieldName);
} else if (!druidTable.timestampFieldName.equals(fieldName)
&& !DruidTable.DEFAULT_TIMESTAMP_COLUMN.equals(fieldName)) {
&& !DruidTable.DEFAULT_TIMESTAMP_COLUMN.equals(fieldName)) {
dimensions.add(fieldName);
}
}
Expand Down Expand Up @@ -916,7 +916,7 @@ public void run() throws InterruptedException {

private static boolean containsLimit(QuerySpec querySpec) {
return querySpec.queryString.contains("\"context\":{\""
+ DRUID_QUERY_FETCH + "\":true");
+ DRUID_QUERY_FETCH + "\":true");
}

private ColumnMetaData.Rep getPrimitive(RelDataTypeField field) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ private static Pair<List<RexNode>, List<RexNode>> splitProjects(final RexBuilder
final int index = positions.indexOf(ref.getIndex());
return rexBuilder.makeInputRef(belowTypes.get(index), index);
}
}
)
);
}));
}
return Pair.of(aboveNodes, belowNodes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@
public class DruidTable extends AbstractTable implements TranslatableTable {

public static final String DEFAULT_TIMESTAMP_COLUMN = "__time";
public static final Interval DEFAULT_INTERVAL = new Interval(
new DateTime("1900-01-01"),
new DateTime("3000-01-01")
);
public static final Interval DEFAULT_INTERVAL =
new Interval(new DateTime("1900-01-01"), new DateTime("3000-01-01"));

final DruidSchema schema;
final String dataSource;
Expand Down

0 comments on commit baaf256

Please sign in to comment.