<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>article Multi-table operations made simple with DiscoverX in Technical Blog</title>
    <link>https://community.databricks.com/t5/technical-blog/multi-table-operations-made-simple-with-discoverx/ba-p/67429</link>
    <description>&lt;H2&gt;&lt;SPAN&gt;&lt;STRONG&gt;Multi-Table Operations Made Simple&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;P&gt;&lt;SPAN&gt;In the ever-evolving landscape of data science and engineering, the ability to efficiently manage and manipulate data across multiple tables and databases is paramount. DiscoverX is a Python package that simplifies maintenance and optimization tasks like vacuuming and z-order by applying them concurrently across multiple tables with a single command. In this blog post, we'll walk through the process of installing DiscoverX, initializing it, and executing a multi-table count operation.&lt;/SPAN&gt;&lt;/P&gt;
&lt;H2&gt;&lt;SPAN&gt;Getting Started with DiscoverX&lt;/SPAN&gt;&lt;/H2&gt;
&lt;P&gt;&lt;SPAN&gt;To begin using DiscoverX, you first need to install the package within your Databricks environment. This can be done using the `%pip install` command as shown below:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;%pip install dbl-discoverx&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="archana986db_1-1719603072251.jpeg" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/9025i5F9ADCAA9ED1E3F6/image-size/large?v=v2&amp;amp;px=999" role="button" title="archana986db_1-1719603072251.jpeg" alt="archana986db_1-1719603072251.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;After the installation, it's recommended to restart the Python kernel to ensure that the newly installed package is properly loaded. This can be achieved with the following command:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;dbutils.library.restartPython()&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;Running Counts Across Tables&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;One of the common tasks in data analysis is to count the number of records in tables. DiscoverX simplifies this process by allowing you to define a set of tables and then apply a SQL template to each table.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;First, you need to import DiscoverX and initialize it:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;from discoverx import DX
dx = DX()&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="archana986db_2-1719603197199.jpeg" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/9026i0816EFEE69C578D7/image-size/large?v=v2&amp;amp;px=999" role="button" title="archana986db_2-1719603197199.jpeg" alt="archana986db_2-1719603197199.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Next, define the set of tables you want to run the operation on. In this example, we're using a wildcard to select all tables within a specific schema:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;from_tables = "archana_krish_fe_dsa.*.*"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is my test catalog: "&lt;SPAN&gt;archana_krish_fe_dsa" and the code considers all schemas and tables under it.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Then, you can specify the SQL operation you want to perform. In this case, we're counting the number of records in each table:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;dx.from_tables(from_tables).with_sql("""SELECT COUNT(*) FROM {full_table_name}""").explain()&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The &lt;EM&gt;explain()&lt;/EM&gt; method provides a preview of the SQL queries that will be executed without actually running them. This is useful for verification purposes to ensure that the correct operations will be applied.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="archana986db_4-1719603788021.jpeg" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/9028i232953D6266BEEF7/image-size/large?v=v2&amp;amp;px=999" role="button" title="archana986db_4-1719603788021.jpeg" alt="archana986db_4-1719603788021.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Finally, to execute the count operation across the selected tables, use the &lt;EM&gt;apply()&lt;/EM&gt; method:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;table_counts=dx.from_tables(from_tables).with_sql("""SELECT COUNT(*) FROM {full_table_name}""").apply()&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="archana986db_5-1719604756301.jpeg" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/9029iA4A526D8D5EE906F/image-size/large?v=v2&amp;amp;px=999" role="button" title="archana986db_5-1719604756301.jpeg" alt="archana986db_5-1719604756301.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The results can then be displayed using the &lt;EM&gt;display()&lt;/EM&gt; method, which will show the count of records for each table:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;table_counts.display()&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="archana986db_6-1719605020400.jpeg" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/9030iCFD27BCDF2B0F1D4/image-size/large?v=v2&amp;amp;px=999" role="button" title="archana986db_6-1719605020400.jpeg" alt="archana986db_6-1719605020400.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;You may further diagnose via a data profile or visualization.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="archana986db_7-1719605033012.jpeg" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/9031iC78D5B45E1BB66A9/image-size/large?v=v2&amp;amp;px=999" role="button" title="archana986db_7-1719605033012.jpeg" alt="archana986db_7-1719605033012.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;H2&gt;&lt;SPAN&gt;Conclusion&lt;/SPAN&gt;&lt;/H2&gt;
&lt;P&gt;&lt;SPAN&gt;In summary,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;DiscoverX offers a powerful and efficient way to perform multi-table operations within a Databricks Data Intelligence Platform. By simplifying tasks such as running counts across tables, it enables data professionals to focus more on analysis and less on the repetitive aspects of data management.This straightforward solution has been frequently requested by multiple customers and proven beneficial for them for simple discovery and auditing. Whether you're dealing with governance, compliance, or simply trying to get a quick overview of your datasets, DiscoverX is a tool worth exploring.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Citations:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;[1] &lt;A href="https://github.com/databrickslabs" target="_blank" rel="noopener"&gt;https://github.com/databrickslabs&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;[2] &lt;A href="https://github.com/databrickslabs/discoverx" target="_blank" rel="noopener"&gt;https://github.com/databrickslabs/discoverx&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;[3] &lt;A href="https://www.databricks.com/blog/2022/04/29/announcing-general-availability-of-databricks-feature-store.html" target="_blank" rel="noopener"&gt;https://www.databricks.com/blog/2022/04/29/announcing-general-availability-of-databricks-feature-store.html&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;[4] &lt;A href="https://www.youtube.com/watch?v=yWT13TUM8lk" target="_blank" rel="noopener"&gt;https://www.youtube.com/watch?v=yWT13TUM8lk&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;[5] &lt;A href="https://pypi.org/project/dbl-discoverx/" target="_blank" rel="noopener"&gt;https://pypi.org/project/dbl-discoverx/&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;[6] &lt;A href="https://www.databricks.com/learn/labs" target="_blank" rel="noopener"&gt;https://www.databricks.com/learn/labs&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Jul 2024 15:16:59 GMT</pubDate>
    <dc:creator>archana986db</dc:creator>
    <dc:date>2024-07-10T15:16:59Z</dc:date>
    <item>
      <title>Multi-table operations made simple with DiscoverX</title>
      <link>https://community.databricks.com/t5/technical-blog/multi-table-operations-made-simple-with-discoverx/ba-p/67429</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="archana986db_1-1714153699882.jpeg" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/7289i0A5DEE4039A0E9D8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="archana986db_1-1714153699882.jpeg" alt="archana986db_1-1714153699882.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="archana986db_0-1714153659303.jpeg" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/7287iAA107BFE32E2D44B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="archana986db_0-1714153659303.jpeg" alt="archana986db_0-1714153659303.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Multi-Table Operations Made Simple&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;DiscoverX is engineered to execute operations across many tables with a single command, making it an indispensable tool for data administrators and engineers. Whether you're dealing with maintenance tasks like vacuuming all tables or optimizing them with z-order, DiscoverX simplifies these operations, applying them concurrently across multiple tables. This not only saves time but also ensures consistency across your data assets.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 15:16:59 GMT</pubDate>
      <guid>https://community.databricks.com/t5/technical-blog/multi-table-operations-made-simple-with-discoverx/ba-p/67429</guid>
      <dc:creator>archana986db</dc:creator>
      <dc:date>2024-07-10T15:16:59Z</dc:date>
    </item>
  </channel>
</rss>

