Giter VIP home page Giter VIP logo

Comments (6)

Fleapse avatar Fleapse commented on September 22, 2024
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.

Fleapse avatar Fleapse commented on September 22, 2024
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.

Fleapse avatar Fleapse commented on September 22, 2024

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.

jayvynl avatar jayvynl commented on September 22, 2024

@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.

jayvynl avatar jayvynl commented on September 22, 2024

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.

Fleapse avatar Fleapse commented on September 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.