MCPcopy Create free account
hub / github.com/apache/datafusion / binary_nested

Function binary_nested

datafusion/physical-expr/src/expressions/binary.rs:1063–1107  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1061
1062 #[test]
1063 fn binary_nested() -> Result<()> {
1064 let schema = Schema::new(vec![
1065 Field::new("a", DataType::Int32, false),
1066 Field::new("b", DataType::Int32, false),
1067 ]);
1068 let a = Int32Array::from(vec![2, 4, 6, 8, 10]);
1069 let b = Int32Array::from(vec![2, 5, 4, 8, 8]);
1070
1071 // expression: "a < b OR a == b"
1072 let expr = binary(
1073 binary(
1074 col("a", &schema)?,
1075 Operator::Lt,
1076 col("b", &schema)?,
1077 &schema,
1078 )?,
1079 Operator::Or,
1080 binary(
1081 col("a", &schema)?,
1082 Operator::Eq,
1083 col("b", &schema)?,
1084 &schema,
1085 )?,
1086 &schema,
1087 )?;
1088 let batch =
1089 RecordBatch::try_new(Arc::new(schema), vec![Arc::new(a), Arc::new(b)])?;
1090
1091 assert_eq!("a@0 < b@1 OR a@0 = b@1", format!("{expr}"));
1092
1093 let result = expr
1094 .evaluate(&batch)?
1095 .into_array(batch.num_rows())
1096 .expect("Failed to convert to array");
1097 assert_eq!(result.len(), 5);
1098
1099 let expected = [true, true, false, true, false];
1100 let result =
1101 as_boolean_array(&result).expect("failed to downcast to BooleanArray");
1102 for (i, &expected_item) in expected.iter().enumerate().take(5) {
1103 assert_eq!(result.value(i), expected_item);
1104 }
1105
1106 Ok(())
1107 }
1108
1109 // runs an end-to-end test of physical type coercion:
1110 // 1. construct a record batch with two columns of type A and B

Callers

nothing calls this directly

Calls 8

newFunction · 0.85
binaryFunction · 0.85
as_boolean_arrayFunction · 0.85
colFunction · 0.70
into_arrayMethod · 0.45
evaluateMethod · 0.45
takeMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…