I have created a function that writes out a dataframe to an s3 location with some parameters. All works except for re-partition list parameter. It fails with the error: raise TypeError("numPartitions should be an int or Column")
The year is an int column and the date is a sate type column. When I hard-code the 2 columns as
.repartition("parti_create_date", "parti_hour") it works.
I tried supplying them as a list, string, and col.
Nothing seems to work.
parti_list = ["parti_year", "parti_create_date", "parti_hour"]
re_parti_list = ["parti_create_date", "parti_hour"]
def spark_write(in_df, write_tgt_loc, parti_list, re_parti_list, tgt_file_format, write_mode, tgt_file_compression):
(in_df
.repartition(re_parti_list) #(re_parti_str)
.write
.partitionBy(parti_str)
.mode(write_mode).format(tgt_file_format)
.option('compression', tgt_file_compression).option("nullValue", "null").option("treatEmptyValuesAsNulls,", "true")
.save(write_tgt_loc))
spark_write(tgt_df, "s3://bucket/out/", parti_list, re_parti_list, "parquet", "overwrite","snappy")
Can you please help me figure out how to pass the re-partition columns as parameters in PySpark?