Hi Matthias,

ah, that makes a lot of sense. So this can be used as a hint for optimisation of the ~"bandwidth" of the function so to speak. What a cool feature! My dataset was a tiny local geopackage so no surprise it just gave me access to all columns straight-away.

When I find time to make a PR I'll add a clearer sentence to the documentation and to change the new function template to either remove the parameter (so it uses the default) or make it use QgsFeatureRequest.ALL_ATTRIBUTES explicitely as hint that one could optimize that. (I prefer to remove it, it's optional with a sensible default...)

Cheers
Hannes

Am 22.11.21 um 14:48 schrieb Matthias Kuhn:
Hi Hannes,

This information can be used by the expression engine to determine what needs to be requested from the provider. This can lead to significant performance improvements, depending on the scenario.

Depending on other functions used in the expression and the capabilities of the provider itself, the request may or may not include them.

As stated in the help, it's what the function *requires*, these attributes are guaranteed to be available. Others may still be there.

Cheers
Matthias


On Mon, Nov 22, 2021 at 2:41 PM Johannes Kröger (WhereGroup) <johannes.kroe...@wheregroup.com <mailto:johannes.kroe...@wheregroup.com>> wrote:

    Hi list,

    
https://docs.qgis.org/3.22/en/docs/user_manual/expressions/expression.html#function-editor
    
<https://docs.qgis.org/3.22/en/docs/user_manual/expressions/expression.html#function-editor>

    mentions the optional keyword argument "referenced_columns" to the
    `@qgsfunction` decorator. It says

     > referenced_columns=[list]: An array of attribute names that are
    required to the function. Defaults to
     > [QgsFeatureRequest.ALL_ATTRIBUTES].

    That, and examples where it is used in other people's code, led me to
    believe that the feature's attributes would not be accessible unless
    listed in that parameter or if the parameter was omitted (-> default
    value getting used -> default is all attributes).

    The default code that gets inserted into the editor includes the
    decorator `@qgsfunction(args='auto', group='Custom',
    referenced_columns=[])` so I'd assume that I would not be able to use
    any attributes in the function.

    In reality I can access them just fine though, e. g.
    `feature["name"]`
    if I had features with a "name" attribute and that default
    `referenced_columns=[]`.

    I can even do so if I used `referenced_columns=["foo", "bar"]`!
    `feature["name"]` is still perfectly accessible.

    Is this a bug or by design? If by design, what purpose does this
    parameter have?

    Thanks
    Hannes

-- Johannes Kröger / GIS-Entwickler/-Berater
    WhereGroup GmbH
    Eifelstraße 7
    53119 Bonn
    Germany

    Tel: +49 (0)228 / 90 90 38 - 36
    Fax: +49 (0)228 / 90 90 38 - 11

    johannes.kroe...@wheregroup.com
    <mailto:johannes.kroe...@wheregroup.com>
    www.wheregroup.com <http://www.wheregroup.com>
    Geschäftsführer:
    Olaf Knopp, Peter Stamm
    Amtsgericht Bonn, HRB 9885
    -------------------------------

    ********************************************
    Where2B Konferenz 2021
    16. Dezember 2021
    im Universitätsclub Bonn und online
    https://where2b-conference.com/ <https://where2b-conference.com/>
    ********************************************

    _______________________________________________
    QGIS-Developer mailing list
    QGIS-Developer@lists.osgeo.org <mailto:QGIS-Developer@lists.osgeo.org>
    List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
    <https://lists.osgeo.org/mailman/listinfo/qgis-developer>
    Unsubscribe:
    https://lists.osgeo.org/mailman/listinfo/qgis-developer
    <https://lists.osgeo.org/mailman/listinfo/qgis-developer>

--
Johannes Kröger / GIS-Entwickler/-Berater
WhereGroup GmbH
Eifelstraße 7
53119 Bonn
Germany

Tel: +49 (0)228 / 90 90 38 - 36
Fax: +49 (0)228 / 90 90 38 - 11

johannes.kroe...@wheregroup.com
www.wheregroup.com
Geschäftsführer:
Olaf Knopp, Peter Stamm
Amtsgericht Bonn, HRB 9885
-------------------------------

********************************************
Where2B Konferenz 2021
16. Dezember 2021
im Universitätsclub Bonn und online
https://where2b-conference.com/
********************************************

Attachment: OpenPGP_0xBF7B268A77C202D5.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

_______________________________________________
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to