Comments (6)
qs = model.objects.filter(
timestamp__gte=start, sku=self.kwargs.get("sku")
).values(
"sku",
"marketplace",
).annotate(
t=Func(
F("timestamp"),
RawSQL("INTERVAL 1 hour", []),
function="toStartOfInterval",
output_field=DateTimeField()
),
price=Func(F("price_u"), function="any"),
sale_price=Func(F("sale_price_u"), function="any"),
c=Count("sku")
).values(
"sku",
"marketplace",
"t",
"price",
"sale_price"
)
SELECT
"prices"."sku",
"prices"."marketplace",
toStartOfInterval("prices"."timestamp", (INTERVAL 1 hour)) AS "t",
any("prices"."priceU") AS "price",
any("prices"."salePriceU") AS "sale_price"
FROM "prices"
WHERE ("prices"."sku" = 126129665 AND "prices"."timestamp" >= 2023-08-29 16:21:51+00:00)
GROUP BY "prices"."sku", "prices"."marketplace", toStartOfInterval("prices"."timestamp", (INTERVAL 1 hour)), any("prices"."priceU"), any("prices"."salePriceU")
and here the annotation functions fall into GROUP BY
from django-clickhouse-backend.
qs = model.objects.filter(
timestamp__gte=start, sku=self.kwargs.get("sku")
).values(
"sku",
"marketplace",
).annotate(
t=Func(
F("timestamp"),
RawSQL("INTERVAL 1 hour", []),
function="toStartOfInterval",
output_field=DateTimeField()
),
price=Func(F("price_u"), function="any"),
sale_price=Func(F("sale_price_u"), function="any"),
).values(
"sku",
"marketplace",
"t",
"price",
"sale_price"
)
SELECT "prices"."sku", "prices"."marketplace", toStartOfInterval("prices"."timestamp", (INTERVAL 1 hour)) AS "t", any("prices"."priceU") AS "price", any("prices"."salePriceU") AS "sale_price" FROM "prices" WHERE ("prices"."sku" = 126129665 AND "prices"."timestamp" >= 2023-08-29 16:27:52+00:00)
without Count - there is no Group by, but it must be
from django-clickhouse-backend.
because you have a new project - it’s normal that you haven’t implemented many sql methods, but then you need to ensure that Func and F work well so that you can deal with this :)
anyway thanks for this backend, it's a great job
from django-clickhouse-backend.
@Fleapse Try this:
qs = model.objects.filter(timestamp__gte=start, sku=self.kwargs.get("sku")).values("sku", "marketplace").annotate(c=Count("sku")).order_by()
Order of values
, annotate
and order_by
do matter
from django-clickhouse-backend.
You can try any sql functions from django library, most of them should work, if any of them don't work, don't hesitate to report the bug.
I also have implemented some funtions in clickhouse_backend.models.functions
module. But only the fuctions I used in my project. If you think some functions are important, any PR or feature request is welcomed.
from django-clickhouse-backend.
I double-checked, and the problem is really in the order of calling the methods, and it also works in the pgsql backend, so I’m closing the issue.
It still seems to me that some of the points above work strangely, I’ll double-check everything with how it works with older backends, and if something doesn’t work well, I’ll open another issue
The by group works very strangely in Django.
Thanks for answers!
from django-clickhouse-backend.
Related Issues (20)
- [BUG] partition by single expression raise TypeError HOT 4
- [BUG] django_migrations.deleted HOT 7
- [BUG] Connection pool does not take effect HOT 1
- 请问是否考虑支持物化视图?包括分布式的物化视图哇~ HOT 3
- python manage.py migrate not working HOT 18
- [BUG] inspectdb dosent work with leatest backend version HOT 2
- [BUG] DB Error 386 when updating JSONField HOT 2
- [BUG ] UUID like id dont work afrter upate 1.0.1 -> 1.1.4 HOT 1
- Supporting Integration Engines HOT 1
- [Feature Request] Support for CityHash64
- [DOCS] The changelog does not list version 1.1.4 HOT 4
- [BUG] - Package taking time to render response. HOT 7
- Window func not working HOT 2
- Support for AggregateFunction under AMT HOT 3
- Unexpected 'driver' HOT 1
- [QUESTION] DB::Exception: Syntax error: failed at position 268 ('<'): <clickhouse_backend.models.fields.integer.UInt64Field> HOT 3
- [BUG] AttributeError: 'ReplicatedReplacingMergeTree' object has no attribute 'expressions' HOT 6
- Error. Code 102 HOT 3
- [Issue] HOT 1
- support for "prewhere" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-clickhouse-backend.