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

Fix: Unsigned integer types being cast to integers #2640

Merged
merged 3 commits into from
Feb 13, 2024
Merged
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
14 changes: 11 additions & 3 deletions crates/datasources/src/native/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ fn arrow_to_delta_safe(arrow_type: &DataType) -> DeltaResult<DeltaField> {
metadata: Some(metadata),
})
}
dtype @ (DataType::UInt8 | DataType::UInt16 | DataType::UInt32 | DataType::UInt64) => {
let mut metadata = HashMap::new();
metadata.insert("arrow_type".to_string(), json!(dtype));

let delta_type = dtype.try_into()?;

Ok(DeltaField {
data_type: delta_type,
metadata: Some(metadata),
})
}
other => {
let delta_type = other.try_into()?;
Ok(DeltaField {
Expand All @@ -130,7 +141,6 @@ fn arrow_to_delta_safe(arrow_type: &DataType) -> DeltaResult<DeltaField> {
}
}


impl NativeTableStorage {
/// Create a native table storage provider from a URL and an object store instance
/// rooted at that location.
Expand Down Expand Up @@ -194,7 +204,6 @@ impl NativeTableStorage {
.with_table_name(&table.meta.name)
.with_log_store(delta_store);


for col in &opts.columns {
let delta_col = arrow_to_delta_safe(&col.arrow_type)?;

Expand Down Expand Up @@ -371,7 +380,6 @@ impl TableProvider for NativeTable {
if let Some(arrow_type) = metadata.get("arrow_type") {
// this is dumb AF, delta-lake is returning a string of a json object instead of a json object


// any panics here are bugs in writing the metadata in the first place
let s: String =
serde_json::from_str(arrow_type).expect("metadata was not correctly written");
Expand Down
18 changes: 17 additions & 1 deletion testdata/sqllogictests/datatypes.slt
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,20 @@ statement error
select array_element(1, f) from test;

statement error
select array_append(f, 3) from test;
select array_append(f, 3) from test;



# 2588 Unsigned integers downgraded to integers in delta-lake
statement ok
create table datatypes (u8 tinyint unsigned, u16 smallint unsigned, u32 int unsigned, u64 bigint unsigned);


# Inserting negative values to test validity of unsigned integers
statement error
insert into datatypes (u8, u16, u32, u64) values (-1, -1, -1, -1);


# Inserting positive values
statement ok
insert into datatypes (u8, u16, u32, u64) values (1, 1, 1, 1);
Loading