Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(read): hash_fn attribute #41

Merged
merged 4 commits into from
May 25, 2024
Merged

feat(read): hash_fn attribute #41

merged 4 commits into from
May 25, 2024

Conversation

Fyko
Copy link
Owner

@Fyko Fyko commented May 25, 2024

This PR implements a hash_fn attribute for the fields of a ReadQuery struct.

The way scyllax query coalescing works, the query is Hashed
https://github.com/trufflehq/scyllax/blob/e08edab62b979aee1f0d4af96e31b4cd901e70ea/scyllax/src/executor.rs#L148-L154
and added to a HashMap as the key for other receivers to wait on
https://github.com/trufflehq/scyllax/blob/e08edab62b979aee1f0d4af96e31b4cd901e70ea/scyllax/src/executor.rs#L142

To support column types that are not made by the end user, the hash_fn attribute accepts the value and expects it to be mapped to a value that implements Hash.

For example, the CqlTimestamp type from the scylla library:

#[inline]
fn hash_cql_timestamp(timestamp: &CqlTimestamp) -> i64 {
    timestamp.0
}

#[derive(Debug, Clone, PartialEq, SerializeRow, ReadQuery)]
#[read_query(
    query = r#"select * from "person_by_createdAt" where "createdAt" <= :created_before limit :rowlimit"#,
    return_type = "Vec<super::model::PersonEntity>"
)]
pub struct GetPeopleCreatedBefore {
    #[read_query(coalesce_shard_key, hash_fn = "hash_cql_timestamp")]
    pub created_before: CqlTimestamp,
    pub rowlimit: i32,
}

Copy link

codecov bot commented May 25, 2024

Codecov Report

Attention: Patch coverage is 52.17391% with 11 lines in your changes are missing coverage. Please review.

Project coverage is 80.59%. Comparing base (e08edab) to head (5c3c218).

Files Patch % Lines
example/src/entities/person/queries.rs 0.00% 10 Missing ⚠️
scyllax-macros-core/src/queries/read.rs 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #41      +/-   ##
==========================================
- Coverage   80.80%   80.59%   -0.22%     
==========================================
  Files          32       32              
  Lines        2422     2437      +15     
==========================================
+ Hits         1957     1964       +7     
- Misses        465      473       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Fyko Fyko merged commit 919b0bb into main May 25, 2024
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant