<?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 what does the coalesce and eval in my query do? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/what-does-the-coalesce-and-eval-in-my-query-do/m-p/300795#M90563</link>
    <description>&lt;P&gt;Could anyone explain what does the below search string means ?&lt;/P&gt;

&lt;P&gt;| eval fieldA=coalesce(abc, "def")&lt;/P&gt;</description>
    <pubDate>Thu, 18 May 2017 19:38:21 GMT</pubDate>
    <dc:creator>pavanae</dc:creator>
    <dc:date>2017-05-18T19:38:21Z</dc:date>
    <item>
      <title>what does the coalesce and eval in my query do?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/what-does-the-coalesce-and-eval-in-my-query-do/m-p/300795#M90563</link>
      <description>&lt;P&gt;Could anyone explain what does the below search string means ?&lt;/P&gt;

&lt;P&gt;| eval fieldA=coalesce(abc, "def")&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2017 19:38:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/what-does-the-coalesce-and-eval-in-my-query-do/m-p/300795#M90563</guid>
      <dc:creator>pavanae</dc:creator>
      <dc:date>2017-05-18T19:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: what does the coalesce and eval in my query do?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/what-does-the-coalesce-and-eval-in-my-query-do/m-p/300796#M90564</link>
      <description>&lt;P&gt;it would create a field called &lt;STRONG&gt;fieldA&lt;/STRONG&gt; and if there was a value in field &lt;STRONG&gt;abc&lt;/STRONG&gt; it would use that value, otherwise it would fill in &lt;STRONG&gt;def&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.6.0/SearchReference/ConditionalFunctions#coalesce.28X.2C....29"&gt;http://docs.splunk.com/Documentation/Splunk/6.6.0/SearchReference/ConditionalFunctions#coalesce.28X.2C....29&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2017 20:13:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/what-does-the-coalesce-and-eval-in-my-query-do/m-p/300796#M90564</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-05-18T20:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: what does the coalesce and eval in my query do?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/what-does-the-coalesce-and-eval-in-my-query-do/m-p/300797#M90565</link>
      <description>&lt;P&gt;The verb &lt;CODE&gt;eval&lt;/CODE&gt; is similar to the way that the word &lt;CODE&gt;set&lt;/CODE&gt; is used in java or c.  It flags to splunk that it is supposed to calculate whatever is to the right of the equals sign and assign that value to the variable on the left side of the equals sign.&lt;/P&gt;

&lt;P&gt;The verb &lt;CODE&gt;coalesce&lt;/CODE&gt; indicates that the first non-null value is to be used.  In this case, it is equivalent to either of the following lines...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval fieldA=if(isnotnull(abc),abc,"def")
| eval fieldA=if(isnull(abc),"def",abc)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;when there are only two values, &lt;CODE&gt;coalesce&lt;/CODE&gt; is not much better than the &lt;CODE&gt;if-isnull&lt;/CODE&gt;, but at three values, the usefulness of &lt;CODE&gt;coalesce&lt;/CODE&gt; becomes obvious, and at four, using anything else is ridiculous.&lt;/P&gt;

&lt;P&gt;The following are equivalent for three items...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval fieldA=coalesce(fieldA,fieldB,fieldC)
| eval fieldA=if(isnotnull(fieldA),fieldA,if(isnotnull(fieldB),fieldB,fieldC))
| eval fieldA=if(isnull(fieldA),if(isnull(fieldB),fieldC,fieldB),fieldA)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The following are equivalent for four items...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval fieldA=coalesce(fieldA,fieldB,fieldC,fieldD)
| eval fieldA=if(isnotnull(fieldA),fieldA,if(isnotnull(fieldB),fieldB,if(isnotnull(fieldC),fieldC,fieldD)))
| eval fieldA=if(isnull(fieldA),if(isnull(fieldB),if(isnull(fieldC),fieldC,fieldD),fieldB),fieldA)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;... and so on...&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2017 20:14:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/what-does-the-coalesce-and-eval-in-my-query-do/m-p/300797#M90565</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-05-18T20:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: what does the coalesce and eval in my query do?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/what-does-the-coalesce-and-eval-in-my-query-do/m-p/300798#M90566</link>
      <description>&lt;P&gt;Returns the value of abc if it is not null, otherwise defaults to "def" if abc field value is null. You can do the same with if() and case() using isnull() or isnotnull() functions on the field abc.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | eval fieldA= if(isnull(abc),"def",abc) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/ConditionalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/ConditionalFunctions&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2017 20:17:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/what-does-the-coalesce-and-eval-in-my-query-do/m-p/300798#M90566</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-05-18T20:17:25Z</dc:date>
    </item>
  </channel>
</rss>

