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

Add serialization traits #819

Merged
merged 1 commit into from
Sep 29, 2023
Merged

Conversation

Lorak-mmk
Copy link
Collaborator

@Lorak-mmk Lorak-mmk commented Sep 28, 2023

This commit adds experimental version of new serialization traits. Blanket implementation are provided to support older traits.
For now there are no comments / other implementations with real type checking as the purpose of this PR is to unblock the work on macros
and other parts of refactor.

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • I added relevant tests for new features and bug fixes.
  • All commits compile, pass static checks and pass test.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have provided docstrings for the public items that I want to introduce.
  • I have adjusted the documentation in ./docs/source/.
  • I added appropriate Fixes: annotations to PR description.

&self,
_ctx: &RowSerializationContext<'_>,
out: &mut Vec<u8>,
) -> Result<(), Arc<dyn Any + Send + Sync>> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please introduce an alias for Arc<dyn Any + Send + Sync>, e.g. SerializationError.

use crate::{_macro_internal::Value, frame::response::result::ColumnType};

pub trait SerializeCql {
fn preliminary_type_check(&self, typ: &ColumnType) -> bool;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the preliminary type check should return Result<(), SerializationError> so that it can return some information about the error.

Comment on lines 40 to 41
let err: Arc<dyn Any + Send + Sync> = Arc::new(err);
err
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this can be written as Arc::new(err) as Arc<dyn Any + Send + Sync>, or Arc::new(err) as SerializationError

@@ -0,0 +1,29 @@
use std::{any::Any, sync::Arc};

use crate::{_macro_internal::Value, frame::response::result::ColumnType};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid using the _macro_internal paths.

Comment on lines 1 to 2
pub mod serialize_row;
pub mod serialize_value;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The serialize_ part seems unnecessary, these already are in a module called serialize.

Comment on lines 10 to 12
pub fn column_by_idx(&self, i: usize) -> Option<&ColumnSpec> {
self.columns.get(i)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not exactly a fan of this... This doesn't allow to easily get information about the number of columns, and makes iteration over the columns slightly awkward. How about exposing this field through a getter that returns &'a [ColumnSpec]?

}

pub trait SerializeRow {
fn preliminary_type_check(&self, ctx: &RowSerializationContext<'_>) -> bool;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that this was supposed to be an associated function, not a method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops, yes - that's what I did in previous version but forgot about in this, sorry

@Lorak-mmk
Copy link
Collaborator Author

Adressed review comments

self.columns
}

// TODO: change RowSerializationContext to make this faster
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: what do you mean by this comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from list of clumns we can also keep a hashmap from name to column spec so that name lookups are in constant time instead of linear.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.

}

impl<'a> RowSerializationContext<'a> {
pub fn columns(&self) -> &'a [ColumnSpec] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this method and column_by_name could be made #[inline] - they are small and simple, and without it the compiler won't consider inlining them in when used in external crates.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Collaborator

@piodul piodul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small issues/comments, otherwise LGTM.

This commit adds experimental version of new serialization traits.
Blanket implementation are provided to support older traits.
@piodul piodul merged commit b51ac06 into scylladb:main Sep 29, 2023
8 checks passed
piodul added a commit that referenced this pull request Oct 5, 2023
piodul added a commit that referenced this pull request Oct 5, 2023
piodul added a commit that referenced this pull request Oct 6, 2023
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.

2 participants