配置单元将配置单元中的值替换为null值



我有一个配置单元表,它将空记录表示为值为"N/a"的字符串,而不是NULL,是否有任何查询会在配置单元中将"N/A"转换为NULL值数据类型。

您可以尝试ifcase whendecode,如下所示-

select 
case when mycol='N/A' then NULL else mycol end as mycol,
if(mycol='N/A', NULL,mycol) as mycol_if
from mytable

;CASE WHEN";语法可能会有所帮助。创建配置单元表并导入数据。

hive> create table mytable(
name string,
mycol string
)
row format delimited fields terminated by "t";

hive> load data local inpath '/opt/tempdata/mytable.txt' into table mytable;

sql语法:

hive> select 
name,
case mycol when 'N/A' then NULL else mycol end as mycol
from mytable

希望它能帮助你。

最新更新