如何将数据帧与字符串变量进行比较

时间:2015-11-06 06:09:00

标签: dataframe pyspark rdd

我有一个字符串变量dest,它包含一定的值。我需要检查注册的temptable上是否存在此变量。我使用以下查询来查找它。

terminatecheck = sqlContext.sql("""
       SELECT 1 as op from known where node = """+dest +""" and 1=1 
    """)

现在我需要将terminatecheck的值与" 1"进行比较。并终止循环。 我查了一下,发现terminatecheck是一个行对象。我究竟如何比较这个?

 if  terminatecheck.op =="1":

不起作用

1 个答案:

答案 0 :(得分:0)

调用sqlContext.sql("Select...")将返回惰性评估的dataframe。您需要调用firsttakecollect之类的操作来获取评估的表达式并返回值。您可能希望调用first,它返回单行(类型为Row)。 takecollect返回一个数组(类型为Array[Row])。

terminatecheck = sqlContext
    .sql("""SELECT 1 as op from known where node = """+dest +""" and 1=1""")
    .first
相关问题