由于缺乏在pyspark / python中编写代码的知识,我决定在spark.sql中编写查询。我用两种格式编写了查询。第一种格式允许EOL中断。但是,以这种格式我会遇到错误,请参见下文:
results5 = spark.sql("SELECT\
appl_stock.Open\
,appl_stock.Close\
FROM appl_stock\
WHERE appl_stock.Close < 500")
上面的格式产生以下错误:
---------------------------------------------------------------------------
Py4JJavaError Traceback (most recent call last)
~/spark-2.1.0-bin-hadoop2.7/python/pyspark/sql/utils.py in deco(*a, **kw)
62 try:
---> 63 return f(*a, **kw)
64 except py4j.protocol.Py4JJavaError as e:
~/spark-2.1.0-bin-hadoop2.7/python/lib/py4j-0.10.4-src.zip/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name)
318 "An error occurred while calling {0}{1}{2}.\n".
--> 319 format(target_id, ".", name), value)
320 else:
Py4JJavaError: An error occurred while calling o19.sql.
: org.apache.spark.sql.catalyst.parser.ParseException:
mismatched input '.' expecting {<EOF>, ',', 'FROM', 'WHERE', 'GROUP', 'ORDER', 'HAVING', 'LIMIT', 'LATERAL', 'WINDOW', 'UNION', 'EXCEPT', 'MINUS', 'INTERSECT', 'SORT', 'CLUSTER', 'DISTRIBUTE'}(line 1, pos 35)
而以下代码可产生成功的结果,请参见下文:
results6 = spark.sql("SELECT appl_stock.Open ,appl_stock.Close FROM appl_stock WHERE appl_stock.Close < 500")
有人可以让我知道为什么第一个代码不起作用,而第二个代码却不起作用吗?
繁星点点滴滴
料青山看我应如是
慕村225694
相关分类