Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execution of cmd cells in databricks notebook based on some condition

I have a python 3.5 notebook in databricks. I have a requirement to execute databricks notebook cells based on some conditions. I didn't see any functionality out of the box.

I have tried creating a python egg with the below code and installed it in databricks cluster.

def skip(line, cell=None):
'''Skips execution of the current line/cell if line evaluates to True.'''
  if eval(line):
    return

  get_ipython().ex(cell)

def load_ipython_extension(shell):

  '''Registers the skip magic when the extension loads.'''
  shell.register_magic_function(skip, 'line_cell')

def unload_ipython_extension(shell):
  '''Unregisters the skip magic when the extension unloads.'''
  del shell.magics_manager.magics['cell']['skip']

But while I'm trying to load that with extension using %load_ext skip_cell it's throwing an error saying "The module is not an IPython module". Any help or suggestion is appreciated. Thanks.

like image 769
Samrat De Avatar asked Oct 25 '25 20:10

Samrat De


1 Answers

Databricks notebooks are not based on Jupyter/IPython, which is why you are seeing that error.

If you are trying to build conditional workflows I would recommend combining the Notebook Workflows functionality with the Databricks REST API. This will allow you to control the flow of your program based on conditional statements and results of other processes.

Think of a notebook as a function that can be parameterized to accept and return exit values.

For an example, see the official documentation here.

like image 82
Raphael K Avatar answered Oct 27 '25 11:10

Raphael K