无法使用 SerDe 加载具有固定宽度文件的配置单元 table
Unable to load hive table with fixed width file using SerDe
我有固定宽度的文件,其中包含 5 个固定宽度的列。这是文件的结构。 {col1:3char, col2:35char, col3:3char, col4:11char, col5:4char}
。这是示例文件
111 SagarKhatavkar 030 9999ABIT
112 VishalKataria 028 9999ABIT
113 GauravSomvanshi 032 9999ABIT
114 SonalKartekiya 029 9999ABIT
因此,正如其他帖子中所建议的那样,我使用了 RegEx。这是我创建的 DDL。
CREATE TABLE emp (emplid STRING, name STRING, age String, salary String, dept STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe'
WITH SERDEPROPERTIES (
"input.regex" = "(.{4})(.{35})(.{3})(.{11})(.{4})",
"output.format.string" = "%1$s %2$s %3$s %4$s %5$s"
)
在使用从本地加载数据后,table 将所有值都设为 NULL。
load data local inpath '/home/test1/emp.txt' into table emp;
Running select on the table
hive> select * from emp;
OK
NULL NULL NULL NULL NULL
NULL NULL NULL NULL NULL
NULL NULL NULL NULL NULL
NULL NULL NULL NULL NULL
Time taken: 0.959 seconds, Fetched: 4 row(s)
请指教DDL有什么问题?我正在使用 2.4.2.0-258 版本的 Hive。
我知道了。第一列数据有问题。该文件应该有 EXACT 57 字节。否则它会将完整的行标记为 NULL。
我有固定宽度的文件,其中包含 5 个固定宽度的列。这是文件的结构。 {col1:3char, col2:35char, col3:3char, col4:11char, col5:4char}
。这是示例文件
111 SagarKhatavkar 030 9999ABIT
112 VishalKataria 028 9999ABIT
113 GauravSomvanshi 032 9999ABIT
114 SonalKartekiya 029 9999ABIT
因此,正如其他帖子中所建议的那样,我使用了 RegEx。这是我创建的 DDL。
CREATE TABLE emp (emplid STRING, name STRING, age String, salary String, dept STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe'
WITH SERDEPROPERTIES (
"input.regex" = "(.{4})(.{35})(.{3})(.{11})(.{4})",
"output.format.string" = "%1$s %2$s %3$s %4$s %5$s"
)
在使用从本地加载数据后,table 将所有值都设为 NULL。
load data local inpath '/home/test1/emp.txt' into table emp;
Running select on the table
hive> select * from emp;
OK
NULL NULL NULL NULL NULL
NULL NULL NULL NULL NULL
NULL NULL NULL NULL NULL
NULL NULL NULL NULL NULL
Time taken: 0.959 seconds, Fetched: 4 row(s)
请指教DDL有什么问题?我正在使用 2.4.2.0-258 版本的 Hive。
我知道了。第一列数据有问题。该文件应该有 EXACT 57 字节。否则它会将完整的行标记为 NULL。