<?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 is the limit on the number of branches in a single CASE statement in Splunk, and how can I optimize my current eval case statement? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/What-is-the-limit-on-the-number-of-branches-in-a-single-CASE/m-p/240781#M71570</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I have defined api_names and calculating counts and sigma limits for alert based on uri stem.&lt;BR /&gt;
Example uri stem: &lt;CODE&gt;/api/v1/customer/details/customernumber/12345&lt;/CODE&gt;&lt;BR /&gt;
I can't use regex here (or I am not that skilled). I've created this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval cs_uri_stem=lower(cs_uri_stem)
| rex field=cs_uri_stem "/api/v\d/(?&amp;lt;api_name&amp;gt;\w+[a-z-]\w+).*"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, it will parse out api name only till the first slash &lt;CODE&gt;/&lt;/CODE&gt;, so I'll match &lt;CODE&gt;customer&lt;/CODE&gt;. However, I do not match &lt;CODE&gt;customer/details/customernumber&lt;/CODE&gt; as they follow between additional slashes.&lt;BR /&gt;
Due to this limitation, I've created big case statement with 122 x 2 branches.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval api_name = case(
like(cs_uri_stem,"/api/v%/customers/%"),"customers",    like(cs_uri_stem,"/api/v%/customers%"),"customers",
like(cs_uri_stem,"/api/v%/customer-groups/%"),"customer-groups",    like(cs_uri_stem,"/api/v%/customer-groups%"),"customer-groups",
like(cs_uri_stem,"/api/v%/customer-bases/%"),"customer-bases",  like(cs_uri_stem,"/api/v%/customer-bases%"),"customer-bases",
like(cs_uri_stem,"/api/v%/customer/shippingaddresses/list/%"),"customer/shippingaddresses/list",    like(cs_uri_stem,"/api/v%/customer/shippingaddresses/list%"),"customer/shippingaddresses/list",
like(cs_uri_stem,"/api/v%/customer/search/%"),"customer/search",    like(cs_uri_stem,"/api/v%/customer/search%"),"customer/search",
like(cs_uri_stem,"/api/v%/customer/details/customernumber/%"),"customer/details/customernumber",    like(cs_uri_stem,"/api/v%/customer/details/customernumber%"),"customer/details/customernumber",
like(cs_uri_stem,"/api/v%/customer/%"),"customer",  like(cs_uri_stem,"/api/v%/customer%"),"customer",
1=1,"OTHER")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now questions:&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;1. What is the SPLUNK limitation on the number of branches in a single CASE statement?&lt;BR /&gt;
 2. What is impact of running such big case statement?&lt;BR /&gt;
 3. I assume that SPLUNK case statement is working in same manner as in SQL, so I've organized patterns  in descending order to match first &lt;CODE&gt;customer/details/customernumber&lt;/CODE&gt; and &lt;CODE&gt;customer&lt;/CODE&gt; only on the rest. Am I correct?&lt;BR /&gt;
 4. Is there any opportunity to optimize this case statement?&lt;BR /&gt;
 5. Is there any alternative? (already thinking about leveraging rex and do it in multiple levels like customer = api_name_L1, details = api_name_L2, customernumnber = api_name_L3&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;I'll appreciate any help/comments here.&lt;/P&gt;

&lt;P&gt;Thank you!&lt;BR /&gt;
m.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 07:56:22 GMT</pubDate>
    <dc:creator>magorinahory</dc:creator>
    <dc:date>2020-09-29T07:56:22Z</dc:date>
    <item>
      <title>What is the limit on the number of branches in a single CASE statement in Splunk, and how can I optimize my current eval case statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-is-the-limit-on-the-number-of-branches-in-a-single-CASE/m-p/240781#M71570</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I have defined api_names and calculating counts and sigma limits for alert based on uri stem.&lt;BR /&gt;
Example uri stem: &lt;CODE&gt;/api/v1/customer/details/customernumber/12345&lt;/CODE&gt;&lt;BR /&gt;
I can't use regex here (or I am not that skilled). I've created this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval cs_uri_stem=lower(cs_uri_stem)
| rex field=cs_uri_stem "/api/v\d/(?&amp;lt;api_name&amp;gt;\w+[a-z-]\w+).*"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, it will parse out api name only till the first slash &lt;CODE&gt;/&lt;/CODE&gt;, so I'll match &lt;CODE&gt;customer&lt;/CODE&gt;. However, I do not match &lt;CODE&gt;customer/details/customernumber&lt;/CODE&gt; as they follow between additional slashes.&lt;BR /&gt;
Due to this limitation, I've created big case statement with 122 x 2 branches.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval api_name = case(
like(cs_uri_stem,"/api/v%/customers/%"),"customers",    like(cs_uri_stem,"/api/v%/customers%"),"customers",
like(cs_uri_stem,"/api/v%/customer-groups/%"),"customer-groups",    like(cs_uri_stem,"/api/v%/customer-groups%"),"customer-groups",
like(cs_uri_stem,"/api/v%/customer-bases/%"),"customer-bases",  like(cs_uri_stem,"/api/v%/customer-bases%"),"customer-bases",
like(cs_uri_stem,"/api/v%/customer/shippingaddresses/list/%"),"customer/shippingaddresses/list",    like(cs_uri_stem,"/api/v%/customer/shippingaddresses/list%"),"customer/shippingaddresses/list",
like(cs_uri_stem,"/api/v%/customer/search/%"),"customer/search",    like(cs_uri_stem,"/api/v%/customer/search%"),"customer/search",
like(cs_uri_stem,"/api/v%/customer/details/customernumber/%"),"customer/details/customernumber",    like(cs_uri_stem,"/api/v%/customer/details/customernumber%"),"customer/details/customernumber",
like(cs_uri_stem,"/api/v%/customer/%"),"customer",  like(cs_uri_stem,"/api/v%/customer%"),"customer",
1=1,"OTHER")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now questions:&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;1. What is the SPLUNK limitation on the number of branches in a single CASE statement?&lt;BR /&gt;
 2. What is impact of running such big case statement?&lt;BR /&gt;
 3. I assume that SPLUNK case statement is working in same manner as in SQL, so I've organized patterns  in descending order to match first &lt;CODE&gt;customer/details/customernumber&lt;/CODE&gt; and &lt;CODE&gt;customer&lt;/CODE&gt; only on the rest. Am I correct?&lt;BR /&gt;
 4. Is there any opportunity to optimize this case statement?&lt;BR /&gt;
 5. Is there any alternative? (already thinking about leveraging rex and do it in multiple levels like customer = api_name_L1, details = api_name_L2, customernumnber = api_name_L3&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;I'll appreciate any help/comments here.&lt;/P&gt;

&lt;P&gt;Thank you!&lt;BR /&gt;
m.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 07:56:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-is-the-limit-on-the-number-of-branches-in-a-single-CASE/m-p/240781#M71570</guid>
      <dc:creator>magorinahory</dc:creator>
      <dc:date>2020-09-29T07:56:22Z</dc:date>
    </item>
    <item>
      <title>Re: What is the limit on the number of branches in a single CASE statement in Splunk, and how can I optimize my current eval case statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-is-the-limit-on-the-number-of-branches-in-a-single-CASE/m-p/240782#M71571</link>
      <description>&lt;P&gt;Try this regex to extract path till last slash. This might eliminate the need to have a complex case statement. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;v\d+(?&amp;lt;path&amp;gt;[\w\/]+)\/
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Nov 2015 01:11:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-is-the-limit-on-the-number-of-branches-in-a-single-CASE/m-p/240782#M71571</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2015-11-20T01:11:16Z</dc:date>
    </item>
  </channel>
</rss>

