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

[dagster-pipes-rust] 🔥 Simplify PipesMetadataValue construction #61

Merged
merged 9 commits into from
Dec 19, 2024

Conversation

christeefy
Copy link
Collaborator

Summary & Motivation

Fixes #46.

Approach

  • Utilize Rust's From<T> trait wherever possible, allowing native types to be converted using PipesMetadataValue::from(10). This has been implemented for f64, i64, bool, String, HashMap and Vec.
  • For types that don't derive directly from a native type (e.g. dagster_run, timestamp, null), a ::from_* method is used instead. For example, PipesMetadataValue::from_asset("my_asset").

Alternatives Considered: Use of Custom Types

The RawValue and Type enums from jsonschema have implicit connections to each other (e.g. Type::Int should have a RawValue::Integer(...), and nothing else). Currently users are responsible for knowing this implicit mapping.

I thought of using user-facing, custom MetadataValue enum that is separately defined from jsonschema. This MetadataValue (different from PipesMetadata) is responsible for

  1. encoding the relationships between RawValue and Type
  2. mapping user-facing inputs over to PipesMetadataValue, RawValue and Type.

Something as follows:

pub enum MetadataValue {
    Asset(String),
    Bool(bool),
    ...
}

impl From<MetadataValue> for PipesMetadata { ... }

// main.rs
HashMap::from([("asset", MetadataValue::Asset("my_asset").into()])

In the end, the idea was scrapped because it introduces another enum that is very similar to existing public jsonschema types.

How I Tested These Changes

  • cargo nextest and no errors from compiler

Changelog

Ensure that an entry has been created in CHANGELOG.md outlining additions, deletions, and/or modifications.

See: keepachangelog.com

@christeefy christeefy changed the title 🔥 Simplify PipesMetadata construction [dagster-pipes-rust] 🔥 Simplify PipesMetadata construction Dec 18, 2024
@christeefy christeefy changed the title [dagster-pipes-rust] 🔥 Simplify PipesMetadata construction [dagster-pipes-rust] 🔥 Simplify PipesMetadataValue construction Dec 18, 2024
Copy link
Collaborator

@marijncv marijncv left a comment

Choose a reason for hiding this comment

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

Really nice!

}
}

pub fn none() -> Self {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What do you think about this method name? Should it be none, from_none, or null?

pub fn none() -> Self {
PipesMetadataValue {
raw_value: None,
pipes_metadata_value_type: None, // TODO: Should this be `Some(Type::Null)`?
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And should this be None, or Some(Type::Null)? Not sure what's the difference with either option though.

Copy link
Collaborator

@marijncv marijncv Dec 19, 2024

Choose a reason for hiding this comment

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

I would go with:

    pub fn null() -> Self {
        PipesMetadataValue {
            raw_value: None,
            pipes_metadata_value_type: Some(Type::Null),

Function name: null is similar to the python implementation here. Some(Type::Null) follows the convention used by the other types in the rust implementation

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! Will merge in an hour, if everything's still looks good.

Copy link
Collaborator

Choose a reason for hiding this comment

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

LGTM!

@christeefy christeefy merged commit d5feab5 into main Dec 19, 2024
3 checks passed
@christeefy christeefy deleted the simplify-api/metadata-instantiation branch December 19, 2024 17:38
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.

[dagster-pipes-rust] Simpler and error-free API for PipesMetadataValue
2 participants