diff --git a/datafusion/jit/src/jit.rs b/datafusion/jit/src/jit.rs index 21b0d44fb0b5b..9c28940fe701d 100644 --- a/datafusion/jit/src/jit.rs +++ b/datafusion/jit/src/jit.rs @@ -205,8 +205,13 @@ impl JIT { builder.seal_block(entry_block); // Walk the AST and declare all variables. - let variables = - declare_variables(&mut builder, ¶ms, &the_return, &stmts, entry_block); + let variables = declare_variables( + &mut builder, + ¶ms, + the_return.as_ref(), + &stmts, + entry_block, + ); // Now translate the statements of the function body. let mut trans = FunctionTranslator { @@ -652,7 +657,7 @@ fn typed_zero(typ: JITType, builder: &mut FunctionBuilder) -> Value { fn declare_variables( builder: &mut FunctionBuilder, params: &[(String, JITType)], - the_return: &Option<(String, JITType)>, + the_return: Option<&(String, JITType)>, stmts: &[Stmt], entry_block: Block, ) -> HashMap { diff --git a/datafusion/physical-expr/src/crypto_expressions.rs b/datafusion/physical-expr/src/crypto_expressions.rs index 228e6a196c534..07ebdbfd19440 100644 --- a/datafusion/physical-expr/src/crypto_expressions.rs +++ b/datafusion/physical-expr/src/crypto_expressions.rs @@ -72,10 +72,12 @@ fn digest_process( ))), }, ColumnarValue::Scalar(scalar) => match scalar { - ScalarValue::Utf8(a) | ScalarValue::LargeUtf8(a) => Ok(digest_algorithm - .digest_scalar(&a.as_ref().map(|s: &String| s.as_bytes()))), + ScalarValue::Utf8(a) | ScalarValue::LargeUtf8(a) => { + Ok(digest_algorithm + .digest_scalar(a.as_ref().map(|s: &String| s.as_bytes()))) + } ScalarValue::Binary(a) | ScalarValue::LargeBinary(a) => Ok(digest_algorithm - .digest_scalar(&a.as_ref().map(|v: &Vec| v.as_slice()))), + .digest_scalar(a.as_ref().map(|v: &Vec| v.as_slice()))), other => Err(DataFusionError::Internal(format!( "Unsupported data type {:?} for function {}", other, digest_algorithm, @@ -112,7 +114,7 @@ macro_rules! digest_to_scalar { impl DigestAlgorithm { /// digest an optional string to its hash value, null values are returned as is - fn digest_scalar(self, value: &Option<&[u8]>) -> ColumnarValue { + fn digest_scalar(self, value: Option<&[u8]>) -> ColumnarValue { ColumnarValue::Scalar(match self { Self::Md5 => digest_to_scalar!(Md5, value), Self::Sha224 => digest_to_scalar!(Sha224, value), diff --git a/datafusion/proto/src/from_proto.rs b/datafusion/proto/src/from_proto.rs index a30e7b323aba5..1496050d27548 100644 --- a/datafusion/proto/src/from_proto.rs +++ b/datafusion/proto/src/from_proto.rs @@ -894,10 +894,16 @@ pub fn parse_expr( .when_then_expr .iter() .map(|e| { - let when_expr = - parse_required_expr_inner(&e.when_expr, registry, "when_expr")?; - let then_expr = - parse_required_expr_inner(&e.then_expr, registry, "then_expr")?; + let when_expr = parse_required_expr_inner( + e.when_expr.as_ref(), + registry, + "when_expr", + )?; + let then_expr = parse_required_expr_inner( + e.then_expr.as_ref(), + registry, + "then_expr", + )?; Ok((Box::new(when_expr), Box::new(then_expr))) }) .collect::, Box)>, Error>>()?; @@ -1352,7 +1358,7 @@ fn parse_required_expr( } fn parse_required_expr_inner( - p: &Option, + p: Option<&protobuf::LogicalExprNode>, registry: &dyn FunctionRegistry, field: impl Into, ) -> Result { diff --git a/datafusion/proto/src/physical_plan/from_proto.rs b/datafusion/proto/src/physical_plan/from_proto.rs index c61339a31877b..825399825ff0b 100644 --- a/datafusion/proto/src/physical_plan/from_proto.rs +++ b/datafusion/proto/src/physical_plan/from_proto.rs @@ -144,13 +144,13 @@ pub(crate) fn parse_physical_expr( .map(|e| { Ok(( parse_required_physical_expr( - &e.when_expr, + e.when_expr.as_ref(), registry, "when_expr", input_schema, )?, parse_required_physical_expr( - &e.then_expr, + e.then_expr.as_ref(), registry, "then_expr", input_schema, @@ -237,7 +237,7 @@ fn parse_required_physical_box_expr( } fn parse_required_physical_expr( - expr: &Option, + expr: Option<&protobuf::PhysicalExprNode>, registry: &dyn FunctionRegistry, field: &str, input_schema: &Schema, diff --git a/datafusion/proto/src/to_proto.rs b/datafusion/proto/src/to_proto.rs index a73565ae6baec..92e4214b8ab01 100644 --- a/datafusion/proto/src/to_proto.rs +++ b/datafusion/proto/src/to_proto.rs @@ -912,43 +912,53 @@ impl TryFrom<&ScalarValue> for protobuf::ScalarValue { let data_type = val.get_datatype(); match val { scalar::ScalarValue::Boolean(val) => { - create_proto_scalar(val, &data_type, |s| Value::BoolValue(*s)) + create_proto_scalar(val.as_ref(), &data_type, |s| Value::BoolValue(*s)) } scalar::ScalarValue::Float32(val) => { - create_proto_scalar(val, &data_type, |s| Value::Float32Value(*s)) + create_proto_scalar(val.as_ref(), &data_type, |s| Value::Float32Value(*s)) } scalar::ScalarValue::Float64(val) => { - create_proto_scalar(val, &data_type, |s| Value::Float64Value(*s)) + create_proto_scalar(val.as_ref(), &data_type, |s| Value::Float64Value(*s)) } scalar::ScalarValue::Int8(val) => { - create_proto_scalar(val, &data_type, |s| Value::Int8Value(*s as i32)) + create_proto_scalar(val.as_ref(), &data_type, |s| { + Value::Int8Value(*s as i32) + }) } scalar::ScalarValue::Int16(val) => { - create_proto_scalar(val, &data_type, |s| Value::Int16Value(*s as i32)) + create_proto_scalar(val.as_ref(), &data_type, |s| { + Value::Int16Value(*s as i32) + }) } scalar::ScalarValue::Int32(val) => { - create_proto_scalar(val, &data_type, |s| Value::Int32Value(*s)) + create_proto_scalar(val.as_ref(), &data_type, |s| Value::Int32Value(*s)) } scalar::ScalarValue::Int64(val) => { - create_proto_scalar(val, &data_type, |s| Value::Int64Value(*s)) + create_proto_scalar(val.as_ref(), &data_type, |s| Value::Int64Value(*s)) } scalar::ScalarValue::UInt8(val) => { - create_proto_scalar(val, &data_type, |s| Value::Uint8Value(*s as u32)) + create_proto_scalar(val.as_ref(), &data_type, |s| { + Value::Uint8Value(*s as u32) + }) } scalar::ScalarValue::UInt16(val) => { - create_proto_scalar(val, &data_type, |s| Value::Uint16Value(*s as u32)) + create_proto_scalar(val.as_ref(), &data_type, |s| { + Value::Uint16Value(*s as u32) + }) } scalar::ScalarValue::UInt32(val) => { - create_proto_scalar(val, &data_type, |s| Value::Uint32Value(*s)) + create_proto_scalar(val.as_ref(), &data_type, |s| Value::Uint32Value(*s)) } scalar::ScalarValue::UInt64(val) => { - create_proto_scalar(val, &data_type, |s| Value::Uint64Value(*s)) + create_proto_scalar(val.as_ref(), &data_type, |s| Value::Uint64Value(*s)) } scalar::ScalarValue::Utf8(val) => { - create_proto_scalar(val, &data_type, |s| Value::Utf8Value(s.to_owned())) + create_proto_scalar(val.as_ref(), &data_type, |s| { + Value::Utf8Value(s.to_owned()) + }) } scalar::ScalarValue::LargeUtf8(val) => { - create_proto_scalar(val, &data_type, |s| { + create_proto_scalar(val.as_ref(), &data_type, |s| { Value::LargeUtf8Value(s.to_owned()) }) } @@ -977,10 +987,10 @@ impl TryFrom<&ScalarValue> for protobuf::ScalarValue { }) } datafusion::scalar::ScalarValue::Date32(val) => { - create_proto_scalar(val, &data_type, |s| Value::Date32Value(*s)) + create_proto_scalar(val.as_ref(), &data_type, |s| Value::Date32Value(*s)) } datafusion::scalar::ScalarValue::TimestampMicrosecond(val, tz) => { - create_proto_scalar(val, &data_type, |s| { + create_proto_scalar(val.as_ref(), &data_type, |s| { Value::TimestampValue(protobuf::ScalarTimestampValue { timezone: tz.as_ref().unwrap_or(&"".to_string()).clone(), value: Some( @@ -992,7 +1002,7 @@ impl TryFrom<&ScalarValue> for protobuf::ScalarValue { }) } datafusion::scalar::ScalarValue::TimestampNanosecond(val, tz) => { - create_proto_scalar(val, &data_type, |s| { + create_proto_scalar(val.as_ref(), &data_type, |s| { Value::TimestampValue(protobuf::ScalarTimestampValue { timezone: tz.as_ref().unwrap_or(&"".to_string()).clone(), value: Some( @@ -1022,10 +1032,10 @@ impl TryFrom<&ScalarValue> for protobuf::ScalarValue { }), }, datafusion::scalar::ScalarValue::Date64(val) => { - create_proto_scalar(val, &data_type, |s| Value::Date64Value(*s)) + create_proto_scalar(val.as_ref(), &data_type, |s| Value::Date64Value(*s)) } datafusion::scalar::ScalarValue::TimestampSecond(val, tz) => { - create_proto_scalar(val, &data_type, |s| { + create_proto_scalar(val.as_ref(), &data_type, |s| { Value::TimestampValue(protobuf::ScalarTimestampValue { timezone: tz.as_ref().unwrap_or(&"".to_string()).clone(), value: Some( @@ -1035,7 +1045,7 @@ impl TryFrom<&ScalarValue> for protobuf::ScalarValue { }) } datafusion::scalar::ScalarValue::TimestampMillisecond(val, tz) => { - create_proto_scalar(val, &data_type, |s| { + create_proto_scalar(val.as_ref(), &data_type, |s| { Value::TimestampValue(protobuf::ScalarTimestampValue { timezone: tz.as_ref().unwrap_or(&"".to_string()).clone(), value: Some( @@ -1047,27 +1057,31 @@ impl TryFrom<&ScalarValue> for protobuf::ScalarValue { }) } datafusion::scalar::ScalarValue::IntervalYearMonth(val) => { - create_proto_scalar(val, &data_type, |s| { + create_proto_scalar(val.as_ref(), &data_type, |s| { Value::IntervalYearmonthValue(*s) }) } datafusion::scalar::ScalarValue::IntervalDayTime(val) => { - create_proto_scalar(val, &data_type, |s| Value::IntervalDaytimeValue(*s)) + create_proto_scalar(val.as_ref(), &data_type, |s| { + Value::IntervalDaytimeValue(*s) + }) } datafusion::scalar::ScalarValue::Null => Ok(protobuf::ScalarValue { value: Some(Value::NullValue((&data_type).try_into()?)), }), scalar::ScalarValue::Binary(val) => { - create_proto_scalar(val, &data_type, |s| Value::BinaryValue(s.to_owned())) + create_proto_scalar(val.as_ref(), &data_type, |s| { + Value::BinaryValue(s.to_owned()) + }) } scalar::ScalarValue::LargeBinary(val) => { - create_proto_scalar(val, &data_type, |s| { + create_proto_scalar(val.as_ref(), &data_type, |s| { Value::LargeBinaryValue(s.to_owned()) }) } scalar::ScalarValue::FixedSizeBinary(length, val) => { - create_proto_scalar(val, &data_type, |s| { + create_proto_scalar(val.as_ref(), &data_type, |s| { Value::FixedSizeBinaryValue(protobuf::ScalarFixedSizeBinary { values: s.to_owned(), length: *length, @@ -1076,7 +1090,7 @@ impl TryFrom<&ScalarValue> for protobuf::ScalarValue { } datafusion::scalar::ScalarValue::Time32Second(v) => { - create_proto_scalar(v, &data_type, |v| { + create_proto_scalar(v.as_ref(), &data_type, |v| { Value::Time32Value(protobuf::ScalarTime32Value { value: Some( protobuf::scalar_time32_value::Value::Time32SecondValue(*v), @@ -1086,7 +1100,7 @@ impl TryFrom<&ScalarValue> for protobuf::ScalarValue { } datafusion::scalar::ScalarValue::Time32Millisecond(v) => { - create_proto_scalar(v, &data_type, |v| { + create_proto_scalar(v.as_ref(), &data_type, |v| { Value::Time32Value(protobuf::ScalarTime32Value { value: Some( protobuf::scalar_time32_value::Value::Time32MillisecondValue( @@ -1098,7 +1112,7 @@ impl TryFrom<&ScalarValue> for protobuf::ScalarValue { } datafusion::scalar::ScalarValue::Time64Microsecond(v) => { - create_proto_scalar(v, &data_type, |v| { + create_proto_scalar(v.as_ref(), &data_type, |v| { Value::Time64Value(protobuf::ScalarTime64Value { value: Some( protobuf::scalar_time64_value::Value::Time64MicrosecondValue( @@ -1110,7 +1124,7 @@ impl TryFrom<&ScalarValue> for protobuf::ScalarValue { } datafusion::scalar::ScalarValue::Time64Nanosecond(v) => { - create_proto_scalar(v, &data_type, |v| { + create_proto_scalar(v.as_ref(), &data_type, |v| { Value::Time64Value(protobuf::ScalarTime64Value { value: Some( protobuf::scalar_time64_value::Value::Time64NanosecondValue( @@ -1286,16 +1300,15 @@ impl From<&IntervalUnit> for protobuf::IntervalUnit { /// Creates a scalar protobuf value from an optional value (T), and /// encoding None as the appropriate datatype fn create_proto_scalar protobuf::scalar_value::Value>( - v: &Option, + v: Option<&I>, null_arrow_type: &DataType, constructor: T, ) -> Result { - let value = - v.as_ref() - .map(constructor) - .unwrap_or(protobuf::scalar_value::Value::NullValue( - null_arrow_type.try_into()?, - )); + let value = v + .map(constructor) + .unwrap_or(protobuf::scalar_value::Value::NullValue( + null_arrow_type.try_into()?, + )); Ok(protobuf::ScalarValue { value: Some(value) }) }