<?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: GroupBy in delta live tables fails with error &amp;quot;RuntimeError: Query function must return either a Spark or Koalas DataFrame&amp;quot; in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/groupby-in-delta-live-tables-fails-with-error-quot-runtimeerror/m-p/33394#M24399</link>
    <description>&lt;P&gt;Are you trying to join two live tables using python? &lt;/P&gt;&lt;P&gt;Please refer the code here: &lt;A href="https://stackoverflow.com/questions/73112299/is-there-a-way-to-join-two-live-tables-on-delta-live-tables-using-python" target="test_blank"&gt;https://stackoverflow.com/questions/73112299/is-there-a-way-to-join-two-live-tables-on-delta-live-tables-using-python&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please let us know if this helps or if any further clarification is needed on the same. &lt;/P&gt;</description>
    <pubDate>Fri, 26 Aug 2022 14:56:00 GMT</pubDate>
    <dc:creator>Debayan</dc:creator>
    <dc:date>2022-08-26T14:56:00Z</dc:date>
    <item>
      <title>GroupBy in delta live tables fails with error "RuntimeError: Query function must return either a Spark or Koalas DataFrame"</title>
      <link>https://community.databricks.com/t5/data-engineering/groupby-in-delta-live-tables-fails-with-error-quot-runtimeerror/m-p/33393#M24398</link>
      <description>&lt;P&gt;I have a delta live table that I'm trying to run GroupBy on, but getting an error: "RuntimeError: Query function must return either a Spark or Koalas DataFrame". &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;@dlt.table
def groups_hierarchy():
&amp;nbsp;
     df = dlt.read_stream("groups_hierarchy_vw")
     return(df
        .select("id","name",split("path","/").alias("groups_in_path"),posexplode(split("path","/")).alias("pos","value"))
        .drop("val")
        .select("id","name",concat(lit("group"),"pos").alias("group_name"),expr("groups_in_path[pos]").alias("val"))
        .groupBy([df.id, df.name])&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Edit:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Something as simple as the following works just fine (you will notice I I am now reading a regular table and not a stream, just for testing purposes):&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;@dlt.table
def groups_hierarchy():
     return dlt.read("streaming_silver").groupBy("id").count()&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And it works fine when I apply my select statements and transformations, but the absolute last .groupBy() seems to convert it to a non Spark/Koalas DataFrame&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;@dlt.table
def groups_hierarchy():
     return dlt.read("streaming_silver").select("id","name",split("path","/").alias("groups_in_path"),posexplode(split("path","/")).alias("pos","value")).drop("val").select("id","name",concat(lit("group"),"pos").alias("group_name"),expr("groups_in_path[pos]").alias("val")).groupBy("id")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2022 11:31:47 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/groupby-in-delta-live-tables-fails-with-error-quot-runtimeerror/m-p/33393#M24398</guid>
      <dc:creator>PrebenOlsen</dc:creator>
      <dc:date>2022-08-26T11:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: GroupBy in delta live tables fails with error "RuntimeError: Query function must return either a Spark or Koalas DataFrame"</title>
      <link>https://community.databricks.com/t5/data-engineering/groupby-in-delta-live-tables-fails-with-error-quot-runtimeerror/m-p/33395#M24400</link>
      <description>&lt;P&gt;No, there is no join in my code above. The problem occurs at the very last line, when trying to use a .groupBy. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This works fine when reading a non-streaming view, but fails as soon as it is a stream. Is groupBy not supported yet for streams?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2022 06:58:27 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/groupby-in-delta-live-tables-fails-with-error-quot-runtimeerror/m-p/33395#M24400</guid>
      <dc:creator>PrebenOlsen</dc:creator>
      <dc:date>2022-08-29T06:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: GroupBy in delta live tables fails with error "RuntimeError: Query function must return either a Spark or Koalas DataFrame"</title>
      <link>https://community.databricks.com/t5/data-engineering/groupby-in-delta-live-tables-fails-with-error-quot-runtimeerror/m-p/33397#M24402</link>
      <description>&lt;P&gt;Hi @Preben Olsen​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does @Debayan Mukherjee​&amp;nbsp; response answer your question? If yes, would you be happy to mark it as best so that other members can find the solution more quickly?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We'd love to hear from you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 10:33:44 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/groupby-in-delta-live-tables-fails-with-error-quot-runtimeerror/m-p/33397#M24402</guid>
      <dc:creator>Vidula</dc:creator>
      <dc:date>2022-09-15T10:33:44Z</dc:date>
    </item>
    <item>
      <title>Re: GroupBy in delta live tables fails with error "RuntimeError: Query function must return either a Spark or Koalas DataFrame"</title>
      <link>https://community.databricks.com/t5/data-engineering/groupby-in-delta-live-tables-fails-with-error-quot-runtimeerror/m-p/33394#M24399</link>
      <description>&lt;P&gt;Are you trying to join two live tables using python? &lt;/P&gt;&lt;P&gt;Please refer the code here: &lt;A href="https://stackoverflow.com/questions/73112299/is-there-a-way-to-join-two-live-tables-on-delta-live-tables-using-python" target="test_blank"&gt;https://stackoverflow.com/questions/73112299/is-there-a-way-to-join-two-live-tables-on-delta-live-tables-using-python&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please let us know if this helps or if any further clarification is needed on the same. &lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2022 14:56:00 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/groupby-in-delta-live-tables-fails-with-error-quot-runtimeerror/m-p/33394#M24399</guid>
      <dc:creator>Debayan</dc:creator>
      <dc:date>2022-08-26T14:56:00Z</dc:date>
    </item>
    <item>
      <title>Re: GroupBy in delta live tables fails with error "RuntimeError: Query function must return either a Spark or Koalas DataFrame"</title>
      <link>https://community.databricks.com/t5/data-engineering/groupby-in-delta-live-tables-fails-with-error-quot-runtimeerror/m-p/33396#M24401</link>
      <description>&lt;P&gt;Could you please try to update your spark version. For few of the used cases , spark version 2.3.0 was throwing the same error which was fixed in 2.4.0. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please refer:&lt;/P&gt;&lt;P&gt;&lt;A href="https://issues.apache.org/jira/browse/SPARK-24156" target="test_blank"&gt;https://issues.apache.org/jira/browse/SPARK-24156&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 21:19:07 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/groupby-in-delta-live-tables-fails-with-error-quot-runtimeerror/m-p/33396#M24401</guid>
      <dc:creator>Debayan</dc:creator>
      <dc:date>2022-09-02T21:19:07Z</dc:date>
    </item>
  </channel>
</rss>

