Skip to content

Commit e4851c0

Browse files
committed
Clippy-induced improvements
1 parent 2a3739a commit e4851c0

File tree

3 files changed

+23
-29
lines changed

3 files changed

+23
-29
lines changed

datafusion_remote_tables/src/factory.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ impl TableProviderFactory for RemoteTableFactory {
2222
let table = RemoteTable::new(
2323
cmd.options
2424
.get("name")
25-
.ok_or(DataFusionError::Execution(
26-
"Missing 'name' option".to_string(),
27-
))?
25+
.ok_or_else(|| {
26+
DataFusionError::Execution("Missing 'name' option".to_string())
27+
})?
2828
.clone(),
2929
cmd.location.clone(),
3030
SchemaRef::from(cmd.schema.deref().clone()),

src/wasm_udf/data_types.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,22 @@ pub enum CreateFunctionDataType {
6262

6363
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, EnumString, Display, Clone)]
6464
#[serde(rename_all = "camelCase")]
65+
#[derive(Default)]
6566
pub enum CreateFunctionVolatility {
6667
Immutable,
6768
Stable,
69+
#[default]
6870
Volatile,
6971
}
70-
impl Default for CreateFunctionVolatility {
71-
fn default() -> Self {
72-
CreateFunctionVolatility::Volatile
73-
}
74-
}
7572

7673
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, EnumString, Display, Clone)]
7774
#[serde(rename_all = "camelCase")]
75+
#[derive(Default)]
7876
pub enum CreateFunctionLanguage {
77+
#[default]
7978
Wasm,
8079
WasmMessagePack,
8180
}
82-
impl Default for CreateFunctionLanguage {
83-
fn default() -> Self {
84-
CreateFunctionLanguage::Wasm
85-
}
86-
}
8781

8882
fn parse_create_function_data_type(
8983
raw: &str,

src/wasm_udf/wasm.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ impl WasmMessagePackUDFInstance {
112112
let alloc = get_wasm_module_exported_fn(&instance, &mut store, "alloc")?;
113113
let dealloc = get_wasm_module_exported_fn(&instance, &mut store, "dealloc")?;
114114
let udf = get_wasm_module_exported_fn(&instance, &mut store, function_name)?;
115-
let memory = instance.get_memory(&mut store, "memory").ok_or(
115+
let memory = instance.get_memory(&mut store, "memory").ok_or_else(|| {
116116
DataFusionError::Internal(
117117
"could not find module's exported memory".to_string(),
118-
),
119-
)?;
118+
)
119+
})?;
120120
Ok(Self {
121121
store,
122122
alloc,
@@ -376,7 +376,7 @@ fn messagepack_decode_results(
376376
arrow::datatypes::Int16Type,
377377
>(encoded_results, &|v| {
378378
v.as_i64()
379-
.ok_or(DataFusionError::Internal(format!(
379+
.ok_or_else(|| DataFusionError::Internal(format!(
380380
"Expected to find i64 value, but received {v:?} instead"
381381
)))
382382
.and_then(|v_i64| {
@@ -392,7 +392,7 @@ fn messagepack_decode_results(
392392
encoded_results,
393393
&|v| {
394394
v.as_i64()
395-
.ok_or(DataFusionError::Internal(format!(
395+
.ok_or_else(|| DataFusionError::Internal(format!(
396396
"Expected to find i64 value, but received {v:?} instead"
397397
)))
398398
.and_then(|v_i64| {
@@ -409,7 +409,7 @@ fn messagepack_decode_results(
409409
decode_udf_result_primitive_array::<arrow::datatypes::Int64Type>(
410410
encoded_results,
411411
&|v| {
412-
v.as_i64().ok_or(DataFusionError::Internal(format!(
412+
v.as_i64().ok_or_else(|| DataFusionError::Internal(format!(
413413
"Expected to find i64 value, but received {v:?} instead"
414414
)))
415415
},
@@ -420,7 +420,7 @@ fn messagepack_decode_results(
420420
| CreateFunctionDataType::TEXT => encoded_results
421421
.iter()
422422
.map(|i| {
423-
Some(i.as_str().ok_or(DataFusionError::Internal(format!(
423+
Some(i.as_str().ok_or_else(|| DataFusionError::Internal(format!(
424424
"Expected to find string value, received {:?} instead",
425425
&i
426426
))))
@@ -432,7 +432,7 @@ fn messagepack_decode_results(
432432
arrow::datatypes::Date32Type,
433433
>(encoded_results, &|v| {
434434
v.as_i64()
435-
.ok_or(DataFusionError::Internal(format!(
435+
.ok_or_else(|| DataFusionError::Internal(format!(
436436
"Expected to find i64 value, but received {v:?} instead"
437437
)))
438438
.and_then(|v_i64| {
@@ -446,14 +446,14 @@ fn messagepack_decode_results(
446446
CreateFunctionDataType::TIMESTAMP => decode_udf_result_primitive_array::<
447447
arrow::datatypes::TimestampNanosecondType,
448448
>(encoded_results, &|v| {
449-
v.as_i64().ok_or(DataFusionError::Internal(format!(
449+
v.as_i64().ok_or_else(|| DataFusionError::Internal(format!(
450450
"Expected to find i64 value, but received {v:?} instead"
451451
)))
452452
}),
453453
CreateFunctionDataType::BOOLEAN => encoded_results
454454
.iter()
455455
.map(|i| {
456-
Some(i.as_bool().ok_or(DataFusionError::Internal(format!(
456+
Some(i.as_bool().ok_or_else(|| DataFusionError::Internal(format!(
457457
"Expected to find string value, received {i:?} instead"
458458
))))
459459
.transpose()
@@ -465,7 +465,7 @@ fn messagepack_decode_results(
465465
decode_udf_result_primitive_array::<arrow::datatypes::Float64Type>(
466466
encoded_results,
467467
&|v| {
468-
v.as_f64().ok_or(DataFusionError::Internal(format!(
468+
v.as_f64().ok_or_else(|| DataFusionError::Internal(format!(
469469
"Expected to find f64 value, but received {v:?} instead"
470470
)))
471471
},
@@ -491,15 +491,15 @@ fn messagepack_decode_results(
491491
.map(|i| {
492492
Some(
493493
i.as_array()
494-
.ok_or(DataFusionError::Internal(format!(
494+
.ok_or_else(|| DataFusionError::Internal(format!(
495495
"Expected to find array containing decimal parts, received {i:?} instead"
496496
)))
497497
.and_then(|decimal_array| {
498498
if decimal_array.len() != 4 {
499499
return Err(DataFusionError::Internal(format!("DECIMAL UDF result array should have 4 elements, found {:?} instead.", decimal_array.len())));
500500
}
501501
decimal_array[0].as_u64()
502-
.ok_or(DataFusionError::Internal(format!("Decimal precision expected to be integer, found {:?} instead", decimal_array[0])))
502+
.ok_or_else(|| DataFusionError::Internal(format!("Decimal precision expected to be integer, found {:?} instead", decimal_array[0])))
503503
.and_then(|p_u64| {
504504
let p_u8:u8 = p_u64.try_into().map_err(|err| DataFusionError::Internal(format!("Couldn't convert 64-bit precision value {p_u64:?} to u8 {err:?}")))?;
505505
if p_u8 != *p {
@@ -508,7 +508,7 @@ fn messagepack_decode_results(
508508
Ok(p_u8)
509509
})?;
510510
decimal_array[1].as_u64()
511-
.ok_or(DataFusionError::Internal(format!("Decimal scale expected to be integer, found {:?} instead", decimal_array[1])))
511+
.ok_or_else(|| DataFusionError::Internal(format!("Decimal scale expected to be integer, found {:?} instead", decimal_array[1])))
512512
.and_then(|s_u64| {
513513
let s_i8: i8 = s_u64.try_into().map_err(|err| DataFusionError::Internal(format!("Couldn't convert 64-bit scale value {s_u64:?} to i8 {err:?}")))?;
514514
if s_i8 != *s {
@@ -517,9 +517,9 @@ fn messagepack_decode_results(
517517
Ok(s_i8)
518518
})?;
519519
let high = decimal_array[2].as_i64()
520-
.ok_or(DataFusionError::Internal(format!("Decimal value high half expected to be integer, found {:?} instead", decimal_array[2])))?;
520+
.ok_or_else(|| DataFusionError::Internal(format!("Decimal value high half expected to be integer, found {:?} instead", decimal_array[2])))?;
521521
let low = decimal_array[3].as_i64()
522-
.ok_or(DataFusionError::Internal(format!("Decimal value low half expected to be integer, found {:?} instead", decimal_array[3])))?;
522+
.ok_or_else(|| DataFusionError::Internal(format!("Decimal value low half expected to be integer, found {:?} instead", decimal_array[3])))?;
523523
let value:i128 = (low as i128) + ((high as i128) << 64);
524524
Ok(value)
525525
}),

0 commit comments

Comments
 (0)