<?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>topic Re: Delta Live Tables: Creating table with spark.sql and everything gets ingested at the first colum in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/delta-live-tables-creating-table-with-spark-sql-and-everything/m-p/105906#M42306</link>
    <description>&lt;P&gt;Can you try with the following code?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;query_a = """
SELECT
a.column_a as id_column,
a.column_b as val_column
FROM 
    catalog_a.schema_a.table_a a
"""

query_b = """
SELECT
b.column_a as id_column,
b.column_b as val_column
FROM 
    catalog_b.schema_b.table_b b
"""

@dlt.table
def table_a_data():
    return spark.sql(query_a)

@dlt.table
def table_b_data():
    return spark.sql(query_b)

@dlt.table
def dim_ship():
    return spark.sql("""
    SELECT * FROM table_a_data
    UNION ALL
    SELECT * FROM table_b_data
    """)&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 16 Jan 2025 13:19:09 GMT</pubDate>
    <dc:creator>Walter_C</dc:creator>
    <dc:date>2025-01-16T13:19:09Z</dc:date>
    <item>
      <title>Delta Live Tables: Creating table with spark.sql and everything gets ingested at the first column</title>
      <link>https://community.databricks.com/t5/data-engineering/delta-live-tables-creating-table-with-spark-sql-and-everything/m-p/105896#M42305</link>
      <description>&lt;P&gt;Hello everyone. I am new to DLT and I am trying to practice with it by doing some basic ingestions. I have a query like the following where I am getting data from &lt;STRONG&gt;two tables using &lt;STRONG&gt;UNION. &lt;/STRONG&gt;&lt;/STRONG&gt;I have noticed that everything gets&lt;STRONG&gt;&lt;STRONG&gt; ingested at the &lt;STRONG&gt;first column&amp;nbsp;as a &lt;STRONG&gt;comma separated string. &lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;In my pipeline I am executing somethin like the following. Any suggestions would be appreciated. Cheers!&lt;STRONG&gt;&lt;STRONG&gt;&lt;STRONG&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;query = """
SELECT
a.column_a as id_column
a.column_b as val_column
FROM 
    catalog_a.schema_a.table_a a

UNION ALL

SELECT
b.column_a as id_column
b.column_b as val_column
FROM 
    catalog_b.shema_b.table_b b"""


@dlt.table
def dim_ship():
    return spark.sql(query)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2025 13:02:59 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/delta-live-tables-creating-table-with-spark-sql-and-everything/m-p/105896#M42305</guid>
      <dc:creator>Costas96</dc:creator>
      <dc:date>2025-01-16T13:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: Delta Live Tables: Creating table with spark.sql and everything gets ingested at the first colum</title>
      <link>https://community.databricks.com/t5/data-engineering/delta-live-tables-creating-table-with-spark-sql-and-everything/m-p/105906#M42306</link>
      <description>&lt;P&gt;Can you try with the following code?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;query_a = """
SELECT
a.column_a as id_column,
a.column_b as val_column
FROM 
    catalog_a.schema_a.table_a a
"""

query_b = """
SELECT
b.column_a as id_column,
b.column_b as val_column
FROM 
    catalog_b.schema_b.table_b b
"""

@dlt.table
def table_a_data():
    return spark.sql(query_a)

@dlt.table
def table_b_data():
    return spark.sql(query_b)

@dlt.table
def dim_ship():
    return spark.sql("""
    SELECT * FROM table_a_data
    UNION ALL
    SELECT * FROM table_b_data
    """)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 16 Jan 2025 13:19:09 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/delta-live-tables-creating-table-with-spark-sql-and-everything/m-p/105906#M42306</guid>
      <dc:creator>Walter_C</dc:creator>
      <dc:date>2025-01-16T13:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: Delta Live Tables: Creating table with spark.sql and everything gets ingested at the first colum</title>
      <link>https://community.databricks.com/t5/data-engineering/delta-live-tables-creating-table-with-spark-sql-and-everything/m-p/105908#M42308</link>
      <description>&lt;P&gt;You are missing the commas that separate the columns.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2025 13:24:03 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/delta-live-tables-creating-table-with-spark-sql-and-everything/m-p/105908#M42308</guid>
      <dc:creator>adriennn</dc:creator>
      <dc:date>2025-01-16T13:24:03Z</dc:date>
    </item>
    <item>
      <title>Re: Delta Live Tables: Creating table with spark.sql and everything gets ingested at the first colum</title>
      <link>https://community.databricks.com/t5/data-engineering/delta-live-tables-creating-table-with-spark-sql-and-everything/m-p/105909#M42309</link>
      <description>&lt;P&gt;Unfortunately I am getting the same behavior.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2025 13:32:03 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/delta-live-tables-creating-table-with-spark-sql-and-everything/m-p/105909#M42309</guid>
      <dc:creator>Costas96</dc:creator>
      <dc:date>2025-01-16T13:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: Delta Live Tables: Creating table with spark.sql and everything gets ingested at the first colum</title>
      <link>https://community.databricks.com/t5/data-engineering/delta-live-tables-creating-table-with-spark-sql-and-everything/m-p/105928#M42317</link>
      <description>&lt;P&gt;The weird thing also is that it doesn't fetch only the specified columns but all the columns from the relevant tables.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2025 15:10:27 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/delta-live-tables-creating-table-with-spark-sql-and-everything/m-p/105928#M42317</guid>
      <dc:creator>Costas96</dc:creator>
      <dc:date>2025-01-16T15:10:27Z</dc:date>
    </item>
    <item>
      <title>Re: Delta Live Tables: Creating table with spark.sql and everything gets ingested at the first colum</title>
      <link>https://community.databricks.com/t5/data-engineering/delta-live-tables-creating-table-with-spark-sql-and-everything/m-p/105933#M42320</link>
      <description>&lt;P&gt;try to run the DLT pipeline with the code either as an SQL cell in a notebook or an *.sql file to see if you have the same problem:&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;SELECT&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;a&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;column_a&lt;/SPAN&gt; &lt;SPAN&gt;as&lt;/SPAN&gt;&lt;SPAN&gt; id_column,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;a&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;column_b&lt;/SPAN&gt; &lt;SPAN&gt;as&lt;/SPAN&gt;&lt;SPAN&gt; val_column&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;FROM&lt;/SPAN&gt; &lt;SPAN&gt;catalog_a&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;schema_a&lt;/SPAN&gt;&lt;SPAN&gt;.table_a&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;UNION ALL&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;SELECT&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;column_a &lt;/SPAN&gt;&lt;SPAN&gt;as&lt;/SPAN&gt;&lt;SPAN&gt; id_column,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;column_b &lt;/SPAN&gt;&lt;SPAN&gt;as&lt;/SPAN&gt;&lt;SPAN&gt; val_column&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;FROM&lt;/SPAN&gt;&lt;SPAN&gt; &amp;nbsp;catalog_shema_table_b;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 16 Jan 2025 15:53:35 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/delta-live-tables-creating-table-with-spark-sql-and-everything/m-p/105933#M42320</guid>
      <dc:creator>adriennn</dc:creator>
      <dc:date>2025-01-16T15:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: Delta Live Tables: Creating table with spark.sql and everything gets ingested at the first colum</title>
      <link>https://community.databricks.com/t5/data-engineering/delta-live-tables-creating-table-with-spark-sql-and-everything/m-p/105938#M42322</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/121795"&gt;@Costas96&lt;/a&gt;&amp;nbsp;I would recommend to verify the sql behavior in a notebook/sql editor.&amp;nbsp;&lt;/P&gt;&lt;P&gt;# SQL query with proper comma separation between columns&lt;BR /&gt;query = """&lt;BR /&gt;SELECT&lt;BR /&gt;a.column_a as id_column,&lt;BR /&gt;a.column_b as val_column&lt;BR /&gt;FROM&lt;BR /&gt;catalog_a.schema_a.table_a a&lt;/P&gt;&lt;P&gt;UNION ALL&lt;/P&gt;&lt;P&gt;SELECT&lt;BR /&gt;b.column_a as id_column,&lt;BR /&gt;b.column_b as val_column&lt;BR /&gt;FROM&lt;BR /&gt;catalog_b.shema_b.table_b b"""&lt;/P&gt;&lt;P&gt;# Define the Delta Live Table&lt;BR /&gt;@dlt.table&lt;BR /&gt;def dim_ship():&lt;BR /&gt;return spark.sql(query)&lt;/P&gt;&lt;P&gt;# Optional: Verify the output&lt;BR /&gt;df = spark.sql(query)&lt;/P&gt;&lt;P&gt;# Check schema&lt;BR /&gt;print("Schema:")&lt;BR /&gt;df.printSchema()&lt;/P&gt;&lt;P&gt;# Preview data&lt;BR /&gt;print("\nData Preview:")&lt;BR /&gt;df.show(5)&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2025 16:25:31 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/delta-live-tables-creating-table-with-spark-sql-and-everything/m-p/105938#M42322</guid>
      <dc:creator>MadhuB</dc:creator>
      <dc:date>2025-01-16T16:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: Delta Live Tables: Creating table with spark.sql and everything gets ingested at the first colum</title>
      <link>https://community.databricks.com/t5/data-engineering/delta-live-tables-creating-table-with-spark-sql-and-everything/m-p/106044#M42364</link>
      <description>&lt;P&gt;Actually I found the solution by using&amp;nbsp;&lt;STRONG&gt;spark.readStream&amp;nbsp;&lt;/STRONG&gt;to read the external tables a and b into two dataframes and then I just did&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&lt;SPAN&gt;combined_df &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;df_a.&lt;/SPAN&gt;&lt;SPAN&gt;union&lt;/SPAN&gt;&lt;SPAN&gt;(df_b)&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;to create my DLT table. Thank you!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jan 2025 09:22:22 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/delta-live-tables-creating-table-with-spark-sql-and-everything/m-p/106044#M42364</guid>
      <dc:creator>Costas96</dc:creator>
      <dc:date>2025-01-17T09:22:22Z</dc:date>
    </item>
  </channel>
</rss>

