Skip to content

Commit f0860b5

Browse files
authored
YQ-3848 RD support mod pushdown (#11543)
1 parent 70ca966 commit f0860b5

File tree

6 files changed

+18
-3
lines changed

6 files changed

+18
-3
lines changed

ydb/library/yql/providers/common/pushdown/collection.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ bool CheckExpressionNodeForPushdown(const TExprBase& node, const TExprNode* lamb
360360
} else if (const auto op = node.Maybe<TCoUnaryArithmetic>(); op && settings.IsEnabled(TSettings::EFeatureFlag::UnaryOperators)) {
361361
return CheckExpressionNodeForPushdown(op.Cast().Arg(), lambdaArg, settings);
362362
} else if (const auto op = node.Maybe<TCoBinaryArithmetic>(); op && settings.IsEnabled(TSettings::EFeatureFlag::ArithmeticalExpressions)) {
363+
if (!settings.IsEnabled(TSettings::EFeatureFlag::DivisionExpressions) && (op.Maybe<TCoDiv>() || op.Maybe<TCoMod>())) {
364+
return false;
365+
}
363366
return CheckExpressionNodeForPushdown(op.Cast().Left(), lambdaArg, settings) && CheckExpressionNodeForPushdown(op.Cast().Right(), lambdaArg, settings);
364367
}
365368
return false;

ydb/library/yql/providers/common/pushdown/settings.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ struct TSettings {
2828
JustPassthroughOperators = 1 << 18, // if + coalesce + just
2929
InOperator = 1 << 19, // IN()
3030
IsDistinctOperator = 1 << 20, // IS NOT DISTINCT FROM / IS DISTINCT FROM
31+
DivisionExpressions = 1 << 21, // %, / -- NOTE: division by zero is not handled and also pushdown
3132

3233
// Option which enables partial pushdown for sequence of OR
3334
// For example next predicate:
3435
// ($A AND $B) OR ($C AND $D)
3536
// May be partially pushdowned as:
3637
// $A OR $C
3738
// In case of unsupported / complicated expressions $B and $D
38-
SplitOrOperator = 1 << 21
39+
SplitOrOperator = 1 << 22
3940
};
4041

4142
explicit TSettings(NLog::EComponent logComponent)

ydb/library/yql/providers/generic/connector/api/service/protos/connector.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,11 @@ message TExpression {
327327
MUL = 1; // left_value * right_value
328328
ADD = 2; // left_value + right_value
329329
SUB = 3; // left_value - right_value
330+
DIV = 7; // left_value / right_value
331+
MOD = 8; // left_value % right_value
330332
BIT_AND = 4; // left_value & right_value
331333
BIT_OR = 5; // left_value | right_value
332334
BIT_XOR = 6; // left_value ^ right_value
333-
// TODO: support `/` and `%`
334335
}
335336
EOperation operation = 1;
336337
TExpression left_value = 2;

ydb/library/yql/providers/generic/provider/yql_generic_predicate_pushdown.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ namespace NYql {
8686
MATCH_ARITHMETICAL(Sub, SUB);
8787
MATCH_ARITHMETICAL(Add, ADD);
8888
MATCH_ARITHMETICAL(Mul, MUL);
89+
MATCH_ARITHMETICAL(Div, DIV);
90+
MATCH_ARITHMETICAL(Mod, MOD);
8991

9092
if (auto maybeNull = expression.Maybe<TCoNull>()) {
9193
proto->mutable_null();
@@ -342,6 +344,12 @@ namespace NYql {
342344
case TExpression_TArithmeticalExpression::SUB:
343345
operation = " - ";
344346
break;
347+
case TExpression_TArithmeticalExpression::DIV:
348+
operation = " / ";
349+
break;
350+
case TExpression_TArithmeticalExpression::MOD:
351+
operation = " % ";
352+
break;
345353
case TExpression_TArithmeticalExpression::BIT_AND:
346354
operation = " & ";
347355
break;

ydb/library/yql/providers/pq/provider/yql_pq_logical_opt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace {
3434
// Operator features
3535
EFlag::ExpressionAsPredicate | EFlag::ArithmeticalExpressions | EFlag::ImplicitConversionToInt64 |
3636
EFlag::StringTypes | EFlag::LikeOperator | EFlag::DoNotCheckCompareArgumentsTypes | EFlag::InOperator |
37-
EFlag::IsDistinctOperator | EFlag::JustPassthroughOperators |
37+
EFlag::IsDistinctOperator | EFlag::JustPassthroughOperators | DivisionExpressions |
3838

3939
// Split features
4040
EFlag::SplitOrOperator

ydb/tests/fq/yds/test_row_dispatcher.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ def test_filters_optional_field(self, kikimr, client):
351351
self.run_and_check(kikimr, client, sql + filter, data, expected, 'predicate: WHERE `flag`')
352352
filter = 'time * (field2 - field1) != 0'
353353
self.run_and_check(kikimr, client, sql + filter, data, expected, 'predicate: WHERE (`time` * (`field2` - `field1`)) <> 0')
354+
filter = '(field1 % field2) / 5 = 1'
355+
self.run_and_check(kikimr, client, sql + filter, data, expected, 'predicate: WHERE ((`field1` % `field2`) / 5) = 1')
354356
filter = ' event IS NOT DISTINCT FROM "event2"'
355357
self.run_and_check(kikimr, client, sql + filter, data, expected, 'predicate: WHERE `event` IS NOT DISTINCT FROM \\"event2\\"')
356358
filter = ' event IS DISTINCT FROM "event1"'

0 commit comments

Comments
 (0)