You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/03/28 20:00:54 UTC

[GitHub] [arrow-datafusion] alamb commented on a change in pull request #2103: Create jit-expression from datafusion expression

alamb commented on a change in pull request #2103:
URL: https://github.com/apache/arrow-datafusion/pull/2103#discussion_r836798190



##########
File path: datafusion-jit/src/ast.rs
##########
@@ -137,6 +138,58 @@ pub enum Literal {
     Typed(TypedLit),
 }
 
+impl TryFrom<datafusion_expr::Expr> for Expr {
+    type Error = DataFusionError;
+
+    fn try_from(value: datafusion_expr::Expr) -> Result<Self, Self::Error> {
+        match &value {
+            datafusion_expr::Expr::BinaryExpr { left, op, right } => {
+                let op = match op {
+                    datafusion_expr::Operator::Eq => BinaryExpr::Eq,
+                    datafusion_expr::Operator::NotEq => BinaryExpr::Ne,
+                    datafusion_expr::Operator::Lt => BinaryExpr::Lt,
+                    datafusion_expr::Operator::LtEq => BinaryExpr::Le,
+                    datafusion_expr::Operator::Gt => BinaryExpr::Gt,
+                    datafusion_expr::Operator::GtEq => BinaryExpr::Ge,
+                    datafusion_expr::Operator::Plus => BinaryExpr::Add,
+                    datafusion_expr::Operator::Minus => BinaryExpr::Sub,
+                    datafusion_expr::Operator::Multiply => BinaryExpr::Mul,
+                    datafusion_expr::Operator::Divide => BinaryExpr::Div,
+                    _ => {
+                        return Err(DataFusionError::NotImplemented(format!(
+                            "Compiling binary expression {} not yet supported",
+                            value
+                        )))
+                    }
+                };
+                Ok(Expr::Binary(op(
+                    Box::new((*left.clone()).try_into()?),
+                    Box::new((*right.clone()).try_into()?),
+                )))
+            }
+            datafusion_expr::Expr::Literal(s) => {
+                let lit = match s {
+                    ScalarValue::Boolean(Some(b)) => TypedLit::Bool(*b),
+                    ScalarValue::Float32(Some(f)) => TypedLit::Float(*f),
+                    ScalarValue::Float64(Some(f)) => TypedLit::Double(*f),
+                    ScalarValue::Int64(Some(i)) => TypedLit::Int(*i),
+                    _ => {
+                        return Err(DataFusionError::NotImplemented(format!(
+                            "Scalar {} not yet supported",

Review comment:
       ```suggestion
                               Comparing Scalar {} not yet supported in JIT mode",
   ```

##########
File path: datafusion-jit/src/lib.rs
##########
@@ -85,6 +85,30 @@ mod tests {
         Ok(())
     }
 
+    #[test]
+    fn from_datafusion_expression() -> Result<()> {
+        let e = datafusion_expr::Expr::BinaryExpr {
+            left: Box::new(datafusion_expr::Expr::Literal(ScalarValue::Float32(Some(
+                1.0,
+            )))),
+            right: Box::new(datafusion_expr::Expr::Literal(ScalarValue::Float32(Some(
+                2.0,
+            )))),
+            op: datafusion_expr::Operator::Plus,
+        };

Review comment:
       ```suggestion
           let e = lit(1.0f32) + lit(2.0f32);
   ```

##########
File path: datafusion-jit/src/ast.rs
##########
@@ -137,6 +138,58 @@ pub enum Literal {
     Typed(TypedLit),
 }
 
+impl TryFrom<datafusion_expr::Expr> for Expr {
+    type Error = DataFusionError;
+
+    fn try_from(value: datafusion_expr::Expr) -> Result<Self, Self::Error> {

Review comment:
       ```suggestion
       // Try to JIT compile the Expr for faster evaluation
       fn try_from(value: datafusion_expr::Expr) -> Result<Self, Self::Error> {
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org