Skip to content

Conversation

@adriangb
Copy link
Collaborator

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Dec 17, 2025

Codecov Report

❌ Patch coverage is 93.98496% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.28%. Comparing base (9cb9b1d) to head (6f5a676).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/json_from_scalar.rs 93.93% 6 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #103      +/-   ##
==========================================
+ Coverage   84.12%   85.28%   +1.16%     
==========================================
  Files          16       17       +1     
  Lines        1216     1346     +130     
  Branches     1216     1346     +130     
==========================================
+ Hits         1023     1148     +125     
- Misses        131      134       +3     
- Partials       62       64       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

adriangb added a commit that referenced this pull request Dec 17, 2025
Copy link
Member

@friendlymatthew friendlymatthew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me. I think we should address 2 comments below before merge

impl Default for JsonFromScalar {
fn default() -> Self {
Self {
signature: Signature::variadic_any(Volatility::Immutable),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit odd that we model this as Signature::variadic_any when the function requires exactly 1 argument

Signature::any(1, Volatility::Immutable) seems like a better fit

}
}

fn scalar_to_json_union_field(scalar: ScalarValue) -> DataFusionResult<Option<JsonUnionField>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the return type's Option wrap is superfluous. I don't see any of the arms below return an Ok(None)

Comment on lines 157 to 311
match array.data_type() {
DataType::Null => {
for _ in 0..array.len() {
union.push(JsonUnionField::JsonNull);
}
}

DataType::Boolean => {
let arr = array.as_boolean();
for i in 0..arr.len() {
if arr.is_null(i) {
union.push_none();
} else {
union.push(JsonUnionField::Bool(arr.value(i)));
}
}
}

// Integer types - coerce to i64
DataType::Int8 => {
let arr = array.as_primitive::<Int8Type>();
for i in 0..arr.len() {
if arr.is_null(i) {
union.push_none();
} else {
union.push(JsonUnionField::Int(i64::from(arr.value(i))));
}
}
}
DataType::Int16 => {
let arr = array.as_primitive::<Int16Type>();
for i in 0..arr.len() {
if arr.is_null(i) {
union.push_none();
} else {
union.push(JsonUnionField::Int(i64::from(arr.value(i))));
}
}
}
DataType::Int32 => {
let arr = array.as_primitive::<Int32Type>();
for i in 0..arr.len() {
if arr.is_null(i) {
union.push_none();
} else {
union.push(JsonUnionField::Int(i64::from(arr.value(i))));
}
}
}
DataType::Int64 => {
let arr = array.as_primitive::<Int64Type>();
for i in 0..arr.len() {
if arr.is_null(i) {
union.push_none();
} else {
union.push(JsonUnionField::Int(arr.value(i)));
}
}
}
DataType::UInt8 => {
let arr = array.as_primitive::<UInt8Type>();
for i in 0..arr.len() {
if arr.is_null(i) {
union.push_none();
} else {
union.push(JsonUnionField::Int(i64::from(arr.value(i))));
}
}
}
DataType::UInt16 => {
let arr = array.as_primitive::<UInt16Type>();
for i in 0..arr.len() {
if arr.is_null(i) {
union.push_none();
} else {
union.push(JsonUnionField::Int(i64::from(arr.value(i))));
}
}
}
DataType::UInt32 => {
let arr = array.as_primitive::<UInt32Type>();
for i in 0..arr.len() {
if arr.is_null(i) {
union.push_none();
} else {
union.push(JsonUnionField::Int(i64::from(arr.value(i))));
}
}
}
DataType::UInt64 => {
let arr = array.as_primitive::<UInt64Type>();
for i in 0..arr.len() {
if arr.is_null(i) {
union.push_none();
} else {
union.push(JsonUnionField::Int(i64::try_from(arr.value(i)).map_err(|_| {
exec_datafusion_err!("UInt64 value {} is out of range for i64", arr.value(i))
})?));
}
}
}

// Float types - coerce to f64
DataType::Float32 => {
let arr = array.as_primitive::<Float32Type>();
for i in 0..arr.len() {
if arr.is_null(i) {
union.push_none();
} else {
union.push(JsonUnionField::Float(f64::from(arr.value(i))));
}
}
}
DataType::Float64 => {
let arr = array.as_primitive::<Float64Type>();
for i in 0..arr.len() {
if arr.is_null(i) {
union.push_none();
} else {
union.push(JsonUnionField::Float(arr.value(i)));
}
}
}

// String types
DataType::Utf8 => {
let arr = array.as_string::<i32>();
for i in 0..arr.len() {
if arr.is_null(i) {
union.push_none();
} else {
union.push(JsonUnionField::Str(arr.value(i).to_string()));
}
}
}
DataType::LargeUtf8 => {
let arr = array.as_string::<i64>();
for i in 0..arr.len() {
if arr.is_null(i) {
union.push_none();
} else {
union.push(JsonUnionField::Str(arr.value(i).to_string()));
}
}
}
DataType::Utf8View => {
let arr = array.as_string_view();
for i in 0..arr.len() {
if arr.is_null(i) {
union.push_none();
} else {
union.push(JsonUnionField::Str(arr.value(i).to_string()));
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More of a nit and note about future work, we could probably remove a lot of this code if we impl JsonUnion::from_iter where the Iterator::Item is an Option<T> where None represents null 🤔

@adriangb adriangb merged commit 9c37683 into main Dec 17, 2025
7 checks passed
@adriangb adriangb deleted the cast-integers branch December 17, 2025 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants