cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Autoloader ignore one folder in path

deng_dev
New Contributor III

Hi everyone!

I am trying to setup Autoloader to read json file with specific name from all subfolders under the path except one.

Could someone advice how this can be achieved? 

For example, I need to read from .../*/specific_name.json, but ignore test folder

So ../test/../specific_name.json should be ignored

I have tried this GLOB expression, but seems that this one is not working: 

"<bucket_name>/!(*test*)/specific_name.json"
3 REPLIES 3

standup1
Contributor

I think you can use REGEXP to achieve this. This might not be the best way, but it should get the job done. It's all about filtering that file in the df from getting loaded. Try something like this
df.select(“*”,”_metadata”).select(“*”,”_metadata.file_path”).filter(“file_path not REGEXP ‘/folder_name/’ “)

Make sure you change the folder name and df to yours.

You can also look into (pathGlobfilter) if the file name is static.

 

deng_dev
New Contributor III

Hi @standup1 , thank you for the response. The problem is I need to filter those files before they are loaded with Autoloader, as I need Autoloader to ignore them in schema inference.

oh I see, I know this is one of the limitation of the Autoloader. However, if your file path is different from test and static. you can increase your path in load() to make sure the load doesn't read from test. for example.

If your prod path is ...prod/*/specific_name.json and your test path is ...test/*/specific_name.json. Then, in load() do load(" ...prod/*/specific_name.json"). Whatever distinguishes your other path from test is what you use in load() so it will skip the test one. I hope this help or if you can share your full path of the files that would be helpful to see.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group