Skip to content

Commit 7e1bb76

Browse files
committed
style: apply spotless and rustfmt
1 parent 60e0c38 commit 7e1bb76

2 files changed

Lines changed: 21 additions & 32 deletions

File tree

‎core/src/test/java/org/apache/datafusion/ScalarUdfTest.java‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,10 @@ void udfAppliedToMultiRowQuery_processesAllRows() throws Exception {
451451
}
452452

453453
/**
454-
* Nullary UDF returning a length-1 Float8 vector. Marked VOLATILE so DataFusion's constant
455-
* folder does not collapse the call before reaching us. Exercises the path that the abandoned
456-
* PR #57 added a separate rowCount parameter for: a nullary UDF can now broadcast its value
457-
* through {@link ColumnarValue#scalar(FieldVector)} and the framework handles per-row expansion.
454+
* Nullary UDF returning a length-1 Float8 vector. Marked VOLATILE so DataFusion's constant folder
455+
* does not collapse the call before reaching us. Exercises the path that the abandoned PR #57
456+
* added a separate rowCount parameter for: a nullary UDF can now broadcast its value through
457+
* {@link ColumnarValue#scalar(FieldVector)} and the framework handles per-row expansion.
458458
*/
459459
static final class JavaPi extends AbstractScalarFunction {
460460
JavaPi() {
@@ -478,8 +478,7 @@ void nullaryScalarReturnUdf_overMultiRowQuery_broadcasts() throws Exception {
478478
BufferAllocator allocator = new RootAllocator()) {
479479
ctx.registerUdf(new ScalarUdf(new JavaPi()));
480480

481-
try (DataFrame df =
482-
ctx.sql("SELECT java_pi() AS p FROM (VALUES (1), (2), (3)) AS t(x)");
481+
try (DataFrame df = ctx.sql("SELECT java_pi() AS p FROM (VALUES (1), (2), (3)) AS t(x)");
483482
ArrowReader r = df.collect(allocator)) {
484483
assertEquals(true, r.loadNextBatch());
485484
VectorSchemaRoot root = r.getVectorSchemaRoot();
@@ -494,8 +493,8 @@ void nullaryScalarReturnUdf_overMultiRowQuery_broadcasts() throws Exception {
494493
}
495494

496495
/**
497-
* UDF over (int_col, int_literal). On every invocation it asserts that arg 0 is an Array and
498-
* arg 1 is a Scalar (length-1 vector). Proves the FFI protocol preserves scalar-ness end-to-end
496+
* UDF over (int_col, int_literal). On every invocation it asserts that arg 0 is an Array and arg
497+
* 1 is a Scalar (length-1 vector). Proves the FFI protocol preserves scalar-ness end-to-end
499498
* rather than materialising the literal to a length-N array on the native side.
500499
*/
501500
static final class AssertSecondArgIsScalar extends AbstractScalarFunction {

‎native/src/udf.rs‎

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -130,21 +130,13 @@ impl ScalarUDFImpl for JavaScalarUdf {
130130
let ty = signature_types[i].clone();
131131
match cv {
132132
ColumnarValue::Array(a) => {
133-
array_fields.push(Field::new(
134-
format!("arg{}", array_arrays.len()),
135-
ty,
136-
true,
137-
));
133+
array_fields.push(Field::new(format!("arg{}", array_arrays.len()), ty, true));
138134
array_arrays.push(a.clone());
139135
arg_kinds.push(0);
140136
}
141137
ColumnarValue::Scalar(s) => {
142138
let arr = s.to_array_of_size(1)?;
143-
scalar_fields.push(Field::new(
144-
format!("arg{}", scalar_arrays.len()),
145-
ty,
146-
true,
147-
));
139+
scalar_fields.push(Field::new(format!("arg{}", scalar_arrays.len()), ty, true));
148140
scalar_arrays.push(arr);
149141
arg_kinds.push(1);
150142
}
@@ -160,13 +152,9 @@ impl ScalarUDFImpl for JavaScalarUdf {
160152
number_rows,
161153
)
162154
.map_err(|e| DataFusionError::ArrowError(Box::new(e), None))?;
163-
let scalar_struct = StructArray::try_new_with_length(
164-
Fields::from(scalar_fields),
165-
scalar_arrays,
166-
None,
167-
1,
168-
)
169-
.map_err(|e| DataFusionError::ArrowError(Box::new(e), None))?;
155+
let scalar_struct =
156+
StructArray::try_new_with_length(Fields::from(scalar_fields), scalar_arrays, None, 1)
157+
.map_err(|e| DataFusionError::ArrowError(Box::new(e), None))?;
170158

171159
let (array_ffi_arr, array_ffi_sch) = to_ffi(&array_struct.into_data())
172160
.map_err(|e| DataFusionError::ArrowError(Box::new(e), None))?;
@@ -198,11 +186,9 @@ impl ScalarUDFImpl for JavaScalarUdf {
198186
.map_err(|e| DataFusionError::Execution(format!("JNI attach failed: {}", e)))?;
199187

200188
// 6. Build the byte[] for argKinds inside the JVM heap. JNI local; freed when env drops.
201-
let arg_kinds_array = env
202-
.byte_array_from_slice(&arg_kinds)
203-
.map_err(|e| {
204-
DataFusionError::Execution(format!("byte_array_from_slice failed: {}", e))
205-
})?;
189+
let arg_kinds_array = env.byte_array_from_slice(&arg_kinds).map_err(|e| {
190+
DataFusionError::Execution(format!("byte_array_from_slice failed: {}", e))
191+
})?;
206192

207193
let expected_rows = i32::try_from(number_rows).map_err(|_| {
208194
DataFusionError::Execution(format!(
@@ -214,12 +200,16 @@ impl ScalarUDFImpl for JavaScalarUdf {
214200
let udf_jobject = self.udf_global_ref.as_obj();
215201
// SAFETY: udf_global_ref and arg_kinds_array are alive for the duration of this call.
216202
let call_args: [jvalue; 9] = [
217-
jvalue { l: udf_jobject.as_raw() },
203+
jvalue {
204+
l: udf_jobject.as_raw(),
205+
},
218206
jvalue { j: array_arr_addr },
219207
jvalue { j: array_sch_addr },
220208
jvalue { j: scalar_arr_addr },
221209
jvalue { j: scalar_sch_addr },
222-
jvalue { l: arg_kinds_array.as_raw() },
210+
jvalue {
211+
l: arg_kinds_array.as_raw(),
212+
},
223213
jvalue { j: result_arr_addr },
224214
jvalue { j: result_sch_addr },
225215
jvalue { i: expected_rows },

0 commit comments

Comments
 (0)