使用 createOrReplaceTempView 替换未按预期工作的临时视图

发布于 2025-01-09 07:02:15 字数 1297 浏览 1 评论 0原文

我有一个与此类似的数据集

{"name": "Michael", "age": "30", "producta1": "blah1", "producta3": "blah2"}
{"name": "Michael", "age": "31", "producta1": "blah3", "producta3": "blah4"}
{"name": "Michael", "age": "30", "producta1": "blah5", "producta3": "blah6"}
{"name": "Andy", "age": "28", "producta1": "blah5", "producta3": "blah6"}
{"name": "Andy", "age": "28", "producta1": "blah5", "producta3": "blah6"}
{"name": "Andy", "age": "28", "producta1": "blah5", "producta3": "blah6"}
{"name": "Justin", "age": "12", "producta1": "blah5", "producta3": "blah6"}
{"name": "Justin", "age": "12", "producta1": "blah5", "producta3": "blah6"}

我的 Spark 代码是

SparkSession sc = SparkSession.builder().appName("example app").config("spark.master","local").getOrCreate();

Dataset<Row> df = sc.read().json("/Users/g.bhageshpur/Downloads/spark-master/examples/src/main/examples/src/main/resources/people.json");

df.createOrReplaceTempView("people");

Dataset<Row> dfpeople = sc.sql("select * from people where name='Michael'");

dfpeople.createOrReplaceTempView("people");

我尝试通过调用 createOrReplaceTempView 来替换人员视图

,但出现以下错误

Recursive view `people` detected (cycle: `people` -> `people`)

如何替换 Spark 中的视图?

I have a dataset something similar to this

{"name": "Michael", "age": "30", "producta1": "blah1", "producta3": "blah2"}
{"name": "Michael", "age": "31", "producta1": "blah3", "producta3": "blah4"}
{"name": "Michael", "age": "30", "producta1": "blah5", "producta3": "blah6"}
{"name": "Andy", "age": "28", "producta1": "blah5", "producta3": "blah6"}
{"name": "Andy", "age": "28", "producta1": "blah5", "producta3": "blah6"}
{"name": "Andy", "age": "28", "producta1": "blah5", "producta3": "blah6"}
{"name": "Justin", "age": "12", "producta1": "blah5", "producta3": "blah6"}
{"name": "Justin", "age": "12", "producta1": "blah5", "producta3": "blah6"}

My spark code is

SparkSession sc = SparkSession.builder().appName("example app").config("spark.master","local").getOrCreate();

Dataset<Row> df = sc.read().json("/Users/g.bhageshpur/Downloads/spark-master/examples/src/main/examples/src/main/resources/people.json");

df.createOrReplaceTempView("people");

Dataset<Row> dfpeople = sc.sql("select * from people where name='Michael'");

dfpeople.createOrReplaceTempView("people");

I am trying to replace the people view by calling createOrReplaceTempView

but i get the following error as below

Recursive view `people` detected (cycle: `people` -> `people`)

How do I replace the view in spark?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

平生欢 2025-01-16 07:02:15

所以我通过以下代码得到了上述问题的解决方案


Dataset<Row> df = sc.read().json("/Users/g.bhageshpur/Downloads/spark-master/examples/src/main/examples/src/main/resources/people.json");

df.createOrReplaceTempView("people");

Dataset<Row> dfpeople = sc.sql("select * from people where name='Michael'");

sc.sqlContext().dropTempTable("people");

dfpeople.createOrReplaceTempView("people");

So I got the solution to the above question by the following code


Dataset<Row> df = sc.read().json("/Users/g.bhageshpur/Downloads/spark-master/examples/src/main/examples/src/main/resources/people.json");

df.createOrReplaceTempView("people");

Dataset<Row> dfpeople = sc.sql("select * from people where name='Michael'");

sc.sqlContext().dropTempTable("people");

dfpeople.createOrReplaceTempView("people");

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文