Skip to content

Commit

Permalink
Revert "SQL: Make row extractions extensible and add one for lookups. (
Browse files Browse the repository at this point in the history
…apache#3989)"

The PR was merged to master accidentally.

This reverts commit 23927a3.
  • Loading branch information
gianm committed Mar 2, 2017
1 parent 5fb1638 commit e63eefd
Show file tree
Hide file tree
Showing 25 changed files with 308 additions and 556 deletions.
11 changes: 1 addition & 10 deletions docs/content/querying/sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,6 @@ Druid's SQL language supports a number of time operations, including:
By default, time operations use the UTC time zone. You can change the time zone for time operations by setting the
connection context parameter "sqlTimeZone" to the name of the time zone, like "America/Los_Angeles".

### Query-time lookups

Druid [query-time lookups](lookups.html) can be accessed through the `LOOKUP(expression, lookupName)` function. The
"lookupName" must refer to a lookup you have registered with Druid's lookup framework. For example, the following
query can be used to perform a groupBy on looked-up values:

```sql
SELECT LOOKUP(col, 'my_lookup') AS col_with_lookup FROM data_source GROUP BY LOOKUP(col, 'my_lookup')
```

### Subqueries

Druid's SQL layer supports many types of subqueries, including the ones listed below.
Expand Down Expand Up @@ -239,6 +229,7 @@ language. Some unsupported SQL features include:
Additionally, some Druid features are not supported by the SQL language. Some unsupported Druid features include:

- [Multi-value dimensions](multi-value-dimensions.html).
- [Query-time lookups](lookups.html).
- [DataSketches](../development/extensions-core/datasketches-aggregators.html).

## Third-party SQL libraries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import io.druid.sql.calcite.aggregation.SqlAggregator;
import io.druid.sql.calcite.expression.Expressions;
import io.druid.sql.calcite.expression.RowExtraction;
import io.druid.sql.calcite.planner.DruidOperatorTable;
import io.druid.sql.calcite.planner.PlannerContext;
import io.druid.sql.calcite.table.RowSignature;
import org.apache.calcite.rel.core.AggregateCall;
Expand Down Expand Up @@ -65,7 +64,6 @@ public SqlAggFunction calciteFunction()
public Aggregation toDruidAggregation(
final String name,
final RowSignature rowSignature,
final DruidOperatorTable operatorTable,
final PlannerContext plannerContext,
final List<Aggregation> existingAggregations,
final Project project,
Expand All @@ -74,7 +72,6 @@ public Aggregation toDruidAggregation(
)
{
final RowExtraction rex = Expressions.toRowExtraction(
operatorTable,
plannerContext,
rowSignature.getRowOrder(),
Expressions.fromFieldAccess(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import io.druid.segment.TestHelper;
import io.druid.segment.incremental.IncrementalIndexSchema;
import io.druid.sql.calcite.aggregation.SqlAggregator;
import io.druid.sql.calcite.expression.SqlExtractionOperator;
import io.druid.sql.calcite.filtration.Filtration;
import io.druid.sql.calcite.planner.Calcites;
import io.druid.sql.calcite.planner.DruidOperatorTable;
Expand Down Expand Up @@ -131,8 +130,9 @@ public void setUp() throws Exception
)
);
final DruidOperatorTable operatorTable = new DruidOperatorTable(
ImmutableSet.<SqlAggregator>of(new QuantileSqlAggregator()),
ImmutableSet.<SqlExtractionOperator>of()
ImmutableSet.<SqlAggregator>of(
new QuantileSqlAggregator()
)
);
plannerFactory = new PlannerFactory(rootSchema, walker, operatorTable, plannerConfig);
}
Expand Down
5 changes: 0 additions & 5 deletions sql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.druid</groupId>
<artifactId>druid-processing</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import io.druid.sql.calcite.expression.Expressions;
import io.druid.sql.calcite.expression.RowExtraction;
import io.druid.sql.calcite.planner.Calcites;
import io.druid.sql.calcite.planner.DruidOperatorTable;
import io.druid.sql.calcite.planner.PlannerContext;
import io.druid.sql.calcite.table.RowSignature;
import org.apache.calcite.rel.core.AggregateCall;
Expand Down Expand Up @@ -64,7 +63,6 @@ public SqlAggFunction calciteFunction()
public Aggregation toDruidAggregation(
final String name,
final RowSignature rowSignature,
final DruidOperatorTable operatorTable,
final PlannerContext plannerContext,
final List<Aggregation> existingAggregations,
final Project project,
Expand All @@ -78,7 +76,6 @@ public Aggregation toDruidAggregation(
Iterables.getOnlyElement(aggregateCall.getArgList())
);
final RowExtraction rex = Expressions.toRowExtraction(
operatorTable,
plannerContext,
rowSignature.getRowOrder(),
rexNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package io.druid.sql.calcite.aggregation;

import io.druid.query.filter.DimFilter;
import io.druid.sql.calcite.planner.DruidOperatorTable;
import io.druid.sql.calcite.planner.PlannerContext;
import io.druid.sql.calcite.table.RowSignature;
import org.apache.calcite.rel.core.AggregateCall;
Expand All @@ -47,7 +46,6 @@ public interface SqlAggregator
*
* @param name desired output name of the aggregation
* @param rowSignature signature of the rows being aggregated
* @param operatorTable Operator table that can be used to convert sub-expressions
* @param plannerContext SQL planner context
* @param existingAggregations existing aggregations for this query; useful for re-using aggregations. May be safely
* ignored if you do not want to re-use existing aggregations.
Expand All @@ -61,7 +59,6 @@ public interface SqlAggregator
Aggregation toDruidAggregation(
final String name,
final RowSignature rowSignature,
final DruidOperatorTable operatorTable,
final PlannerContext plannerContext,
final List<Aggregation> existingAggregations,
final Project project,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Licensed to Metamarkets Group Inc. (Metamarkets) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Metamarkets 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.
*/

package io.druid.sql.calcite.expression;

import org.apache.calcite.sql.SqlKind;

public abstract class AbstractExpressionConversion implements ExpressionConversion
{
private final SqlKind kind;
private final String operatorName;

public AbstractExpressionConversion(SqlKind kind)
{
this(kind, null);
}

public AbstractExpressionConversion(SqlKind kind, String operatorName)
{
this.kind = kind;
this.operatorName = operatorName;

if (kind == SqlKind.OTHER_FUNCTION && operatorName == null) {
throw new NullPointerException("operatorName must be non-null for kind OTHER_FUNCTION");
} else if (kind != SqlKind.OTHER_FUNCTION && operatorName != null) {
throw new NullPointerException("operatorName must be non-null for kind " + kind);
}
}

@Override
public SqlKind sqlKind()
{
return kind;
}

@Override
public String operatorName()
{
return operatorName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,37 @@
package io.druid.sql.calcite.expression;

import io.druid.query.extraction.StrlenExtractionFn;
import io.druid.sql.calcite.planner.DruidOperatorTable;
import io.druid.sql.calcite.planner.PlannerContext;
import org.apache.calcite.rex.RexCall;
import org.apache.calcite.rex.RexNode;
import org.apache.calcite.sql.SqlFunction;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.sql.SqlKind;

import java.util.List;

public class CharacterLengthExtractionOperator implements SqlExtractionOperator
public class CharLengthExpressionConversion extends AbstractExpressionConversion
{
@Override
public SqlFunction calciteFunction()
private static final CharLengthExpressionConversion INSTANCE = new CharLengthExpressionConversion();

private CharLengthExpressionConversion()
{
super(SqlKind.OTHER_FUNCTION, "CHAR_LENGTH");
}

public static CharLengthExpressionConversion instance()
{
return SqlStdOperatorTable.CHAR_LENGTH;
return INSTANCE;
}

@Override
public RowExtraction convert(
final DruidOperatorTable operatorTable,
final ExpressionConverter converter,
final PlannerContext plannerContext,
final List<String> rowOrder,
final RexNode expression
)
{
final RexCall call = (RexCall) expression;
final RowExtraction arg = Expressions.toRowExtraction(
operatorTable,
plannerContext,
rowOrder,
call.getOperands().get(0)
);
final RowExtraction arg = converter.convert(plannerContext, rowOrder, call.getOperands().get(0));
if (arg == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,41 @@

package io.druid.sql.calcite.expression;

import io.druid.sql.calcite.planner.DruidOperatorTable;
import io.druid.sql.calcite.planner.PlannerContext;
import org.apache.calcite.rex.RexNode;
import org.apache.calcite.sql.SqlFunction;
import org.apache.calcite.sql.SqlKind;

import java.util.List;

public interface SqlExtractionOperator
public interface ExpressionConversion
{
/**
* Returns the SQL operator corresponding to this aggregation function. Should be a singleton.
* SQL kind that this converter knows how to convert.
*
* @return operator
* @return sql kind
*/
SqlFunction calciteFunction();
SqlKind sqlKind();

/**
* Returns the Druid {@link RowExtraction} corresponding to a SQL {@code RexNode}.
* Operator name, if {@link #sqlKind()} is {@code OTHER_FUNCTION}.
*
* @param operatorTable Operator table that can be used to convert sub-expressions
* @return operator name, or null
*/
String operatorName();

/**
* Translate a row-expression to a Druid column reference. Note that this signature will probably need to change
* once we support extractions from multiple columns.
*
* @param converter converter that can be used to convert sub-expressions
* @param plannerContext SQL planner context
* @param rowOrder order of fields in the Druid rows to be extracted from
* @param expression expression meant to be applied on top of the table
*
* @return (columnName, extractionFn) or null
*
* @see ExpressionConversion#convert(ExpressionConverter, PlannerContext, List, RexNode)
*/
RowExtraction convert(
DruidOperatorTable operatorTable,
ExpressionConverter converter,
PlannerContext plannerContext,
List<String> rowOrder,
RexNode expression
Expand Down
Loading

0 comments on commit e63eefd

Please sign in to comment.