Skip to content

Commit

Permalink
[CALCITE-1581] UDTF like in hive
Browse files Browse the repository at this point in the history
[CALCITE-2953] LatticeTest.testTileAlgorithm2 and LatticeTest.testTileAlgorithm3 fail intermittently

Close #1134

In RelFieldCollation, add a "withX" copy method for each attribute "X", and deprecate "copy"

Annotate SqlNode.getKind() and SqlCall.getOperandList() as Nonnull.

[CALCITE-2796] JDBC adapter should convert 'GROUP BY ROLLUP(x, y)' to 'GROUP BY x, y WITH ROLLUP' for MySQL 5

Add 'Util.select(List<E>, List<Integer>)'.

In Aggregate.Group, broaden patterns of grouping sets that are
considered a "rollup". Previously [{}, {0}, {0,1}] would have been
considered a rollup, but [{}, {1}, {0, 1}] would not, because of bit
order. Now they are both considered rollups. Add Group.getRollup(),
which generates the sequence of bits, for example [0, 1] and [1, 0]
for the previous examples.

Suppress deprecation warning, and remove unicode character from Java source file

Re-format and re-order change log in 1.19 release notes, and fix release date.

Site: Add Alibaba MaxCompute to powered-by page

Close #1113

[CALCITE-2958] Upgrade SQLLine to 1.7.0

Close #1136

[CALCITE-2877] Make GeodeSchema constructor public to pass client cache object (Sandeep Chada)

Update instructions for publishing site; we previously used subversion, now we use git

[CALCITE-2903] Exception thrown when decorrelating query with TEMPORAL TABLE

Close #1098

[CALCITE-2808] Add the JSON_LENGTH function (xuqianjin)

Close #1070

[CALCITE-2729] Introducing WindowReduceExpressionsRule (Chunwei Lei)

[CALCITE-2927] The Javadoc and implement of RuleQueue.computeImportance() is inconsistent (Meng Wang)

Close #1111

remove unused empty line
  • Loading branch information
pengzhiwei committed Mar 28, 2019
1 parent 11c067f commit 8d17df4
Show file tree
Hide file tree
Showing 68 changed files with 1,708 additions and 236 deletions.
5 changes: 2 additions & 3 deletions babel/src/main/codegen/config.fmpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ data: {
"JSON"
"JSON_TYPE"
"JSON_DEPTH"
"JSON_LENGTH"
"JSON_PRETTY"
"K"
"KEY"
"KEY_MEMBER"
Expand Down Expand Up @@ -555,9 +557,6 @@ data: {
"JSON_ARRAYAGG",
"JSON_EXISTS",
"JSON_VALUE",
"JSON_TYPE",
"JSON_DEPTH"
"JSON_PRETTY",
"JSON_OBJECT",
"JSON_OBJECTAGG",
"JSON_QUERY",
Expand Down
1 change: 1 addition & 0 deletions core/src/main/codegen/config.fmpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ data: {
"JSON"
"JSON_TYPE"
"JSON_DEPTH"
"JSON_LENGTH"
"JSON_PRETTY"
"K"
"KEY"
Expand Down
81 changes: 67 additions & 14 deletions core/src/main/codegen/templates/Parser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -1560,15 +1560,38 @@ List<SqlNode> SelectList() :
SqlNode SelectItem() :
{
SqlNode e;
final SqlIdentifier id;
SqlIdentifier id;
final List<SqlNode> ids = new ArrayList();
final Span s = span();
}
{
e = SelectExpression()
[
[ <AS> ]
id = SimpleIdentifier() {
e = SqlStdOperatorTable.AS.createCall(span().end(e), e, id);
}
(
(
id = SimpleIdentifier()
{
e = SqlStdOperatorTable.AS.createCall(s.end(e), e, id);
}
)
|
(
<LPAREN>
id = SimpleIdentifier()
{
ids.add(id);
}
( <COMMA> id = SimpleIdentifier() { ids.add(id);} )*
<RPAREN>
{
if (!this.conformance.allowSelectTableFunction()) {
throw new ParseException(RESOURCE.notAllowTableFunctionInSelect().str());
}
e = SqlStdOperatorTable.AS.createCall(s.end(e), e, new SqlNodeList(ids, s.end(e)));
}
)
)
]
{
return e;
Expand Down Expand Up @@ -4863,6 +4886,8 @@ SqlNode BuiltinFunctionCall() :
node = JsonTypeFunctionCall() { return node; }
|
node = JsonDepthFunctionCall() { return node; }
|
node = JsonLengthFunctionCall() { return node; }
|
node = JsonObjectAggFunctionCall() { return node; }
|
Expand Down Expand Up @@ -4958,21 +4983,32 @@ SqlNode JsonPathSpec() :
}
}

SqlNode JsonApiCommonSyntax() :
SqlNode JsonApiCommonSyntax(boolean acceptNonPath) :
{
SqlNode e;
List<SqlNode> args = new ArrayList<SqlNode>();
Span span;
SqlOperator op;
}
{
e = JsonValueExpression(true) {
args.add(e);
span = Span.of(e);
}
<COMMA>
e = Expression(ExprContext.ACCEPT_NON_QUERY) {
args.add(e);
}
(
<COMMA>
e = Expression(ExprContext.ACCEPT_NON_QUERY) {
op = SqlStdOperatorTable.JSON_API_COMMON_SYNTAX;
args.add(e);
}
|
{
if (!acceptNonPath) {
throw new ParseException(RESOURCE.jsonPathMustBeSpecified().str());
}
op = SqlStdOperatorTable.JSON_API_COMMON_SYNTAX_WITHOUT_PATH;
}
)
[
<PASSING> e = JsonValueExpression(false) {
args.add(e);
Expand All @@ -4991,9 +5027,8 @@ SqlNode JsonApiCommonSyntax() :
)*
]
{
return SqlStdOperatorTable.JSON_API_COMMON_SYNTAX.createCall(span.end(this), args);
return op.createCall(span.end(this), args);
}

}

SqlJsonExistsErrorBehavior JsonExistsErrorBehavior() :
Expand All @@ -5019,7 +5054,7 @@ SqlCall JsonExistsFunctionCall() :
}
{
<JSON_EXISTS> { span = span(); }
<LPAREN> e = JsonApiCommonSyntax() {
<LPAREN> e = JsonApiCommonSyntax(false) {
args = new ArrayList<SqlNode>();
args.add(e);
}
Expand Down Expand Up @@ -5076,7 +5111,7 @@ SqlCall JsonValueFunctionCall() :
}
{
<JSON_VALUE> { span = span(); }
<LPAREN> e = JsonApiCommonSyntax() {
<LPAREN> e = JsonApiCommonSyntax(false) {
args[0] = e;
}
[
Expand Down Expand Up @@ -5185,7 +5220,7 @@ SqlCall JsonQueryFunctionCall() :
}
{
<JSON_QUERY> { span = span(); }
<LPAREN> e = JsonApiCommonSyntax() {
<LPAREN> e = JsonApiCommonSyntax(false) {
args[0] = e;
}
[
Expand Down Expand Up @@ -5331,6 +5366,23 @@ SqlCall JsonDepthFunctionCall() :
}
}

SqlCall JsonLengthFunctionCall() :
{
final SqlNode[] args = new SqlNode[1];
SqlNode e;
final Span span;
List<SqlNode> behavior;
}
{
<JSON_LENGTH> { span = span(); }
<LPAREN> e = JsonApiCommonSyntax(true) {
args[0] = e;
}
<RPAREN> {
return SqlStdOperatorTable.JSON_LENGTH.createCall(span.end(this), args);
}
}

SqlCall JsonObjectAggFunctionCall() :
{
final SqlNode[] args = new SqlNode[2];
Expand Down Expand Up @@ -6408,6 +6460,7 @@ SqlPostfixOperator PostfixRowOperator() :
| < JSON_OBJECT: "JSON_OBJECT">
| < JSON_TYPE: "JSON_TYPE">
| < JSON_DEPTH: "JSON_DEPTH">
| < JSON_LENGTH: "JSON_LENGTH">
| < JSON_OBJECTAGG: "JSON_OBJECTAGG">
| < JSON_QUERY: "JSON_QUERY" >
| < K: "K" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ Expression generateComparator(
/** Converts an enumerable of this physical type to an enumerable that uses a
* given physical type for its rows.
*
* @deprecated As of 1.19, use {@link #convertTo(Expression, JavaRowFormat)}.
* @deprecated Use {@link #convertTo(Expression, JavaRowFormat)}.
* The use of PhysType as a second parameter is misleading since only the row
* format of the expression is affected by the conversion. Moreover it requires
* to have at hand a PhysType object which is not really necessary for achieving
* the desired result.*/
@Deprecated
* the desired result. */
@Deprecated // to be removed before 2.0
Expression convertTo(Expression expression, PhysType targetPhysType);

/** Converts an enumerable of this physical type to an enumerable that uses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public PhysType makeNullable(boolean nullable) {
Primitive.box(javaRowClass), format);
}

@SuppressWarnings("deprecation")
public Expression convertTo(Expression exp, PhysType targetPhysType) {
return convertTo(exp, targetPhysType.getFormat());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,12 @@
import static org.apache.calcite.sql.fun.SqlStdOperatorTable.IS_TRUE;
import static org.apache.calcite.sql.fun.SqlStdOperatorTable.ITEM;
import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_API_COMMON_SYNTAX;
import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_API_COMMON_SYNTAX_WITHOUT_PATH;
import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_ARRAY;
import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_ARRAYAGG;
import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_DEPTH;
import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_EXISTS;
import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_LENGTH;
import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_OBJECT;
import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_OBJECTAGG;
import static org.apache.calcite.sql.fun.SqlStdOperatorTable.JSON_PRETTY;
Expand Down Expand Up @@ -454,7 +456,9 @@ public Expression implement(RexToLixTranslator translator,
defineMethod(JSON_STRUCTURED_VALUE_EXPRESSION,
BuiltInMethod.JSON_STRUCTURED_VALUE_EXPRESSION.method, NullPolicy.STRICT);
defineMethod(JSON_API_COMMON_SYNTAX, BuiltInMethod.JSON_API_COMMON_SYNTAX.method,
NullPolicy.NONE);
NullPolicy.NONE);
defineMethod(JSON_API_COMMON_SYNTAX_WITHOUT_PATH,
BuiltInMethod.JSON_API_COMMON_SYNTAX_WITHOUT_PATH.method, NullPolicy.NONE);
defineMethod(JSON_EXISTS, BuiltInMethod.JSON_EXISTS.method, NullPolicy.NONE);
defineMethod(JSON_VALUE_ANY, BuiltInMethod.JSON_VALUE_ANY.method, NullPolicy.NONE);
defineMethod(JSON_QUERY, BuiltInMethod.JSON_QUERY.method, NullPolicy.NONE);
Expand All @@ -463,6 +467,7 @@ public Expression implement(RexToLixTranslator translator,
defineMethod(JSON_TYPE, BuiltInMethod.JSON_TYPE.method, NullPolicy.NONE);
defineMethod(JSON_DEPTH, BuiltInMethod.JSON_DEPTH.method, NullPolicy.NONE);
defineMethod(JSON_PRETTY, BuiltInMethod.JSON_PRETTY.method, NullPolicy.NONE);
defineMethod(JSON_LENGTH, BuiltInMethod.JSON_LENGTH.method, NullPolicy.NONE);
aggMap.put(JSON_OBJECTAGG.with(SqlJsonConstructorNullClause.ABSENT_ON_NULL),
JsonObjectAggImplementor
.supplierFor(BuiltInMethod.JSON_OBJECTAGG_ADD.method));
Expand Down
11 changes: 1 addition & 10 deletions core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3014,16 +3014,7 @@ public RexNode get(int index) {
return relBuilder.getRexBuilder().makeInputRef(child, pos);
}
};
final List<String> names = new AbstractList<String>() {
public int size() {
return posList.size();
}

public String get(int index) {
final int pos = posList.get(index);
return fieldNames.get(pos);
}
};
final List<String> names = Util.select(fieldNames, posList);
return relBuilder
.push(child)
.projectNamed(exprs, names, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ void addMatch(VolcanoRuleMatch match) {
*
* <ul>
* <li>the root {@link RelSubset} has an importance of 1</li>
* <li>the importance of any other subset is the sum of its importance to
* <li>the importance of any other subset is the max of its importance to
* its parents</li>
* <li>The importance of children is pro-rated according to the cost of the
* children. Consider a node which has a cost of 3, and children with costs
Expand All @@ -368,7 +368,7 @@ void addMatch(VolcanoRuleMatch match) {
*
* <p>The formula for the importance <i>I</i> of node n is:
*
* <blockquote>I<sub>n</sub> = Sum<sub>parents p of n</sub>{I<sub>p</sub> .
* <blockquote>I<sub>n</sub> = Max<sub>parents p of n</sub>{I<sub>p</sub> .
* W <sub>n, p</sub>}</blockquote>
*
* <p>where W<sub>n, p</sub>, the weight of n within its parent p, is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public class CalcitePrepareImpl implements CalcitePrepare {
ReduceExpressionsRule.PROJECT_INSTANCE,
ReduceExpressionsRule.FILTER_INSTANCE,
ReduceExpressionsRule.CALC_INSTANCE,
ReduceExpressionsRule.WINDOW_INSTANCE,
ReduceExpressionsRule.JOIN_INSTANCE,
ValuesReduceRule.FILTER_INSTANCE,
ValuesReduceRule.PROJECT_FILTER_INSTANCE,
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/apache/calcite/rel/RelCollations.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public static RelCollation permute(RelCollation collation,
Map<Integer, Integer> mapping) {
return of(
Util.transform(collation.getFieldCollations(),
fc -> fc.copy(mapping.get(fc.getFieldIndex()))));
fc -> fc.withFieldIndex(mapping.get(fc.getFieldIndex()))));
}

/** Creates a copy of this collation that changes the ordinals of input
Expand All @@ -204,7 +204,7 @@ public static RelCollation permute(RelCollation collation,
Mappings.TargetMapping mapping) {
return of(
Util.transform(collation.getFieldCollations(),
fc -> fc.copy(mapping.getTarget(fc.getFieldIndex()))));
fc -> fc.withFieldIndex(mapping.getTarget(fc.getFieldIndex()))));
}
}

Expand Down
29 changes: 23 additions & 6 deletions core/src/main/java/org/apache/calcite/rel/RelFieldCollation.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.calcite.sql.validate.SqlMonotonicity;

import java.util.Objects;
import javax.annotation.Nonnull;

/**
* Definition of the ordering of one field of a {@link RelNode} whose
Expand Down Expand Up @@ -125,7 +126,7 @@ public static Direction of(SqlMonotonicity monotonicity) {

/** Returns the null direction if not specified. Consistent with Oracle,
* NULLS are sorted as if they were positive infinity. */
public NullDirection defaultNullDirection() {
public @Nonnull NullDirection defaultNullDirection() {
switch (this) {
case ASCENDING:
case STRICTLY_ASCENDING:
Expand Down Expand Up @@ -216,19 +217,35 @@ public RelFieldCollation(
/**
* Creates a copy of this RelFieldCollation against a different field.
*/
public RelFieldCollation withFieldIndex(int fieldIndex) {
return this.fieldIndex == fieldIndex ? this
: new RelFieldCollation(fieldIndex, direction, nullDirection);
}

@Deprecated // to be removed before 2.0
public RelFieldCollation copy(int target) {
if (target == fieldIndex) {
return this;
}
return new RelFieldCollation(target, direction, nullDirection);
return withFieldIndex(target);
}

/** Creates a copy of this RelFieldCollation with a different direction. */
public RelFieldCollation withDirection(Direction direction) {
return this.direction == direction ? this
: new RelFieldCollation(fieldIndex, direction, nullDirection);
}

/** Creates a copy of this RelFieldCollation with a different null
* direction. */
public RelFieldCollation withNullDirection(NullDirection nullDirection) {
return this.nullDirection == nullDirection ? this
: new RelFieldCollation(fieldIndex, direction, nullDirection);
}

/**
* Returns a copy of this RelFieldCollation with the field index shifted
* {@code offset} to the right.
*/
public RelFieldCollation shift(int offset) {
return copy(fieldIndex + offset);
return withFieldIndex(fieldIndex + offset);
}

@Override public boolean equals(Object o) {
Expand Down
Loading

0 comments on commit 8d17df4

Please sign in to comment.