Skip to content

Commit

Permalink
Add file headers; fix rat, assembly and checkstyle warnings
Browse files Browse the repository at this point in the history
Rename a few private Druid rule classes to be consistent with naming
convention, and fix javadoc.
  • Loading branch information
julianhyde committed Mar 21, 2017
1 parent 9c8b597 commit a89c62c
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 56 deletions.
132 changes: 79 additions & 53 deletions druid/src/main/java/org/apache/calcite/adapter/druid/DruidRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,35 +75,37 @@ private DruidRules() {}
public static final DruidFilterRule FILTER = new DruidFilterRule();
public static final DruidProjectRule PROJECT = new DruidProjectRule();
public static final DruidAggregateRule AGGREGATE = new DruidAggregateRule();
public static final DruidProjectAggregateRule PROJECT_AGGREGATE = new DruidProjectAggregateRule();
public static final DruidAggregateProjectRule AGGREGATE_PROJECT =
new DruidAggregateProjectRule();
public static final DruidSortRule SORT = new DruidSortRule();
public static final DruidProjectSortRule PROJECT_SORT = new DruidProjectSortRule();
public static final DruidSortProjectRule SORT_PROJECT = new DruidSortProjectRule();

public static final DruidProjectFilterTransposeRule PROJECT_FILTER_TRANSPOSE_RULE =
public static final DruidSortProjectTransposeRule SORT_PROJECT_TRANSPOSE =
new DruidSortProjectTransposeRule();
public static final DruidProjectSortTransposeRule PROJECT_SORT_TRANSPOSE =
new DruidProjectSortTransposeRule();
public static final DruidProjectFilterTransposeRule PROJECT_FILTER_TRANSPOSE =
new DruidProjectFilterTransposeRule();

public static final DruidFilterProjectTransposeRule FILTER_PROJECT_TRANSPOSE_RULE =
public static final DruidFilterProjectTransposeRule FILTER_PROJECT_TRANSPOSE =
new DruidFilterProjectTransposeRule();

public static final DruidAggregateFilterTransposeRule AGGREGATE_FILTER_TRANSPOSE_RULE =
public static final DruidAggregateFilterTransposeRule AGGREGATE_FILTER_TRANSPOSE =
new DruidAggregateFilterTransposeRule();

public static final DruidFilterAggregateTransposeRule FILTER_AGGREGATE_TRANSPOSE_RULE =
public static final DruidFilterAggregateTransposeRule FILTER_AGGREGATE_TRANSPOSE =
new DruidFilterAggregateTransposeRule();

public static final List<RelOptRule> RULES =
ImmutableList.of(FILTER,
PROJECT_FILTER_TRANSPOSE_RULE,
PROJECT_FILTER_TRANSPOSE,
// Disabled, per
// [CALCITE-1706] DruidAggregateFilterTransposeRule
// causes very fine-grained aggregations to be pushed to Druid
// AGGREGATE_FILTER_TRANSPOSE_RULE,
PROJECT_AGGREGATE,
PROJECT, AGGREGATE,
FILTER_AGGREGATE_TRANSPOSE_RULE,
FILTER_PROJECT_TRANSPOSE_RULE,
PROJECT_SORT, SORT, SORT_PROJECT);
// AGGREGATE_FILTER_TRANSPOSE,
AGGREGATE_PROJECT,
PROJECT,
AGGREGATE,
FILTER_AGGREGATE_TRANSPOSE,
FILTER_PROJECT_TRANSPOSE,
PROJECT_SORT_TRANSPOSE,
SORT,
SORT_PROJECT_TRANSPOSE);

/** Predicate that returns whether Druid can not handle an aggregate. */
private static final Predicate<Aggregate> BAD_AGG =
Expand Down Expand Up @@ -201,10 +203,10 @@ public void onMatch(RelOptRuleCall call) {
call.transformTo(newDruidQuery);
}

/* Splits the filter condition in two groups: those that filter on the timestamp column
* and those that filter on other fields */
/** Splits the filter condition in two groups: those that filter on the timestamp column
* and those that filter on other fields. */
private static Pair<List<RexNode>, List<RexNode>> splitFilters(final RexBuilder rexBuilder,
final DruidQuery input, RexNode cond, final int timestampFieldIdx) {
final DruidQuery input, RexNode cond, final int timestampFieldIdx) {
final List<RexNode> timeRangeNodes = new ArrayList<>();
final List<RexNode> otherNodes = new ArrayList<>();
List<RexNode> conjs = RelOptUtil.conjunctions(cond);
Expand Down Expand Up @@ -370,9 +372,12 @@ private static boolean validAggregate(Aggregate aggregate, DruidQuery query) {
* Rule to push an {@link org.apache.calcite.rel.core.Aggregate} and
* {@link org.apache.calcite.rel.core.Project} into a {@link DruidQuery}.
*/
private static class DruidProjectAggregateRule extends RelOptRule {
private DruidProjectAggregateRule() {
super(operand(Aggregate.class, operand(Project.class, operand(DruidQuery.class, none()))));
private static class DruidAggregateProjectRule extends RelOptRule {
private DruidAggregateProjectRule() {
super(
operand(Aggregate.class,
operand(Project.class,
operand(DruidQuery.class, none()))));
}

public void onMatch(RelOptRuleCall call) {
Expand Down Expand Up @@ -465,9 +470,12 @@ private static boolean validAggregate(Aggregate aggregate, int idx) {
* {@link org.apache.calcite.rel.core.Project}. Useful to transform
* to complex Druid queries.
*/
private static class DruidProjectSortRule extends SortProjectTransposeRule {
private DruidProjectSortRule() {
super(operand(Sort.class, operand(Project.class, operand(DruidQuery.class, none()))));
private static class DruidSortProjectTransposeRule
extends SortProjectTransposeRule {
private DruidSortProjectTransposeRule() {
super(
operand(Sort.class,
operand(Project.class, operand(DruidQuery.class, none()))));
}
}

Expand All @@ -476,14 +484,18 @@ private DruidProjectSortRule() {
* {@link org.apache.calcite.rel.core.Sort}. Useful if after pushing Sort,
* we could not push it inside DruidQuery.
*/
private static class DruidSortProjectRule extends ProjectSortTransposeRule {
private DruidSortProjectRule() {
super(operand(Project.class, operand(Sort.class, operand(DruidQuery.class, none()))));
private static class DruidProjectSortTransposeRule
extends ProjectSortTransposeRule {
private DruidProjectSortTransposeRule() {
super(
operand(Project.class,
operand(Sort.class, operand(DruidQuery.class, none()))));
}
}

/**
* Rule to push an {@link org.apache.calcite.rel.core.Aggregate} into a {@link DruidQuery}.
* Rule to push a {@link org.apache.calcite.rel.core.Sort}
* into a {@link DruidQuery}.
*/
private static class DruidSortRule extends RelOptRule {
private DruidSortRule() {
Expand All @@ -510,7 +522,7 @@ public void onMatch(RelOptRuleCall call) {
call.transformTo(DruidQuery.extendQuery(query, newSort));
}

/* Check sort valid */
/** Checks whether sort is valid. */
private static boolean validSortLimit(Sort sort, DruidQuery query) {
if (sort.offset != null && RexLiteral.intValue(sort.offset) != 0) {
// offset not supported by Druid
Expand Down Expand Up @@ -557,7 +569,7 @@ private static boolean validSortLimit(Sort sort, DruidQuery query) {
}
}

/* Check if any of the references leads to the timestamp column */
/** Checks whether any of the references leads to the timestamp column. */
private static boolean checkTimestampRefOnQuery(ImmutableBitSet set, RelNode top,
DruidQuery query) {
if (top instanceof Project) {
Expand Down Expand Up @@ -589,52 +601,66 @@ private static boolean checkTimestampRefOnQuery(ImmutableBitSet set, RelNode top
}

/**
* Rule to push an {@link org.apache.calcite.rel.core.Project} past a
* {@link org.apache.calcite.rel.core.Filter} when filter is on top of {@link org.apache.calcite.adapter.druid.DruidQuery}
* Rule to push a {@link org.apache.calcite.rel.core.Project}
* past a {@link org.apache.calcite.rel.core.Filter}
* when {@code Filter} is on top of a {@link DruidQuery}.
*/
private static class DruidProjectFilterTransposeRule extends ProjectFilterTransposeRule {
private static class DruidProjectFilterTransposeRule
extends ProjectFilterTransposeRule {
private DruidProjectFilterTransposeRule() {
super(
operand(Project.class, operand(Filter.class, any())), PushProjector.ExprCondition.FALSE,
operand(Project.class,
operand(Filter.class, any())),
PushProjector.ExprCondition.FALSE,
RelFactories.LOGICAL_BUILDER);
}
}

/**
* Rule to push an {@link org.apache.calcite.rel.core.Filter} past a
* {@link org.apache.calcite.rel.core.Project} when project is on top of {@link org.apache.calcite.adapter.druid.DruidQuery}
* Rule to push a {@link org.apache.calcite.rel.core.Filter}
* past a {@link org.apache.calcite.rel.core.Project}
* when {@code Project} is on top of a {@link DruidQuery}.
*/
private static class DruidFilterProjectTransposeRule extends FilterProjectTransposeRule {
private static class DruidFilterProjectTransposeRule
extends FilterProjectTransposeRule {
private DruidFilterProjectTransposeRule() {
super(
operand(Filter.class, operand(Project.class, operand(DruidQuery.class, none()))), true,
true, RelFactories.LOGICAL_BUILDER
);
operand(Filter.class,
operand(Project.class,
operand(DruidQuery.class, none()))),
true, true, RelFactories.LOGICAL_BUILDER);
}
}

/**
* Rule to push an {@link org.apache.calcite.rel.core.Filter} past a
* {@link org.apache.calcite.rel.core.Project} when project is on top of {@link org.apache.calcite.adapter.druid.DruidQuery}
* Rule to push an {@link org.apache.calcite.rel.core.Aggregate}
* past a {@link org.apache.calcite.rel.core.Filter}
* when {@code Filter} is on top of a {@link DruidQuery}.
*/
private static class DruidAggregateFilterTransposeRule extends AggregateFilterTransposeRule {
private static class DruidAggregateFilterTransposeRule
extends AggregateFilterTransposeRule {
private DruidAggregateFilterTransposeRule() {
super(
operand(Aggregate.class, operand(Filter.class, operand(DruidQuery.class, none()))),
operand(Aggregate.class,
operand(Filter.class,
operand(DruidQuery.class, none()))),
RelFactories.LOGICAL_BUILDER);
}
}

/**
* Rule to push an {@link org.apache.calcite.rel.core.Aggregate} past a
* {@link org.apache.calcite.rel.core.Filter} when filter is on top of {@link org.apache.calcite.adapter.druid.DruidQuery}
* Rule to push an {@link org.apache.calcite.rel.core.Filter}
* past an {@link org.apache.calcite.rel.core.Aggregate}
* when {@code Aggregate} is on top of a {@link DruidQuery}.
*/
private static class DruidFilterAggregateTransposeRule extends FilterAggregateTransposeRule {
private static class DruidFilterAggregateTransposeRule
extends FilterAggregateTransposeRule {
private DruidFilterAggregateTransposeRule() {
super(
operand(Filter.class, operand(Aggregate.class, operand(DruidQuery.class, none()))),
RelFactories.LOGICAL_BUILDER
);
operand(Filter.class,
operand(Aggregate.class,
operand(DruidQuery.class, none()))),
RelFactories.LOGICAL_BUILDER);
}
}

Expand Down
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,11 @@ limitations under the License.
license notices. -->
<exclude>src/main/resources/META-INF/services/java.sql.Driver</exclude>
<exclude>**/src/test/resources/**/*.csv</exclude>
<exclude>**/src/test/resources/**/*.txt</exclude>
<exclude>**/src/test/resources/bug/archers.json</exclude>
<exclude>**/src/test/resources/foodmart-schema.spec</exclude>
<exclude>**/data.txt</exclude>
<exclude>**/data2.txt</exclude>

<!-- Exclude all of avatica, RAT is run in Avatica -->
<exclude>avatica/**</exclude>
Expand Down
18 changes: 18 additions & 0 deletions site/_docs/avatica_json_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,21 @@ redirect_to: /avatica/docs/json_reference.html
permalink: /docs/avatica_json_reference.html
---

<!--
{% comment %}
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to you under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
{% endcomment %}
-->
19 changes: 19 additions & 0 deletions site/_docs/avatica_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,22 @@ sidebar_title: Overview
permalink: /docs/avatica_overview.html
redirect_to: /avatica/docs/index.html
---

<!--
{% comment %}
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to you under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
{% endcomment %}
-->
19 changes: 19 additions & 0 deletions site/_docs/avatica_protobuf_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,22 @@ sidebar_title: Protobuf Reference
redirect_to: /avatica/docs/protobuf_reference.html
permalink: /docs/avatica_protobuf_reference.html
---

<!--
{% comment %}
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to you under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
{% endcomment %}
-->
19 changes: 19 additions & 0 deletions site/_docs/avatica_roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,22 @@ sidebar_title: Roadmap
permalink: /docs/avatica_roadmap.html
redirect_to: /avatica/docs/roadmap.html
---

<!--
{% comment %}
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to you under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
{% endcomment %}
-->
6 changes: 3 additions & 3 deletions src/main/config/assemblies/source-assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ limitations under the License.
<!-- main project directory structure -->
<fileSet>
<directory>.</directory>
<outputDirectory>/</outputDirectory>
<outputDirectory/>
<useDefaultExcludes>true</useDefaultExcludes>
<excludes>
<!-- build output -->
Expand Down Expand Up @@ -93,14 +93,14 @@ limitations under the License.
<fileSet>
<directory>${project.build.directory}/maven-shared-archive-resources/META-INF
</directory>
<outputDirectory>/</outputDirectory>
<outputDirectory/>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<includes>
<include>git.properties</include>
</includes>
<outputDirectory>/</outputDirectory>
<outputDirectory/>
</fileSet>
</fileSets>
</assembly>

0 comments on commit a89c62c

Please sign in to comment.