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

refactor(common): (WIP/Preview) optional name for struct data type #19538

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions proto/data.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ message DataType {
repeated DataType field_type = 6;
// Name of the fields if it is a struct type. For other types it will be empty.
repeated string field_names = 7;
// Optional name of custom type.
// Informative-only and populated at best effort.
// NOT to be used for comparison or lookup.
optional string unqualified_name = 8;
}

message StructArrayData {
Expand Down
11 changes: 10 additions & 1 deletion src/common/src/types/struct_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ impl Debug for StructType {
}
}

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, educe::Educe)]
#[educe(PartialEq, Eq, PartialOrd, Ord, Hash)]
struct StructTypeInner {
/// Details about a struct type. There are 2 cases for a struct:
/// 1. `field_names.len() == field_types.len()`: it represents a struct with named fields,
Expand All @@ -44,6 +45,10 @@ struct StructTypeInner {
/// e.g. `ROW(1, 2)`.
field_names: Box<[String]>,
field_types: Box<[DataType]>,
#[educe(PartialEq(ignore))]
#[educe(Ord(ignore))]
#[educe(Hash(ignore))]
unqualified_name: Option<Box<str>>,
}

impl StructType {
Expand All @@ -59,6 +64,7 @@ impl StructType {
Self(Arc::new(StructTypeInner {
field_types: field_types.into(),
field_names: field_names.into(),
unqualified_name: None,
}))
}

Expand All @@ -68,6 +74,7 @@ impl StructType {
Self(Arc::new(StructTypeInner {
field_types: Box::new([]),
field_names: Box::new([]),
unqualified_name: None,
}))
}

Expand All @@ -76,6 +83,7 @@ impl StructType {
Self(Arc::new(StructTypeInner {
field_types: fields.into(),
field_names: Box::new([]),
unqualified_name: None,
}))
}

Expand Down Expand Up @@ -164,6 +172,7 @@ impl FromStr for StructType {
Ok(Self(Arc::new(StructTypeInner {
field_types: field_types.into(),
field_names: field_names.into(),
unqualified_name: None,
})))
}
}
4 changes: 4 additions & 0 deletions src/prost/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,17 @@ impl std::fmt::Debug for data::DataType {
type_name,
// currently all data types are nullable
is_nullable: _,
unqualified_name,
} = self;

let type_name = data::data_type::TypeName::try_from(*type_name)
.map(|t| t.as_str_name())
.unwrap_or("Unknown");

let mut s = f.debug_struct(type_name);
if let Some(unqualified_name) = unqualified_name {
s.field("unqualified_name", unqualified_name);
}
if self.precision != 0 {
s.field("precision", precision);
}
Expand Down
Loading