Hive 编程专题 之 – 列组合与算术组合

  • 2019 年 12 月 25 日
  • 筆記

列组合

环境:

Hive: 2.7.7  Oracle SQL Developer  Cloudera JDBC Driver  

案例:

select type + '.' + type_desc + ': ' + nameobject as full_name,type,type_desc,nameobject  from tblobj2  limit 10  

错误:

1 – 使用 Oracle SQL Developer 执行上述 HQL 语句第一列为 null :

image

解决方案:

select concat( type ,'.' , type_desc , ': ', nameobject ) as full_name,type,type_desc,nameobject  from tblobj2  limit 10  

image

用 || 快捷符号也可以连接字符串或者文本列

select type || type_desc || nameobject  from tblobj2  limit 10  

算术组合

环境:

Hive: 2.7.7  Oracle SQL Developer  Cloudera JDBC Driver  

案例:

select object_id,schema_id  , object_id + schema_id  , object_id-schema_id  ,object_id*schema_id  ,object_id/schema_id  ,object_id % schema_id  , object_id | schema_id  --, object_id & schema_id  , object_id ^ schema_id  , ~schema_id  from tblobj2  limit 10  

异常:

  1. 在运行被注释掉的表达式 object_id & schema_id 时,出现输入 schema_id 的对话框:

image

解决方案:

select object_id,schema_id  , object_id + schema_id  , object_id-schema_id  ,object_id*schema_id  ,object_id/schema_id  ,object_id % schema_id  , object_id | schema_id  , object_id & (schema_id)  , object_id ^ schema_id  , ~schema_id  from tblobj2  limit 10  

解决问题的关键在于 object_id & (schema_id)