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/27 22:05:55 UTC

[GitHub] [arrow-datafusion] Dandandan opened a new pull request #2103: Create jit-expression from datafusion expression

Dandandan opened a new pull request #2103:
URL: https://github.com/apache/arrow-datafusion/pull/2103


   # Which issue does this PR close?
   
   Closes #2102
   
    # Rationale for this change
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   # What changes are included in this PR?
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


-- 
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



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

Posted by GitBox <gi...@apache.org>.
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
                               Compiling Scalar {} not yet supported in JIT mode",
   ```




-- 
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



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

Posted by GitBox <gi...@apache.org>.
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



[GitHub] [arrow-datafusion] yjshen merged pull request #2103: Create jit-expression from datafusion expression

Posted by GitBox <gi...@apache.org>.
yjshen merged pull request #2103:
URL: https://github.com/apache/arrow-datafusion/pull/2103


   


-- 
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