[
https://issues.apache.org/jira/browse/IGNITE-22739?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Maksim Zhuravkov updated IGNITE-22739:
--------------------------------------
Description:
1. AccumulatorsFactory use `RexToLitTranslator` from
`org.apache.ignite.internal.sql.engine.exec.exp` instead of the one provided by
calcite. Because the fixed version correctly handles cast overflows:
{noformat}
SELECT AVG(12345678::TINYINT)
{noformat}
Code generated by calcite:
{noformat}
inTypes: [TINYINT] // AVG argument cast
COMPILE
public Object apply(Object in) {
return Double.valueOf(org.apache.calcite.runtime.SqlFunctions.toByte(in));
}
inType: DOUBLE, outType: TINYINT // AVG output cast
COMPILE
public Object apply(Object in) {
return (Double) in == null ? null : (Byte)
org.apache.calcite.linq4j.tree.Primitive.integerCast(org.apache.calcite.linq4j.tree.Primitive.BYTE,
((Double) in).doubleValue());
}
COMPILE
public void execute(org.apache.ignite.internal.sql.engine.exec.ExecutionContext
ctx, Object in1,
org.apache.ignite.internal.sql.engine.exec.RowHandler.RowBuilder out) {
try {
out.addField(org.apache.ignite.internal.sql.engine.util.IgniteMath.convertToByteExact(12345678));
} catch (Exception e) {
throw new org.apache.ignite.sql.SqlException(
262151,
e);
}
}
{noformat}
Code generated by the updated version of the RexToLitTranslator
{noformat}
inTypes: [TINYINT]
COMPILE
public Object apply(Object in) {
return Double.valueOf(org.apache.calcite.runtime.SqlFunctions.toByte(in));
}
inType: DOUBLE, outType: TINYINT
COMPILE
public Object apply(Object in) {
return (Double) in == null ? null :
Byte.valueOf(org.apache.ignite.internal.sql.engine.util.IgniteMath.convertToByteExact(((Double)
in).doubleValue()));
}
COMPILE
public void execute(org.apache.ignite.internal.sql.engine.exec.ExecutionContext
ctx, Object in1,
org.apache.ignite.internal.sql.engine.exec.RowHandler.RowBuilder out) {
try {
out.addField(org.apache.ignite.internal.sql.engine.util.IgniteMath.convertToByteExact(12345678));
} catch (Exception e) {
throw new org.apache.ignite.sql.SqlException(
262151,
e);
}
}
{noformat}
2. RexExecutorImpl used by RexSimplifier also uses `RexToLitTranslator`
provided by calcite. See:
{code:java}
Frameworks.newConfigBuilder().executor(new RexExecutorImpl(DataContexts.EMPTY))
// in org.apache.ignite.internal.sql.engine.util.Commons
{code}
was:
1. AccumulatorsFactory use `RexToLitTranslator` from
`org.apache.ignite.internal.sql.engine.exec.exp` instead of the one provided by
calcite. Because the fixed version correctly handles cast overflows:
{noformat}
SELECT AVG(12345678::TINYINT)
{noformat}
Code generated by calcite:
{noformat}
inTypes: [TINYINT] // AVG argument cast
COMPILE
public Object apply(Object in) {
return Double.valueOf(org.apache.calcite.runtime.SqlFunctions.toByte(in));
}
inType: DOUBLE, outType: TINYINT // AVG output cast
COMPILE
public Object apply(Object in) {
return (Double) in == null ? null : (Byte)
org.apache.calcite.linq4j.tree.Primitive.integerCast(org.apache.calcite.linq4j.tree.Primitive.BYTE,
((Double) in).doubleValue());
}
COMPILE
public void execute(org.apache.ignite.internal.sql.engine.exec.ExecutionContext
ctx, Object in1,
org.apache.ignite.internal.sql.engine.exec.RowHandler.RowBuilder out) {
try {
out.addField(org.apache.ignite.internal.sql.engine.util.IgniteMath.convertToByteExact(12345678));
} catch (Exception e) {
throw new org.apache.ignite.sql.SqlException(
262151,
e);
}
}
{noformat}
Code generated by the updated version of the RexToLitTranslator
{noformat}
inTypes: [TINYINT]
COMPILE
public Object apply(Object in) {
return Double.valueOf(org.apache.calcite.runtime.SqlFunctions.toByte(in));
}
inType: DOUBLE, outType: TINYINT
COMPILE
public Object apply(Object in) {
return (Double) in == null ? null :
Byte.valueOf(org.apache.ignite.internal.sql.engine.util.IgniteMath.convertToByteExact(((Double)
in).doubleValue()));
}
COMPILE
public void execute(org.apache.ignite.internal.sql.engine.exec.ExecutionContext
ctx, Object in1,
org.apache.ignite.internal.sql.engine.exec.RowHandler.RowBuilder out) {
try {
out.addField(org.apache.ignite.internal.sql.engine.util.IgniteMath.convertToByteExact(12345678));
} catch (Exception e) {
throw new org.apache.ignite.sql.SqlException(
262151,
e);
}
}
{noformat}
2. RexExecutorImpl used by RexSimplifier also uses `RexToLitTranslator`
provided by calcite. See:
{code:java}
Frameworks.newConfigBuilder().executor(new RexExecutorImpl(DataContexts.EMPTY))
// in Commons
{code}
> Sql. Use modified version of the RexToLitTranslator
> ---------------------------------------------------
>
> Key: IGNITE-22739
> URL: https://issues.apache.org/jira/browse/IGNITE-22739
> Project: Ignite
> Issue Type: Improvement
> Components: sql
> Reporter: Maksim Zhuravkov
> Priority: Major
> Labels: ignite-3
>
> 1. AccumulatorsFactory use `RexToLitTranslator` from
> `org.apache.ignite.internal.sql.engine.exec.exp` instead of the one provided
> by calcite. Because the fixed version correctly handles cast overflows:
> {noformat}
> SELECT AVG(12345678::TINYINT)
> {noformat}
> Code generated by calcite:
> {noformat}
> inTypes: [TINYINT] // AVG argument cast
> COMPILE
> public Object apply(Object in) {
> return Double.valueOf(org.apache.calcite.runtime.SqlFunctions.toByte(in));
> }
> inType: DOUBLE, outType: TINYINT // AVG output cast
> COMPILE
> public Object apply(Object in) {
> return (Double) in == null ? null : (Byte)
> org.apache.calcite.linq4j.tree.Primitive.integerCast(org.apache.calcite.linq4j.tree.Primitive.BYTE,
> ((Double) in).doubleValue());
> }
> COMPILE
> public void
> execute(org.apache.ignite.internal.sql.engine.exec.ExecutionContext ctx,
> Object in1, org.apache.ignite.internal.sql.engine.exec.RowHandler.RowBuilder
> out) {
> try {
>
> out.addField(org.apache.ignite.internal.sql.engine.util.IgniteMath.convertToByteExact(12345678));
> } catch (Exception e) {
> throw new org.apache.ignite.sql.SqlException(
> 262151,
> e);
> }
> }
> {noformat}
> Code generated by the updated version of the RexToLitTranslator
> {noformat}
> inTypes: [TINYINT]
> COMPILE
> public Object apply(Object in) {
> return Double.valueOf(org.apache.calcite.runtime.SqlFunctions.toByte(in));
> }
> inType: DOUBLE, outType: TINYINT
> COMPILE
> public Object apply(Object in) {
> return (Double) in == null ? null :
> Byte.valueOf(org.apache.ignite.internal.sql.engine.util.IgniteMath.convertToByteExact(((Double)
> in).doubleValue()));
> }
> COMPILE
> public void
> execute(org.apache.ignite.internal.sql.engine.exec.ExecutionContext ctx,
> Object in1, org.apache.ignite.internal.sql.engine.exec.RowHandler.RowBuilder
> out) {
> try {
>
> out.addField(org.apache.ignite.internal.sql.engine.util.IgniteMath.convertToByteExact(12345678));
> } catch (Exception e) {
> throw new org.apache.ignite.sql.SqlException(
> 262151,
> e);
> }
> }
> {noformat}
> 2. RexExecutorImpl used by RexSimplifier also uses `RexToLitTranslator`
> provided by calcite. See:
> {code:java}
> Frameworks.newConfigBuilder().executor(new
> RexExecutorImpl(DataContexts.EMPTY)) // in
> org.apache.ignite.internal.sql.engine.util.Commons
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)