自学内容网 自学内容网

查询hive数据库报错Required field ‘type‘ is unset

一、报错内容TProtocolException: Required field ‘type’ is unset

org.apache.thrift.protocol.TProtocolException: 
Required field ‘typeis unset! Struct:TPrimitiveTypeEntry(type:null, 
typeQualifiers:TTypeQualifiers(qualifiers:{characterMaximumLength=}))

报错sql:

执行以下sql时报错:

select  tx_code||tx_amt from trans;

报错原因:
因为用了||拼接两个字段的值,然后发现这两个字段不是string类型,tx_code是int类型,tx_amt是decimal类型,这两种类型拼接时不能直接转换成string类型,所以需要转换。

解决方法:

遇到||需要将两个字段拼接在一起时,若字段类型不是string类型,可以通过cast函数将类型转换成string类型
select  cast(tx_code as string)||cast(tx_amt as string) from trans;

原文地址:https://blog.csdn.net/weixin_49114503/article/details/142853037

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!