Notebook Parameter Issue

Rohit Kulkarni 731 Reputation points
2023-03-28T10:41:30.5+00:00

I have passed the parameter in Notebook 1

%run /Development/Tickets/silver_object_lead_cdf_latest $VarA="source_full_object_name" $VarB="destination_full_object_name"

And I am trying to call the parameter $VarA in notebook 2 with following query :

SELECT * FROM $VarA

But i am getting error :

AnalysisException: Invalid usage of '*' in expression 'alias'.

Please advise.

Regards Rohit

Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
{count} votes

1 answer

Sort by: Most helpful
  1. Matheus Fanali Giraldes 0 Reputation points
    2023-04-04T20:16:21.9433333+00:00

    Hi, Rohit! User's image

    To solve the error above In python, try this:
    intead of:

    salesforce_df = spark.sql(f"select Id,IsDeleted FROM $VarA")
    display(salesforce_df)

    do this:
    salesforce_df = spark.sql(f"select Id,IsDeleted FROM {VarA}")
    display(salesforce_df)
    To call a variable in a f-string, in python, you have to use {}. Furthermore, you can use a normal string and .format(), like below: \ salesforce_df = spark.sql("select Id,IsDeleted FROM {}".format(VarA)) \ display(salesforce_df)

    Hope it Helps!

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.