我正在使用 Delta Lake 运行 Pyspark,但是当我尝试导入 Delta 模块时,我得到了一个ModuleNotFoundError: No module named 'delta'
。这是在一台没有互联网连接的机器上,所以我必须手动下载 delta-core jarMaven并将其放入%SPARK_HOME%/jars
folder.
我的程序运行没有任何问题,我能够从 Delta Lake 写入和读取,所以我很高兴我得到了正确的罐子。但是当我尝试导入 delta 模块时from delta.tables import *
我得到了错误。
有关信息,我的代码是:
import os
from pyspark.sql import SparkSession
from pyspark.sql.types import TimestampType, FloatType, StructType, StructField
from pyspark.sql.functions import input_file_name
from Constants import Constants
if __name__ == "__main__":
constants = Constants()
spark = SparkSession.builder.master("local[*]")\
.appName("Delta Lake Testing")\
.getOrCreate()
# have to start spark session before importing: https://docs.delta.io/latest/quick-start.html#python
from delta.tables import *
# set logging level to limit output
spark.sparkContext.setLogLevel("ERROR")
spark.conf.set("spark.sql.session.timeZone", "UTC")
# push additional python files to the worker nodes
base_path = os.path.abspath(os.path.dirname(__file__))
spark.sparkContext.addPyFile(os.path.join(base_path, 'Constants.py'))
# start pipeline
schema = StructType([StructField("Timestamp", TimestampType(), False),\
StructField("ParamOne", FloatType(), False),\
StructField("ParamTwo", FloatType(), False),\
StructField("ParamThree", FloatType(), False)])
df = spark.readStream\
.option("header", "true")\
.option("timestampFormat", "yyyy-MM-dd HH:mm:ss")\
.schema(schema)\
.csv(constants.input_path)\
.withColumn("input_file_name", input_file_name())
df.writeStream\
.format("delta")\
.outputMode("append")\
.option("checkpointLocation", constants.checkpoint_location)\
.start("/tmp/bronze")
# await on stream
sqm = spark.streams
sqm.awaitAnyTermination()
这是使用 Spark v2.4.4 和 Python v3.6.1 并使用以下命令提交作业spark-submit path/to/job.py