-
Notifications
You must be signed in to change notification settings - Fork 37
Feat : Row data type support in Rust #442
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ | |
|
|
||
| use crate::error::Error::IllegalArgument; | ||
| use crate::error::Result; | ||
| use crate::metadata::DataType; | ||
| use crate::metadata::{DataType, RowType}; | ||
| use crate::row::Datum; | ||
| use crate::row::binary::BinaryRowFormat; | ||
|
|
||
|
|
@@ -136,7 +136,7 @@ pub enum InnerValueWriter { | |
| Time(u32), // precision (not used in wire format, but kept for consistency) | ||
| TimestampNtz(u32), // precision | ||
| TimestampLtz(u32), // precision | ||
| // TODO Array, Row | ||
| Row(RowType), | ||
| } | ||
|
|
||
| /// Accessor for writing the fields/elements of a binary writer during runtime, the | ||
|
|
@@ -175,6 +175,7 @@ impl InnerValueWriter { | |
| // Validation is done at TimestampLTzType construction time | ||
| Ok(InnerValueWriter::TimestampLtz(t.precision())) | ||
| } | ||
| DataType::Row(row_type) => Ok(InnerValueWriter::Row(row_type.clone())), | ||
| _ => unimplemented!( | ||
| "ValueWriter for DataType {:?} is currently not implemented", | ||
| data_type | ||
|
|
@@ -237,6 +238,26 @@ impl InnerValueWriter { | |
| (InnerValueWriter::TimestampLtz(p), Datum::TimestampLtz(ts)) => { | ||
| writer.write_timestamp_ltz(ts, *p); | ||
| } | ||
| (InnerValueWriter::Row(row_type), Datum::Row(inner_row)) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't we delegate like on Java side?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 currently, i think a new writer is created per write call, which is not ideal |
||
| use crate::row::compacted::CompactedRowWriter; | ||
| let field_count = row_type.fields().len(); | ||
| let mut nested = CompactedRowWriter::new(field_count); | ||
| for (i, field) in row_type.fields().iter().enumerate() { | ||
| let datum = &inner_row.values[i]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. potential panic on OOB? |
||
| if datum.is_null() { | ||
| if field.data_type.is_nullable() { | ||
| nested.set_null_at(i); | ||
| } | ||
| } else { | ||
| let vw = | ||
| InnerValueWriter::create_inner_value_writer(&field.data_type, None) | ||
| .expect("create_inner_value_writer failed for nested row field"); | ||
| vw.write_value(&mut nested, i, datum) | ||
| .expect("write_value failed for nested row field"); | ||
| } | ||
|
Comment on lines
+253
to
+257
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think in current way, it will panic inside a |
||
| } | ||
| writer.write_bytes(nested.buffer()); | ||
| } | ||
| _ => { | ||
| return Err(IllegalArgument { | ||
| message: format!("{self:?} used to write value {value:?}"), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we should not store clone in
innervaluewriter::row, probabl store in pre built child writer is better?