<?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: Is there an efficient way to convert booleans in my data from 0 and 1 to true and false? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Is-there-an-efficient-way-to-convert-booleans-in-my-data-from-0/m-p/341497#M101230</link>
    <description>&lt;P&gt;I'm not super familiar with macros in Splunk yet but I'll keep this in mind.  Thanks&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jun 2017 18:22:38 GMT</pubDate>
    <dc:creator>dkrichards16</dc:creator>
    <dc:date>2017-06-09T18:22:38Z</dc:date>
    <item>
      <title>Is there an efficient way to convert booleans in my data from 0 and 1 to true and false?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-an-efficient-way-to-convert-booleans-in-my-data-from-0/m-p/341493#M101226</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;I'm switching from dbquery to dbxquery and I noticed that it brings in booleans as 0/1 instead of true/false.  For my reports/dashboards I'd like them to read as true/false.  I got the following to work, but was wondering if there was a way to do it for all booleans in a report without setting an if statement for each field:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|eval LogA=if(LogA=1,"True","False")
|eval LogB=if(LogB=1,"True","False")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've been doing some research on isbool, but not seeing a ton of documentation on it yet.  Does anyone out there have a more efficient way to do that?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 17:45:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-an-efficient-way-to-convert-booleans-in-my-data-from-0/m-p/341493#M101226</guid>
      <dc:creator>dkrichards16</dc:creator>
      <dc:date>2017-06-09T17:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: Is there an efficient way to convert booleans in my data from 0 and 1 to true and false?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-an-efficient-way-to-convert-booleans-in-my-data-from-0/m-p/341494#M101227</link>
      <description>&lt;P&gt;i'm not sure if it is more efficient or not, but another option is &lt;CODE&gt;|replace "1" with "True", "0" with "False" in LogA, LogB&lt;/CODE&gt; or &lt;CODE&gt;|foreach Log* [eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=if('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'=1,"True","False")]&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 18:13:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-an-efficient-way-to-convert-booleans-in-my-data-from-0/m-p/341494#M101227</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-06-09T18:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: Is there an efficient way to convert booleans in my data from 0 and 1 to true and false?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-an-efficient-way-to-convert-booleans-in-my-data-from-0/m-p/341495#M101228</link>
      <description>&lt;P&gt;Macros appear to be a pita also, since there is no single documentation page that describes what eval verbs you can and cannot use, and there are only trivial examples in the documentation, but ...&lt;/P&gt;

&lt;P&gt;HERE's the one you need.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;convertbool(1)

args = fieldlist
definition = replace(replace("$fieldlist$"," (\s+)"," ")." ","(\w+)\s","| eval \1 = if(\1=1,\"True\",\"False\") ")
iseval = true

description = takes a single string of fieldnames separated by one or more spaces, and creates the code to convert each field from 1 to True or 0 to False.  Does not require a pipe character before call.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;A run-anywhere example call is &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval LogA=1 | eval LogB=0 | eval LogC=1
`convertbool("LogA LogB LogC")`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Notice that the names of the fields are passed as a single string of an arbitrary number of arguments with spaces between the names.  You don't have to worry if you have a single or multiple spaces between the names... that has been coded for.&lt;/P&gt;

&lt;P&gt;Example output is &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;LogA    LogB    LogC    _time
True    False   True    2017-06-09 21:28:33
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;here's the version if you prefer the style with a pipe before the macro&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;definition = replace(replace(replace("$fieldlist$"," (\s+)"," ")." ","(\w+)\s","| eval \1 = if(\1=1,\"True\",\"False\") "),"^\|","")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;sample call (same other code as above and same output)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| `convertbool("LogA LogB LogC")`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;Update... format to call the macro turned out to be different, see above.&lt;/P&gt;

&lt;P&gt;splunk doesn't handle booleans very well.  What you have there looks fairly efficient, although it would probably be a pain to code much of.  &lt;/P&gt;

&lt;P&gt;My suggestion is to code a macro that turns... &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;`convertbool( LogA LogB ...)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;into &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; |eval LogA=if(LogA=1,"True","False")
 |eval LogB=if(LogB=1,"True","False")
 ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Jun 2017 18:17:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-an-efficient-way-to-convert-booleans-in-my-data-from-0/m-p/341495#M101228</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-06-09T18:17:33Z</dc:date>
    </item>
    <item>
      <title>Re: Is there an efficient way to convert booleans in my data from 0 and 1 to true and false?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-an-efficient-way-to-convert-booleans-in-my-data-from-0/m-p/341496#M101229</link>
      <description>&lt;P&gt;The replace didn't created some null values but the foreach worked and shaved .668 sec off of my query. lol&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 18:21:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-an-efficient-way-to-convert-booleans-in-my-data-from-0/m-p/341496#M101229</guid>
      <dc:creator>dkrichards16</dc:creator>
      <dc:date>2017-06-09T18:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: Is there an efficient way to convert booleans in my data from 0 and 1 to true and false?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-an-efficient-way-to-convert-booleans-in-my-data-from-0/m-p/341497#M101230</link>
      <description>&lt;P&gt;I'm not super familiar with macros in Splunk yet but I'll keep this in mind.  Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 18:22:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-an-efficient-way-to-convert-booleans-in-my-data-from-0/m-p/341497#M101230</guid>
      <dc:creator>dkrichards16</dc:creator>
      <dc:date>2017-06-09T18:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: Is there an efficient way to convert booleans in my data from 0 and 1 to true and false?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-an-efficient-way-to-convert-booleans-in-my-data-from-0/m-p/341498#M101231</link>
      <description>&lt;P&gt;I would cast them in the SQL, rather than convert them in the SPL.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 19:23:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-an-efficient-way-to-convert-booleans-in-my-data-from-0/m-p/341498#M101231</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-06-09T19:23:57Z</dc:date>
    </item>
  </channel>
</rss>

