You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/06/25 08:40:50 UTC

[GitHub] [ignite] vladErmakov07 opened a new pull request #9199: IGNITE-14589

vladErmakov07 opened a new pull request #9199:
URL: https://github.com/apache/ignite/pull/9199


   Thank you for submitting the pull request to the Apache Ignite.
   
   In order to streamline the review of the contribution 
   we ask you to ensure the following steps have been taken:
   
   ### The Contribution Checklist
   - [ ] 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 pull request body describes changes that have been made. 
   The description explains _WHAT_ and _WHY_ was made instead of _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.
   - [ ] A reviewer has been mentioned through the JIRA comments 
   (see [the Maintainers list](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute#HowtoContribute-ReviewProcessandMaintainers)) 
   - [ ] The pull request has been checked by the Teamcity Bot and 
   the `green visa` attached to the JIRA ticket (see [TC.Bot: Check PR](https://mtcga.gridgain.com/prs.html))
   
   ### Notes
   - [How to Contribute](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute)
   - [Coding abbreviation rules](https://cwiki.apache.org/confluence/display/IGNITE/Abbreviation+Rules)
   - [Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines)
   - [Apache Ignite Teamcity Bot](https://cwiki.apache.org/confluence/display/IGNITE/Apache+Ignite+Teamcity+Bot)
   
   If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com _#ignite_ channel.
   


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] vladErmakov07 commented on a change in pull request #9199: IGNITE-14589 DECIMAL sql type refactoring

Posted by GitBox <gi...@apache.org>.
vladErmakov07 commented on a change in pull request #9199:
URL: https://github.com/apache/ignite/pull/9199#discussion_r659790266



##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rex/RexExecutorImpl.java
##########
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.rex;
+
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.DataContext;
+import org.apache.calcite.adapter.enumerable.EnumUtils;

Review comment:
       Fixed




-- 
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



[GitHub] [ignite] tledkov-gridgain commented on a change in pull request #9199: IGNITE-14589 DECIMAL sql type refactoring

Posted by GitBox <gi...@apache.org>.
tledkov-gridgain commented on a change in pull request #9199:
URL: https://github.com/apache/ignite/pull/9199#discussion_r659796361



##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/RexExecutorImpl.java
##########
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.exec.exp;
+
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.DataContext;
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.config.CalciteSystemProperty;
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.linq4j.tree.BlockBuilder;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.IndexExpression;
+import org.apache.calcite.linq4j.tree.MethodCallExpression;
+import org.apache.calcite.linq4j.tree.MethodDeclaration;
+import org.apache.calcite.linq4j.tree.ParameterExpression;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexExecutable;
+import org.apache.calcite.rex.RexExecutor;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexProgram;
+import org.apache.calcite.rex.RexProgramBuilder;
+import org.apache.calcite.sql.validate.SqlConformance;
+import org.apache.calcite.sql.validate.SqlConformanceEnum;
+import org.apache.calcite.util.BuiltInMethod;
+import org.apache.calcite.util.Util;
+
+/**
+ * Evaluates a {@link RexNode} expression.
+ *
+ * <p>For this impl, all the public methods should be
+ * static except that it inherits from {@link RexExecutor}.
+ * This pretends that other code in the project assumes
+ * the executor instance is {@link RexExecutorImpl}.
+*/
+public class RexExecutorImpl implements RexExecutor {
+

Review comment:
       Please remove empty line? according with codestyle 

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/RexExecutorImpl.java
##########
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.exec.exp;
+
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.DataContext;
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.config.CalciteSystemProperty;
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.linq4j.tree.BlockBuilder;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.IndexExpression;
+import org.apache.calcite.linq4j.tree.MethodCallExpression;
+import org.apache.calcite.linq4j.tree.MethodDeclaration;
+import org.apache.calcite.linq4j.tree.ParameterExpression;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexExecutable;
+import org.apache.calcite.rex.RexExecutor;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexProgram;
+import org.apache.calcite.rex.RexProgramBuilder;
+import org.apache.calcite.sql.validate.SqlConformance;
+import org.apache.calcite.sql.validate.SqlConformanceEnum;
+import org.apache.calcite.util.BuiltInMethod;
+import org.apache.calcite.util.Util;
+
+/**
+ * Evaluates a {@link RexNode} expression.
+ *
+ * <p>For this impl, all the public methods should be
+ * static except that it inherits from {@link RexExecutor}.
+ * This pretends that other code in the project assumes
+ * the executor instance is {@link RexExecutorImpl}.
+*/
+public class RexExecutorImpl implements RexExecutor {
+

Review comment:
       Please remove empty line according with codestyle 




-- 
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



[GitHub] [ignite] vladErmakov07 commented on a change in pull request #9199: IGNITE-14589 DECIMAL sql type refactoring

Posted by GitBox <gi...@apache.org>.
vladErmakov07 commented on a change in pull request #9199:
URL: https://github.com/apache/ignite/pull/9199#discussion_r659791088



##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ConverterUtils.java
##########
@@ -175,6 +175,54 @@ public static Expression convert(Expression operand, Type toType) {
         return convert(operand, fromType, toType);
     }
 
+    /**
+     * Convert {@code operand} from {@code targetType} to BigDecimal type.

Review comment:
       Fixed javadocs

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ConverterUtils.java
##########
@@ -175,6 +175,54 @@ public static Expression convert(Expression operand, Type toType) {
         return convert(operand, fromType, toType);
     }
 
+    /**
+     * Convert {@code operand} from {@code targetType} to BigDecimal type.
+     *
+     * @param operand The expression to convert
+     * @param targetType Target type
+     * @param fromType Field type
+     * @return An expression with BidDecimal type, which calls IgniteSqlFunctions.toBigDecimal function.
+     */
+    public static Expression convertToDecimal(Expression operand, Type fromType, RelDataType targetType) {
+        final Primitive fromBox = Primitive.ofBox(fromType);

Review comment:
       Added an assertion




-- 
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



[GitHub] [ignite] vladErmakov07 commented on a change in pull request #9199: IGNITE-14589 DECIMAL sql type refactoring

Posted by GitBox <gi...@apache.org>.
vladErmakov07 commented on a change in pull request #9199:
URL: https://github.com/apache/ignite/pull/9199#discussion_r659790499



##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rex/RexExecutorImpl.java
##########
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.rex;

Review comment:
       Moved to the exec.exp package




-- 
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



[GitHub] [ignite] vladErmakov07 commented on a change in pull request #9199: IGNITE-14589 DECIMAL sql type refactoring

Posted by GitBox <gi...@apache.org>.
vladErmakov07 commented on a change in pull request #9199:
URL: https://github.com/apache/ignite/pull/9199#discussion_r659792011



##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/IgniteSqlFunctions.java
##########
@@ -53,6 +59,46 @@ public static ScannableTable systemRange(Object rangeStart, Object rangeEnd, Obj
         return new RangeTable(rangeStart, rangeEnd, increment);
     }
 
+    /** CAST(DECIMAL AS VARCHAR). */
+    public static String toString(BigDecimal x) {
+        return x.toPlainString();
+    }
+
+    /** CAST(VARCHAR AS DECIMAL). */
+    public static BigDecimal toBigDecimal(String s, int precision, int scale) {
+        BigDecimal decimal = new BigDecimal(s.trim());
+        return precision == PRECISION_NOT_SPECIFIED ? decimal : decimal.setScale(scale, RoundingMode.HALF_UP);
+    }
+
+    /** CAST(FLOAT AS DECIMAL). */
+    public static BigDecimal toBigDecimal(float val, int precision, int scale) {
+        BigDecimal decimal = new BigDecimal(String.valueOf(val));
+        return precision == PRECISION_NOT_SPECIFIED ? decimal : decimal.setScale(scale, RoundingMode.HALF_UP);
+    }
+
+    /** CAST(DOUBLE AS DECIMAL). */
+    public static BigDecimal toBigDecimal(double val, int precision, int scale) {
+        BigDecimal decimal = BigDecimal.valueOf(val);
+        return precision == PRECISION_NOT_SPECIFIED ? decimal : decimal.setScale(scale, RoundingMode.HALF_UP);
+    }
+
+    /** CAST(REAL AS DECIMAL). */

Review comment:
       Renamed to FLOAT




-- 
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



[GitHub] [ignite] vladErmakov07 commented on a change in pull request #9199: IGNITE-14589 DECIMAL sql type refactoring

Posted by GitBox <gi...@apache.org>.
vladErmakov07 commented on a change in pull request #9199:
URL: https://github.com/apache/ignite/pull/9199#discussion_r659792412



##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ConverterUtils.java
##########
@@ -175,6 +175,54 @@ public static Expression convert(Expression operand, Type toType) {
         return convert(operand, fromType, toType);
     }
 
+    /**
+     * Convert {@code operand} from {@code targetType} to BigDecimal type.
+     *
+     * @param operand The expression to convert
+     * @param targetType Target type
+     * @param fromType Field type
+     * @return An expression with BidDecimal type, which calls IgniteSqlFunctions.toBigDecimal function.
+     */
+    public static Expression convertToDecimal(Expression operand, Type fromType, RelDataType targetType) {
+        final Primitive fromBox = Primitive.ofBox(fromType);
+        final Primitive fromPrimitive = Primitive.of(fromType);
+        if (fromBox != null) {
+            // E.g. from "Integer" to "BigDecimal".
+            // Generate "x == null ? null : new BigDecimal(x.intValue())"
+
+            return Expressions.condition(
+                Expressions.equal(operand, RexImpTable.NULL_EXPR),
+                RexImpTable.NULL_EXPR,
+                Expressions.call(
+                    IgniteSqlFunctions.class,
+                    "toBigDecimal",
+                    Expressions.unbox(operand, fromBox),

Review comment:
       Realized that we actually dont need it. Refactored this method. 




-- 
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



[GitHub] [ignite] tledkov-gridgain commented on a change in pull request #9199: IGNITE-14589 DECIMAL sql type refactoring

Posted by GitBox <gi...@apache.org>.
tledkov-gridgain commented on a change in pull request #9199:
URL: https://github.com/apache/ignite/pull/9199#discussion_r659796361



##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/RexExecutorImpl.java
##########
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.exec.exp;
+
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.DataContext;
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.config.CalciteSystemProperty;
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.linq4j.tree.BlockBuilder;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.IndexExpression;
+import org.apache.calcite.linq4j.tree.MethodCallExpression;
+import org.apache.calcite.linq4j.tree.MethodDeclaration;
+import org.apache.calcite.linq4j.tree.ParameterExpression;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexExecutable;
+import org.apache.calcite.rex.RexExecutor;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexProgram;
+import org.apache.calcite.rex.RexProgramBuilder;
+import org.apache.calcite.sql.validate.SqlConformance;
+import org.apache.calcite.sql.validate.SqlConformanceEnum;
+import org.apache.calcite.util.BuiltInMethod;
+import org.apache.calcite.util.Util;
+
+/**
+ * Evaluates a {@link RexNode} expression.
+ *
+ * <p>For this impl, all the public methods should be
+ * static except that it inherits from {@link RexExecutor}.
+ * This pretends that other code in the project assumes
+ * the executor instance is {@link RexExecutorImpl}.
+*/
+public class RexExecutorImpl implements RexExecutor {
+

Review comment:
       Please remove empty line? according with codestyle 

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/RexExecutorImpl.java
##########
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.exec.exp;
+
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.DataContext;
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.config.CalciteSystemProperty;
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.linq4j.tree.BlockBuilder;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.IndexExpression;
+import org.apache.calcite.linq4j.tree.MethodCallExpression;
+import org.apache.calcite.linq4j.tree.MethodDeclaration;
+import org.apache.calcite.linq4j.tree.ParameterExpression;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexExecutable;
+import org.apache.calcite.rex.RexExecutor;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexProgram;
+import org.apache.calcite.rex.RexProgramBuilder;
+import org.apache.calcite.sql.validate.SqlConformance;
+import org.apache.calcite.sql.validate.SqlConformanceEnum;
+import org.apache.calcite.util.BuiltInMethod;
+import org.apache.calcite.util.Util;
+
+/**
+ * Evaluates a {@link RexNode} expression.
+ *
+ * <p>For this impl, all the public methods should be
+ * static except that it inherits from {@link RexExecutor}.
+ * This pretends that other code in the project assumes
+ * the executor instance is {@link RexExecutorImpl}.
+*/
+public class RexExecutorImpl implements RexExecutor {
+

Review comment:
       Please remove empty line according with codestyle 




-- 
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



[GitHub] [ignite] vladErmakov07 commented on a change in pull request #9199: IGNITE-14589 DECIMAL sql type refactoring

Posted by GitBox <gi...@apache.org>.
vladErmakov07 commented on a change in pull request #9199:
URL: https://github.com/apache/ignite/pull/9199#discussion_r659830310



##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/RexExecutorImpl.java
##########
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.exec.exp;
+
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.DataContext;
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.config.CalciteSystemProperty;
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.linq4j.tree.BlockBuilder;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.IndexExpression;
+import org.apache.calcite.linq4j.tree.MethodCallExpression;
+import org.apache.calcite.linq4j.tree.MethodDeclaration;
+import org.apache.calcite.linq4j.tree.ParameterExpression;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexExecutable;
+import org.apache.calcite.rex.RexExecutor;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexProgram;
+import org.apache.calcite.rex.RexProgramBuilder;
+import org.apache.calcite.sql.validate.SqlConformance;
+import org.apache.calcite.sql.validate.SqlConformanceEnum;
+import org.apache.calcite.util.BuiltInMethod;
+import org.apache.calcite.util.Util;
+
+/**
+ * Evaluates a {@link RexNode} expression.
+ *
+ * <p>For this impl, all the public methods should be
+ * static except that it inherits from {@link RexExecutor}.
+ * This pretends that other code in the project assumes
+ * the executor instance is {@link RexExecutorImpl}.
+*/
+public class RexExecutorImpl implements RexExecutor {
+

Review comment:
       fixed




-- 
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



[GitHub] [ignite] vladErmakov07 commented on a change in pull request #9199: IGNITE-14589 DECIMAL sql type refactoring

Posted by GitBox <gi...@apache.org>.
vladErmakov07 commented on a change in pull request #9199:
URL: https://github.com/apache/ignite/pull/9199#discussion_r659792913



##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ConverterUtils.java
##########
@@ -175,6 +175,54 @@ public static Expression convert(Expression operand, Type toType) {
         return convert(operand, fromType, toType);
     }
 
+    /**
+     * Convert {@code operand} from {@code targetType} to BigDecimal type.
+     *
+     * @param operand The expression to convert
+     * @param targetType Target type
+     * @param fromType Field type
+     * @return An expression with BidDecimal type, which calls IgniteSqlFunctions.toBigDecimal function.
+     */
+    public static Expression convertToDecimal(Expression operand, Type fromType, RelDataType targetType) {
+        final Primitive fromBox = Primitive.ofBox(fromType);
+        final Primitive fromPrimitive = Primitive.of(fromType);
+        if (fromBox != null) {
+            // E.g. from "Integer" to "BigDecimal".
+            // Generate "x == null ? null : new BigDecimal(x.intValue())"
+
+            return Expressions.condition(
+                Expressions.equal(operand, RexImpTable.NULL_EXPR),
+                RexImpTable.NULL_EXPR,
+                Expressions.call(
+                    IgniteSqlFunctions.class,
+                    "toBigDecimal",
+                    Expressions.unbox(operand, fromBox),
+                    Expressions.constant(targetType.getPrecision()),
+                    Expressions.constant(targetType.getScale())));
+        }
+        if (fromPrimitive != null) {
+            // E.g. from "int" to "BigDecimal".

Review comment:
       Added IgniteSqlFunctionsTest that covers all the cases.




-- 
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



[GitHub] [ignite] tledkov-gridgain merged pull request #9199: IGNITE-14589 DECIMAL sql type refactoring

Posted by GitBox <gi...@apache.org>.
tledkov-gridgain merged pull request #9199:
URL: https://github.com/apache/ignite/pull/9199


   


-- 
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



[GitHub] [ignite] tledkov-gridgain merged pull request #9199: IGNITE-14589 DECIMAL sql type refactoring

Posted by GitBox <gi...@apache.org>.
tledkov-gridgain merged pull request #9199:
URL: https://github.com/apache/ignite/pull/9199


   


-- 
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



[GitHub] [ignite] vladErmakov07 commented on a change in pull request #9199: IGNITE-14589 DECIMAL sql type refactoring

Posted by GitBox <gi...@apache.org>.
vladErmakov07 commented on a change in pull request #9199:
URL: https://github.com/apache/ignite/pull/9199#discussion_r659790266



##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rex/RexExecutorImpl.java
##########
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.rex;
+
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.DataContext;
+import org.apache.calcite.adapter.enumerable.EnumUtils;

Review comment:
       Fixed

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rex/RexExecutorImpl.java
##########
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.rex;

Review comment:
       Moved to the exec.exp package

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ConverterUtils.java
##########
@@ -304,32 +352,6 @@ else if (fromPrimitive != null && toBox != null) {
             if (operand != originTypedOperand)
               return originTypedOperand;
         }
-        if (toType == BigDecimal.class) {

Review comment:
       Added AssertionException with related error message

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ConverterUtils.java
##########
@@ -175,6 +175,54 @@ public static Expression convert(Expression operand, Type toType) {
         return convert(operand, fromType, toType);
     }
 
+    /**
+     * Convert {@code operand} from {@code targetType} to BigDecimal type.

Review comment:
       Fixed javadocs

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ConverterUtils.java
##########
@@ -175,6 +175,54 @@ public static Expression convert(Expression operand, Type toType) {
         return convert(operand, fromType, toType);
     }
 
+    /**
+     * Convert {@code operand} from {@code targetType} to BigDecimal type.
+     *
+     * @param operand The expression to convert
+     * @param targetType Target type
+     * @param fromType Field type
+     * @return An expression with BidDecimal type, which calls IgniteSqlFunctions.toBigDecimal function.
+     */
+    public static Expression convertToDecimal(Expression operand, Type fromType, RelDataType targetType) {
+        final Primitive fromBox = Primitive.ofBox(fromType);

Review comment:
       Added an assertion

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/IgniteSqlFunctions.java
##########
@@ -53,6 +59,46 @@ public static ScannableTable systemRange(Object rangeStart, Object rangeEnd, Obj
         return new RangeTable(rangeStart, rangeEnd, increment);
     }
 
+    /** CAST(DECIMAL AS VARCHAR). */
+    public static String toString(BigDecimal x) {
+        return x.toPlainString();
+    }
+
+    /** CAST(VARCHAR AS DECIMAL). */
+    public static BigDecimal toBigDecimal(String s, int precision, int scale) {
+        BigDecimal decimal = new BigDecimal(s.trim());
+        return precision == PRECISION_NOT_SPECIFIED ? decimal : decimal.setScale(scale, RoundingMode.HALF_UP);
+    }
+
+    /** CAST(FLOAT AS DECIMAL). */
+    public static BigDecimal toBigDecimal(float val, int precision, int scale) {
+        BigDecimal decimal = new BigDecimal(String.valueOf(val));
+        return precision == PRECISION_NOT_SPECIFIED ? decimal : decimal.setScale(scale, RoundingMode.HALF_UP);
+    }
+
+    /** CAST(DOUBLE AS DECIMAL). */
+    public static BigDecimal toBigDecimal(double val, int precision, int scale) {
+        BigDecimal decimal = BigDecimal.valueOf(val);
+        return precision == PRECISION_NOT_SPECIFIED ? decimal : decimal.setScale(scale, RoundingMode.HALF_UP);
+    }
+
+    /** CAST(REAL AS DECIMAL). */

Review comment:
       Renamed to FLOAT

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ConverterUtils.java
##########
@@ -175,6 +175,54 @@ public static Expression convert(Expression operand, Type toType) {
         return convert(operand, fromType, toType);
     }
 
+    /**
+     * Convert {@code operand} from {@code targetType} to BigDecimal type.
+     *
+     * @param operand The expression to convert
+     * @param targetType Target type
+     * @param fromType Field type
+     * @return An expression with BidDecimal type, which calls IgniteSqlFunctions.toBigDecimal function.
+     */
+    public static Expression convertToDecimal(Expression operand, Type fromType, RelDataType targetType) {
+        final Primitive fromBox = Primitive.ofBox(fromType);
+        final Primitive fromPrimitive = Primitive.of(fromType);
+        if (fromBox != null) {
+            // E.g. from "Integer" to "BigDecimal".
+            // Generate "x == null ? null : new BigDecimal(x.intValue())"
+
+            return Expressions.condition(
+                Expressions.equal(operand, RexImpTable.NULL_EXPR),
+                RexImpTable.NULL_EXPR,
+                Expressions.call(
+                    IgniteSqlFunctions.class,
+                    "toBigDecimal",
+                    Expressions.unbox(operand, fromBox),

Review comment:
       Realized that we actually dont need it. Refactored this method. 

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ConverterUtils.java
##########
@@ -175,6 +175,54 @@ public static Expression convert(Expression operand, Type toType) {
         return convert(operand, fromType, toType);
     }
 
+    /**
+     * Convert {@code operand} from {@code targetType} to BigDecimal type.
+     *
+     * @param operand The expression to convert
+     * @param targetType Target type
+     * @param fromType Field type
+     * @return An expression with BidDecimal type, which calls IgniteSqlFunctions.toBigDecimal function.
+     */
+    public static Expression convertToDecimal(Expression operand, Type fromType, RelDataType targetType) {
+        final Primitive fromBox = Primitive.ofBox(fromType);
+        final Primitive fromPrimitive = Primitive.of(fromType);
+        if (fromBox != null) {
+            // E.g. from "Integer" to "BigDecimal".
+            // Generate "x == null ? null : new BigDecimal(x.intValue())"
+
+            return Expressions.condition(
+                Expressions.equal(operand, RexImpTable.NULL_EXPR),
+                RexImpTable.NULL_EXPR,
+                Expressions.call(
+                    IgniteSqlFunctions.class,
+                    "toBigDecimal",
+                    Expressions.unbox(operand, fromBox),
+                    Expressions.constant(targetType.getPrecision()),
+                    Expressions.constant(targetType.getScale())));
+        }
+        if (fromPrimitive != null) {
+            // E.g. from "int" to "BigDecimal".

Review comment:
       Added IgniteSqlFunctionsTest that covers all the cases.

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/RexExecutorImpl.java
##########
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.exec.exp;
+
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.DataContext;
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.config.CalciteSystemProperty;
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.linq4j.tree.BlockBuilder;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.IndexExpression;
+import org.apache.calcite.linq4j.tree.MethodCallExpression;
+import org.apache.calcite.linq4j.tree.MethodDeclaration;
+import org.apache.calcite.linq4j.tree.ParameterExpression;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexExecutable;
+import org.apache.calcite.rex.RexExecutor;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexProgram;
+import org.apache.calcite.rex.RexProgramBuilder;
+import org.apache.calcite.sql.validate.SqlConformance;
+import org.apache.calcite.sql.validate.SqlConformanceEnum;
+import org.apache.calcite.util.BuiltInMethod;
+import org.apache.calcite.util.Util;
+
+/**
+ * Evaluates a {@link RexNode} expression.
+ *
+ * <p>For this impl, all the public methods should be
+ * static except that it inherits from {@link RexExecutor}.
+ * This pretends that other code in the project assumes
+ * the executor instance is {@link RexExecutorImpl}.
+*/
+public class RexExecutorImpl implements RexExecutor {
+

Review comment:
       fixed




-- 
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



[GitHub] [ignite] vladErmakov07 commented on a change in pull request #9199: IGNITE-14589 DECIMAL sql type refactoring

Posted by GitBox <gi...@apache.org>.
vladErmakov07 commented on a change in pull request #9199:
URL: https://github.com/apache/ignite/pull/9199#discussion_r659790956



##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ConverterUtils.java
##########
@@ -304,32 +352,6 @@ else if (fromPrimitive != null && toBox != null) {
             if (operand != originTypedOperand)
               return originTypedOperand;
         }
-        if (toType == BigDecimal.class) {

Review comment:
       Added AssertionException with related error message




-- 
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



[GitHub] [ignite] korlov42 commented on a change in pull request #9199: IGNITE-14589

Posted by GitBox <gi...@apache.org>.
korlov42 commented on a change in pull request #9199:
URL: https://github.com/apache/ignite/pull/9199#discussion_r658867489



##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rex/RexExecutorImpl.java
##########
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.rex;

Review comment:
       it would be better to place this under `org.apache.ignite.internal.processors.query.calcite.exec.exp` package

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rex/RexExecutorImpl.java
##########
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.rex;
+
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.DataContext;
+import org.apache.calcite.adapter.enumerable.EnumUtils;

Review comment:
       all invocations of EnumUtils should be replaced with ConverterUtils

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ConverterUtils.java
##########
@@ -175,6 +175,54 @@ public static Expression convert(Expression operand, Type toType) {
         return convert(operand, fromType, toType);
     }
 
+    /**
+     * Convert {@code operand} from {@code targetType} to BigDecimal type.
+     *
+     * @param operand The expression to convert
+     * @param targetType Target type
+     * @param fromType Field type
+     * @return An expression with BidDecimal type, which calls IgniteSqlFunctions.toBigDecimal function.
+     */
+    public static Expression convertToDecimal(Expression operand, Type fromType, RelDataType targetType) {
+        final Primitive fromBox = Primitive.ofBox(fromType);
+        final Primitive fromPrimitive = Primitive.of(fromType);
+        if (fromBox != null) {
+            // E.g. from "Integer" to "BigDecimal".
+            // Generate "x == null ? null : new BigDecimal(x.intValue())"
+
+            return Expressions.condition(
+                Expressions.equal(operand, RexImpTable.NULL_EXPR),
+                RexImpTable.NULL_EXPR,
+                Expressions.call(
+                    IgniteSqlFunctions.class,
+                    "toBigDecimal",
+                    Expressions.unbox(operand, fromBox),
+                    Expressions.constant(targetType.getPrecision()),
+                    Expressions.constant(targetType.getScale())));
+        }
+        if (fromPrimitive != null) {
+            // E.g. from "int" to "BigDecimal".

Review comment:
       looks like only few primitives are supported: flood and double. How is would work with other types like int or short? 
   
   Let's write a simple test that verifies a whole spectrum of conversions to decimal types: from byte, short, int, long, float, double. For both Nullable and Non Nullable cases.
   
   Negative cases could be covered too, like attempt to convert from bool, for example 

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ConverterUtils.java
##########
@@ -175,6 +175,54 @@ public static Expression convert(Expression operand, Type toType) {
         return convert(operand, fromType, toType);
     }
 
+    /**
+     * Convert {@code operand} from {@code targetType} to BigDecimal type.
+     *
+     * @param operand The expression to convert
+     * @param targetType Target type
+     * @param fromType Field type
+     * @return An expression with BidDecimal type, which calls IgniteSqlFunctions.toBigDecimal function.
+     */
+    public static Expression convertToDecimal(Expression operand, Type fromType, RelDataType targetType) {
+        final Primitive fromBox = Primitive.ofBox(fromType);
+        final Primitive fromPrimitive = Primitive.of(fromType);
+        if (fromBox != null) {
+            // E.g. from "Integer" to "BigDecimal".
+            // Generate "x == null ? null : new BigDecimal(x.intValue())"
+
+            return Expressions.condition(
+                Expressions.equal(operand, RexImpTable.NULL_EXPR),
+                RexImpTable.NULL_EXPR,
+                Expressions.call(
+                    IgniteSqlFunctions.class,
+                    "toBigDecimal",
+                    Expressions.unbox(operand, fromBox),

Review comment:
       why do we need to unbox operand? 

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/IgniteSqlFunctions.java
##########
@@ -53,6 +59,46 @@ public static ScannableTable systemRange(Object rangeStart, Object rangeEnd, Obj
         return new RangeTable(rangeStart, rangeEnd, increment);
     }
 
+    /** CAST(DECIMAL AS VARCHAR). */
+    public static String toString(BigDecimal x) {
+        return x.toPlainString();
+    }
+
+    /** CAST(VARCHAR AS DECIMAL). */
+    public static BigDecimal toBigDecimal(String s, int precision, int scale) {
+        BigDecimal decimal = new BigDecimal(s.trim());
+        return precision == PRECISION_NOT_SPECIFIED ? decimal : decimal.setScale(scale, RoundingMode.HALF_UP);
+    }
+
+    /** CAST(FLOAT AS DECIMAL). */
+    public static BigDecimal toBigDecimal(float val, int precision, int scale) {
+        BigDecimal decimal = new BigDecimal(String.valueOf(val));
+        return precision == PRECISION_NOT_SPECIFIED ? decimal : decimal.setScale(scale, RoundingMode.HALF_UP);
+    }
+
+    /** CAST(DOUBLE AS DECIMAL). */
+    public static BigDecimal toBigDecimal(double val, int precision, int scale) {
+        BigDecimal decimal = BigDecimal.valueOf(val);
+        return precision == PRECISION_NOT_SPECIFIED ? decimal : decimal.setScale(scale, RoundingMode.HALF_UP);
+    }
+
+    /** CAST(REAL AS DECIMAL). */

Review comment:
       REAL == FLOAT

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ConverterUtils.java
##########
@@ -304,32 +352,6 @@ else if (fromPrimitive != null && toBox != null) {
             if (operand != originTypedOperand)
               return originTypedOperand;
         }
-        if (toType == BigDecimal.class) {

Review comment:
       let's throw an assertion here with link to the method that should be used instead

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ConverterUtils.java
##########
@@ -175,6 +175,54 @@ public static Expression convert(Expression operand, Type toType) {
         return convert(operand, fromType, toType);
     }
 
+    /**
+     * Convert {@code operand} from {@code targetType} to BigDecimal type.
+     *
+     * @param operand The expression to convert
+     * @param targetType Target type
+     * @param fromType Field type
+     * @return An expression with BidDecimal type, which calls IgniteSqlFunctions.toBigDecimal function.
+     */
+    public static Expression convertToDecimal(Expression operand, Type fromType, RelDataType targetType) {
+        final Primitive fromBox = Primitive.ofBox(fromType);

Review comment:
       let's put an assertion here to validate that `targetType` _is_ a DECIMAL

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ConverterUtils.java
##########
@@ -175,6 +175,54 @@ public static Expression convert(Expression operand, Type toType) {
         return convert(operand, fromType, toType);
     }
 
+    /**
+     * Convert {@code operand} from {@code targetType} to BigDecimal type.

Review comment:
       actually it converts an operand of _fromType_ to the target type




-- 
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