How can i get the current command number dynamically from a cell in Azure databricks notebook? Is there any dbutils command to retrieve it?
For below cell, it should return 1.
How can i get the current command number dynamically from a cell in Azure databricks notebook? Is there any dbutils command to retrieve it?
For below cell, it should return 1.
Copyright © 2021 Jogjafile Inc.

There is no direct built-in function in dbutils or Spark to retrieve the current command number dynamically from a cell in an Azure Databricks notebook.
I have tried the following approach:
Result:
spark._jsparkSession.sparkContext().getLocalProperty("spark.databricks.notebook.id"): The command above retrieves the number of the current cell in the Databricks notebook.It uses the SparkSession (spark) to access the underlying Java SparkSession, then gets the local property "
spark.databricks.notebook.id" which holds the command number.The code uses the Spark context
(spark._jsparkSession.sparkContext())to access a property that represents the current command number associated with the notebook.This property,
spark.databricks.notebook.id, uniquely identifies each command execution within the notebook. ThegetLocalPropertymethod is then used to retrieve the value of this property, which corresponds to the command number.