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

Support partition value string deserialization for timestamp/binary #371

Merged
merged 5 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
38 changes: 37 additions & 1 deletion rust/src/checkpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ fn typed_partition_value_from_string(
) -> Result<Value, CheckpointError> {
match data_type {
SchemaDataType::primitive(primitive_type) => match primitive_type.as_str() {
"string" => Ok(string_value.to_owned().into()),
"string" | "binary" => Ok(string_value.to_owned().into()),
"long" | "integer" | "short" | "byte" => Ok(string_value
.parse::<i64>()
.map_err(|_| CheckpointError::PartitionValueNotParseable(string_value.to_owned()))?
Expand All @@ -312,6 +312,14 @@ fn typed_partition_value_from_string(
// day 0 is 1970-01-01 (719163 days from ce)
Ok((d.num_days_from_ce() - 719_163).into())
}
"timestamp" => {
let ts =
chrono::naive::NaiveDateTime::parse_from_str(string_value, "%Y-%m-%d %H:%M:%S")
.map_err(|_| {
CheckpointError::PartitionValueNotParseable(string_value.to_owned())
})?;
Ok((ts.timestamp_millis() * 1000).into())
}
s => unimplemented!(
"Primitive type {} is not supported for partition column values.",
s
Expand Down Expand Up @@ -462,6 +470,34 @@ mod tests {
.unwrap()
);
}

for (s, v) in [
("2021-08-08 01:00:01", 1628384401000000i64),
("1970-01-02 12:59:59", 133199000000i64),
("1970-01-01 13:00:01", 46801000000i64),
("1969-12-31 00:00:00", -86400000000i64),
("1677-09-21 00:12:44", -9223372036000000i64),
] {
let timestamp_value: Value = v.into();
assert_eq!(
timestamp_value,
typed_partition_value_from_option_string(
&Some(s.to_string()),
&SchemaDataType::primitive("timestamp".to_string()),
)
.unwrap()
);
}

let binary_value: Value = "\u{2081}\u{2082}\u{2083}\u{2084}".into();
assert_eq!(
binary_value,
typed_partition_value_from_option_string(
&Some("₁₂₃₄".to_string()),
&SchemaDataType::primitive("binary".to_string()),
)
.unwrap()
);
}

#[test]
Expand Down
3 changes: 2 additions & 1 deletion rust/src/delta_arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ impl TryFrom<&schema::SchemaDataType> for ArrowDataType {
"float" => Ok(ArrowDataType::Float32),
"double" => Ok(ArrowDataType::Float64),
"boolean" => Ok(ArrowDataType::Boolean),
"binary" => Ok(ArrowDataType::Binary),
// Change to binary type after https://github.com/apache/arrow-rs/pull/702 is released
"binary" => Ok(ArrowDataType::Utf8),
houqp marked this conversation as resolved.
Show resolved Hide resolved
decimal if DECIMAL_REGEX.is_match(decimal) => {
let extract = DECIMAL_REGEX.captures(decimal).ok_or_else(|| {
ArrowError::SchemaError(format!(
Expand Down