<?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>idea Add a SQL Clause to the FeatureSet tool calls in ArcGIS Online Ideas</title>
    <link>https://community.esri.com/t5/arcgis-online-ideas/add-a-sql-clause-to-the-featureset-tool-calls/idi-p/1137871</link>
    <description>&lt;P&gt;I would like to see a SQL clause type parameter added to the FeatureSet tools like Search Cursor has.&lt;/P&gt;&lt;P&gt;FeatureSetByName( map, title, fieldList?, includeGeometry? )&lt;/P&gt;&lt;P&gt;SearchCursor(in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points},&lt;STRONG&gt; {sql_clause}&lt;/STRONG&gt;)&lt;/P&gt;&lt;P&gt;I am using FeatureSet wrapped with a Filter now and it does work&lt;/P&gt;&lt;P&gt;var sql = "PointID = '" + $feature.PointID + "'";&lt;BR /&gt;var tbl = Filter(FeatureSetByName($map,"Points", ['DesignLat'], false), sql);&lt;BR /&gt;return First(tbl).DesignLat&lt;/P&gt;&lt;P&gt;In my case I have 100,000+ records in this table but I just want the 1 record.&amp;nbsp; The way it is now the return is all 100,000 then I have to filter out the one I need.&amp;nbsp; If a sql clause was added to the call it would just have to return not only just one row but just one field.&amp;nbsp; Would be so much faster right?&lt;/P&gt;&lt;P&gt;I have 30 of these simple lookups in one popup and it is getting slow.&amp;nbsp; Of course the other bummer with Arcade setup is I have to query these 100,000+ records 30 times!&amp;nbsp; Would be nice to some do one lookup but have the return in multiple fields.&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 27 Jan 2022 14:45:41 GMT</pubDate>
    <dc:creator>DougBrowning</dc:creator>
    <dc:date>2022-01-27T14:45:41Z</dc:date>
    <item>
      <title>Add a SQL Clause to the FeatureSet tool calls</title>
      <link>https://community.esri.com/t5/arcgis-online-ideas/add-a-sql-clause-to-the-featureset-tool-calls/idi-p/1137871</link>
      <description>&lt;P&gt;I would like to see a SQL clause type parameter added to the FeatureSet tools like Search Cursor has.&lt;/P&gt;&lt;P&gt;FeatureSetByName( map, title, fieldList?, includeGeometry? )&lt;/P&gt;&lt;P&gt;SearchCursor(in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points},&lt;STRONG&gt; {sql_clause}&lt;/STRONG&gt;)&lt;/P&gt;&lt;P&gt;I am using FeatureSet wrapped with a Filter now and it does work&lt;/P&gt;&lt;P&gt;var sql = "PointID = '" + $feature.PointID + "'";&lt;BR /&gt;var tbl = Filter(FeatureSetByName($map,"Points", ['DesignLat'], false), sql);&lt;BR /&gt;return First(tbl).DesignLat&lt;/P&gt;&lt;P&gt;In my case I have 100,000+ records in this table but I just want the 1 record.&amp;nbsp; The way it is now the return is all 100,000 then I have to filter out the one I need.&amp;nbsp; If a sql clause was added to the call it would just have to return not only just one row but just one field.&amp;nbsp; Would be so much faster right?&lt;/P&gt;&lt;P&gt;I have 30 of these simple lookups in one popup and it is getting slow.&amp;nbsp; Of course the other bummer with Arcade setup is I have to query these 100,000+ records 30 times!&amp;nbsp; Would be nice to some do one lookup but have the return in multiple fields.&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jan 2022 14:45:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-ideas/add-a-sql-clause-to-the-featureset-tool-calls/idi-p/1137871</guid>
      <dc:creator>DougBrowning</dc:creator>
      <dc:date>2022-01-27T14:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: Add a SQL Clause to the FeatureSet tool calls</title>
      <link>https://community.esri.com/t5/arcgis-online-ideas/add-a-sql-clause-to-the-featureset-tool-calls/idc-p/1137885#M8626</link>
      <description>&lt;P&gt;I've been curious about this sort of thing. If the FeatureSet() is nested within the Filter(), is the script still pulling the whole FeatureSet? It seems that way.&lt;/P&gt;&lt;P&gt;The &lt;STRONG&gt;Filter&lt;/STRONG&gt; actually seems to be the big time suck, at least in a quick test. So it would seem that if the filter could be applied at the FeatureSet level, performance would improve.&lt;/P&gt;&lt;P&gt;Oddly, the "nested" style seems to actually perform &lt;EM&gt;worse &lt;/EM&gt;than doing it in two steps. I tested it a bunch of times, and the two-step method is consistently as quick or significantly quicker than the nested.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var start = Now()
var fs = FeatureSetByName($datastore,"Building_Footprints")
var end = Now()
Console(`Pulling FeatureSet: ${DateDiff(end, start, 'milliseconds')} ms`)

var filter_start = Now()
var filter_fs = Filter(FeatureSetByName($datastore,"Building_Footprints"), "OBJECTID = 1")
var filter_end = Now()
Console(`Pulling Filtered FeatureSet: ${DateDiff(filter_end, filter_start, 'milliseconds')} ms`)

var twostep_start = Now()
var twostep_fs = FeatureSetByName($datastore,"Building_Footprints")
var twostep_filter_fs = Filter(twostep_fs, "OBJECTID = 1")
var twostep_end = Now()
Console(`Pulling FeatureSet, then Filtering: ${DateDiff(twostep_end, twostep_start, 'milliseconds')} ms`)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Returns&lt;/P&gt;&lt;PRE&gt;Pulling FeatureSet: 1 ms
Pulling Filtered FeatureSet: 19 ms
Pulling FeatureSet, then Filtering: 15 ms&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jan 2022 15:16:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-ideas/add-a-sql-clause-to-the-featureset-tool-calls/idc-p/1137885#M8626</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-01-27T15:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: Add a SQL Clause to the FeatureSet tool calls</title>
      <link>https://community.esri.com/t5/arcgis-online-ideas/add-a-sql-clause-to-the-featureset-tool-calls/idc-p/1137888#M8627</link>
      <description>&lt;P&gt;Good to know.&amp;nbsp; I have seen great speed increases by having it not return the geometry.&lt;/P&gt;&lt;P&gt;And by having it return just the one field vs using *.&amp;nbsp; Note specifying a field had a bug for awhile in Field Maps (I think) but I reported it and they fixed it.&lt;/P&gt;&lt;P&gt;Here the&amp;nbsp; ['DesignLat'] is just getting one field and the false is so no geometry is returned.&amp;nbsp; I just mentioned it since your code seems to return it all.&lt;/P&gt;&lt;P&gt;FeatureSetByName($map,"Points", ['DesignLat'], false)&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;Oh and big thanks on Console I had not see that before.&amp;nbsp; Finally a way to see what my script is doing!&amp;nbsp; Now we just need a var tracker.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jan 2022 15:24:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-ideas/add-a-sql-clause-to-the-featureset-tool-calls/idc-p/1137888#M8627</guid>
      <dc:creator>DougBrowning</dc:creator>
      <dc:date>2022-01-27T15:24:33Z</dc:date>
    </item>
    <item>
      <title>Re: Add a SQL Clause to the FeatureSet tool calls</title>
      <link>https://community.esri.com/t5/arcgis-online-ideas/add-a-sql-clause-to-the-featureset-tool-calls/idc-p/1138048#M8631</link>
      <description>&lt;P&gt;Yes, good point. I typically don't return geometry unless I need it, but I was just doing a quick speed test. Turns out the nested and two-step processes are basically equivalent.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function speedtest(n){

    var comps = []
    
    for(var i=0; i&amp;lt;n; i++){
        var start = Now()
        var fs = FeatureSetByName($datastore,"Building_Footprints", ['OBJECTID'], False)
        var end = Now()
          
        var filter_start = Now()
        var filter_fs = Filter(FeatureSetByName($datastore,"Building_Footprints", ['OBJECTID'], False), "OBJECTID = 1")
        var filter_end = Now()
        
        var twostep_start = Now()
        var twostep_fs = FeatureSetByName($datastore,"Building_Footprints", ['OBJECTID'], False)
        var twostep_filter_fs = Filter(twostep_fs, "OBJECTID = 1")
        var twostep_end = Now()
        
        Push(comps, {
            attributes: {
                fs: DateDiff(end, start),
                filtered: DateDiff(filter_end, filter_start),
                twostep: DateDiff(twostep_end, twostep_start),
                diff: DateDiff(filter_end, filter_start) - DateDiff(twostep_end, twostep_start)
            }
        })
    }
    
    var out_dict = {
        fields: [
            {name: 'fs', alias: 'Pulling the FeatureSet', type: 'esriFieldTypeInteger'},
            {name: 'filtered', alias: 'Nested FeatureSet and Filter', type: 'esriFieldTypeInteger'},
            {name: 'twostep', alias: 'Pulling FeatureSet and Filtering Separately', type: 'esriFieldTypeInteger'},
            {name: 'diff', alias: 'Difference', type: 'esriFieldTypeInteger'}],
        geometryType: '',
        features: comps
    }
    
    var set =  FeatureSet(Text(out_dict))
    
    return `Mean Values across ${n} Tests:
    FeatureSet returned in ${Mean(set, 'fs')}
    Nested Filter returned in ${Mean(set, 'filtered')}
    Two-Step Filter returned in ${Mean(set, 'twostep')}
    Nested - Two-Step: ${Mean(set, 'diff')}`
    
}

speedtest(250)&lt;/LI-CODE&gt;&lt;P&gt;Returns:&lt;/P&gt;&lt;PRE&gt;Mean Values across 250 Tests:&lt;BR /&gt;FeatureSet returned in 1.832&lt;BR /&gt;Nested Filter returned in 160.868&lt;BR /&gt;Two-Step Filter returned in 162.384&lt;BR /&gt;Nested - Two-Step: -1.516&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Jan 2022 19:43:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-ideas/add-a-sql-clause-to-the-featureset-tool-calls/idc-p/1138048#M8631</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-01-27T19:43:28Z</dc:date>
    </item>
  </channel>
</rss>

