Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pyspark 过滤掉hivecontext.sql中的空字符串和空字符串_Pyspark_Hivecontext - Fatal编程技术网

Pyspark 过滤掉hivecontext.sql中的空字符串和空字符串

Pyspark 过滤掉hivecontext.sql中的空字符串和空字符串,pyspark,hivecontext,Pyspark,Hivecontext,我正在使用pyspark和hivecontext.sql,我想从数据中过滤掉所有空值和空值 因此,我使用简单的sql命令首先过滤掉空值,但它不起作用 我的代码: hiveContext.sql("select column1 from table where column2 is not null") 但是它在没有表达式“where column2不为null”的情况下工作 错误: Py4JavaError: An error occurred while calling o577.showS

我正在使用pyspark和hivecontext.sql,我想从数据中过滤掉所有空值和空值

因此,我使用简单的sql命令首先过滤掉空值,但它不起作用

我的代码:

hiveContext.sql("select column1 from table where column2 is not null")
但是它在没有表达式“where column2不为null”的情况下工作

错误:

Py4JavaError: An error occurred while calling o577.showString
我认为这是由于我的选择是错误的

数据示例:

column 1 | column 2
null     |   1
null     |   2
1        |   3
2        |   4
null     |   2
3        |   8
目标:

column 1 | column 2
1        |   3
2        |   4
3        |   8

Tks

我们无法将配置单元表名直接传递给配置单元上下文sql方法,因为它不理解配置单元表名。读取配置单元表的方法之一是使用pysaprk shell


我们需要注册从读取配置单元表中获得的数据帧。然后,我们可以运行SQL查询。

您必须为database_name.table指定一个名称,然后运行与之相同的查询。如果有帮助,请告诉我

Have you entered null values manually?
If yes then it will treat those as normal strings,
I tried following two use cases

dbname.person table in hive

name    age

aaa     null // this null is entered manually -case 1
Andy    30
Justin  19
okay       NULL // this null came as this field was left blank. case 2

---------------------------------
hiveContext.sql("select * from dbname.person").show();
+------+----+
|   name| age|
+------+----+
|  aaa |null|
|  Andy|  30|
|Justin|  19|
|  okay|null|
+------+----+

-----------------------------
case 2 
hiveContext.sql("select * from dbname.person where age is not null").show();
+------+----+
|  name|age |
+------+----+
|  aaa |null|
|  Andy| 30 |
|Justin| 19 |
+------+----+
------------------------------------
case 1
hiveContext.sql("select * from dbname.person where age!= 'null'").show();
+------+----+
|  name| age|
+------+----+
|  Andy|  30|
|Justin|  19|
|  okay|null|
+------+----+
------------------------------------
我希望上述用例能够消除您对过滤空值的疑虑 出来 如果您要查询在spark中注册的表,请使用sqlContext。

它适合我:

df.na.drop(subset=["column1"])