serde配置单元表中的二进制摄取十进制

omqzjyyz  于 2021-06-24  发布在  Hive
关注(0)|答案(1)|浏览(463)

我正在检查是否可以用avro-serde更改配置单元中十进制字段的精度和比例,所以我编写了下面的代码。

create database test_avro;
use test_avro_table;
create external table test_table(
  name string,
  salary decimal(17,2),
  country string
)
row format delimited
fields terminated by ","
STORED AS textfile;

LOAD DATA LOCAL INPATH '/home/appsdesdssu/data/CACS_POC/data/' INTO TABLE 
test_table;

create external table test_table_avro
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.avro.AvroSerDe'
STORED AS INPUTFORMAT 
'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat'
tblproperties ('avro.schema.literal'='{
"name": "my_record",
"type": "record",
"fields": [
 {"name":"name", "type":"string"},
 {"name":"salary","type": "bytes","logicalType": "decimal","precision": 
 17,"scale": 2},
 {"name":"country", "type":"string"}
 ]}');

 insert overwrite table test_table_avro  select * from test_table;

在这里,我得到错误的说法

FAILED: UDFArgumentException Only string, char, varchar or binary data can be cast into binary data types.

数据文件:

steve,976475632987465.257,USA
rogers,349643905318384.137,mexico
groot,534563663653653.896,titan

如果我漏了什么,请告诉我。

wtzytmuj

wtzytmuj1#

到目前为止,配置单元还不支持十进制到二进制的版本。所以我们必须先把它转换成字符串,然后再转换成二进制

insert overwrite table test_table_avro  select * from test_table;

需要更改为

insert overwrite table test_table_avro  select name,cast(cast(salary as string) as binary),country from test_table;

相关问题