<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Renan Raschcowetzki Matos on Medium]]></title>
        <description><![CDATA[Stories by Renan Raschcowetzki Matos on Medium]]></description>
        <link>https://medium.com/@renanmatos57?source=rss-92c1deff8899------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*DQptJj3JSbbv33LBU_cXEw.png</url>
            <title>Stories by Renan Raschcowetzki Matos on Medium</title>
            <link>https://medium.com/@renanmatos57?source=rss-92c1deff8899------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 17:49:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@renanmatos57/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a Interactive Data App within Databricks]]></title>
            <link>https://medium.com/@renanmatos57/building-a-interactive-data-app-within-databricks-bede5847c6bd?source=rss-92c1deff8899------2</link>
            <guid isPermaLink="false">https://medium.com/p/bede5847c6bd</guid>
            <category><![CDATA[databricks]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[data-engineering]]></category>
            <dc:creator><![CDATA[Renan Raschcowetzki Matos]]></dc:creator>
            <pubDate>Thu, 23 Nov 2023 16:25:17 GMT</pubDate>
            <atom:updated>2023-11-24T17:06:58.543Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IEc1gV61k8UNL611" /></figure><p>The world has become extremely data-centric. We can see this by the continued increase in all data jobs (Scientist, Engineer, Analyst). This also applies to the amount of data we produce daily, the need for jobs keeps pace with the need and increase in data.</p><p>Although the increase in raw data makes it more complex to relate everything and generate valueble insights, we have become more agile and want to find things that make everything simpler and simpler. All the drag-and-drop softwares, all the custom platform ecosystem, we want something that just works. And why don’t we try to make it? Every data team have their own strugles, having the possibility to overcome each one in their own manner is the objective of this post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tx7Q81ouD4UFaV7tWBUSBA.gif" /></figure><p>The main problem we had in my current job was the interaction between the Analysts and Engineers. The idea was that every data object must come from the Analysts but should be created by the Engineers team. Not having a interface or automation between these two made everything slow and manual. Our platform was somehow limited to using Databricks and Databricks only.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1EIgEM_EQo_eyNhGw7MmvA.gif" /></figure><p>How do we create something for data analysts with no knowledge in Python or any other programming language besides SQL. More than that, how we make something user-friendly and already integrated into the existing data platform?</p><p>With that in mind, we produced our first proof of concept, creating an application that facilitated some services for our data analysts, such as creating a <strong>VIEW </strong>from an E<strong>xcel</strong> or <strong>CSV</strong> file with just a few clicks or providing a connection to a <strong>database </strong>outside the data lake. They knew SQL, so everything before the SQL code should be intuitive.</p><p>The next step was to solve our biggest difficulty, creating and maintaining data objects through the application and making pipelines to automate basically everything. From now on, this will be a step by step guide on how we did it.</p><h3><strong><em>1. The interface(frontend):</em></strong></h3><p>There are not many ways to create and display something inside a Databricks notebook. Searching for things that work on Jupyter, we found Ipywidgets.</p><pre>!pip install ipywidgets</pre><p>The goal of this lib was to make plots more interactive, like in a dashboard, but we decided to go beyond that and built a menu-like interface.</p><pre>from ipywidgets import widgets<br><br>#create a list of options for the menu<br>menu_options=[<br>        &quot;Create View&quot;,<br>        &quot;Create Table&quot;,<br>        &quot;Edit Table&quot;<br>    ]<br><br>#create the menu<br>menu = widgets.ToggleButtons(<br>    value=None,<br>    button_style=&quot;success&quot;,<br>    button_width=&quot;430px&quot;,<br>    options=menu_options<br>)</pre><p>With a static layout created we need to handle the interactive part: the click and the action for each option. That can be done with the <strong><em>on_click </em></strong>and<strong><em> observe </em></strong>functions. We also need an output to this buttons clicks, for this we can use O<strong><em>utput</em></strong>:</p><pre>#create outuput for interaction<br>output = widgets.Output()<br><br>#handles interaction<br>def handle_btn_click(change):<br>    if change[&quot;new&quot;] == &quot;Create View&quot;:<br>        output.clear_output()<br>        #add action<br>        <br>    elif change[&quot;new&quot;] == &quot;Create Table&quot;:<br>        output.clear_output()<br>        #add action<br><br>    elif change[&quot;new&quot;] == &quot;Edit Table&quot;:<br>        output.clear_output()<br>        #add action<br><br>#gives the functionality to the existing menu widget<br>menu.observe(handle_btn_click, &quot;value&quot;)<br><br>#displays the menu<br>display(menu)</pre><p>This is the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*LOs4Lw3f5bNVunZJqtulxQ.png" /></figure><p>With the basic menu done, we can add custom user inputs for each menu option. We can create all the custom inputs with <strong><em>Text </em></strong>and <strong><em>Textarea </em></strong>widgets, and wrap it up for them to show together. This can be done using <strong><em>Vbox </em></strong>or <strong><em>Hbox</em></strong>, the V and H stands for vertical and horizontal respectively.</p><pre>#create outuput for interaction<br>output      = widgets.Output()<br><br>#text inputs<br>query       = widgets.Textarea(placeholder=&quot;Place for SQL&quot;, rows=30, value=None)<br>name_vw     = widgets.Textarea(placeholder=&quot;Name for View&quot;, rows=1, value=None)<br>name_tb     = widgets.Textarea(placeholder=&quot;Name for Table&quot;, rows=1, value=None)<br>name_old_tb = widgets.Textarea(placeholder=&quot;Table to be edited&quot;, rows=1, value=None)<br><br>#wraper<br>vbox        = widgets.VBox([])<br><br>#handles interaction<br>def handle_btn_click(change):<br>    if change[&quot;new&quot;] == &quot;Create View&quot;:<br>        output.clear_output()<br>        vbox.children = [name_vw,query]<br>        <br>    elif change[&quot;new&quot;] == &quot;Create Table&quot;:<br>        output.clear_output()<br>        vbox.children = [name_tb,query]<br><br>    elif change[&quot;new&quot;] == &quot;Edit Table&quot;:<br>        output.clear_output()<br>        vbox.children = [name_old_tb,query]<br><br>#gives the functionality to the existing menu widget<br>menu.observe(handle_btn_click, &quot;value&quot;)<br><br>#displays the menu<br>display(menu)<br>display(vbox)<br>display(widgets.VBox([output]))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/1*Zj23vku9HHuROem9HFIXyA.png" /></figure><p>To finish our menu, we need to add an action button. This button will trigger a process to read the input and validate the data. That is where Apache Spark comes in.</p><pre>#create button<br>button = widgets.Button(description=&quot;Validate&quot;, button_style=&quot;success&quot;)<br><br><br>#create action to button<br>def on_button_clicked(b):<br>  with output:<br>    output.clear_output()<br>    if menu.value == &quot;Create Table&quot;:<br>      #add action<br>    elif buttons.value == &quot;Edit Table&quot;:<br>      #add action<br>    elif buttons.value == &quot;Create View&quot;:<br>      #add action<br>    <br>#add action to the button     <br>button.on_click(on_button_clicked)</pre><h3><strong>2. The backend:</strong></h3><p>One great thing about creating this app inside Databricks is the native use of Apache Spark and connection with the Delta Lake. With this, we can create a SQL query field for the current menu options, and we can validate it with Pyspark. If there is any problem with our code, it will raise an error, eliminating the issue of finding bad SQL code down in the pipeline.</p><p>After instantiating our dataframe we implemented a dynamic description field for each column of the query to use as comments. We can just use df.columns to get them and this is fast because of Spark`s Lazy Evaluation. Doing this allows us to keep good metadata as soon as the object is created.</p><pre># create button<br>button = widgets.Button(description=&quot;Validate&quot;, button_style=&quot;success&quot;)<br><br><br>columns_comments = {}<br># create action to button<br>def on_button_clicked(b):<br>   with output:<br>       output.clear_output()<br>       columns_comments.clear()<br>       if menu.value == &quot;Create Table&quot;:<br>           df = spark.sql(query.value)<br>           columns = df.columns<br>           display(widgets.HTML(value=&quot;&lt;b&gt;Put the description for each column&lt;/b&gt;&quot;))<br>           for column in columns:<br>               display(widgets.HTML(value=f&quot;&lt;b&gt;{column}:&lt;/b&gt;&quot;))<br>               columns_comments[column] = widgets.Text(placeholder=column, value=None)<br>               display(columns_comments[column])</pre><p>After adding custom inputs for every option on the menu, we can move on and save these records to use on our future pipeline, as well as save the current user that is making these actions. We can go even further and create a task on our agility board to keep every step well documented. Here we will do this using Jira, but you can do this using any other similar software.</p><pre>user     = spark.sql(&#39;select current_user as user&#39;).collect()[0].user.split(&#39;@&#39;)[0]<br><br><br>metadata = {<br>   &quot;metadata&quot;: f&quot;{metadata}&quot;,<br>   &quot;table_comment&quot;: f&quot;{table_comment}&quot;,<br>   &quot;type_insert&quot;: f&quot;{type_insert}&quot;,<br>   &quot;sql_generator&quot;: f&quot;{query.value}&quot;,<br>   &quot;table_name&quot;: f&quot;{name_tb.value}&quot;,<br>   &quot;schema&quot;: f&quot;{schema}&quot;,<br>   &quot;append_column&quot;: f&quot;{append_column}&quot;,<br>   &quot;periodicity&quot;: f&quot;{periodicity}&quot;,<br>   &quot;engine&quot;: f&quot;{engine}&quot;,<br>   &quot;user&quot;: f&quot;{user}&quot;<br>}</pre><h4>2.1 Jira API:</h4><p>In the same way we designed the object creation process to be completely intuitive and automated, we seek the same level of convenience in recording user actions within our tool. We have eliminated the need to manually create tasks on our agility board, making the process entirely dynamic.</p><p>Following the submission of object creation information to Databricks through Pyspark, a trigger is activated to create a task on our activity board.</p><pre>def create_task_jira_exp(metadata):<br><br><br>#create a JSON-formatted description with various metadata<br>    description = json.dumps(metadata)<br>#write the description to a file in the /tmp directory<br>    dbutils.fs.put(&quot;/tmp/jira.txt&quot;, description, True)<br><br><br>#determine the type of task based on the value of buttons.value<br>    if buttons.value == &quot;Edit Table&quot;:<br>        type_task = &quot;Edit&quot;<br>    else:<br>        type_task = &quot;Create&quot;<br><br><br>#define fields for creating a Jira issue<br>    fields = {<br>        &quot;project&quot;: {&quot;id&quot;: 00000},<br>        &quot;summary&quot;: f&quot;[Engineering]{type_task} {metadata[&#39;table_name&#39;]}&quot;,<br>        &quot;description&quot;: &quot;attachment&quot;,<br>        &quot;issuetype&quot;: {&quot;name&quot;: &quot;History&quot;},<br>        &quot;labels&quot;: [&quot;Engineering&quot;, &quot;DATA_APP&quot;]<br>    }<br><br><br>#create a Jira instance and issue creation with provided fields<br>    jira = Jira(<br>        url=https://your-jira-user/rest/api/2/issue/,<br>        username=dbutils.secrets.get(&quot;your-jira-user&quot;),<br>        password=dbutils.secrets.get(&quot;your-jira-password&quot;),<br>    )<br>    response = jira.issue_create(fields)<br><br><br>#add the attachment (description) to the created Jira issue<br>    jira.add_attachment(response[&quot;key&quot;], &quot;/dbfs/tmp/jira.txt&quot;)<br><br><br>#remove the temporary file after attaching it to the Jira issue<br>    dbutils.fs.rm(&quot;/tmp/jira.txt&quot;, True)<br><br><br>#display a link to track the progress of the created Jira issue<br>    displayHTML(<br>        f&quot;&quot;&quot;&lt;h4&gt;&lt;b&gt;You can track the progress of your request in the task<br>&lt;a href=https://https://your-jira-user.io/browse/{response[&#39;key&#39;]}&gt;{response[&#39;key&#39;]}&lt;/a&gt;&lt;/b&gt;&lt;/h4&gt;&quot;&quot;&quot;<br>    )<br>#return the key of the created Jira issue<br>    return response[&quot;key&quot;]</pre><h4>2.2 Databricks API</h4><p>The next step is data object creation by a Databricks workflow. The run is triggered at the same time the Jira issue is created, with the proposition that the user is creating it now and wants to use it for testing as quickly as possible. Our platform has two environments: DEV and PRD. The idea is that there are no restrictions on the creation of objects in DEV, since it is a testing environment. That’s why the workflow creates the object first in DEV. Unfortunately, in our current context there is no access between environments to share data or use the Databricks API to trigger workflows. Because of this, we turned Jira into our data object deployment tool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oAMJa1ZtMoJoUMhVK60obA.png" /><figcaption>The current Architecture</figcaption></figure><p>We save the information about the object in a txt file and attach to the jira issue. Then we trigger the Databricks workflow with the Jira issue key as a variable. The workflow reads the data from the issue and proceeds to creation of the object.</p><p>With the object created the workflow moves the jira issue to the <strong><em>Under development</em></strong> lane. In addition it also comments the issue tagging the user that requested it to notify that the object is ready for use in DEV environment.</p><p>After further validation from both teams, someone from the engineering team will move the issue to the next lane. In the PRD environment, one scheduled Databricks Workflow will read the issues in this lane that have the <strong>DATA_APP. </strong>From there, the pipeline is basically the same from DEV, the object will be created based on the txt file and one comment will be placed to notify the user. The issue will be automatically finished and this will end our process.</p><h3>Conclusion</h3><p>The idea of this post and of the project is to present something new and expand the possibilities of what can be done inside Databricks and Notebooks in general. Following these steps will provide a start point for anyone to create an interactive application, what it will do is up to you. You can integrate it with basically anything, maybe transform it on a StreamDeck for data. The sky is the limit.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bede5847c6bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>