节目:
spark = SparkSession.builder.getOrCreate()
spark.sql("CREATE DATABASE icebergdb2")
spark.sql("USE icebergdb2")
schema = StructType([
StructField("vendor_id", LongType(), True),
StructField("trip_id", LongType(), True),
StructField("trip_distance", FloatType(), True),
StructField("fare_amount", DoubleType(), True),
StructField("store_and_fwd_flag", StringType(), True)
])
spark.sql("CREATE TABLE icebergdb2.iceberg_table (vendor_id LONG, trip_id LONG, trip_distance FLOAT, fare_amount DOUBLE, store_and_fwd_flag STRING) USING iceberg")
执行上述程序时出现此错误:
WARN Shell: Did not find winutils.exe: java.io.FileNotFoundException: Hadoop bin directory does not exist: C:\Users\abc\Desktop\ice\hadoop-3.3.1\etc\hadoop\bin -see https://wiki.apache.org/hadoop/WindowsProblems
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
Traceback (most recent call last):
File "C:\Users\abc\Desktop\ice\ice.py", line 24, in <module>
spark.sql("CREATE TABLE icebergdb2.iceberg_table \
File "C:\Users\abc\anaconda3\lib\site-packages\pyspark\sql\session.py", line 1034, in sql
return DataFrame(self._jsparkSession.sql(sqlQuery), self)
File "C:\Users\abc\anaconda3\lib\site-packages\py4j\java_gateway.py", line 1321, in __call__
return_value = get_return_value(
File "C:\Users\abc\anaconda3\lib\site-packages\pyspark\sql\utils.py", line 190, in deco
return f(*a, **kw)
PS C:\Users\abc\Desktop\ice> SUCCESS: The process with PID 1204 (child process of PID 8780) has been terminated.
SUCCESS: The process with PID 8780 (child process of PID 14136) has been terminated.
SUCCESS: The process with PID 14136 (child process of PID 14132) has been terminated.
使用 Apache Spark 创建 Apache Iceberg 表。
看起来您正在尝试在 Windows 上运行 Spark。为此,您需要一个名为“winutils”的工具。在错误消息中,您可以看到
Did not find winutils.exe: java.io.FileNotFoundException: Hadoop bin directory does not exist
。
让我们看看您必须采取哪些步骤才能在 PC 上正确运行 Spark 实例:
spark-3.3.1-bin-hadoop3.tgz
。C:\Spark
SPARK_HOME
的环境变量,并将其指向您刚刚提取和移动的文件夹(来自第 2 点的 C:\Spark
)。%SPARK_HOME%/bin
添加到您的 PATH
环境变量中。这使您能够运行 spark-submit
和 spark-shell
等 Spark 命令。现在您已经安装了 Spark!为了让它在 Windows 上正常运行,我们现在需要让这个 winutils 工具工作:
此网站下载
winutils.exe
和hadoop.dll
。由于它们是在 64 位 JVM 上预编译的,因此您必须确保安装了 64 位 JDK。当然,如果您愿意,也可以使用其他的,这里只是举个例子。bin
的文件夹中。例如,C:\hadoop\bin
。HADOOP_HOME
环境变量,并将其指向放置 2 个文件的 bin 文件夹的父文件夹。在前面的示例中,它将是 C:\hadoop
。%HADOOP_HOME%/bin
添加到您的 PATH
环境变量中。当你完成所有这些事情后,你的问题就应该消失了!