<?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: help with where / append needed in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/help-with-where-append-needed/m-p/461497#M130154</link>
    <description>&lt;P&gt;The &lt;CODE&gt;where&lt;/CODE&gt; statement in SPL filters events.  It doesn't control the execution of later SPL statements.  There is no means for that.  See &lt;A href="https://ideas.splunk.com"&gt;https://ideas.splunk.com&lt;/A&gt;.&lt;/P&gt;</description>
    <pubDate>Mon, 30 Mar 2020 16:00:22 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2020-03-30T16:00:22Z</dc:date>
    <item>
      <title>help with where / append needed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-with-where-append-needed/m-p/461496#M130153</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I need help with what I thought will be easy: I need to execute the 2-nd select depending on the result of the 1-st select and append the results 2-nd to 1-st.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|dbxquery query="select top 1  m.host, s.service_name, round(m.used_memory_size/1024/1024/1024) as used_memory_size_gb , round(i.memory_allocation_limit/1024/1024/124) as memory_allocation_limit_gb, to_int(round(m.used_memory_size * 100 / i.memory_allocation_limit )) percent
from isp_iop_kpistore.sys.m_service_component_memory as m
join (select host, port, MEMORY_ALLOCATION_LIMIT from isp_iop_kpistore.sys.M_LOAD_HISTORY_SERVICE where time &amp;gt;= add_seconds(now(), -60)) as i
on m.host = i.host and m.port = i.port
join isp_iop_kpistore.sys.m_services as s
on i.host = s.host and i.port = s.port
where m.component = 'Statement Execution &amp;amp; Intermediate Results'
and m.used_memory_size &amp;gt;= i.memory_allocation_limit * 0.01
order by round(m.used_memory_size/1024/1024/1024) desc
" connection="HANA_MLBSO"

|where PERCENT &amp;gt; 20
|append [
 | dbxquery query="
 select now() from dummy
/*select  top 100
component,
category, 
SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 1) as "TYPE_1",
SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 2) as id_1,
SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 3) as "TYPE_2",
SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 4) as id_2,
SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 5) as "TYPE_3",
SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 6) as id_3,
sum(round(inclusive_allocated_size/1024/1024/1024,2)) as allocated_gb,
sum(round(inclusive_size_in_use/1024/1024/1024, 2)) as used_gb
from isp_iop_kpistore.sys.m_context_memory
group by component,
category, 
SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 1) ,
SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 2) ,
SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 3),
SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 4) ,
SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 5) ,
SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 6) 
order by used_gb desc */
 " connection="HANA_MLBSO"]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Somehow there is no way I can force it to work as I want. When the where condition is met, then yes, I get both results appended. However, when the where the condition is false, still the second SQL gets executed, the results of the first are erased and what I get is only the result of the second SQL.&lt;BR /&gt;
I guess I make some conceptual mistake here.&lt;/P&gt;

&lt;P&gt;Could you please advise?&lt;/P&gt;

&lt;P&gt;Kind Regards,&lt;BR /&gt;
Kamil&lt;/P&gt;</description>
      <pubDate>Mon, 30 Mar 2020 15:36:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-with-where-append-needed/m-p/461496#M130153</guid>
      <dc:creator>damucka</dc:creator>
      <dc:date>2020-03-30T15:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: help with where / append needed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-with-where-append-needed/m-p/461497#M130154</link>
      <description>&lt;P&gt;The &lt;CODE&gt;where&lt;/CODE&gt; statement in SPL filters events.  It doesn't control the execution of later SPL statements.  There is no means for that.  See &lt;A href="https://ideas.splunk.com"&gt;https://ideas.splunk.com&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Mar 2020 16:00:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-with-where-append-needed/m-p/461497#M130154</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-03-30T16:00:22Z</dc:date>
    </item>
    <item>
      <title>Re: help with where / append needed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-with-where-append-needed/m-p/461498#M130155</link>
      <description>&lt;P&gt;Thank you, it helped my understanding.&lt;BR /&gt;
This is not the first time that I miss the real if-else functionality in Splunk SPL, but I guess I am spoiled by other programming languages and this is not that easy to implement here.&lt;/P&gt;

&lt;P&gt;I solved above in relatively dirty way with the map command&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|dbxquery query="select top 1  m.host, s.service_name, round(m.used_memory_size/1024/1024/1024) as used_memory_size_gb , round(i.memory_allocation_limit/1024/1024/124) as memory_allocation_limit_gb, to_int(round(m.used_memory_size * 100 / i.memory_allocation_limit )) percent
from isp_iop_kpistore.sys.m_service_component_memory as m
join (select host, port, MEMORY_ALLOCATION_LIMIT from isp_iop_kpistore.sys.M_LOAD_HISTORY_SERVICE where time &amp;gt;= add_seconds(now(), -60)) as i
on m.host = i.host and m.port = i.port
join isp_iop_kpistore.sys.m_services as s
on i.host = s.host and i.port = s.port
where m.component = 'Statement Execution &amp;amp; Intermediate Results'
and m.used_memory_size &amp;gt;= i.memory_allocation_limit * 0.01
order by round(m.used_memory_size/1024/1024/1024) desc
" connection="HANA_MLBSO" 

| eval QUERY = "select  top 100 component, category, SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 1) as \"TYPE_1\", SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 2) as id_1, SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 3) as \"TYPE_2\", SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 4) as id_2, SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 5) as \"TYPE_3\", SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 6) as id_3, sum(round(inclusive_allocated_size/1024/1024/1024,2)) as allocated_gb, sum(round(inclusive_size_in_use/1024/1024/1024, 2)) as used_gb from isp_iop_kpistore.sys.m_context_memory group by component, category, SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 1) , SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 2) , SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 3), SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 4) , SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 5) , SUBSTRING_REGEXPR('[^/]+' IN category FROM 1 OCCURRENCE 6)  order by used_gb desc"

| eval DUMMY_QUERY = "select now() from dummy"
| eval SQL_TEXT = if(PERCENT &amp;gt;= 20, QUERY, "")

| map maxsearches=20 search="dbxquery query=\"$SQL_TEXT$\" connection=\"HANA_MLBSO\" 
       | append[|makeresults
       | eval HOST=\"$HOST$\" 
       | eval MEMORY_ALLOCATION_LIMIT_GB=\"$MEMORY_ALLOCATION_LIMIT_GB$\" 
       | eval PERCENT=\"$PERCENT$\" 
       | eval SERVICE_NAME = \"$SERVICE_NAME$\" 
       | eval USED_MEMORY_SIZE_GB = \"$USED_MEMORY_SIZE_GB$\"
       ] "
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Kind Regards,&lt;BR /&gt;
Kamil&lt;/P&gt;</description>
      <pubDate>Mon, 30 Mar 2020 18:24:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-with-where-append-needed/m-p/461498#M130155</guid>
      <dc:creator>damucka</dc:creator>
      <dc:date>2020-03-30T18:24:46Z</dc:date>
    </item>
  </channel>
</rss>

