更改列位置后无法查询表
当使用“select * from t2p”查询表时,响应如下。我想我错过了一些概念,请帮助我。
失败,异常 java.io.IOException:java.lang.ClassCastException: org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyMapObjectInspector 无法转换为 org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector
第 1 步,创建表
create table t2p(id int, name string, score map<string,double>)
partitioned by (class int)
row format delimited
fields terminated by ','
collection items terminated by '\\;'
map keys terminated by ':'
lines terminated by '\n'
stored as textfile;
Step2,像Step3一样插入数据
1,zs,math:90.0;english:92.0
2,ls,chinese:89.0;math:80.0
3,xm,geo:87.0;math:80.0
4,lh,chinese:89.0;english:81.0
5,xw,physics:91v;english:81.0
,添加另一列
alter table t2p add columns (school string);
Step4,更改列的顺序
alter table t2p change school school string after name;
Step5,执行查询并得到错误如上所述。
select * from t2p;
When querying table using "select * from t2p", the reponse is as blow. I think I have missed some concepts, please help me out.
Failed with exception java.io.IOException:java.lang.ClassCastException: org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyMapObjectInspector cannot be cast to org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector
Step1, create table
create table t2p(id int, name string, score map<string,double>)
partitioned by (class int)
row format delimited
fields terminated by ','
collection items terminated by '\\;'
map keys terminated by ':'
lines terminated by '\n'
stored as textfile;
Step2, insert data like
1,zs,math:90.0;english:92.0
2,ls,chinese:89.0;math:80.0
3,xm,geo:87.0;math:80.0
4,lh,chinese:89.0;english:81.0
5,xw,physics:91v;english:81.0
Step3, add another column
alter table t2p add columns (school string);
Step4, change column's order
alter table t2p change school school string after name;
Step5, do query and get error as mentioned above.
select * from t2p;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个明显的错误。
您的命令
alter table t2p change school school string after name;
仅更改元数据。如果您要移动列,则数据必须已经与新架构匹配,或者您必须通过其他方式更改它以匹配。这意味着,地图列必须与新列匹配。换句话说,如果要移动列,请确保新列和现有数据类型相同。
我用 int 数据类型做了一个简单的实验。它之所以有效,是因为数据类型没有太大不同,但您可以看到元数据发生了变化,但数据保持不变。
您可以看到新的列 school 映射到位置 3(定义为 INT)。
解决方案 - 您可以执行此操作,但要确保新结构+数据类型与旧结构兼容。
This is an obvious error.
Your command
alter table t2p change school school string after name;
changes metadata only. If you are moving columns, the data must already match the new schema or you must change it to match by some other means.Which means, the map column has to be matching to the new column. In other words, if you want to move column around, make sure new column and existing data types are same.
I did a simple experiment with int data type. It worked because data type are not hugely different but you can see metadata changed but data stayed same.
You can see new column school is mapped to position 3( defined as INT).
Solution - You can do this but make sure new structure+data type is compatible to old structure.