在PySpark中,您可以定义一个架构并使用此预定义的架构读取数据源,例如:
Schema = StructType([ StructField("temperature", DoubleType(), True),
StructField("temperature_unit", StringType(), True),
StructField("humidity", DoubleType(), True),
StructField("humidity_unit", StringType(), True),
StructField("pressure", DoubleType(), True),
StructField("pressure_unit", StringType(), True)
])
Run Code Online (Sandbox Code Playgroud)
对于某些数据源,可以从数据源推断模式并使用此模式定义获取数据框。
是否可以从以前推断过数据的数据帧中获取模式定义(采用上述形式)?
df.printSchema()
将模式打印为树,但是我需要重用该模式(如上定义),因此我可以读取以前从另一个数据源推断出的具有该模式的数据源。
我创建了一个PySpark应用程序,它通过定义的Schema读取数据帧中的JSON文件.下面的代码示例
schema = StructType([
StructField("domain", StringType(), True),
StructField("timestamp", LongType(), True),
])
df= sqlContext.read.json(file, schema)
Run Code Online (Sandbox Code Playgroud)
我需要一种方法来找到如何在一种配置或ini文件等中定义此模式.并在主要的PySpark应用程序中阅读.
如果将来有任何需要而不更改主PySpark代码,这将帮助我修改更改JSON的模式.
感谢任何帮助,谢谢.
我正在尝试从 Azure Data Lake Gen1 读取 avro 数据,这些数据是从 Azure EventHubs 生成的,在 Azure Databricks 中使用 pyspark 启用了 Azure Event Hubs Capture:
inputdata = "evenhubscapturepath/*/*"
rawData = spark.read.format("avro").load(inputdata)
Run Code Online (Sandbox Code Playgroud)
以下语句失败
rawData.count()
Run Code Online (Sandbox Code Playgroud)
和
org.apache.spark.SparkException: Job aborted due to stage failure: Task 162 in stage 48.0 failed 4 times, most recent failure: Lost task 162.3 in stage 48.0 (TID 2807, 10.3.2.4, executor 1): java.io.IOException: Not an Avro data file
Run Code Online (Sandbox Code Playgroud)
EventHub-Capture 是否正在写入非 Avro 数据?是否有使用 Spark 读取 EventHub 捕获数据的最佳实践?
azure azure-eventhub pyspark azure-eventhub-capture azure-databricks