nodecosmos / charybdis

Rust ORM for ScyllaDB and Apache Cassandra
MIT License
108 stars 6 forks source link

Composed Partition Keys in Materialized Views #24

Closed DanielHe4rt closed 2 months ago

DanielHe4rt commented 2 months ago

Hey! I'm trying to create a MV with two keys in the partition key but seems to not work. Maybe it's a syntax error. It's suppose to work?

#[charybdis_view_model(
table_name=timeline_liked,
base_table=timeline,
partition_keys=[(username, liked)], // <- 
clustering_keys=[created_at, tweet_id],
table_options = "CLUSTERING ORDER BY (created_at DESC)"
)]
pub struct TimelineLiked {
    pub username: Text,
    pub tweet_id: Uuid,
    pub author: Text,
    pub text: Text,
    pub liked: Boolean,
    pub bookmarked: Boolean,
    pub retweeted: Boolean,
    pub created_at: Timeuuid
}

The output:

image

The expected query to be executed:

CREATE MATERIALIZED VIEW IF NOT EXISTS timeline_liked AS
    SELECT
        text,
        created_at,
        tweet_id,
        retweeted,
        bookmarked,
        author,
        liked,
        username
    FROM 
        timeline
    WHERE
        username IS NOT NULL AND
        liked IS NOT NULL AND
        created_at IS NOT NULL AND
        tweet_id IS NOT NULL
PRIMARY KEY ((username, liked), created_at, tweet_id) WITH CLUSTERING ORDER BY (created_at DESC);
GoranBrkuljan commented 2 months ago

@DanielHe4rt you have parentheses in you macro partition_key part: [(username, liked)]. It should be [username, liked].

GoranBrkuljan commented 2 months ago

Agh, I see now, it won't correctly set partition key part.

GoranBrkuljan commented 2 months ago

fixed in https://github.com/nodecosmos/charybdis/releases/tag/v0.4.18

DanielHe4rt commented 2 months ago

@GoranBrkuljan I tested the new version 0.4.18 and seems to not work yet. Maybe the syntax changed?

GoranBrkuljan commented 2 months ago

It works. As I said in prev comment, make sure you don't have parentheses here: [(username, liked)]. It should be [username, liked].