aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorivanmorozov <ivanmorozov@yandex-team.com>2023-01-25 15:46:03 +0300
committerivanmorozov <ivanmorozov@yandex-team.com>2023-01-25 15:46:03 +0300
commit5f0b2322355dab51c50246070586eec0fb00671c (patch)
tree95600bda8b1394655cf30875ffb7290ae5386a73
parent809ca6e81245ec987e443da796da7100555be599 (diff)
downloadydb-5f0b2322355dab51c50246070586eec0fb00671c.tar.gz
Merged revision(s) 10732152 from trunk/arcadia/ydb/library/yql:
correct avg in yql RE VIEW: 3363901 ........ revert Note: mandatory check (NEED_CHECK) was skipped
-rw-r--r--ydb/library/yql/core/peephole_opt/yql_opt_peephole_physical.cpp2
-rw-r--r--ydb/library/yql/mount/lib/yql/aggregate.yql30
-rw-r--r--ydb/library/yql/mount/lib/yql/window.yql16
3 files changed, 24 insertions, 24 deletions
diff --git a/ydb/library/yql/core/peephole_opt/yql_opt_peephole_physical.cpp b/ydb/library/yql/core/peephole_opt/yql_opt_peephole_physical.cpp
index c37e13ccf2..24ad460afe 100644
--- a/ydb/library/yql/core/peephole_opt/yql_opt_peephole_physical.cpp
+++ b/ydb/library/yql/core/peephole_opt/yql_opt_peephole_physical.cpp
@@ -4531,7 +4531,7 @@ TExprNode::TPtr OptimizeWideCombiner(const TExprNode::TPtr& node, TExprContext&
tupleExpandMap.resize(originalStateSize);
structExpandMap.resize(originalStateSize);
- const auto needStateFlatten = GetExpandMapsForLambda<false>(*node->Child(3U), tupleExpandMap, structExpandMap);
+ const auto needStateFlatten = GetExpandMapsForLambda<true>(*node->Child(3U), tupleExpandMap, structExpandMap);
if (needStateFlatten.front()) {
const auto flattenSize = *needStateFlatten.front();
diff --git a/ydb/library/yql/mount/lib/yql/aggregate.yql b/ydb/library/yql/mount/lib/yql/aggregate.yql
index 4b368d8d3f..d0ea4e1c98 100644
--- a/ydb/library/yql/mount/lib/yql/aggregate.yql
+++ b/ydb/library/yql/mount/lib/yql/aggregate.yql
@@ -44,10 +44,10 @@
# list_type:type init:lambda
# doesn't support optional values
(let count_traits_factory (lambda '(list_type init) (block '(
- (let update (lambda '(value state) (AggrAdd state (Apply init value))))
+ (let update (lambda '(value state) (+ state (Apply init value))))
(let save (lambda '(state) state))
(let load (lambda '(state) state))
- (let merge (lambda '(state1 state2) (AggrAdd state1 state2)))
+ (let merge (lambda '(state1 state2) (+ state1 state2)))
(let finish (lambda '(state) state))
(return (AggregationTraits (ListItemType list_type) init update save load merge finish (Uint64 '0)))
))))
@@ -59,7 +59,7 @@
(let update (lambda '(value state) (AggrCountUpdate value state)))
(let save (lambda '(state) state))
(let load (lambda '(state) state))
- (let merge (lambda '(state1 state2) (AggrAdd state1 state2)))
+ (let merge (lambda '(state1 state2) (+ state1 state2)))
(let finish (lambda '(state) state))
(return (AggregationTraits (ListItemType list_type) init update save load merge finish (Uint64 '0)))
))))
@@ -79,14 +79,14 @@
'Interval (lambda '() (Apply convert_interval_to_decimal value ))
(lambda '() (Convert value 'Double))
) (Uint64 '1))))
- (let update (lambda '(value state) '((AggrAdd (Nth state '0) (MatchType (TypeOf value)
+ (let update (lambda '(value state) '((+ (Nth state '0) (MatchType (TypeOf value)
'Decimal (lambda '() (WidenIntegral value))
'Interval (lambda '() (Apply convert_interval_to_decimal value ))
(lambda '() (Convert value 'Double)))
) (Inc (Nth state '1)))))
(let save (lambda '(state) state))
(let load (lambda '(state) state))
- (let merge (lambda '(state1 state2) '((AggrAdd (Nth state1 '0) (Nth state2 '0)) (AggrAdd (Nth state1 '1) (Nth state2 '1)))))
+ (let merge (lambda '(state1 state2) '((+ (Nth state1 '0) (Nth state2 '0)) (+ (Nth state1 '1) (Nth state2 '1)))))
(let finish (lambda '(state)
(MatchType (ListItemType list_type)
'Decimal
@@ -147,21 +147,21 @@
(Double '0))))
(let update (lambda '(value state) (block '(
(let delta (- (Convert value 'Double) (Nth state '0)))
- (let next_n (AggrAdd (Nth state '1) (Double '1)))
+ (let next_n (+ (Nth state '1) (Double '1)))
(return '(
- (AggrAdd (Nth state '0) (/ delta next_n))
+ (+ (Nth state '0) (/ delta next_n))
next_n
- (AggrAdd (Nth state '2) (/ (* (* delta delta) (Nth state '1)) next_n))
+ (+ (Nth state '2) (/ (* (* delta delta) (Nth state '1)) next_n))
))))))
(let save (lambda '(state) state))
(let load (lambda '(state) state))
(let merge (lambda '(one two) (block '(
(let delta (- (Nth one '0) (Nth two '0)))
- (let sum_n (AggrAdd (Nth one '1) (Nth two '1)))
+ (let sum_n (+ (Nth one '1) (Nth two '1)))
(return '(
- (/ (AggrAdd (* (Nth one '0) (Nth one '1)) (* (Nth two '0) (Nth two '1))) sum_n)
+ (/ (+ (* (Nth one '0) (Nth one '1)) (* (Nth two '0) (Nth two '1))) sum_n)
sum_n
- (AggrAdd (AggrAdd (Nth one '2) (Nth two '2)) (/ (* (* (* delta delta) (Nth one '1)) (Nth two '1)) sum_n))
+ (+ (+ (Nth one '2) (Nth two '2)) (/ (* (* (* delta delta) (Nth one '1)) (Nth two '1)) sum_n))
)
)))))
(let finish (lambda '(state) (block '(
@@ -182,10 +182,10 @@
# doesn't support optional values
(let correlation_traits_factory_raw (lambda '(list_type) (block '(
(let init (lambda '(value) '((Uint64 '1) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0))) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0))) (* (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0))))))
- (let update (lambda '(value state) '((AggrAdd (Nth state '0) (Uint64 '1)) (AggrAdd (Nth state '1) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0))) (AggrAdd (Nth state '2) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0))) (AggrAdd (Nth state '3) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)))) (AggrAdd (Nth state '4) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)))) (AggrAdd (Nth state '5) (* (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)))))))
+ (let update (lambda '(value state) '((+ (Nth state '0) (Uint64 '1)) (+ (Nth state '1) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0))) (+ (Nth state '2) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0))) (+ (Nth state '3) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)))) (+ (Nth state '4) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)))) (+ (Nth state '5) (* (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)))))))
(let save (lambda '(state) state))
(let load (lambda '(state) state))
- (let merge (lambda '(one two) '((AggrAdd (Nth one '0) (Nth two '0)) (AggrAdd (Nth one '1) (Nth two '1)) (AggrAdd (Nth one '2) (Nth two '2)) (AggrAdd (Nth one '3) (Nth two '3)) (AggrAdd (Nth one '4) (Nth two '4)) (AggrAdd (Nth one '5) (Nth two '5)))))
+ (let merge (lambda '(one two) '((+ (Nth one '0) (Nth two '0)) (+ (Nth one '1) (Nth two '1)) (+ (Nth one '2) (Nth two '2)) (+ (Nth one '3) (Nth two '3)) (+ (Nth one '4) (Nth two '4)) (+ (Nth one '5) (Nth two '5)))))
(let finish (lambda '(state) (block '(
# Math comes from ISO9075-2:2011(E) and differs from what Excel uses
(let dividend (* (Nth state '3) (Nth state '0)))
@@ -203,10 +203,10 @@
# doesn't support optional values
(let covariance_traits_factory_raw (lambda '(list_type sample) (block '(
(let init (lambda '(value) '((Uint64 '1) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0))))))
- (let update (lambda '(value state) '((AggrAdd (Nth state '0) (Uint64 '1)) (AggrAdd (Nth state '1) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0))) (AggrAdd (Nth state '2) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0))) (AggrAdd (Nth state '3) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)))))))
+ (let update (lambda '(value state) '((+ (Nth state '0) (Uint64 '1)) (+ (Nth state '1) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0))) (+ (Nth state '2) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0))) (+ (Nth state '3) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)))))))
(let save (lambda '(state) state))
(let load (lambda '(state) state))
- (let merge (lambda '(one two) '((AggrAdd (Nth one '0) (Nth two '0)) (AggrAdd (Nth one '1) (Nth two '1)) (AggrAdd (Nth one '2) (Nth two '2)) (AggrAdd (Nth one '3) (Nth two '3)))))
+ (let merge (lambda '(one two) '((+ (Nth one '0) (Nth two '0)) (+ (Nth one '1) (Nth two '1)) (+ (Nth one '2) (Nth two '2)) (+ (Nth one '3) (Nth two '3)))))
(let finish (lambda '(state) (block '(
(let covariance_result (- (Nth state '3) (/ (* (Nth state '1) (Nth state '2)) (Nth state '0))))
(let covariance_result (/ covariance_result (If sample (- (Nth state '0) (Uint64 '1)) (Nth state '0))))
diff --git a/ydb/library/yql/mount/lib/yql/window.yql b/ydb/library/yql/mount/lib/yql/window.yql
index b75031f5bf..6a24834e64 100644
--- a/ydb/library/yql/mount/lib/yql/window.yql
+++ b/ydb/library/yql/mount/lib/yql/window.yql
@@ -91,8 +91,8 @@
# list_type:type init:lambda
# doesn't support optional values
(let count_traits_factory (lambda '(list_type init) (block '(
- (let update (lambda '(value state) (AggrAdd state (Apply init value))))
- (let shift (lambda '(value state) (AggrAdd state (Minus (Apply init value)))))
+ (let update (lambda '(value state) (+ state (Apply init value))))
+ (let shift (lambda '(value state) (+ state (Minus (Apply init value)))))
(let current (lambda '(state) state))
(return (WindowTraits (ListItemType list_type) init update shift current (Uint64 '0)))
))))
@@ -118,7 +118,7 @@
(let convert_interval_to_decimal (lambda '(value) (StrictCast (StrictCast value (DataType 'Int64)) (DataType 'Decimal '35 '0))))
(let convert_decimal_to_interval (lambda '(value) (Unwrap (StrictCast (StrictCast value (DataType 'Int64)) (DataType 'Interval)))))
(let init (lambda '(value) '((MatchType (TypeOf value) 'Decimal (lambda '() (WidenIntegral value)) 'Interval (lambda '() (Apply convert_interval_to_decimal value )) (lambda '() (Convert value 'Double))) (Uint64 '1))))
- (let update (lambda '(value state) '((AggrAdd (Nth state '0) (MatchType (TypeOf value) 'Decimal (lambda '() (WidenIntegral value)) 'Interval (lambda '() (Apply convert_interval_to_decimal value )) (lambda '() (Convert value 'Double)))) (Inc (Nth state '1)))))
+ (let update (lambda '(value state) '((+ (Nth state '0) (MatchType (TypeOf value) 'Decimal (lambda '() (WidenIntegral value)) 'Interval (lambda '() (Apply convert_interval_to_decimal value )) (lambda '() (Convert value 'Double)))) (Inc (Nth state '1)))))
(let shift (lambda '(value state) '((- (Nth state '0) value) (Dec (Nth state '1)))))
(let current (lambda '(state) (MatchType (ListItemType list_type)
'Decimal (lambda '() (Cast (Div (Nth state '0) (Nth state '1)) (ListItemType list_type)))
@@ -156,11 +156,11 @@
(Double '0))))
(let update (lambda '(value state) (block '(
(let delta (- (Convert value 'Double) (Nth state '0)))
- (let next_n (AggrAdd (Nth state '1) (Double '1)))
+ (let next_n (+ (Nth state '1) (Double '1)))
(return '(
- (AggrAdd (Nth state '0) (/ delta next_n))
+ (+ (Nth state '0) (/ delta next_n))
next_n
- (AggrAdd (Nth state '2) (/ (* (* delta delta) (Nth state '1)) next_n))
+ (+ (Nth state '2) (/ (* (* delta delta) (Nth state '1)) next_n))
))))))
(let shift (lambda '(value state) (Void)))
(let current (lambda '(state) (block '(
@@ -182,7 +182,7 @@
# doesn't support optional values
(let correlation_traits_factory_raw (lambda '(list_type) (block '(
(let init (lambda '(value) '((Uint64 '1) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0))) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0))) (* (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0))))))
- (let update (lambda '(value state) '((AggrAdd (Nth state '0) (Uint64 '1)) (AggrAdd (Nth state '1) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0))) (AggrAdd (Nth state '2) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0))) (AggrAdd (Nth state '3) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)))) (AggrAdd (Nth state '4) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)))) (AggrAdd (Nth state '5) (* (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)))))))
+ (let update (lambda '(value state) '((+ (Nth state '0) (Uint64 '1)) (+ (Nth state '1) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0))) (+ (Nth state '2) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0))) (+ (Nth state '3) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)))) (+ (Nth state '4) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)))) (+ (Nth state '5) (* (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)))))))
(let shift (lambda '(value state) (Void)))
(let current (lambda '(state) (block '(
# Math comes from ISO9075-2:2011(E) and differs from what Excel uses
@@ -201,7 +201,7 @@
# doesn't support optional values
(let covariance_traits_factory_raw (lambda '(list_type sample) (block '(
(let init (lambda '(value) '((Uint64 '1) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0))))))
- (let update (lambda '(value state) '((AggrAdd (Nth state '0) (Uint64 '1)) (AggrAdd (Nth state '1) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0))) (AggrAdd (Nth state '2) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0))) (AggrAdd (Nth state '3) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)))))))
+ (let update (lambda '(value state) '((+ (Nth state '0) (Uint64 '1)) (+ (Nth state '1) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0))) (+ (Nth state '2) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0))) (+ (Nth state '3) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)))))))
(let shift (lambda '(value state) (Void)))
(let current (lambda '(state) (block '(
(let covariance_result (- (Nth state '3) (/ (* (Nth state '1) (Nth state '2)) (Nth state '0))))