Skip to content

Apache DataFusion SQL Query Engine

support indexed fields proto (#2707)

Remco Verhoef1db7f00d9715
diff --git a/datafusion/physical-expr/src/expressions/get_indexed_field.rs b/datafusion/physical-expr/src/expressions/get_indexed_field.rs
index e084674de7..506ba96b69 100644
--- a/datafusion/physical-expr/src/expressions/get_indexed_field.rs
+++ b/datafusion/physical-expr/src/expressions/get_indexed_field.rs
@@ -49,6 +49,11 @@ impl GetIndexedFieldExpr {
Self { arg, key }
}
+ /// Get the input key
+ pub fn key(&self) -> &ScalarValue {
+ &self.key
+ }
+
/// Get the input expression
pub fn arg(&self) -> &Arc<dyn PhysicalExpr> {
&self.arg
diff --git a/datafusion/proto/proto/datafusion.proto b/datafusion/proto/proto/datafusion.proto
index d578714422..d17bad8493 100644
--- a/datafusion/proto/proto/datafusion.proto
+++ b/datafusion/proto/proto/datafusion.proto
@@ -301,9 +301,16 @@ message LogicalExprNode {
// Scalar UDF expressions
ScalarUDFExprNode scalar_udf_expr = 20;
+
+ GetIndexedField get_indexed_field = 21;
}
}
+message GetIndexedField {
+ LogicalExprNode expr = 1;
+ ScalarValue key = 2;
+}
+
message IsNull {
LogicalExprNode expr = 1;
}
diff --git a/datafusion/proto/src/from_proto.rs b/datafusion/proto/src/from_proto.rs
index 6717e5b47a..c684b785e6 100644
--- a/datafusion/proto/src/from_proto.rs
+++ b/datafusion/proto/src/from_proto.rs
@@ -928,6 +928,21 @@ pub fn parse_expr(
op: from_proto_binary_op(&binary_expr.op)?,
right: Box::new(parse_required_expr(&binary_expr.r, registry, "r")?),
}),
+ ExprType::GetIndexedField(field) => {
+ let key = field.key.as_ref().ok_or_else(|| Error::required("value"))?;
+
+ let key = typechecked_scalar_value_conversion(
+ key.value.as_ref().ok_or_else(|| Error::required("value"))?,
+ protobuf::PrimitiveScalarType::Utf8,
+ )?;
+
+ let expr = parse_required_expr(&field.expr, registry, "expr")?;
+
+ Ok(Expr::GetIndexedField {
+ expr: Box::new(expr),
+ key,
+ })
+ }
ExprType::Column(column) => Ok(Expr::Column(column.into())),
ExprType::Literal(literal) => {
let scalar_value: ScalarValue = literal.try_into()?;
diff --git a/datafusion/proto/src/to_proto.rs b/datafusion/proto/src/to_proto.rs
index 70c4d57c4c..8df8ff0dd9 100644
--- a/datafusion/proto/src/to_proto.rs
+++ b/datafusion/proto/src/to_proto.rs
@@ -710,8 +710,15 @@ impl TryFrom<&Expr> for protobuf::LogicalExprNode {
// see discussion in https://github.com/apache/arrow-datafusion/issues/2565
unimplemented!("subquery expressions are not supported yet")
}
+ Expr::GetIndexedField { key, expr } => Self {
+ expr_type: Some(ExprType::GetIndexedField(Box::new(
+ protobuf::GetIndexedField {
+ key: Some(key.try_into()?),
+ expr: Some(Box::new(expr.as_ref().try_into()?)),
+ },
+ ))),
+ },
Expr::QualifiedWildcard { .. }
- | Expr::GetIndexedField { .. }
| Expr::TryCast { .. }
| Expr::GroupingSet(_) => unimplemented!(),
};