cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Get Started Discussions
Start your journey with Databricks by joining discussions on getting started guides, tutorials, and introductory topics. Connect with beginners and experts alike to kickstart your Databricks experience.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Unable to log metrics to table/driver using spark StreamingQueryListener

harry546
New Contributor III

Hi Everyone,

Hope everyone is enjoying their holiday time.

I have spark streaming job (copy activity from location A to location B) and a Query Listener and attached to the streaming job.

As mentioned over the attachments I can see numInputRows gets logged to driver logs. But I can't write the finaldf to delta table and even can't log the dataframe to driver logs when I do "show".

I remember the same piece code used to work on earlier versions may be at spark 3.* which was an year back.

Please let me know if I am doing something wrong or suggest me if changes required.

Thanks

Harish Koduru

1 REPLY 1

Kaniz_Fatma
Community Manager
Community Manager

Hi @harry546, It sounds like youโ€™re dealing with a Spark Streaming job that copies data from location A to location B, and youโ€™ve attached a Query Listener to it.

 Youโ€™re encountering issues related to writing the finaldf to a Delta table and logging the DataFrame when using the show method.

 

Letโ€™s break down the problem and explore potential solutions:

 

Writing to Delta Table:

  • If youโ€™re unable to write finaldf to a Delta table, consider the following:
    • Check Permissions: Ensure that the user running the Spark job has the necessary permissions to write to the target Delta table location.
    • Table Exists: Verify that the Delta table exists at the specified location. If not, create it using the appropriate schema.
    • Check Data Types: Confirm that the data types of columns in finaldf match the schema of the Delta table.
    • Checkpoint Location: If youโ€™re using checkpoints, ensure that the checkpoint location is accessible and writable.
    • Error Logs: Check the driver logs for any error messages related to writing to the Delta table.

Logging DataFrame:

  • If youโ€™re unable to log the DataFrame using show, consider the following:
    • Driver Logs: Check the driver logs for any exceptions or issues related to the show operation.
    • Data Size: If finaldf contains a large amount of data, calling show might be resource-intensive. Consider limiting the number of rows displayed (e.g., finaldf.show(10)).
    • Memory Constraints: Ensure that the driver has sufficient memory to handle the DataFrame display.
    • Column Truncation: If the DataFrame has many columns, some columns may be truncated in the output. You can adjust the display settings using spark.conf.set("spark.sql.repl.eagerEval.enabled", True).

Spark Version Compatibility:

  • You mentioned that the code used to work on earlier versions (around Spark 3.*). Itโ€™s possible that there are version-specific changes or compatibility issues.
  • Consider checking the release notes for any relevant changes between your current Spark version and the version where the code worked.

Migration Strategy:

  • If you need to change locations and table names while preserving data and checkpoints, consider the following approach:
    • Read from the old location and write to the new location using Spark Streaming.
    • Create the new Delta table at the new location.
    • Once the migration is complete, update your streaming jobs to read from the new location and use the new table names.

If you encounter any specific errors or need further assistance, feel free to provide additional details, and Iโ€™ll be happy to assist! ๐Ÿš€

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