使用 createOrReplaceTempView 替换未按预期工作的临时视图
我有一个与此类似的数据集
{"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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以我通过以下代码得到了上述问题的解决方案
So I got the solution to the above question by the following code