You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "AMashenkov (via GitHub)" <gi...@apache.org> on 2024/08/27 14:56:55 UTC
[PR] IGNITE-22988 Sql. Align implementations of average calculation (AVG) [ignite-3]
AMashenkov opened a new pull request, #4292:
URL: https://github.com/apache/ignite-3/pull/4292
Thank you for submitting the pull request.
To streamline the review process of the patch and ensure better code quality
we ask both an author and a reviewer to verify the following:
### The Review Checklist
- [ ] **Formal criteria:** TC status, codestyle, mandatory documentation. Also make sure to complete the following:
\- There is a single JIRA ticket related to the pull request.
\- The web-link to the pull request is attached to the JIRA ticket.
\- The JIRA ticket has the Patch Available state.
\- The description of the JIRA ticket explains WHAT was made, WHY and HOW.
\- The pull request title is treated as the final commit message. The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
- [ ] **Design:** new code conforms with the design principles of the components it is added to.
- [ ] **Patch quality:** patch cannot be split into smaller pieces, its size must be reasonable.
- [ ] **Code quality:** code is clean and readable, necessary developer documentation is added if needed.
- [ ] **Tests code quality:** test set covers positive/negative scenarios, happy/edge cases. Tests are effective in terms of execution time and resources.
### Notes
- [Apache Ignite Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Java+Code+Style+Guide)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22988 Sql. Align implementations of average calculation (AVG) [ignite-3]
Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov merged PR #4292:
URL: https://github.com/apache/ignite-3/pull/4292
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22988 Sql. Align implementations of average calculation (AVG) [ignite-3]
Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on code in PR #4292:
URL: https://github.com/apache/ignite-3/pull/4292#discussion_r1737700830
##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItAggregatesTest.java:
##########
@@ -617,14 +613,15 @@ public void testAvgRandom() {
numbers.add(num);
String query = "INSERT INTO numbers (id, int_col, dec10_2_col) VALUES(?, ?, ?)";
- sql(query, i, num.intValue(), num);
+ sql(query, i, NumberUtil.rescaleBigDecimal(num, 0).intValue(), num);
}
BigDecimal avg = numbers.stream()
.reduce(new BigDecimal("0.00"), BigDecimal::add)
- .divide(BigDecimal.valueOf(numbers.size()), MathContext.DECIMAL64);
+ .divide(BigDecimal.valueOf(numbers.size()), 2, RoundingMode.HALF_UP);
for (String[] rules : makePermutations(DISABLED_RULES)) {
+ System.out.println(String.join(",", rules));
Review Comment:
I think this `system.out.println` is unnecessary.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22988 Sql. Align implementations of average calculation (AVG) [ignite-3]
Posted by "ygerzhedovich (via GitHub)" <gi...@apache.org>.
ygerzhedovich commented on code in PR #4292:
URL: https://github.com/apache/ignite-3/pull/4292#discussion_r1743480253
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/agg/MapReduceAggregates.java:
##########
@@ -631,22 +631,21 @@ private static MapReduceAgg createAvgAgg(
RexNode numeratorRef = rexBuilder.makeInputRef(input, args.get(0));
RexInputRef denominatorRef = rexBuilder.makeInputRef(input, args.get(1));
- RelDataType avgType = typeFactory.createTypeWithNullability(mapSum0.type, numeratorRef.getType().isNullable());
- numeratorRef = rexBuilder.ensureType(avgType, numeratorRef, true);
+ numeratorRef = rexBuilder.ensureType(mapSum0.type, numeratorRef, true);
- RexNode sumDivCnt;
- if (call.getType().getSqlTypeName() == SqlTypeName.DECIMAL) {
- // Return correct decimal type with correct scale and precision.
- int precision = call.getType().getPrecision();
- int scale = call.getType().getScale();
+ RelDataType resultType = typeFactory.decimalOf(call.type);
- RexLiteral p = rexBuilder.makeExactLiteral(BigDecimal.valueOf(precision), tf.createSqlType(SqlTypeName.INTEGER));
- RexLiteral s = rexBuilder.makeExactLiteral(BigDecimal.valueOf(scale), tf.createSqlType(SqlTypeName.INTEGER));
+ // Return correct decimal type with correct scale and precision.
+ int precision = resultType.getPrecision(); // not used.
Review Comment:
seems it ok, based on answer below
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22988 Sql. Align implementations of average calculation (AVG) [ignite-3]
Posted by "ygerzhedovich (via GitHub)" <gi...@apache.org>.
ygerzhedovich commented on code in PR #4292:
URL: https://github.com/apache/ignite-3/pull/4292#discussion_r1738324149
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/exp/agg/Accumulators.java:
##########
@@ -102,13 +103,17 @@ private Supplier<Accumulator> accumulatorFunctionFactory(AggregateCall call) {
private Supplier<Accumulator> avgFactory(AggregateCall call) {
switch (call.type.getSqlTypeName()) {
+ case TINYINT:
+ case SMALLINT:
+ case INTEGER:
case BIGINT:
+ return () -> DecimalAvg.FACTORY.apply(0);
case DECIMAL:
- return DecimalAvg.FACTORY;
+ // TODO: support intervals.
Review Comment:
let's add link to ticket - IGNITE-15200
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22988 Sql. Align implementations of average calculation (AVG) [ignite-3]
Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on code in PR #4292:
URL: https://github.com/apache/ignite-3/pull/4292#discussion_r1737756203
##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItAggregatesTest.java:
##########
@@ -617,14 +613,15 @@ public void testAvgRandom() {
numbers.add(num);
String query = "INSERT INTO numbers (id, int_col, dec10_2_col) VALUES(?, ?, ?)";
- sql(query, i, num.intValue(), num);
+ sql(query, i, NumberUtil.rescaleBigDecimal(num, 0).intValue(), num);
}
BigDecimal avg = numbers.stream()
.reduce(new BigDecimal("0.00"), BigDecimal::add)
- .divide(BigDecimal.valueOf(numbers.size()), MathContext.DECIMAL64);
+ .divide(BigDecimal.valueOf(numbers.size()), 2, RoundingMode.HALF_UP);
for (String[] rules : makePermutations(DISABLED_RULES)) {
+ System.out.println(String.join(",", rules));
Review Comment:
When I get the following numbers by the random generator: `{37, 46, 72, 33, 33, 57, 76, 27, 100, 4, 62, 77, 74, 49, 31, 16, 56, 34, 82};`
A get a test failure:
```
Expected: 50 <class java.lang.Integer>
Actual: 51 <class java.lang.Integer>
```
Query results:
```
[[51, 50.84]]
```
Looks like using avg.intValue() ` .returns(avg.intValue(), avg)` is no longer a valid check?
##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItAggregatesTest.java:
##########
@@ -617,14 +613,15 @@ public void testAvgRandom() {
numbers.add(num);
String query = "INSERT INTO numbers (id, int_col, dec10_2_col) VALUES(?, ?, ?)";
- sql(query, i, num.intValue(), num);
+ sql(query, i, NumberUtil.rescaleBigDecimal(num, 0).intValue(), num);
}
BigDecimal avg = numbers.stream()
.reduce(new BigDecimal("0.00"), BigDecimal::add)
- .divide(BigDecimal.valueOf(numbers.size()), MathContext.DECIMAL64);
+ .divide(BigDecimal.valueOf(numbers.size()), 2, RoundingMode.HALF_UP);
for (String[] rules : makePermutations(DISABLED_RULES)) {
+ System.out.println(String.join(",", rules));
Review Comment:
When I get the following numbers by the random generator: `{37, 46, 72, 33, 33, 57, 76, 27, 100, 4, 62, 77, 74, 49, 31, 16, 56, 34, 82};`
I get a test failure:
```
Expected: 50 <class java.lang.Integer>
Actual: 51 <class java.lang.Integer>
```
Query results:
```
[[51, 50.84]]
```
Looks like using avg.intValue() ` .returns(avg.intValue(), avg)` is no longer a valid check?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22988 Sql. Align implementations of average calculation (AVG) [ignite-3]
Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on code in PR #4292:
URL: https://github.com/apache/ignite-3/pull/4292#discussion_r1737756203
##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItAggregatesTest.java:
##########
@@ -617,14 +613,15 @@ public void testAvgRandom() {
numbers.add(num);
String query = "INSERT INTO numbers (id, int_col, dec10_2_col) VALUES(?, ?, ?)";
- sql(query, i, num.intValue(), num);
+ sql(query, i, NumberUtil.rescaleBigDecimal(num, 0).intValue(), num);
}
BigDecimal avg = numbers.stream()
.reduce(new BigDecimal("0.00"), BigDecimal::add)
- .divide(BigDecimal.valueOf(numbers.size()), MathContext.DECIMAL64);
+ .divide(BigDecimal.valueOf(numbers.size()), 2, RoundingMode.HALF_UP);
for (String[] rules : makePermutations(DISABLED_RULES)) {
+ System.out.println(String.join(",", rules));
Review Comment:
When I got a the following numbers by the random generator: `{37, 46, 72, 33, 33, 57, 76, 27, 100, 4, 62, 77, 74, 49, 31, 16, 56, 34, 82};`
A got a test failure:
```
Expected: 50 <class java.lang.Integer>
Actual: 51 <class java.lang.Integer>
```
Query results:
```
[[51, 50.84]]
```
Looks like using avg.intValue() ` .returns(avg.intValue(), avg)` is no longer a valid check?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22988 Sql. Align implementations of average calculation (AVG) [ignite-3]
Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on code in PR #4292:
URL: https://github.com/apache/ignite-3/pull/4292#discussion_r1742614926
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/exp/IgniteSqlFunctions.java:
##########
@@ -361,7 +360,7 @@ public static BigDecimal toBigDecimal(Number value, int precision, int scale) {
* (see {@link IgniteSqlOperatorTable#DECIMAL_DIVIDE}, their values are ignored at runtime.
*/
public static BigDecimal decimalDivide(BigDecimal sum, BigDecimal cnt, int p, int s) {
Review Comment:
You can not do this without losing inference of precision/scale (See `DECIMAL_DIVIDE` operator in `IgniteSqlOperatorTable`). Since you can not have different numbers of parameters at the validation phase and in runtime.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22988 Sql. Align implementations of average calculation (AVG) [ignite-3]
Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on code in PR #4292:
URL: https://github.com/apache/ignite-3/pull/4292#discussion_r1737756203
##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItAggregatesTest.java:
##########
@@ -617,14 +613,15 @@ public void testAvgRandom() {
numbers.add(num);
String query = "INSERT INTO numbers (id, int_col, dec10_2_col) VALUES(?, ?, ?)";
- sql(query, i, num.intValue(), num);
+ sql(query, i, NumberUtil.rescaleBigDecimal(num, 0).intValue(), num);
}
BigDecimal avg = numbers.stream()
.reduce(new BigDecimal("0.00"), BigDecimal::add)
- .divide(BigDecimal.valueOf(numbers.size()), MathContext.DECIMAL64);
+ .divide(BigDecimal.valueOf(numbers.size()), 2, RoundingMode.HALF_UP);
for (String[] rules : makePermutations(DISABLED_RULES)) {
+ System.out.println(String.join(",", rules));
Review Comment:
When I get the following numbers by the random generator: `{37, 46, 72, 33, 33, 57, 76, 27, 100, 4, 62, 77, 74, 49, 31, 16, 56, 34, 82};`
I get a test failure:
```
Expected: 50 <class java.lang.Integer>
Actual: 51 <class java.lang.Integer>
```
Query results:
```
[[51, 50.84]]
```
Looks like using `avg.intValue()` in ` .returns(avg.intValue(), avg)` at line 633 is no longer a valid check?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22988 Sql. Align implementations of average calculation (AVG) [ignite-3]
Posted by "ygerzhedovich (via GitHub)" <gi...@apache.org>.
ygerzhedovich commented on code in PR #4292:
URL: https://github.com/apache/ignite-3/pull/4292#discussion_r1742131200
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/agg/MapReduceAggregates.java:
##########
@@ -631,22 +631,21 @@ private static MapReduceAgg createAvgAgg(
RexNode numeratorRef = rexBuilder.makeInputRef(input, args.get(0));
RexInputRef denominatorRef = rexBuilder.makeInputRef(input, args.get(1));
- RelDataType avgType = typeFactory.createTypeWithNullability(mapSum0.type, numeratorRef.getType().isNullable());
- numeratorRef = rexBuilder.ensureType(avgType, numeratorRef, true);
+ numeratorRef = rexBuilder.ensureType(mapSum0.type, numeratorRef, true);
- RexNode sumDivCnt;
- if (call.getType().getSqlTypeName() == SqlTypeName.DECIMAL) {
- // Return correct decimal type with correct scale and precision.
- int precision = call.getType().getPrecision();
- int scale = call.getType().getScale();
+ RelDataType resultType = typeFactory.decimalOf(call.type);
- RexLiteral p = rexBuilder.makeExactLiteral(BigDecimal.valueOf(precision), tf.createSqlType(SqlTypeName.INTEGER));
- RexLiteral s = rexBuilder.makeExactLiteral(BigDecimal.valueOf(scale), tf.createSqlType(SqlTypeName.INTEGER));
+ // Return correct decimal type with correct scale and precision.
+ int precision = resultType.getPrecision(); // not used.
Review Comment:
What reason to have precision at all in this case?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22988 Sql. Align implementations of average calculation (AVG) [ignite-3]
Posted by "ygerzhedovich (via GitHub)" <gi...@apache.org>.
ygerzhedovich commented on code in PR #4292:
URL: https://github.com/apache/ignite-3/pull/4292#discussion_r1738409560
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/agg/MapReduceAggregates.java:
##########
@@ -645,8 +645,15 @@ private static MapReduceAgg createAvgAgg(
sumDivCnt = rexBuilder.makeCall(IgniteSqlOperatorTable.DECIMAL_DIVIDE, numeratorRef, denominatorRef, p, s);
} else {
- RexNode divideRef = rexBuilder.makeCall(SqlStdOperatorTable.DIVIDE, numeratorRef, denominatorRef);
- sumDivCnt = rexBuilder.makeCast(call.getType(), divideRef, true, false);
+ RelDataType resultType = typeFactory.decimalOf(call.type);
Review Comment:
I propose to use single code for both cases without any branches. Also use ``false`` for ``matchNullability`` in cast - it needs only for literals, but it's not literals in the case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22988 Sql. Align implementations of average calculation (AVG) [ignite-3]
Posted by "ygerzhedovich (via GitHub)" <gi...@apache.org>.
ygerzhedovich commented on code in PR #4292:
URL: https://github.com/apache/ignite-3/pull/4292#discussion_r1742116372
##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItAggregatesTest.java:
##########
@@ -23,13 +23,14 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.math.BigDecimal;
-import java.math.MathContext;
+import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Random;
import java.util.stream.Stream;
+import org.apache.calcite.util.NumberUtil;
Review Comment:
It's not so good use Calcite utils in our tests
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22988 Sql. Align implementations of average calculation (AVG) [ignite-3]
Posted by "ygerzhedovich (via GitHub)" <gi...@apache.org>.
ygerzhedovich commented on code in PR #4292:
URL: https://github.com/apache/ignite-3/pull/4292#discussion_r1742152345
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/exp/IgniteSqlFunctions.java:
##########
@@ -361,7 +360,7 @@ public static BigDecimal toBigDecimal(Number value, int precision, int scale) {
* (see {@link IgniteSqlOperatorTable#DECIMAL_DIVIDE}, their values are ignored at runtime.
*/
public static BigDecimal decimalDivide(BigDecimal sum, BigDecimal cnt, int p, int s) {
Review Comment:
the same question, if precision doesn't used why we have it here? I propose to get rid it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org