You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The root cause is of this bug is how OpenSearch stores results of Sum aggregation. Would it be appropriate to update OpenSearch to return null instead of 0 if an aggregation did not process any rows?
Consider Avg and Sum aggregations in OpenSearch. Avg is stored as sum and count. When count = 0 the whole aggregation is evaluated as null producing the expected result. Sum, on the other hand, is not aware of how many documents were evaluated and so evaluates to the initial value -- 0. See InternalSum and InternalAvg for reference.
@joshuali925
This argument is based on the SQL standard. Unfortunately, there doesn't appear to be a way to change the SQL plugin to match the SQL standard unless we move the aggregation processing to the SQL plugin side - which would be a significant change. This might be worth doing? since MIN/MAX/AVG/SUM/etc for SQL do behave slightly differently than their OpenSearch aggregation equivalents. For example: #279 is another issue where the OpenSearch aggregation function behaves differently than the SQL standard.
Yes - you are correct - this would be a breaking change on the OpenSearch side.
That being said, the counter argument is that AVG returns null when the count is 0. What is the justification for the two being different...? The sum of or doesn't make sense to be 0 either.
@acarbonetto Not sure if we should move aggregations to SQL side. It would mean processing aggregations in memory which is not scaleable. Is it possible to make it an exception from the tdvt tests? My argument would be the plugin is opensearch-sql and we push down as much as possible, and the results will be consistent with opensearch.
That being said, the counter argument is that AVG returns null when the count is 0. What is the justification for the two being different...? The sum of or doesn't make sense to be 0 either.
The other way would be to convince OpenSearch to change behavior, i don't know if this argument is convincing enough to add a breaking change there, but we can try it if no other options.
(To answer the question I was referring to sum(), which i think it's standard for programming language libraries to return 0 if list is empty. But i could be wrong and it's not relevant in our case)
Activity
MaxKsyunz commentedon May 28, 2022
@penghuo @joshuali925
The root cause is of this bug is how OpenSearch stores results of Sum aggregation. Would it be appropriate to update OpenSearch to return
nullinstead of0if an aggregation did not process any rows?Consider Avg and Sum aggregations in OpenSearch. Avg is stored as
sumandcount. Whencount = 0the whole aggregation is evaluated asnullproducing the expected result. Sum, on the other hand, is not aware of how many documents were evaluated and so evaluates to the initial value --0. SeeInternalSumandInternalAvgfor reference.joshuali925 commentedon May 31, 2022
Is this an existing standard? OpenSearch returns
0as 0 is the default value which makes sense to me, maybe SQL standard is different.Based on SQL code when no rows are processed it should already return null
sql/core/src/main/java/org/opensearch/sql/expression/aggregation/SumAggregator.java
Lines 96 to 98 in b2d1a16
For
sumpushed down to OpenSearch side you can create a ticket there, but it will be a breaking change and not sure if there is enough justification.acarbonetto commentedon May 31, 2022
@joshuali925
This argument is based on the SQL standard. Unfortunately, there doesn't appear to be a way to change the SQL plugin to match the SQL standard unless we move the aggregation processing to the SQL plugin side - which would be a significant change. This might be worth doing? since MIN/MAX/AVG/SUM/etc for SQL do behave slightly differently than their OpenSearch aggregation equivalents. For example: #279 is another issue where the OpenSearch aggregation function behaves differently than the SQL standard.
Yes - you are correct - this would be a breaking change on the OpenSearch side.
That being said, the counter argument is that AVG returns null when the count is 0. What is the justification for the two being different...? The sum of or doesn't make sense to be 0 either.
joshuali925 commentedon May 31, 2022
@acarbonetto Not sure if we should move aggregations to SQL side. It would mean processing aggregations in memory which is not scaleable. Is it possible to make it an exception from the tdvt tests? My argument would be the plugin is opensearch-sql and we push down as much as possible, and the results will be consistent with opensearch.
The other way would be to convince OpenSearch to change behavior, i don't know if this argument is convincing enough to add a breaking change there, but we can try it if no other options.
(To answer the question I was referring to
sum(), which i think it's standard for programming language libraries to return0if list is empty. But i could be wrong and it's not relevant in our case)nullvalues should returnnullinstead of0#3408