简体   繁体   English

使用 pyspark 从 S3 读取 parquet 分区表正在从分区列中删除前导零

[英]Reading parquet partitioned table from S3 using pyspark is dropping leading zeros from partition column

I have written a pyspark dataframe as parquet to s3 using EMR(pyspark), this data is partitioned by column(A) which is StringType()我已经使用 EMR(pyspark) 将 pyspark dataframe 作为镶木地板写入 s3,该数据由列 (A) 分区,即 StringType()

in S3 the data looks something like this在 S3 中,数据看起来像这样

table_path:
       A=0003
           part-file.parquet
       A=C456
           part-file.parquet

While I am reading this back as dataframe using pyspark I am loosing leading zeros in column 'A' of the datafram.当我使用 pyspark 将其读回为 dataframe 时,我在数据帧的“A”列中丢失了前导零。 Here is how the data is looking like这是数据的样子

df =  spark.read.parquet(table_path)
df.show()

| A  | B |
| 3  | ..|
|C456| ..|

I don't want to loose the leading zeros here.我不想在这里丢失前导零。 The expected result is:预期结果是:

| A  | B |
|0003| ..|
|C456| ..|

Found the solution of this issue in the delta documentation.在 delta 文档中找到了此问题的解决方案。

Spark has a property enabled by default. Spark 有一个默认启用的属性。 With this property spark tries to infer the schema of the partition column.使用此属性 spark 尝试推断分区列的架构。 For a partition column of string type we can easily go ahead and switch it off.对于字符串类型的分区列,我们可以轻松地提前 go 并将其关闭。

# Update partition data type infer property
from pyspark.conf import SparkConf
from pyspark.sql import SparkSession, Window
conf = (SparkConf().set("spark.sql.sources.partitionColumnTypeInference.enabled", False))
sc=SparkSession.builder.config(conf=conf).getOrCreate()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 python 从 AWS S3 读取在列上分区的镶木地板文件数据 - How to read parquet file data partitioned on column from AWS S3 using python 如何使用 pyarrow 从 s3 读取分区的镶木地板文件? - How do I read partitioned parquet files from s3 using pyarrow? 如何使用 python 从 s3 读取按日期文件夹分区的镶木地板文件? - How to read parquet file partitioned by date folder from s3 using python? 如何在 python 中使用 pyarrow 从 S3 读取分区的镶木地板文件 - How to read partitioned parquet files from S3 using pyarrow in python 使用 pyspark 到 pyspark dataframe 从 s3 位置读取镶木地板文件的文件夹 - Read a folder of parquet files from s3 location using pyspark to pyspark dataframe modin pandas read_parquet() 在 ETag KeyError 上失败,试图从 s3 读取分区的镶木地板 - modin pandas read_parquet() failed on ETag KeyError trying to read a partitioned parquet from s3 在Python Pandas中使用read_parquet从AWS S3读取Parquet文件时出现分段错误 - Segmentation Fault while reading parquet file from AWS S3 using read_parquet in Python Pandas 方案没有文件系统:s3 在读取镶木地板 s3 文件时使用 pyspark - No FileSystem for scheme: s3 using pyspark while reading parquet s3 file 如何使用 python 中的 spark dataframe 从 AWS S3 读取镶木地板文件(pyspark) - How to read parquet files from AWS S3 using spark dataframe in python (pyspark) 使用 S3 中的嵌套分区文件创建数据框,并在架构中加载具有分区列名称的数据框 - Create data frame using Nested partitioned file in S3 and load Data frame with partition column name in schema
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM