[
https://issues.apache.org/jira/browse/HIVE-10313?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14500118#comment-14500118
]
Chaoyu Tang commented on HIVE-10313:
------------------------------------
[~xuefuz] I ran into this problem in coding when I tried to do a conversion
between decimals. For example, if I convert the value of ExprNodeConstantDesc
parsed from a decimal 1111.22BD (typeinfo decimal(6,2)) to a decimal (10,4). I
saw the ClassCastException error:
{code}
ERROR ql.Driver: FAILED: ClassCastException java.lang.String cannot be cast to
org.apache.hadoop.hive.common.type.HiveDecimal
java.lang.ClassCastException: java.lang.String cannot be cast to
org.apache.hadoop.hive.common.type.HiveDecimal
at
org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaHiveDecimalObjectInspector.getPrimitiveJavaObject(JavaHiveDecimalObjectInspector.java:55)
at
org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils.getHiveDecimal(PrimitiveObjectInspectorUtils.java:1001)
at
org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter$HiveDecimalConverter.convert(PrimitiveObjectInspectorConverter.java:349I
...
{code}
Tracing down to TypeCheckProcFactory.NumExprProcessor, I saw the
ExprNodeConstantDesc was created with typeInfo (of decimal) but value is
actually of type String. But as I understand the API
ExprNodeConstantDesc(TypeInfo typeInfo, Object value), the typeInfo should
reflect and interpret the type of value object.
> Literal Decimal ExprNodeConstantDesc should contain value of HiveDecimal
> instead of String
> ------------------------------------------------------------------------------------------
>
> Key: HIVE-10313
> URL: https://issues.apache.org/jira/browse/HIVE-10313
> Project: Hive
> Issue Type: Bug
> Components: Query Processor
> Affects Versions: 1.0.0
> Reporter: Chaoyu Tang
> Assignee: Chaoyu Tang
> Fix For: 1.2.0
>
> Attachments: HIVE-10313.1.patch, HIVE-10313.patch
>
>
> In TyepCheckProcFactory.NumExprProcessor, the ExprNodeConstantDesc is created
> from strVal:
> {code}
> else if (expr.getText().endsWith("BD")) {
> // Literal decimal
> String strVal = expr.getText().substring(0, expr.getText().length()
> - 2);
> HiveDecimal hd = HiveDecimal.create(strVal);
> int prec = 1;
> int scale = 0;
> if (hd != null) {
> prec = hd.precision();
> scale = hd.scale();
> }
> DecimalTypeInfo typeInfo = TypeInfoFactory.getDecimalTypeInfo(prec,
> scale);
> return new ExprNodeConstantDesc(typeInfo, strVal);
> }
> {code}
> It should use HiveDecmal:
> return new ExprNodeConstantDesc(typeInfo, hd);
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)