Proposal for Table Functions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Proposal for Table Functions

Petr Přikryl-2
Hi, I have just implemented Table Function support on Django 2.1. What do you think about adopting it into Django itself? 


It is all about passing function parameters into BaseTable and Join classes https://github.com/django/django/blob/master/django/db/models/sql/datastructures.py


Thanks,
Petr

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/6d16fdfc-332f-4a72-83ae-04ee5c9fd28a%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Proposal for Table Functions

Ahmad A. Hussein
I'm not an expert or even an amateur at the ORM, but here are my thoughts on the matter:
1. Does it carry over well across the four databases?
2. Is it necessary to include it as part of core versus a third-party app?
3. What specific use case will benefit from adopting this idea?

I ask the second question because it seems from your gist that you don't need your proposal to be part of core for it to work. It seems it would work completely well and flourish even as a third-party app given how you're subclassing the API and expanding on its usage. Contrast this with django-pytest for example that can have a harder problem running pytest on Django due to how the test runner is currently built (namely that setup assumes a subclass of the Django test runner).

Regards,
Ahmad
On Sun, May 17, 2020 at 4:36 PM Petr Přikryl <[hidden email]> wrote:
Hi, I have just implemented Table Function support on Django 2.1. What do you think about adopting it into Django itself? 


It is all about passing function parameters into BaseTable and Join classes https://github.com/django/django/blob/master/django/db/models/sql/datastructures.py


Thanks,
Petr

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/6d16fdfc-332f-4a72-83ae-04ee5c9fd28a%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAJNa-uPBFBhOyrMB9X97wVU12Hk6%2Bn7Jy8qSXhZr6-jGn9mOsQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Proposal for Table Functions

Petr Přikryl-2
ad 1. I was testing it on PostgreSQL only. But:
ad 2. Yes, "it is necessary". Because I must do some nasty hacks in my gist. For example:
ad 3. The use case is optimization for me. Because I had SQL View with recursion. The View was mapped into Django through model. But operations with this view takes long time for my app. So I found out that I can optimize that using table function instead view with parameter limiting the recursion depth. But I couldn't switch view to table function because no ORM support. With this gist I could.

ad tests. I used them because I am used to use them :-). And I think that it should be re-writable to classic Django tests.

Petr


Dne neděle 17. května 2020 23:08:08 UTC+2 Ahmad A. Hussein napsal(a):
I'm not an expert or even an amateur at the ORM, but here are my thoughts on the matter:
1. Does it carry over well across the four databases?
2. Is it necessary to include it as part of core versus a third-party app?
3. What specific use case will benefit from adopting this idea?

I ask the second question because it seems from your gist that you don't need your proposal to be part of core for it to work. It seems it would work completely well and flourish even as a third-party app given how you're subclassing the API and expanding on its usage. Contrast this with django-pytest for example that can have a harder problem running pytest on Django due to how the test runner is currently built (namely that setup assumes a subclass of the Django test runner).

Regards,
Ahmad
On Sun, May 17, 2020 at 4:36 PM Petr Přikryl <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="XX5yNZCMAQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">nic...@...> wrote:
Hi, I have just implemented Table Function support on Django 2.1. What do you think about adopting it into Django itself? 

<a href="https://gist.github.com/petrprikryl/7cd765cd723c7df983de03706bf27d1a" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fpetrprikryl%2F7cd765cd723c7df983de03706bf27d1a\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHPfvAtt8-ZvrWpmG_1w8Tuu2fmbg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fpetrprikryl%2F7cd765cd723c7df983de03706bf27d1a\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHPfvAtt8-ZvrWpmG_1w8Tuu2fmbg&#39;;return true;">https://gist.github.com/petrprikryl/7cd765cd723c7df983de03706bf27d1a

It is all about passing function parameters into BaseTable and Join classes <a href="https://github.com/django/django/blob/master/django/db/models/sql/datastructures.py" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fblob%2Fmaster%2Fdjango%2Fdb%2Fmodels%2Fsql%2Fdatastructures.py\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEpDDod_2RZQeqWQqVM73y8ebHwvw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fblob%2Fmaster%2Fdjango%2Fdb%2Fmodels%2Fsql%2Fdatastructures.py\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEpDDod_2RZQeqWQqVM73y8ebHwvw&#39;;return true;">https://github.com/django/django/blob/master/django/db/models/sql/datastructures.py

Here are other thoughts which were inspiring me <a href="https://schinckel.net/2019/10/31/functions-as-tables-in-django-and-postgres/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fschinckel.net%2F2019%2F10%2F31%2Ffunctions-as-tables-in-django-and-postgres%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE1ipUUvAH4MGcjeCKcg-r2dniIuw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fschinckel.net%2F2019%2F10%2F31%2Ffunctions-as-tables-in-django-and-postgres%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE1ipUUvAH4MGcjeCKcg-r2dniIuw&#39;;return true;">https://schinckel.net/2019/10/31/functions-as-tables-in-django-and-postgres/

Thanks,
Petr

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="XX5yNZCMAQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django-d...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-developers/6d16fdfc-332f-4a72-83ae-04ee5c9fd28a%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-developers/6d16fdfc-332f-4a72-83ae-04ee5c9fd28a%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-developers/6d16fdfc-332f-4a72-83ae-04ee5c9fd28a%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-developers/6d16fdfc-332f-4a72-83ae-04ee5c9fd28a%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/ae02ee22-d858-4dd2-ae56-b219e53305d1%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Proposal for Table Functions

Ahmad A. Hussein
Concerning tests, I did not mean to comment about the tests you wrote. I used the third party py-test django app as an example of an app that does need work in core to function better, not as a comment about your usage of tests. You're more than free to work the way you want to :) (I like pytest too)

If there's an optimization to be had in including table functions and it'll be backwards compatible without breaking anything, then I think there's merit in the idea. I suggest you open a ticket on the issue tracker and mention how significant the optimization was. It'll help with getting this new feature adopted.

You can open it here



On Monday, May 18, 2020 at 8:31:04 AM UTC+2, Petr Přikryl wrote:
ad 1. I was testing it on PostgreSQL only. But:
  • Oracle is feasible through custom extendings in compiler <a href="https://livesql.oracle.com/apex/livesql/file/content_C87XCH8SE085LMS3C5KR03VFS.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Flivesql.oracle.com%2Fapex%2Flivesql%2Ffile%2Fcontent_C87XCH8SE085LMS3C5KR03VFS.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH1KMqT-XDvI3aHe7zyHLqWPOcMeg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Flivesql.oracle.com%2Fapex%2Flivesql%2Ffile%2Fcontent_C87XCH8SE085LMS3C5KR03VFS.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH1KMqT-XDvI3aHe7zyHLqWPOcMeg&#39;;return true;">https://livesql.oracle.com/apex/livesql/file/content_C87XCH8SE085LMS3C5KR03VFS.html
  • MySQL is also feasible <a href="https://stackoverflow.com/a/23421816/1763888" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fa%2F23421816%2F1763888\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHRHlBv5ipbZiEHMx7ulNp6y7DvKg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fa%2F23421816%2F1763888\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHRHlBv5ipbZiEHMx7ulNp6y7DvKg&#39;;return true;">https://stackoverflow.com/a/23421816/1763888
  • SQLite has some special limited table functions which should be syntax-compatible with Postgres <a href="https://www.sqlite.org/vtab.html#tabfunc2" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.sqlite.org%2Fvtab.html%23tabfunc2\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGNg-g3fSA8lLNmAF97OQmlmrcpBA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.sqlite.org%2Fvtab.html%23tabfunc2\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGNg-g3fSA8lLNmAF97OQmlmrcpBA&#39;;return true;">https://www.sqlite.org/vtab.html#tabfunc2
ad 2. Yes, "it is necessary". Because I must do some nasty hacks in my gist. For example:
  • SQL regex parsing <a href="https://gist.github.com/petrprikryl/7cd765cd723c7df983de03706bf27d1a#file-function-py-L189" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fpetrprikryl%2F7cd765cd723c7df983de03706bf27d1a%23file-function-py-L189\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHLh1ErG1U2s8-HEqSeJKvoLioIrg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fpetrprikryl%2F7cd765cd723c7df983de03706bf27d1a%23file-function-py-L189\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHLh1ErG1U2s8-HEqSeJKvoLioIrg&#39;;return true;">https://gist.github.com/petrprikryl/7cd765cd723c7df983de03706bf27d1a#file-function-py-L189. Which could be removed if base method would know about parameters.
  • Classic "Join" overriding <a href="https://gist.github.com/petrprikryl/7cd765cd723c7df983de03706bf27d1a#file-function-py-L277" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fpetrprikryl%2F7cd765cd723c7df983de03706bf27d1a%23file-function-py-L277\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEXL_hpJwMlWKmE3J6K9UzC3IqTug&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fpetrprikryl%2F7cd765cd723c7df983de03706bf27d1a%23file-function-py-L277\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEXL_hpJwMlWKmE3J6K9UzC3IqTug&#39;;return true;">https://gist.github.com/petrprikryl/7cd765cd723c7df983de03706bf27d1a#file-function-py-L277. I don't like it because I need work with "level" (order) of joins to map it to user lookups correctly. If ithis would be in core, then the lookups from "filter" could be merged witth lookups from "table_function" more easily. There is also possibility to merge logic from table_function into filter and use only filter method for passing parameters into table functions.
ad 3. The use case is optimization for me. Because I had SQL View with recursion. The View was mapped into Django through model. But operations with this view takes long time for my app. So I found out that I can optimize that using table function instead view with parameter limiting the recursion depth. But I couldn't switch view to table function because no ORM support. With this gist I could.

ad tests. I used them because I am used to use them :-). And I think that it should be re-writable to classic Django tests.

Petr


Dne neděle 17. května 2020 23:08:08 UTC+2 Ahmad A. Hussein napsal(a):
I'm not an expert or even an amateur at the ORM, but here are my thoughts on the matter:
1. Does it carry over well across the four databases?
2. Is it necessary to include it as part of core versus a third-party app?
3. What specific use case will benefit from adopting this idea?

I ask the second question because it seems from your gist that you don't need your proposal to be part of core for it to work. It seems it would work completely well and flourish even as a third-party app given how you're subclassing the API and expanding on its usage. Contrast this with django-pytest for example that can have a harder problem running pytest on Django due to how the test runner is currently built (namely that setup assumes a subclass of the Django test runner).

Regards,
Ahmad
On Sun, May 17, 2020 at 4:36 PM Petr Přikryl <[hidden email]> wrote:
Hi, I have just implemented Table Function support on Django 2.1. What do you think about adopting it into Django itself? 

<a href="https://gist.github.com/petrprikryl/7cd765cd723c7df983de03706bf27d1a" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fpetrprikryl%2F7cd765cd723c7df983de03706bf27d1a\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHPfvAtt8-ZvrWpmG_1w8Tuu2fmbg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fpetrprikryl%2F7cd765cd723c7df983de03706bf27d1a\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHPfvAtt8-ZvrWpmG_1w8Tuu2fmbg&#39;;return true;">https://gist.github.com/petrprikryl/7cd765cd723c7df983de03706bf27d1a

It is all about passing function parameters into BaseTable and Join classes <a href="https://github.com/django/django/blob/master/django/db/models/sql/datastructures.py" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fblob%2Fmaster%2Fdjango%2Fdb%2Fmodels%2Fsql%2Fdatastructures.py\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEpDDod_2RZQeqWQqVM73y8ebHwvw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fblob%2Fmaster%2Fdjango%2Fdb%2Fmodels%2Fsql%2Fdatastructures.py\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEpDDod_2RZQeqWQqVM73y8ebHwvw&#39;;return true;">https://github.com/django/django/blob/master/django/db/models/sql/datastructures.py

Here are other thoughts which were inspiring me <a href="https://schinckel.net/2019/10/31/functions-as-tables-in-django-and-postgres/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fschinckel.net%2F2019%2F10%2F31%2Ffunctions-as-tables-in-django-and-postgres%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE1ipUUvAH4MGcjeCKcg-r2dniIuw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fschinckel.net%2F2019%2F10%2F31%2Ffunctions-as-tables-in-django-and-postgres%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE1ipUUvAH4MGcjeCKcg-r2dniIuw&#39;;return true;">https://schinckel.net/2019/10/31/functions-as-tables-in-django-and-postgres/

Thanks,
Petr

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-developers/6d16fdfc-332f-4a72-83ae-04ee5c9fd28a%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-developers/6d16fdfc-332f-4a72-83ae-04ee5c9fd28a%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-developers/6d16fdfc-332f-4a72-83ae-04ee5c9fd28a%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-developers/6d16fdfc-332f-4a72-83ae-04ee5c9fd28a%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/9c66df8e-237f-43fe-8a7b-e518a1288001%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Proposal for Table Functions

Petr Přikryl-2
Linking the issue https://code.djangoproject.com/ticket/31609


Dne pondělí 18. května 2020 13:57:49 UTC+2 Ahmad A. Hussein napsal(a):
Concerning tests, I did not mean to comment about the tests you wrote. I used the third party py-test django app as an example of an app that does need work in core to function better, not as a comment about your usage of tests. You're more than free to work the way you want to :) (I like pytest too)

If there's an optimization to be had in including table functions and it'll be backwards compatible without breaking anything, then I think there's merit in the idea. I suggest you open a ticket on the issue tracker and mention how significant the optimization was. It'll help with getting this new feature adopted.

You can open it <a href="https://code.djangoproject.com/newticket" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fnewticket\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFsSzl57kLRgxQMzgAb9WFxu0CvgQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fnewticket\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFsSzl57kLRgxQMzgAb9WFxu0CvgQ&#39;;return true;">here



On Monday, May 18, 2020 at 8:31:04 AM UTC+2, Petr Přikryl wrote:
ad 1. I was testing it on PostgreSQL only. But:
  • Oracle is feasible through custom extendings in compiler <a href="https://livesql.oracle.com/apex/livesql/file/content_C87XCH8SE085LMS3C5KR03VFS.html" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Flivesql.oracle.com%2Fapex%2Flivesql%2Ffile%2Fcontent_C87XCH8SE085LMS3C5KR03VFS.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH1KMqT-XDvI3aHe7zyHLqWPOcMeg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Flivesql.oracle.com%2Fapex%2Flivesql%2Ffile%2Fcontent_C87XCH8SE085LMS3C5KR03VFS.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH1KMqT-XDvI3aHe7zyHLqWPOcMeg&#39;;return true;">https://livesql.oracle.com/apex/livesql/file/content_C87XCH8SE085LMS3C5KR03VFS.html
  • MySQL is also feasible <a href="https://stackoverflow.com/a/23421816/1763888" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fa%2F23421816%2F1763888\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHRHlBv5ipbZiEHMx7ulNp6y7DvKg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fa%2F23421816%2F1763888\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHRHlBv5ipbZiEHMx7ulNp6y7DvKg&#39;;return true;">https://stackoverflow.com/a/23421816/1763888
  • SQLite has some special limited table functions which should be syntax-compatible with Postgres <a href="https://www.sqlite.org/vtab.html#tabfunc2" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.sqlite.org%2Fvtab.html%23tabfunc2\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGNg-g3fSA8lLNmAF97OQmlmrcpBA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.sqlite.org%2Fvtab.html%23tabfunc2\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGNg-g3fSA8lLNmAF97OQmlmrcpBA&#39;;return true;">https://www.sqlite.org/vtab.html#tabfunc2
ad 2. Yes, "it is necessary". Because I must do some nasty hacks in my gist. For example:
  • SQL regex parsing <a href="https://gist.github.com/petrprikryl/7cd765cd723c7df983de03706bf27d1a#file-function-py-L189" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fpetrprikryl%2F7cd765cd723c7df983de03706bf27d1a%23file-function-py-L189\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHLh1ErG1U2s8-HEqSeJKvoLioIrg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fpetrprikryl%2F7cd765cd723c7df983de03706bf27d1a%23file-function-py-L189\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHLh1ErG1U2s8-HEqSeJKvoLioIrg&#39;;return true;">https://gist.github.com/petrprikryl/7cd765cd723c7df983de03706bf27d1a#file-function-py-L189. Which could be removed if base method would know about parameters.
  • Classic "Join" overriding <a href="https://gist.github.com/petrprikryl/7cd765cd723c7df983de03706bf27d1a#file-function-py-L277" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fpetrprikryl%2F7cd765cd723c7df983de03706bf27d1a%23file-function-py-L277\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEXL_hpJwMlWKmE3J6K9UzC3IqTug&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fpetrprikryl%2F7cd765cd723c7df983de03706bf27d1a%23file-function-py-L277\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEXL_hpJwMlWKmE3J6K9UzC3IqTug&#39;;return true;">https://gist.github.com/petrprikryl/7cd765cd723c7df983de03706bf27d1a#file-function-py-L277. I don't like it because I need work with "level" (order) of joins to map it to user lookups correctly. If ithis would be in core, then the lookups from "filter" could be merged witth lookups from "table_function" more easily. There is also possibility to merge logic from table_function into filter and use only filter method for passing parameters into table functions.
ad 3. The use case is optimization for me. Because I had SQL View with recursion. The View was mapped into Django through model. But operations with this view takes long time for my app. So I found out that I can optimize that using table function instead view with parameter limiting the recursion depth. But I couldn't switch view to table function because no ORM support. With this gist I could.

ad tests. I used them because I am used to use them :-). And I think that it should be re-writable to classic Django tests.

Petr


Dne neděle 17. května 2020 23:08:08 UTC+2 Ahmad A. Hussein napsal(a):
I'm not an expert or even an amateur at the ORM, but here are my thoughts on the matter:
1. Does it carry over well across the four databases?
2. Is it necessary to include it as part of core versus a third-party app?
3. What specific use case will benefit from adopting this idea?

I ask the second question because it seems from your gist that you don't need your proposal to be part of core for it to work. It seems it would work completely well and flourish even as a third-party app given how you're subclassing the API and expanding on its usage. Contrast this with django-pytest for example that can have a harder problem running pytest on Django due to how the test runner is currently built (namely that setup assumes a subclass of the Django test runner).

Regards,
Ahmad
On Sun, May 17, 2020 at 4:36 PM Petr Přikryl <[hidden email]> wrote:
Hi, I have just implemented Table Function support on Django 2.1. What do you think about adopting it into Django itself? 

<a href="https://gist.github.com/petrprikryl/7cd765cd723c7df983de03706bf27d1a" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fpetrprikryl%2F7cd765cd723c7df983de03706bf27d1a\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHPfvAtt8-ZvrWpmG_1w8Tuu2fmbg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fpetrprikryl%2F7cd765cd723c7df983de03706bf27d1a\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHPfvAtt8-ZvrWpmG_1w8Tuu2fmbg&#39;;return true;">https://gist.github.com/petrprikryl/7cd765cd723c7df983de03706bf27d1a

It is all about passing function parameters into BaseTable and Join classes <a href="https://github.com/django/django/blob/master/django/db/models/sql/datastructures.py" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fblob%2Fmaster%2Fdjango%2Fdb%2Fmodels%2Fsql%2Fdatastructures.py\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEpDDod_2RZQeqWQqVM73y8ebHwvw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fblob%2Fmaster%2Fdjango%2Fdb%2Fmodels%2Fsql%2Fdatastructures.py\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEpDDod_2RZQeqWQqVM73y8ebHwvw&#39;;return true;">https://github.com/django/django/blob/master/django/db/models/sql/datastructures.py

Here are other thoughts which were inspiring me <a href="https://schinckel.net/2019/10/31/functions-as-tables-in-django-and-postgres/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fschinckel.net%2F2019%2F10%2F31%2Ffunctions-as-tables-in-django-and-postgres%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE1ipUUvAH4MGcjeCKcg-r2dniIuw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fschinckel.net%2F2019%2F10%2F31%2Ffunctions-as-tables-in-django-and-postgres%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE1ipUUvAH4MGcjeCKcg-r2dniIuw&#39;;return true;">https://schinckel.net/2019/10/31/functions-as-tables-in-django-and-postgres/

Thanks,
Petr

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-developers/6d16fdfc-332f-4a72-83ae-04ee5c9fd28a%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-developers/6d16fdfc-332f-4a72-83ae-04ee5c9fd28a%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-developers/6d16fdfc-332f-4a72-83ae-04ee5c9fd28a%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-developers/6d16fdfc-332f-4a72-83ae-04ee5c9fd28a%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/38376f17-135c-4ea9-9e86-6f9e07c609ec%40googlegroups.com.