Forum Discussion

RickPeters's avatar
RickPeters
New Member
1 year ago
Solved

input_file_name() function not working when using custom Environment

EDIT;

After a bit more testing I found out that the input_file_name() function is not working when native execution engine is enabled in the Environment attached to the notebook.

 

Any ideas why this does not work?

------------------------------------------------------------------------------------------------------------------------------------------------

Hi,

 

I used to use the input_file_name() pyspark function when running a notebook using the Workspace default environment. In the Workspace settings, Set default environment is toggled Off. Running the following code did work:

 

from pyspark.sql.functions import input_file_name

df = spark.read.load('path/to/file.parquet', format='parquet')
df_file_name = df.withColumn("srcFile", input_file_name())
display(df_file_name)

 

 

When I tried to run the same code using a custom Environment (using the same runtime 1.3, no custom or public libraries), the srcFile field remains empty...

 

Any ideas why this happens and how to fix this?

4 Replies

  • Thanks for this! I was playing around with some Spark configurations and input_file_name also failed and ruined my Data Pipeline. I was unable to find the exact cause, and this helps a lot. 

    It's a real shame when stuff like this breaks a fairly stable ETL prod process.

  • Anonymous's avatar
    Anonymous
    Not applicable

    HI RickPeters,

    So you mean these script can executed on the default environment but not work property on the custom environment? If that is the case, I'd like to suggest you tried to check the library and resource difference between these two environments. 

    For the not existed libraries and resources, you may need to install them at first before import in the notebook.

    Manage Apache Spark libraries - Microsoft Fabric | Microsoft Learn

    Regards,

    Xiaoxin Sheng