Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support indexed fields proto #2707

Merged
merged 2 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions datafusion/physical-expr/src/expressions/get_indexed_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions datafusion/proto/proto/datafusion.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
15 changes: 15 additions & 0 deletions datafusion/proto/src/from_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down
9 changes: 8 additions & 1 deletion datafusion/proto/src/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(),
};
Expand Down