[ 
https://issues.apache.org/jira/browse/BEAM-2281?focusedWorklogId=111560&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-111560
 ]

ASF GitHub Bot logged work on BEAM-2281:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 13/Jun/18 17:11
            Start Date: 13/Jun/18 17:11
    Worklog Time Spent: 10m 
      Work Description: vectorijk commented on a change in pull request #5626: 
[BEAM-2281] Refactoring literal expression type conversion 
URL: https://github.com/apache/beam/pull/5626#discussion_r195165342
 
 

 ##########
 File path: 
sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/interpreter/BeamSqlFnExecutor.java
 ##########
 @@ -171,36 +171,39 @@ static BeamSqlExpression buildExpression(RexNode 
rexNode) {
         //     node.getSqlTypeName() = DECIMAL (the actual internal storage 
format)
         // So we need to do a convert here.
         // check RexBuilder#makeLiteral for more information.
+
         SqlTypeName realType = node.getType().getSqlTypeName();
         Object realValue = value;
-        if (type == SqlTypeName.DECIMAL) {
-          BigDecimal rawValue = (BigDecimal) value;
+
+        if (SqlTypeName.NUMERIC_TYPES.contains(type)) {
           switch (realType) {
             case TINYINT:
-              realValue = (byte) rawValue.intValue();
+              realValue = SqlFunctions.toByte(value);
               break;
             case SMALLINT:
-              realValue = (short) rawValue.intValue();
+              realValue = SqlFunctions.toShort(value);
               break;
             case INTEGER:
-              realValue = rawValue.intValue();
+              realValue = SqlFunctions.toInt(value);
               break;
             case BIGINT:
-              realValue = rawValue.longValue();
+              realValue = SqlFunctions.toLong(value);
+              break;
+            case FLOAT:
+              realValue = SqlFunctions.toFloat(value);
+              break;
+            case DOUBLE:
+              realValue = SqlFunctions.toDouble(value);
               break;
             case DECIMAL:
-              realValue = rawValue;
+              realValue = SqlFunctions.toBigDecimal(value);
               break;
             default:
               throw new IllegalStateException(
-                  "type/realType mismatch: " + type + " VS " + realType);
-          }
-        } else if (type == SqlTypeName.DOUBLE) {
-          Double rawValue = (Double) value;
-          if (realType == SqlTypeName.FLOAT) {
-            realValue = rawValue.floatValue();
+                  "type / realType mismatch: " + type + " <-> " + realType);
 
 Review comment:
   Addressed. Update later.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 111560)
    Time Spent: 4h 10m  (was: 4h)

> call SqlFunctions in operator implementation
> --------------------------------------------
>
>                 Key: BEAM-2281
>                 URL: https://issues.apache.org/jira/browse/BEAM-2281
>             Project: Beam
>          Issue Type: Improvement
>          Components: dsl-sql
>            Reporter: Xu Mingmin
>            Assignee: Kenneth Knowles
>            Priority: Major
>          Time Spent: 4h 10m
>  Remaining Estimate: 0h
>
> Calcite has a collections of functions in 
> {{org.apache.calcite.runtime.SqlFunctions}}. It sounds a good source to 
> leverage when adding operators as {{BeamSqlExpression}}. 
> [~xumingming] [~app-tarush], any comments?



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to