Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/calcite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

<!-- Module specific package versions -->
<properties>
<avatica.version>1.26.0</avatica.version>
<calcite.version>1.40.0</calcite.version>
<avatica.version>1.28.0</avatica.version>
<calcite.version>1.42.0</calcite.version>
<failureaccess.version>1.0.1</failureaccess.version>
<immutables.version>2.8.2</immutables.version>
<janino.version>3.1.12</janino.version>
Expand Down
1 change: 1 addition & 0 deletions modules/calcite/src/main/codegen/config.fmpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ data: {
"UESCAPE"
"UNIQUE"
"UNKNOWN"
"UNSIGNED"
"UPPER"
"UPSERT"
"UUID"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import com.google.common.collect.ImmutableList;
import org.apache.calcite.rel.RelCollation;
import org.apache.calcite.rel.RelFieldCollation;
import org.apache.calcite.rel.RelNode;
Expand Down Expand Up @@ -85,7 +86,6 @@
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteIndexBound;
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteIndexCount;
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteIndexScan;
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteJoinInfo;
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteLimit;
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteMergeJoin;
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteNestedLoopJoin;
Expand Down Expand Up @@ -282,8 +282,6 @@ public LogicalRelImplementor(
RelDataType rightType = rel.getRight().getRowType();
JoinRelType joinType = rel.getJoinType();

IgniteJoinInfo joinInfo = IgniteJoinInfo.of(rel);

RexNode nonEquiConditionExpression = RexUtil.composeConjunction(Commons.emptyCluster().getRexBuilder(),
rel.analyzeCondition().nonEquiConditions, true);

Expand All @@ -295,7 +293,7 @@ public LogicalRelImplementor(
nonEquiCondition = expressionFactory.biPredicate(rel.getCondition(), rowType);
}

Node<Row> node = HashJoinNode.create(ctx, outType, leftType, rightType, joinType, joinInfo,
Node<Row> node = HashJoinNode.create(ctx, outType, leftType, rightType, joinType, rel.analyzeCondition(),
nonEquiCondition);

node.register(Arrays.asList(visit(rel.getLeft()), visit(rel.getRight())));
Expand Down Expand Up @@ -339,23 +337,23 @@ public LogicalRelImplementor(
List<RelFieldCollation> leftCollations = rel.leftCollation().getFieldCollations();
List<RelFieldCollation> rightCollations = rel.rightCollation().getFieldCollations();

ImmutableBitSet allowNulls = rel.allowNulls();
ImmutableBitSet.Builder collsAllowNullsBuilder = ImmutableBitSet.builder();
ImmutableList<Boolean> nullExclusions = rel.analyzeCondition().nullExclusionFlags;
ImmutableBitSet.Builder nullCompAsEqual = ImmutableBitSet.builder();
int lastCollField = -1;

for (int c = 0; c < Math.min(leftCollations.size(), rightCollations.size()); ++c) {
RelFieldCollation leftColl = leftCollations.get(c);
RelFieldCollation rightColl = rightCollations.get(c);
collsAllowNullsBuilder.set(c);
nullCompAsEqual.set(c);

for (int p = 0; p < pairsCnt; ++p) {
IntPair pair = joinPairs.get(p);

if (pair.source == leftColl.getFieldIndex() && pair.target == rightColl.getFieldIndex()) {
lastCollField = c;

if (!allowNulls.get(p)) {
collsAllowNullsBuilder.clear(c);
if (!nullExclusions.get(p)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullExclusions and allowNulls have inverse logic, why here not allowNulls changed to not null exclusion? Shouldn't we remove not?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, i understand what you mean, "not" is changed in comparator implementation side, or if you about namings - let`s discuss it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean logic is changed here. allowNulls.get(p) == !nullExclusions.get(p), but here both collection items processed as not

nullCompAsEqual.clear(c);

break;
}
Expand All @@ -366,7 +364,7 @@ public LogicalRelImplementor(
Comparator<Row> comp = expressionFactory.comparator(
leftCollations.subList(0, lastCollField + 1),
rightCollations.subList(0, lastCollField + 1),
collsAllowNullsBuilder.build()
nullCompAsEqual.build()
);

Node<Row> node = MergeJoinNode.create(ctx, outType, leftType, rightType, joinType, comp, hasExchange(rel));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ else if (c2 != HIGHEST_VALUE)
@Override public Comparator<Row> comparator(
List<RelFieldCollation> left,
List<RelFieldCollation> right,
ImmutableBitSet allowNulls
ImmutableBitSet nullExclusions
) {
if (F.isEmpty(left) || F.isEmpty(right) || left.size() != right.size())
throw new IllegalArgumentException("Both inputs should be non-empty and have the same size: left="
Expand Down Expand Up @@ -232,7 +232,7 @@ else if (c2 != HIGHEST_VALUE)
Object c2 = hnd.get(rIdx, o2);

if (c1 == null && c2 == null && !hasNulls) {
hasNulls = !allowNulls.get(i);
hasNulls = nullExclusions.get(i);

continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public class IgniteExpressions {
/** Make binary expression with arithmetic operations override. */
public static Expression makeBinary(ExpressionType binaryType, Expression left, Expression right) {
switch (binaryType) {
case Add:
case Add, AddChecked:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return addExact(left, right);
case Subtract:
case Subtract, SubtractChecked:
return subtractExact(left, right);
case Multiply:
case Multiply, MultiplyChecked:
return multiplyExact(left, right);
case Divide:
case Divide, DivideChecked:
return divideExact(left, right);
default:
return Expressions.makeBinary(binaryType, left, right);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,21 @@
import static java.util.Objects.requireNonNull;
import static org.apache.calcite.adapter.enumerable.EnumUtils.generateCollatorExpression;
import static org.apache.calcite.linq4j.tree.ExpressionType.Add;
import static org.apache.calcite.linq4j.tree.ExpressionType.AddChecked;
import static org.apache.calcite.linq4j.tree.ExpressionType.Divide;
import static org.apache.calcite.linq4j.tree.ExpressionType.DivideChecked;
import static org.apache.calcite.linq4j.tree.ExpressionType.Equal;
import static org.apache.calcite.linq4j.tree.ExpressionType.GreaterThan;
import static org.apache.calcite.linq4j.tree.ExpressionType.GreaterThanOrEqual;
import static org.apache.calcite.linq4j.tree.ExpressionType.LessThan;
import static org.apache.calcite.linq4j.tree.ExpressionType.LessThanOrEqual;
import static org.apache.calcite.linq4j.tree.ExpressionType.Multiply;
import static org.apache.calcite.linq4j.tree.ExpressionType.MultiplyChecked;
import static org.apache.calcite.linq4j.tree.ExpressionType.Negate;
import static org.apache.calcite.linq4j.tree.ExpressionType.NegateChecked;
import static org.apache.calcite.linq4j.tree.ExpressionType.NotEqual;
import static org.apache.calcite.linq4j.tree.ExpressionType.Subtract;
import static org.apache.calcite.linq4j.tree.ExpressionType.SubtractChecked;
import static org.apache.calcite.linq4j.tree.ExpressionType.UnaryPlus;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.ACOSH;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.ASINH;
Expand Down Expand Up @@ -162,6 +167,7 @@
import static org.apache.calcite.sql.fun.SqlStdOperatorTable.CEIL;
import static org.apache.calcite.sql.fun.SqlStdOperatorTable.CHAR_LENGTH;
import static org.apache.calcite.sql.fun.SqlStdOperatorTable.CHECKED_DIVIDE;
import static org.apache.calcite.sql.fun.SqlStdOperatorTable.CHECKED_DIVIDE_INTEGER;
import static org.apache.calcite.sql.fun.SqlStdOperatorTable.CHECKED_MINUS;
import static org.apache.calcite.sql.fun.SqlStdOperatorTable.CHECKED_MULTIPLY;
import static org.apache.calcite.sql.fun.SqlStdOperatorTable.CHECKED_PLUS;
Expand Down Expand Up @@ -344,6 +350,13 @@ public class RexImpTable {
defineUnary(UNARY_MINUS, Negate, NullPolicy.STRICT,
BuiltInMethod.BIG_DECIMAL_NEGATE.getMethodName());
defineUnary(UNARY_PLUS, UnaryPlus, NullPolicy.STRICT, null);
// checked arithmetic
defineBinary(CHECKED_PLUS, AddChecked, NullPolicy.STRICT, "checkedPlus");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

due to categorical CHECED type without conformance flag check
https://issues.apache.org/jira/browse/CALCITE-7443

defineBinary(CHECKED_MINUS, SubtractChecked, NullPolicy.STRICT, "checkedMinus");
defineBinary(CHECKED_MULTIPLY, MultiplyChecked, NullPolicy.STRICT, "checkedMultiply");
defineBinary(CHECKED_DIVIDE, DivideChecked, NullPolicy.STRICT, "checkedDivide");
defineBinary(CHECKED_DIVIDE_INTEGER, DivideChecked, NullPolicy.STRICT, "checkedDivide");
defineUnary(CHECKED_UNARY_MINUS, NegateChecked, NullPolicy.STRICT, "checkedUnaryMinus");

defineMethod(MOD, "mod", NullPolicy.STRICT);
defineMethod(EXP, "exp", NullPolicy.STRICT);
Expand Down Expand Up @@ -1227,7 +1240,7 @@ private static class BinaryImplementor extends AbstractRexCallImplementor {
@Override Expression implementSafe(
final RexToLixTranslator translator,
final RexCall call,
final List<Expression> argValueList) {
List<Expression> argValueList) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it still final, why final was removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it`s not a final on apache calcite

// neither nullable:
// return x OP y
// x nullable
Expand All @@ -1243,7 +1256,7 @@ private static class BinaryImplementor extends AbstractRexCallImplementor {
// If one or both operands have ANY type, use the late-binding backup
// method.
if (anyAnyOperands(call))
return callBackupMethodAnyType(translator, call, argValueList);
return callBackupMethodAnyType(argValueList);

final Type type0 = argValueList.get(0).getType();
final Type type1 = argValueList.get(1).getType();
Expand Down Expand Up @@ -1272,10 +1285,6 @@ private static class BinaryImplementor extends AbstractRexCallImplementor {
argValueList);
}

// For checked arithmetic call the method.
if (CHECKED_OPERATORS.contains(op))
return Expressions.call(SqlFunctions.class, backupMethodName, argValueList);

return IgniteExpressions.makeBinary(expressionType,
argValueList.get(0), argValueList.get(1));
}
Expand All @@ -1290,8 +1299,7 @@ private boolean anyAnyOperands(RexCall call) {
}

/** */
private Expression callBackupMethodAnyType(RexToLixTranslator translator,
RexCall call, List<Expression> expressions) {
private Expression callBackupMethodAnyType(List<Expression> expressions) {
final String backupMethodNameForAnyType =
backupMethodName + METHOD_POSTFIX_FOR_ANY_TYPE;

Expand Down Expand Up @@ -1343,6 +1351,8 @@ private static class UnaryImplementor extends AbstractRexCallImplementor {
if (expressionType == ExpressionType.Negate && argVal.type == BigDecimal.class
&& null != backupMethodName)
e = Expressions.call(argVal, backupMethodName);
else if (expressionType == NegateChecked && null != backupMethodName)
e = Expressions.call(SqlFunctions.class, backupMethodName, argValueList);
else
e = IgniteExpressions.makeUnary(expressionType, argVal);

Expand Down Expand Up @@ -1562,12 +1572,15 @@ private static class CastImplementor extends AbstractRexCallImplementor {
/** {@inheritDoc} */
@Override Expression implementSafe(final RexToLixTranslator translator,
final RexCall call, final List<Expression> argValueList) {
assert call.getOperands().size() == 1;
assert call.operandCount() <= 2;
final RelDataType srcType = call.getOperands().get(0).getType();

// Short-circuit if no cast is required
RexNode arg = call.getOperands().get(0);
if (call.getType().equals(srcType)) {

// Short-circuit if no cast is required
if (call.getType().equals(srcType)
// However, do not elide casts to decimal types, they perform bounds checking
&& srcType.getSqlTypeName() != SqlTypeName.DECIMAL) {
// No cast required, omit cast
return argValueList.get(0);
}
Expand All @@ -1588,10 +1601,11 @@ private static class CastImplementor extends AbstractRexCallImplementor {
private RelDataType nullifyType(JavaTypeFactory typeFactory,
final RelDataType type, final boolean nullable) {
if (type instanceof RelDataTypeFactoryImpl.JavaType) {
final Primitive primitive = Primitive.ofBox(
((RelDataTypeFactoryImpl.JavaType)type).getJavaClass());
if (primitive != null)
return typeFactory.createJavaType(primitive.primitiveClass);
Class<?> javaCls = ((RelDataTypeFactoryImpl.JavaType)type).getJavaClass();
final Class<?> primitive = Primitive.unbox(javaCls);
if (primitive != javaCls) {
return typeFactory.createJavaType(primitive);
}
}
return typeFactory.createTypeWithNullability(type, nullable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.apache.calcite.rex.RexLiteral;
import org.apache.calcite.rex.RexLocalRef;
import org.apache.calcite.rex.RexNode;
import org.apache.calcite.rex.RexNodeAndFieldIndex;
import org.apache.calcite.rex.RexOver;
import org.apache.calcite.rex.RexPatternFieldRef;
import org.apache.calcite.rex.RexProgram;
Expand Down Expand Up @@ -1343,6 +1344,12 @@ private Result toInnerStorageType(final Result result, final Type storageType) {
return new Result(isNullVariable, valVariable);
}

/** */
@Override public Result visitNodeAndFieldIndex(
RexNodeAndFieldIndex nodeAndFieldIndex) {
throw new RuntimeException("cannot translate expression " + nodeAndFieldIndex);
}

/** */
Expression checkNull(Expression expr) {
if (Primitive.flavor(expr.getType()) == Primitive.Flavor.PRIMITIVE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.ignite.internal.processors.query.calcite.exec.exp.agg;

import java.util.Objects;
import org.apache.calcite.util.ImmutableBitSet;
import com.google.common.collect.ImmutableList;
import org.apache.ignite.binary.BinaryObjectException;
import org.apache.ignite.binary.BinaryRawReader;
import org.apache.ignite.binary.BinaryRawWriter;
Expand Down Expand Up @@ -120,7 +120,7 @@ public RowHandler<Row> rowHandler() {
*/
public static <Row> @Nullable GroupKey<Row> of(Row r, RowHandler<Row> hnd, boolean allowNulls) {
if (!allowNulls)
return of(r, hnd, ImmutableBitSet.of());
return of(r, hnd, ImmutableList.of());

return new GroupKey<>(r, hnd);
}
Expand All @@ -129,9 +129,9 @@ public RowHandler<Row> rowHandler() {
* @return Group key for provided row. Can be {@code null} if key fields of row contain NULL values and nulls are
* not allowed for these columns.
*/
public static <Row> @Nullable GroupKey<Row> of(Row r, RowHandler<Row> hnd, ImmutableBitSet allowNulls) {
public static <Row> @Nullable GroupKey<Row> of(Row r, RowHandler<Row> hnd, ImmutableList<Boolean> nullExclusions) {
for (int i = 0; i < hnd.columnCount(r); i++) {
if (hnd.get(i, r) == null && !allowNulls.get(i))
if (hnd.get(i, r) == null && (i >= nullExclusions.size() || nullExclusions.get(i)))
return null;
}

Expand Down
Loading
Loading