[
https://issues.apache.org/jira/browse/BEAM-2281?focusedWorklogId=111559&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-111559
]
ASF GitHub Bot logged work on BEAM-2281:
----------------------------------------
Author: ASF GitHub Bot
Created on: 13/Jun/18 17:01
Start Date: 13/Jun/18 17:01
Worklog Time Spent: 10m
Work Description: akedin commented on a change in pull request #5626:
[BEAM-2281] Refactoring literal expression type conversion
URL: https://github.com/apache/beam/pull/5626#discussion_r195162242
##########
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:
nit: explain a bit more in the message? E.g. "Attempted convert node zzz of
type xxx to yyy. This conversion is unsupported"
----------------------------------------------------------------
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: 111559)
Time Spent: 4h (was: 3h 50m)
> 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
> 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)