SPRKPY1028

pyspark.sql.readwriter.DataFrameReader.orc has a workaround

Category

Warning.

Description

This issue appears when the tool detects the usage of pyspark.sql.readwriter.DataFrameReader.orc which has a workaround.

Input code:

df = sparkSession.read.orc(path, mergeSchema="True")

Output code:

#EWI: SPRKPY1028 => pyspark.sql.readwriter.DataFrameReader.orc has a workaround, see documentation for more info
df = spark.read.orc(path, mergeSchema="True")

Scenario:

orc(

#Path path,

#Options mergeSchema=None, pathGlobFilter=None, recursiveFileLookup=None, modifiedBefore=None, modifiedAfter=None )

A couple of workarounds are possible in this scenario. Path: The first parameter "path" must be a stage to make an equivalence with Snowpark, so is recommended to implement a temporary stage and add each ".orc" path to the stage, using the prefix "file://", as follows. Source:

stringmap = sparkSession.read.orc(["./data/file1.orc", "./data/file2.orc"])

Expected:

stage = f'{sparkSession.get_fully_qualified_current_schema()}.{_generate_prefix("TEMP_STAGE")}'
sparkSession.sql(f'CREATE TEMPORARY STAGE IF NOT EXISTS {stage}').show()
sparkSession.file.put(f"file://./data/file1.orc", f"@{stage}")
sparkSession.file.put(f"file://./data/file2.orc", f"@{stage}")
stringmap = sparkSession.read.orc(stage)

Options: The additional parameters are also not supported by Snowpark as parameters, but for many of them you can use the "option" function to specify those .orc parameters as options, as follows: Source:

stringmap = sparkSession.read.orc(path, mergeSchema="True")

Expected:

stringmap = sparkSession.read.orc(path)

The following options are not supported for Snowpark: mergeSchema, compression.

Recommendation

  • For more support, you can email us at snowconvert-info@snowflake.com. If you have a contract for support with Snowflake, reach out to your sales engineer and they can direct your support needs.