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 error when querying ABCD datasets from NFDI #486

Merged
merged 9 commits into from
Mar 3, 2022
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
26 changes: 26 additions & 0 deletions datatypes/src/collections/data_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,32 @@ mod tests {
assert!(collection.rename_column("foo", "bar").is_err());
}

#[test]
fn distinguish_null_and_empty_strings() {
let pc = DataCollection::from_data(
vec![],
vec![TimeInterval::default(); 2],
[(
"foo".to_string(),
FeatureData::NullableText(vec![None, Some("".to_owned())]),
)]
.into_iter()
.collect(),
)
.unwrap();
let column = pc.data("foo").unwrap();

assert_eq!(column.nulls(), vec![true, false]);
assert_eq!(
column.get_unchecked(0),
FeatureDataValue::NullableText(None)
);
assert_eq!(
column.get_unchecked(1),
FeatureDataValue::NullableText(Some("".to_string()))
);
}

#[test]
fn iterator() {
let collection = DataCollection::from_data(
Expand Down
15 changes: 7 additions & 8 deletions datatypes/src/primitives/feature_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,11 @@ impl<'r> DataRef<'r, u8> for TextDataRef<'r> {
let end = offsets[pos + 1];

if start == end {
return serde_json::Value::Null;
return if self.is_valid(pos) {
serde_json::Value::String(String::default())
} else {
serde_json::Value::Null
};
}

let text = unsafe {
Expand Down Expand Up @@ -617,12 +621,7 @@ impl<'r> DataRef<'r, u8> for TextDataRef<'r> {
/// ```
///
fn nulls(&self) -> Vec<bool> {
let mut nulls = Vec::with_capacity(self.offsets.len() - 1);
for window in self.offsets.windows(2) {
let (start, end) = (window[0], window[1]);
nulls.push(start == end);
}
nulls
null_bitmap_to_bools(self.valid_bitmap, self.offsets.len() - 1)
}

fn is_valid(&self, i: usize) -> bool {
Expand Down Expand Up @@ -760,7 +759,7 @@ impl<'r> TextDataRef<'r> {
let end = self.offsets[pos + 1];

if start == end {
return Ok(None);
return Ok(if self.is_valid(pos) { Some("") } else { None });
}

let text = unsafe {
Expand Down