2017-06-29 70 views
0

为什么没有得到比较的刺痛?如何使用spark过滤Hive中的记录

我有我的输入为 -

+-------+ 
|  y| 
+-------+ 
| ""no""| 
| ""no""| 
| ""no""| 
|""yes""| 
| ""no""| 
| ""no""| 
| ""no""| 
| ""no""| 
|""yes""| 
| ""no""| 
| ""no""| 
| ""no""| 
| ""no""| 
|""yes""| 
| ""no""| 
| ""no""| 
+-------+ 

而且我querying-

sqlContext.sql("select count(y) from dummy where y='yes'").show() 

,输出为 -

+---+ 
|_c0| 
+---+ 
| 0| 
+---+ 

y被声明为字符串类型的DDL

+0

如果已经使用'.replaceAll( “\” \ “”, “”)'早:d – philantrovert

回答

1

你应该试试这个:

sqlContext.sql("select count(y) from dummy where y='\"\"yes\""'").show() 

请注意,您的数据有""yes""不仅仅是yes

你仍然需要你的数据:)

的清洗或做这种方式:

sqlContext.sql("select count(y) from dummy where y like '%yes%'").show() 
+0

再次感谢!它的工作.. – Ninja

+0

你可以'接受'的答案或upvote,如果这个按问题工作,并在你的情况。 –