AWS Glue 无法读取 JSON 个 Snappy 文件
AWS Glue is not able to read JSON Snappy files
我在 PySpark 中使用 AWS Glue 作业读取数据时遇到问题:
数据从 AWS firehose(示例数据)发送到 s3 存储桶,存储为 JSON 并使用 snappy-hadoop 压缩。
我可以使用 spark.read.json() 从旧的 Spark 数据帧中读取数据,但这不适用于使用 [= 的 Glue 动态框架(模式根本没有被解析) 32=] 或 from_options 方法:
Spark Legacy DataFrame
# import from legacy spark read
spark_df = spark.read.json("s3://my-bucket/sample-json-hadoop-snappy/")
spark_df.printSchema()
- result:
root
|-- change: double (nullable = true)
|-- price: double (nullable = true)
|-- sector: string (nullable = true)
|-- ticker_symbol: string (nullable = true)
|-- year: integer (nullable = true)
|-- dt: date (nullable = true)
粘附DynamicFrame
# import from glue options
options_df = glueContext.create_dynamic_frame.from_options(
connection_type="s3",
connection_options = {"paths": ["s3://my-bucket/sample-json-hadoop-snappy/"]},
format="json"
)
options_df.printSchema()
- result:
root
您也可以在 glue 作业中使用 spark legacy,如果您只想对 glue 库执行操作,然后使用 spark 读取,然后将 df 转换为动态帧。
df = spark.read.json("s3://my-bucket/sample-json-hadoop-snappy/")
from awsglue.dynamicframe import DynamicFrame
DynF = DynamicFrame.fromDF(df, glueContext, "df")
目前仅在 Glue 库中支持 parquet 文件的 snappy 压缩。
我在 PySpark 中使用 AWS Glue 作业读取数据时遇到问题:
数据从 AWS firehose(示例数据)发送到 s3 存储桶,存储为 JSON 并使用 snappy-hadoop 压缩。
我可以使用 spark.read.json() 从旧的 Spark 数据帧中读取数据,但这不适用于使用 [= 的 Glue 动态框架(模式根本没有被解析) 32=] 或 from_options 方法:
Spark Legacy DataFrame
# import from legacy spark read
spark_df = spark.read.json("s3://my-bucket/sample-json-hadoop-snappy/")
spark_df.printSchema()
- result:
root
|-- change: double (nullable = true)
|-- price: double (nullable = true)
|-- sector: string (nullable = true)
|-- ticker_symbol: string (nullable = true)
|-- year: integer (nullable = true)
|-- dt: date (nullable = true)
粘附DynamicFrame
# import from glue options
options_df = glueContext.create_dynamic_frame.from_options(
connection_type="s3",
connection_options = {"paths": ["s3://my-bucket/sample-json-hadoop-snappy/"]},
format="json"
)
options_df.printSchema()
- result:
root
您也可以在 glue 作业中使用 spark legacy,如果您只想对 glue 库执行操作,然后使用 spark 读取,然后将 df 转换为动态帧。
df = spark.read.json("s3://my-bucket/sample-json-hadoop-snappy/")
from awsglue.dynamicframe import DynamicFrame
DynF = DynamicFrame.fromDF(df, glueContext, "df")
目前仅在 Glue 库中支持 parquet 文件的 snappy 压缩。