こんにちは、PySparkで作業している皆さんPythonと、コードについて言及し、いくつかの問題が発生しました。
windowSpec = Window.partitionBy(df_Broadcast['id']).orderBy(df_Broadcast['id'])
windowSpec
IdShift = lag(df_Broadcast["id"]).over(windowSpec).alias('IdShift')
df_Broadcast = df_Broadcast.withColumn('CheckId', df_Broadcast[idI'] != IdShift)
df_Broadcast.show()
これは私のコードです。ブール値true true falseを返します。このコードを初めて実行したときは正常に機能していましたが、カーネルを再起動した後、これがエラーになります。
---------------------------------------------------------------------------
Py4JJavaError Traceback (most recent call last)
<ipython-input-11-2d28913c9e2c> in <module>()
----> 1 df_Broadcast.show()
~/anaconda3/lib/python3.6/site-packages/pyspark/sql/dataframe.py in show(self, n, truncate)
334 """
335 if isinstance(truncate, bool) and truncate:
--> 336 print(self._jdf.showString(n, 20))
337 else:
338 print(self._jdf.showString(n, int(truncate)))
~/anaconda3/lib/python3.6/site-packages/py4j/Java_gateway.py in __call__(self, *args)
1131 answer = self.gateway_client.send_command(command)
1132 return_value = get_return_value(
-> 1133 answer, self.gateway_client, self.target_id, self.name)
1134
1135 for temp_arg in temp_args:
~/anaconda3/lib/python3.6/site-packages/pyspark/sql/utils.py in deco(*a, **kw)
61 def deco(*a, **kw):
62 try:
---> 63 return f(*a, **kw)
64 except py4j.protocol.Py4JJavaError as e:
65 s = e.Java_exception.toString()
~/anaconda3/lib/python3.6/site-packages/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name)
317 raise Py4JJavaError(
318 "An error occurred while calling {0}{1}{2}.\n".
--> 319 format(target_id, ".", name), value)
320 else:
321 raise Py4JError(
Py4JJavaError: An error occurred while calling o48.showString.
: org.Apache.spark.SparkException: Job aborted due to stage failure: Task 18 in stage 5.0 failed 1 times, most recent failure: Lost task 18.0 in stage 5.0 (TID 116, localhost, executor driver): Java.lang.OutOfMemoryError: Java heap space
Driver stacktrace:
at org.Apache.spark.scheduler.DAGScheduler.org$Apache$spark$scheduler$DAGScheduler$$failJobAndIndependentStages(DAGScheduler.scala:1499)
at org.Apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1487)
at org.Apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1486)
at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
at org.Apache.spark.scheduler.DAGScheduler.abortStage(DAGScheduler.scala:1486)
at org.Apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:814)
at org.Apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:814)
at scala.Option.foreach(Option.scala:257)
at org.Apache.spark.scheduler.DAGScheduler.handleTaskSetFailed(DAGScheduler.scala:814)
at org.Apache.spark.scheduler.DAGSchedulerEventProcessLoop.doOnReceive(DAGScheduler.scala:1714)
at org.Apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:1669)
at org.Apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:1658)
at org.Apache.spark.util.EventLoop$$anon$1.run(EventLoop.scala:48)
at org.Apache.spark.scheduler.DAGScheduler.runJob(DAGScheduler.scala:630)
at org.Apache.spark.SparkContext.runJob(SparkContext.scala:2022)
at org.Apache.spark.SparkContext.runJob(SparkContext.scala:2043)
at org.Apache.spark.SparkContext.runJob(SparkContext.scala:2062)
at org.Apache.spark.sql.execution.SparkPlan.executeTake(SparkPlan.scala:336)
at org.Apache.spark.sql.execution.CollectLimitExec.executeCollect(limit.scala:38)
at org.Apache.spark.sql.Dataset.org$Apache$spark$sql$Dataset$$collectFromPlan(Dataset.scala:2853)
at org.Apache.spark.sql.Dataset$$anonfun$head$1.apply(Dataset.scala:2153)
at org.Apache.spark.sql.Dataset$$anonfun$head$1.apply(Dataset.scala:2153)
at org.Apache.spark.sql.Dataset$$anonfun$55.apply(Dataset.scala:2837)
at org.Apache.spark.sql.execution.SQLExecution$.withNewExecutionId(SQLExecution.scala:65)
at org.Apache.spark.sql.Dataset.withAction(Dataset.scala:2836)
at org.Apache.spark.sql.Dataset.head(Dataset.scala:2153)
at org.Apache.spark.sql.Dataset.take(Dataset.scala:2366)
at org.Apache.spark.sql.Dataset.showString(Dataset.scala:245)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
at Java.lang.reflect.Method.invoke(Method.Java:498)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.Java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.Java:357)
at py4j.Gateway.invoke(Gateway.Java:280)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.Java:132)
at py4j.commands.CallCommand.execute(CallCommand.Java:79)
at py4j.GatewayConnection.run(GatewayConnection.Java:214)
at Java.lang.Thread.run(Thread.Java:748)
Caused by: Java.lang.OutOfMemoryError: Java heap space
エラーは
原因:Java.lang.OutOfMemoryError:Javaヒープスペース
操作を実行してOOMエラーを回避するには、より多くのメモリが必要です。
この問題は、Javaバージョンが原因です。 spark 2.3.3とJava 11がありました。Java 11を削除し、Java8をインストールしました。
問題は解決されました..
*********@*********-VirtualBox:/opt/Java$ Sudo update-alternatives --install "/usr/bin/Java" "Java" "/opt/Java/jdk1.8.0_202/"
update-alternatives: --install needs <link> <name> <path> <priority>
Use 'update-alternatives --help' for program usage information.
*********@*********-VirtualBox:/opt/Java$ Sudo update-alternatives --install "/usr/bin/Java" "Java" "/opt/Java/jdk1.8.0_202/" 1
update-alternatives: using /opt/Java/jdk1.8.0_202/ to provide /usr/bin/Java (Java) in auto mode
*********@*********-VirtualBox:/opt/Java$ Sudo update-alternatives --install "/usr/bin/Java" "Java" "/opt/Java/jdk1.8.0_202/bin/Java" 1
*********@*********-VirtualBox:/opt/Java$ Sudo update-alternatives --install "/usr/bin/javac" "javac" "/opt/Java/jdk1.8.0_202/bin/javac" 1
update-alternatives: using /opt/Java/jdk1.8.0_202/bin/javac to provide /usr/bin/javac (javac) in auto mode
*********@*********-VirtualBox:/opt/Java$ Java -version
Command 'Java' not found, but can be installed with:
Sudo apt install default-jre
Sudo apt install openjdk-11-jre-headless
Sudo apt install openjdk-8-jre-headless
*********@*********-VirtualBox:/opt/Java$ Sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/opt/Java/jdk1.8.0_202/bin/javaws" 1
update-alternatives: using /opt/Java/jdk1.8.0_202/bin/javaws to provide /usr/bin/javaws (javaws) in auto mode
*********@*********-VirtualBox:/opt/Java$ Sudo update-alternatives --install "/usr/bin/jar" "jar" "/opt/Java/jdk1.8.0_202/bin/jar" 1
update-alternatives: using /opt/Java/jdk1.8.0_202/bin/jar to provide /usr/bin/jar (jar) in auto mode
*********@*********-VirtualBox:/opt/Java$ Sudo update-alternatives --set "Java" "/opt/Java/jdk1.8.0_202/bin/Java"
update-alternatives: using /opt/Java/jdk1.8.0_202/bin/Java to provide /usr/bin/Java (Java) in manual mode
*********@*********-VirtualBox:/opt/Java$ Sudo update-alternatives --set "javac" "/opt/Java/jdk1.8.0_202/bin/javac"
*********@*********-VirtualBox:/opt/Java$ Sudo update-alternatives --set "javaws" "/opt/Java/jdk1.8.0_202/bin/javaws"
*********@*********-VirtualBox:/opt/Java$ Sudo update-alternatives --set "jar" "/opt/Java/jdk1.8.0_202/bin/jar"
*********@*********-VirtualBox:/opt/Java$ cd
*********@*********-VirtualBox:~$ Java -version
Java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)