<?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: Understanding least common type in databricks in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/understanding-least-common-type-in-databricks/m-p/69254#M33877</link>
    <description>&lt;P&gt;Hey, if &lt;STRONG&gt;STRING&lt;/STRONG&gt; is the wider type then why did you say that the least common type between &lt;STRONG&gt;STRING&lt;/STRONG&gt; and &lt;STRONG&gt;INT&lt;/STRONG&gt; is &lt;STRONG&gt;STRING&lt;/STRONG&gt;?&lt;/P&gt;</description>
    <pubDate>Fri, 17 May 2024 11:22:23 GMT</pubDate>
    <dc:creator>Dhruv-22</dc:creator>
    <dc:date>2024-05-17T11:22:23Z</dc:date>
    <item>
      <title>Understanding least common type in databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/understanding-least-common-type-in-databricks/m-p/65378#M32794</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;I was reading the&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://docs.databricks.com/en/sql/language-manual/sql-ref-datatype-rules.html#type-precedence-list" target="_blank" rel="nofollow noopener noreferrer"&gt;data type rules&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;and found about least common type.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;I have a doubt. What is the least common type of STRING and INT? The referred link gives the following example saying the least common type is BIGINT.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;-- The least common type between an INT and STRING is BIGINT&lt;/SPAN&gt;
&lt;SPAN class=""&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class=""&gt;SELECT&lt;/SPAN&gt; typeof(&lt;SPAN class=""&gt;coalesce&lt;/SPAN&gt;(&lt;SPAN class=""&gt;5&lt;/SPAN&gt;, &lt;SPAN class=""&gt;'6'&lt;/SPAN&gt;));
  &lt;SPAN class=""&gt;BIGINT&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;P&gt;However, running this on Databricks 13.3, Spark 3.4.1 and Scala 2.12 configurations gives the following output.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class=""&gt;SELECT&lt;/SPAN&gt; typeof(&lt;SPAN class=""&gt;coalesce&lt;/SPAN&gt;(&lt;SPAN class=""&gt;5&lt;/SPAN&gt;, &lt;SPAN class=""&gt;'6'&lt;/SPAN&gt;));
  STRING&lt;/PRE&gt;&lt;P&gt;If I run explain on the query, then I get the following output.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;&amp;gt;&lt;/SPAN&gt; EXPLAIN EXTENDED &lt;SPAN class=""&gt;SELECT&lt;/SPAN&gt; typeof(&lt;SPAN class=""&gt;coalesce&lt;/SPAN&gt;(&lt;SPAN class=""&gt;5&lt;/SPAN&gt;, &lt;SPAN class=""&gt;'6'&lt;/SPAN&gt;));
&lt;SPAN class=""&gt;=&lt;/SPAN&gt;&lt;SPAN class=""&gt;=&lt;/SPAN&gt; Analyzed Logical Plan &lt;SPAN class=""&gt;=&lt;/SPAN&gt;&lt;SPAN class=""&gt;=&lt;/SPAN&gt;
typeof(&lt;SPAN class=""&gt;coalesce&lt;/SPAN&gt;(&lt;SPAN class=""&gt;5&lt;/SPAN&gt;, &lt;SPAN class=""&gt;6&lt;/SPAN&gt;)): string
Project [typeof(&lt;SPAN class=""&gt;coalesce&lt;/SPAN&gt;(&lt;SPAN class=""&gt;cast&lt;/SPAN&gt;(&lt;SPAN class=""&gt;5&lt;/SPAN&gt; &lt;SPAN class=""&gt;as&lt;/SPAN&gt; string), &lt;SPAN class=""&gt;6&lt;/SPAN&gt;)) &lt;SPAN class=""&gt;AS&lt;/SPAN&gt; typeof(&lt;SPAN class=""&gt;coalesce&lt;/SPAN&gt;(&lt;SPAN class=""&gt;5&lt;/SPAN&gt;, &lt;SPAN class=""&gt;6&lt;/SPAN&gt;))#&lt;SPAN class=""&gt;239637&lt;/SPAN&gt;]
&lt;SPAN class=""&gt;+&lt;/SPAN&gt;&lt;SPAN class=""&gt;-&lt;/SPAN&gt; OneRowRelation&lt;/PRE&gt;&lt;P&gt;It shows that INT is cast to STRING so the least common type should be STRING.&lt;/P&gt;&lt;P&gt;However, if I run an equal to operation between STRING and INT, then the explain query gives different output.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;&amp;gt;&lt;/SPAN&gt; EXPLAIN EXTENDED &lt;SPAN class=""&gt;SELECT&lt;/SPAN&gt; &lt;SPAN class=""&gt;'1.00'&lt;/SPAN&gt; &lt;SPAN class=""&gt;=&lt;/SPAN&gt; &lt;SPAN class=""&gt;1&lt;/SPAN&gt;;
&lt;SPAN class=""&gt;=&lt;/SPAN&gt;&lt;SPAN class=""&gt;=&lt;/SPAN&gt; Analyzed Logical Plan &lt;SPAN class=""&gt;=&lt;/SPAN&gt;&lt;SPAN class=""&gt;=&lt;/SPAN&gt;
(&lt;SPAN class=""&gt;1.00&lt;/SPAN&gt; &lt;SPAN class=""&gt;=&lt;/SPAN&gt; &lt;SPAN class=""&gt;1):&lt;/SPAN&gt; &lt;SPAN class=""&gt;boolean&lt;/SPAN&gt;
Project [(&lt;SPAN class=""&gt;cast&lt;/SPAN&gt;(&lt;SPAN class=""&gt;1.00&lt;/SPAN&gt; &lt;SPAN class=""&gt;as&lt;/SPAN&gt; &lt;SPAN class=""&gt;int&lt;/SPAN&gt;) &lt;SPAN class=""&gt;=&lt;/SPAN&gt; &lt;SPAN class=""&gt;1&lt;/SPAN&gt;) &lt;SPAN class=""&gt;AS&lt;/SPAN&gt; (&lt;SPAN class=""&gt;1.00&lt;/SPAN&gt; &lt;SPAN class=""&gt;=&lt;/SPAN&gt; &lt;SPAN class=""&gt;1&lt;/SPAN&gt;)#&lt;SPAN class=""&gt;239661&lt;/SPAN&gt;]
&lt;SPAN class=""&gt;+&lt;/SPAN&gt;&lt;SPAN class=""&gt;-&lt;/SPAN&gt; OneRowRelation&lt;/PRE&gt;&lt;P&gt;Here STRING is cast to INT.&lt;/P&gt;&lt;P&gt;Both&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;coalesce&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;=&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;rely on the least common type and give different results. So, what is exactly the least common type of STRING and INT? Also, which is more narrower STRING or INT? Any simple data type can be converted to STRING without any data loss, like an INT can be converted to STRING without any loss. However, the reverse is not true. If a STRING containing a decimal value is converted to INT, there would be a value loss. So shouldn't STRING be the wider type?&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 03 Apr 2024 10:04:55 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/understanding-least-common-type-in-databricks/m-p/65378#M32794</guid>
      <dc:creator>Dhruv-22</dc:creator>
      <dc:date>2024-04-03T10:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding least common type in databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/understanding-least-common-type-in-databricks/m-p/69254#M33877</link>
      <description>&lt;P&gt;Hey, if &lt;STRONG&gt;STRING&lt;/STRONG&gt; is the wider type then why did you say that the least common type between &lt;STRONG&gt;STRING&lt;/STRONG&gt; and &lt;STRONG&gt;INT&lt;/STRONG&gt; is &lt;STRONG&gt;STRING&lt;/STRONG&gt;?&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 11:22:23 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/understanding-least-common-type-in-databricks/m-p/69254#M33877</guid>
      <dc:creator>Dhruv-22</dc:creator>
      <dc:date>2024-05-17T11:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding least common type in databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/understanding-least-common-type-in-databricks/m-p/135491#M50365</link>
      <description>&lt;P&gt;The question is solved here - &lt;A href="https://community.databricks.com/t5/data-engineering/least-common-type-is-different-in-serverless-and-all-purpose/m-p/135481" target="_self"&gt;link&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Oct 2025 08:19:51 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/understanding-least-common-type-in-databricks/m-p/135491#M50365</guid>
      <dc:creator>Dhruv-22</dc:creator>
      <dc:date>2025-10-21T08:19:51Z</dc:date>
    </item>
  </channel>
</rss>

