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

Empty list into object could be inligned #3

Open
finistseb opened this issue Jul 4, 2023 · 5 comments
Open

Empty list into object could be inligned #3

finistseb opened this issue Jul 4, 2023 · 5 comments

Comments

@finistseb
Copy link

Hello, we use descriptor in ovhdata-cli (open sourced recently),
The display of nested empty list can be confusing.

For example, this given struct

    fn create_metadata_error() -> TableMeta {
        TableMeta {
            table_name: Some("table-name".to_string()),
            status: "ERROR".to_string(),
            error: Some("Metadata were not extracted".to_string()),
            error_code: Some("404".to_string()),
            started_at: None,
            ended_at: None,
            metadata: Vec::new(),
        }
    }

Will produce the output :

Table Name: table-name
Status:     ERROR
Error:      Metadata were not extracted
Error Code: 404
Started At: ~
Ended At:   ~
Metadata:
Empty list

Empty list is interesting for display empty tables likes that:

NAME   TYPE   CARDINALITY   MIN   MAX
Empty list

But, IMO, nested list could be displayed likes that

Table Name: table-name
Status:     ERROR
Error:      Metadata were not extracted
Error Code: 404
Started At: ~
Ended At:   ~
Metadata: [~]

This library have not commit since 2 years, is this repo still maintained?
Thanks,
Sebastien

@XciD
Copy link
Owner

XciD commented Jul 4, 2023

Hi Sebatien,

Can you give me the struct definition ?

Vec<> have two way for output:

@finistseb
Copy link
Author

finistseb commented Jul 5, 2023

Hi Adrien,
Thanks for your quick reply

Here is the struct definition

#[derive(Debug, Clone, Deserialize, Serialize, Descriptor)]
#[serde(rename_all = "camelCase")]
pub struct TableMeta {
    pub table_name: Option<String>,
    pub status: String,
    pub error: Option<String>,
    pub error_code: Option<String>,
    #[descriptor(into = OptionDescribedDateTime)]
    pub started_at: Option<DateTime<Utc>>,
    #[descriptor(into = OptionDescribedDateTime)]
    pub ended_at: Option<DateTime<Utc>>,
    #[descriptor(output_table)]
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub metadata: Vec<Metadata>,
}

#[derive(Debug, Clone, Deserialize, Serialize, Descriptor)]
#[serde(rename_all = "camelCase")]
pub struct Metadata {
    pub name: String,
    #[serde(rename = "type")]
    #[descriptor(rename_header = "TYPE")]
    pub type_name: String,
    pub cardinality: i64,
    pub min: i64,
    pub max: i64,
}

This test gives this output

        let describe_metadata = TableMeta {
            table_name: Some("table-name".to_string()),
            status: "PROCESSING".to_string(),
            error: None,
            error_code: None,
            started_at: Some(datetime_micro(2021, 6, 3, 12, 22, 46, 107055)),
            ended_at: None,
            metadata: Vec::new(),
        };
        
        let describe = object_describe_to_string(&describe_metadata).unwrap();

OUTPUT

Table Name: table-name
Status:     PROCESSING
Error:      ~
Error Code: ~
Started At: 03-06-21 12:22:46
Ended At:   ~
Metadata:
Empty list

@XciD
Copy link
Owner

XciD commented Jul 5, 2023

Try to remove the #[descriptor(output_table)]

@finistseb
Copy link
Author

In this case, the output is not smart

Table Name: table-name
Status:     SUCCESS
Error:      ~
Error Code: ~
Started At: 03-06-21 12:22:46
Ended At:   03-06-21 12:24:46
Metadata:
- Name:        id
  Type Name:   num
  Cardinality: 788
  Min:         0
  Max:         788
- Name:        some_column
  Type Name:   txt
  Cardinality: 580
  Min:         0
  Max:         911

@XciD
Copy link
Owner

XciD commented Jul 5, 2023

Very specific use case. will check how I can do that

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

No branches or pull requests

2 participants