简体   繁体   English

如何使用 pyspark 读取包含多行的 sql 文件?

[英]How to read .sql file which contains multiple lines using pyspark?

I have an issue while reading.sql file from s3 bucket using Pyspark and my.sql file contains one sql with multiple lines its very big sql can't put it in a single line. I have an issue while reading.sql file from s3 bucket using Pyspark and my.sql file contains one sql with multiple lines its very big sql can't put it in a single line.

snippet of code.代码片段。

query = sc.textFile(query_path).collect()
df_test = spark.sql(query)

getting below error:出现以下错误:

An error was encountered:
An error occurred while calling o88.sql. Trace:
py4j.Py4JException: Method sql([class java.util.ArrayList]) does not exist
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:318)
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:326)
at py4j.Gateway.invoke(Gateway.java:274)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:238)
at java.lang.Thread.run(Thread.java:748)

any advice and suggestions will be greatly appreciated任何意见和建议将不胜感激

I don't understand why you're reading the query file through spark, but you can perhaps try this, which joins the whole text file into 1 line.我不明白你为什么要通过 spark 读取查询文件,但你也许可以试试这个,它将整个文本文件加入 1 行。

query = ' '.join(sc.textFile(query_path).collect())
df_test = spark.sql(query)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM