3

Databricks throws an error when I try to delete a folder that doe not exist:

databricks workspace delete -r /Shared/myfolder

Error message:

Error: b'{"error_code":"RESOURCE_DOES_NOT_EXIST","message":"Path (/Shared/myfolder) doesn\'t exist."}'

So I would probably need to check if the folder exists before deleting it?

Pseudo code example:

if [ -d "/Shared/myfolder" ]; then databricks workspace delete -r /Shared/myfolder ; fi

How can I implement this using Databricks CLI?

kanimbla
  • 858
  • 1
  • 9
  • 23

1 Answers1

3

There is no separate function in the CLI (and REST API) to check existence of resource. You have two choices:

  1. Just ignore the error - if you don't want to see it in the script, just add > /dev/null at the end of command

  2. Use ls subcommand to check existence of directory, and then delete (but I personally don't see benefit from that). Something like this:

FOLDER=/Shared/myfolder
databricks workspace ls $FOLDER > /dev/null
RES=$?
if [ $RES -eq 0 ]; then
  databricks workspace delete -r $FOLDER
fi

I would personally go with first approach

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
  • Second choice makes my day, I have this as a step in azure pipeline and only with the second solution the pipeline will not fail which is what I was trying to achive. Really appreciate your help here, thanks! – kanimbla Oct 13 '21 at 09:24