Impala-将整个表的NULL替换为零

时间:2019-03-25 01:46:08

标签: null impala

您好,专家们-

反正是在impala中将整个表的null替换为零吗? 到目前为止,我只发现合并或大小写-何时,这使我可以逐列更改..但是我表中有210多个列,因此我在寻找更有效的方法。 >

选择粗线(table1.column1,0) 从table1

谢谢!

1 个答案:

答案 0 :(得分:0)

如果一个人需要替换200列中的NA而不输入200次以上的def isValid(str): if not str.regex_match("^[0-9]{3}-[AEIOU]{3}-[0-9]{3}-[AEIOU]{3}$"): return false return str[0..2] != str[8..10] and str[4..6] != str[12..14] and str[0..2] != "000" and str[8..10] != "000" ,这并不能回答这个普遍问题。

但是我可以从您的个人资料中看到您可能使用R。我也遇到同样的问题:我需要用200列替换表中的NA。

我的解决方案是将implyr与R配合使用。

COALESCE(table1.column1,0)

您还可以根据需要# libraries library(pacman) p_load(implyr ,odbc ,tidyverse ) # connect to database con <- src_impala(drv = odbc::odbc(), HOST="host.xxx.x", PORT=12345, ...) # connect to table table1 <- tbl(con,table1) # get columns with I want to replace NAs in, in my case it's numeric tables numeric_columns_to_replace_NAs <- table1 %>% select_if(is.numeric) %>% colnames # the command which replaces all NAs with 0's query <- table1 %>% mutate_at(.vars = vars(numeric_columns_to_replace_NAs), .funs = funs(coalesce(.,0))) # run command - this will print to the console query compute()(请参见docs

如果您需要在蜂巢中进行查询,则可以通过以下方式提取代码:

collect()
相关问题