You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "waynexia (via GitHub)" <gi...@apache.org> on 2023/03/29 12:43:15 UTC

[GitHub] [arrow-datafusion] waynexia opened a new pull request, #5775: feat: extend substrait types

waynexia opened a new pull request, #5775:
URL: https://github.com/apache/arrow-datafusion/pull/5775

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes https://github.com/apache/arrow-datafusion/issues/5717.
   
   # 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 these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   # 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 merged pull request #5775: feat: extend substrait type support, including type variations

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #5775:
URL: https://github.com/apache/arrow-datafusion/pull/5775


-- 
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] waynexia commented on a diff in pull request #5775: feat: extend substrait types

Posted by "waynexia (via GitHub)" <gi...@apache.org>.
waynexia commented on code in PR #5775:
URL: https://github.com/apache/arrow-datafusion/pull/5775#discussion_r1154552219


##########
datafusion/substrait/tests/roundtrip_logical_plan.rs:
##########
@@ -333,6 +405,23 @@ mod tests {
         Ok(())
     }
 
+    async fn roundtrip_all_types(sql: &str) -> Result<()> {

Review Comment:
   When I wrote cases like `"select cast(a as boolean) from data"` I got an error saying that there is no column a in the table (however `"select a from data"` works). I'm not sure if it's expected. But only cast uses type for now. Do you have any suggestions about testing new types?



##########
datafusion/substrait/tests/roundtrip_logical_plan.rs:
##########
@@ -262,7 +262,79 @@ mod tests {
 
     #[tokio::test]
     async fn qualified_catalog_schema_table_reference() -> Result<()> {
-        roundtrip("SELECT * FROM datafusion.public.data;").await
+        roundtrip("SELECT a,b,c,d,e FROM datafusion.public.data;").await
+    }
+
+    #[tokio::test]
+    async fn read_all_types() -> Result<()> {
+        let mut ctx = create_all_type_context().await?;
+        let df = ctx
+            .sql(
+                "select * from data where 
+                a = TRUE AND
+                b = 0 AND
+                c = 0 AND
+                d = 0 AND
+                e = 0 AND
+                f = 0 AND
+                g = 0 AND
+                h = 0 AND
+                i = 0;",
+            )
+            .await?;
+        println!("{:?}", df.clone().collect().await.unwrap());
+        let plan = df.into_optimized_plan()?;
+        let proto = to_substrait_plan(&plan)?;
+        let plan2 = from_substrait_plan(&mut ctx, &proto).await?;
+        let plan2 = ctx.state().optimize(&plan2)?;
+
+        println!("{plan:#?}");
+        println!("{plan2:#?}");
+
+        let plan1str = format!("{plan:?}");
+        let plan2str = format!("{plan2:?}");
+        assert_eq!(plan1str, plan2str);
+        Ok(())
+    }
+
+    #[tokio::test]
+    async fn integer_type_literal() -> Result<()> {
+        roundtrip_all_types(
+            "select * from data where 
+            a = TRUE AND
+            b = 0 AND
+            c = 0 AND
+            d = 0 AND
+            e = 0 AND
+            f = 0 AND
+            g = 0 AND
+            h = 0 AND
+            i = 0;",
+        )
+        .await
+    }
+
+    // Literal in this cases have incorrect type. This is not a good case
+    #[tokio::test]
+    async fn other_type_literal() -> Result<()> {

Review Comment:
   Literals in this case have different types with the columns :cry: 



-- 
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] waynexia commented on a diff in pull request #5775: feat: extend substrait type support, including type variations

Posted by "waynexia (via GitHub)" <gi...@apache.org>.
waynexia commented on code in PR #5775:
URL: https://github.com/apache/arrow-datafusion/pull/5775#discussion_r1161550000


##########
datafusion/substrait/tests/roundtrip_logical_plan.rs:
##########
@@ -333,6 +405,23 @@ mod tests {
         Ok(())
     }
 
+    async fn roundtrip_all_types(sql: &str) -> Result<()> {

Review Comment:
   It works! I rewrite this case. But only a few SQL types are supported for now (I guess they are defined in [this function](https://github.com/apache/arrow-datafusion/blob/524a3c534a9307e9d29ba5bf8aed2d2a70ae68e6/datafusion/sql/src/planner.rs#L278)).



##########
datafusion/substrait/src/lib.rs:
##########
@@ -18,6 +18,7 @@
 pub mod logical_plan;
 pub mod physical_plan;
 pub mod serializer;
+mod variation_const;

Review Comment:
   Good catch!



##########
datafusion/substrait/src/variation_const.rs:
##########
@@ -0,0 +1,31 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Type variation constants
+
+pub const DEFAULT_TYPE_REF: u32 = 0;

Review Comment:
   Good idea. I add some documents and links to mod-level documentation.



##########
datafusion/substrait/src/logical_plan/consumer.rs:
##########
@@ -910,20 +908,196 @@ fn from_substrait_bound(
     }
 }
 
+fn from_substrait_literal(lit: &Literal) -> Result<ScalarValue> {
+    let scalar_value = match &lit.literal_type {
+        Some(LiteralType::Boolean(b)) => ScalarValue::Boolean(Some(*b)),
+        Some(LiteralType::I8(n)) => match lit.type_variation_reference {
+            DEFAULT_TYPE_REF => ScalarValue::Int8(Some(*n as i8)),
+            UNSIGNED_INTEGER_TYPE_REF => ScalarValue::UInt8(Some(*n as u8)),
+            others => {
+                return Err(DataFusionError::Substrait(format!(
+                    "Unknown type variation reference {others}",
+                )));
+            }
+        },
+        Some(LiteralType::I16(n)) => match lit.type_variation_reference {
+            DEFAULT_TYPE_REF => ScalarValue::Int16(Some(*n as i16)),
+            UNSIGNED_INTEGER_TYPE_REF => ScalarValue::UInt16(Some(*n as u16)),
+            others => {
+                return Err(DataFusionError::Substrait(format!(
+                    "Unknown type variation reference {others}",
+                )));
+            }
+        },
+        Some(LiteralType::I32(n)) => match lit.type_variation_reference {
+            DEFAULT_TYPE_REF => ScalarValue::Int32(Some(*n)),
+            UNSIGNED_INTEGER_TYPE_REF => ScalarValue::UInt32(Some(unsafe {

Review Comment:
   >it is perfectly safe to cast i32 to u32
   
   This is because the "producer" (encoder) transmutes u32 to i32, which changes the actual number. E.g., when encoding an u32::MAX. Thus here we should also transmute back to get the original value.
   
   These transmutations are dangerous and not straightforward. What do you think about replacing them with this [`cast`](https://docs.rs/bytemuck/1.13.1/bytemuck/) method? Though it's also a `transmute` underlying, it would make the code looks more concrete like the following, and I believe those type annotations (`::<u32,i32>`) can be omitted.
   ```rust
   // producer
   ScalarValue::UInt32(Some(n)) => LiteralType::I32(cast::<u32,i32>(n)}),
   
   // consumer
   UNSIGNED_INTEGER_TYPE_REF => ScalarValue::UInt32(Some(cast::<i32,u32>(n))),
   ```



##########
datafusion/substrait/tests/roundtrip_logical_plan.rs:
##########
@@ -373,4 +462,52 @@ mod tests {
             .await?;
         Ok(ctx)
     }
+
+    /// Cover all supported types
+    async fn create_all_type_context() -> Result<SessionContext> {
+        let ctx = SessionContext::new();
+        let mut explicit_options = CsvReadOptions::new();
+        let schema = Schema::new(vec![
+            Field::new("a", DataType::Boolean, true),

Review Comment:
   Thanks for the suggestion, it looks cleaner now 👍 



##########
datafusion/substrait/tests/roundtrip_logical_plan.rs:
##########
@@ -262,7 +262,79 @@ mod tests {
 
     #[tokio::test]
     async fn qualified_catalog_schema_table_reference() -> Result<()> {
-        roundtrip("SELECT * FROM datafusion.public.data;").await
+        roundtrip("SELECT a,b,c,d,e FROM datafusion.public.data;").await
+    }
+
+    #[tokio::test]
+    async fn read_all_types() -> Result<()> {
+        let mut ctx = create_all_type_context().await?;
+        let df = ctx
+            .sql(
+                "select * from data where 
+                a = TRUE AND
+                b = 0 AND
+                c = 0 AND
+                d = 0 AND
+                e = 0 AND
+                f = 0 AND
+                g = 0 AND
+                h = 0 AND
+                i = 0;",
+            )
+            .await?;
+        println!("{:?}", df.clone().collect().await.unwrap());
+        let plan = df.into_optimized_plan()?;
+        let proto = to_substrait_plan(&plan)?;
+        let plan2 = from_substrait_plan(&mut ctx, &proto).await?;
+        let plan2 = ctx.state().optimize(&plan2)?;
+
+        println!("{plan:#?}");
+        println!("{plan2:#?}");
+
+        let plan1str = format!("{plan:?}");
+        let plan2str = format!("{plan2:?}");
+        assert_eq!(plan1str, plan2str);
+        Ok(())
+    }
+
+    #[tokio::test]
+    async fn integer_type_literal() -> Result<()> {
+        roundtrip_all_types(
+            "select * from data where 
+            a = TRUE AND
+            b = 0 AND
+            c = 0 AND
+            d = 0 AND
+            e = 0 AND
+            f = 0 AND
+            g = 0 AND
+            h = 0 AND
+            i = 0;",
+        )
+        .await
+    }
+
+    // Literal in this cases have incorrect type. This is not a good case
+    #[tokio::test]
+    async fn other_type_literal() -> Result<()> {

Review Comment:
   TIL, thanks for your help!



-- 
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 pull request #5775: feat: extend substrait types

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #5775:
URL: https://github.com/apache/arrow-datafusion/pull/5775#issuecomment-1497431305

   If no one else reviews this I will find time to do so later today


-- 
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 diff in pull request #5775: feat: extend substrait type support, including type variations

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #5775:
URL: https://github.com/apache/arrow-datafusion/pull/5775#discussion_r1161755878


##########
datafusion/substrait/src/variation_const.rs:
##########
@@ -0,0 +1,31 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Type variation constants
+
+pub const DEFAULT_TYPE_REF: u32 = 0;

Review Comment:
   this is very helpful



-- 
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] waynexia commented on pull request #5775: feat: extend substrait types

Posted by "waynexia (via GitHub)" <gi...@apache.org>.
waynexia commented on PR #5775:
URL: https://github.com/apache/arrow-datafusion/pull/5775#issuecomment-1496869047

   > @andygrove / @waynexia is there someone who knows the datafusion-substrait crate that can help review this PR?
   
   cc @mbrobbel for who has contributed to this crate. I can also split this PR into two parts for types and literals to reduce the review burden.


-- 
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 diff in pull request #5775: feat: extend substrait type support, including type variations

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #5775:
URL: https://github.com/apache/arrow-datafusion/pull/5775#discussion_r1161788549


##########
datafusion/substrait/src/logical_plan/consumer.rs:
##########
@@ -910,20 +908,196 @@ fn from_substrait_bound(
     }
 }
 
+fn from_substrait_literal(lit: &Literal) -> Result<ScalarValue> {
+    let scalar_value = match &lit.literal_type {
+        Some(LiteralType::Boolean(b)) => ScalarValue::Boolean(Some(*b)),
+        Some(LiteralType::I8(n)) => match lit.type_variation_reference {
+            DEFAULT_TYPE_REF => ScalarValue::Int8(Some(*n as i8)),
+            UNSIGNED_INTEGER_TYPE_REF => ScalarValue::UInt8(Some(*n as u8)),
+            others => {
+                return Err(DataFusionError::Substrait(format!(
+                    "Unknown type variation reference {others}",
+                )));
+            }
+        },
+        Some(LiteralType::I16(n)) => match lit.type_variation_reference {
+            DEFAULT_TYPE_REF => ScalarValue::Int16(Some(*n as i16)),
+            UNSIGNED_INTEGER_TYPE_REF => ScalarValue::UInt16(Some(*n as u16)),
+            others => {
+                return Err(DataFusionError::Substrait(format!(
+                    "Unknown type variation reference {others}",
+                )));
+            }
+        },
+        Some(LiteralType::I32(n)) => match lit.type_variation_reference {
+            DEFAULT_TYPE_REF => ScalarValue::Int32(Some(*n)),
+            UNSIGNED_INTEGER_TYPE_REF => ScalarValue::UInt32(Some(unsafe {

Review Comment:
   I think I found  a way to remove the unsafe code, see https://github.com/apache/arrow-datafusion/pull/5946



-- 
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 diff in pull request #5775: feat: extend substrait type support

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #5775:
URL: https://github.com/apache/arrow-datafusion/pull/5775#discussion_r1160096217


##########
datafusion/substrait/src/lib.rs:
##########
@@ -18,6 +18,7 @@
 pub mod logical_plan;
 pub mod physical_plan;
 pub mod serializer;
+mod variation_const;

Review Comment:
   The rest of these modules are `pub` but the newly added `variation_const` is not -- is that intentional?



##########
datafusion/substrait/src/variation_const.rs:
##########
@@ -0,0 +1,31 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Type variation constants
+
+pub const DEFAULT_TYPE_REF: u32 = 0;

Review Comment:
   I am not familiar with substrait's type variations --perhaps it would help to add a reference here to the subtrait documents that describe this and what they mean



##########
datafusion/substrait/tests/roundtrip_logical_plan.rs:
##########
@@ -373,4 +462,52 @@ mod tests {
             .await?;
         Ok(ctx)
     }
+
+    /// Cover all supported types
+    async fn create_all_type_context() -> Result<SessionContext> {
+        let ctx = SessionContext::new();
+        let mut explicit_options = CsvReadOptions::new();
+        let schema = Schema::new(vec![
+            Field::new("a", DataType::Boolean, true),

Review Comment:
   I would personally find this test setup easier to use and understand if the fields were named for the type (for exmaple `"bool_col"` rather than "a"
   
   The reason is that using just letters means that it is hard to understand what a particular test is testing without looking at this function



##########
datafusion/substrait/tests/roundtrip_logical_plan.rs:
##########
@@ -262,7 +262,79 @@ mod tests {
 
     #[tokio::test]
     async fn qualified_catalog_schema_table_reference() -> Result<()> {
-        roundtrip("SELECT * FROM datafusion.public.data;").await
+        roundtrip("SELECT a,b,c,d,e FROM datafusion.public.data;").await
+    }
+
+    #[tokio::test]
+    async fn read_all_types() -> Result<()> {
+        let mut ctx = create_all_type_context().await?;
+        let df = ctx
+            .sql(
+                "select * from data where 
+                a = TRUE AND
+                b = 0 AND
+                c = 0 AND
+                d = 0 AND
+                e = 0 AND
+                f = 0 AND
+                g = 0 AND
+                h = 0 AND
+                i = 0;",
+            )
+            .await?;
+        println!("{:?}", df.clone().collect().await.unwrap());
+        let plan = df.into_optimized_plan()?;
+        let proto = to_substrait_plan(&plan)?;
+        let plan2 = from_substrait_plan(&mut ctx, &proto).await?;
+        let plan2 = ctx.state().optimize(&plan2)?;
+
+        println!("{plan:#?}");
+        println!("{plan2:#?}");
+
+        let plan1str = format!("{plan:?}");
+        let plan2str = format!("{plan2:?}");
+        assert_eq!(plan1str, plan2str);
+        Ok(())
+    }
+
+    #[tokio::test]
+    async fn integer_type_literal() -> Result<()> {
+        roundtrip_all_types(
+            "select * from data where 
+            a = TRUE AND
+            b = 0 AND
+            c = 0 AND
+            d = 0 AND
+            e = 0 AND
+            f = 0 AND
+            g = 0 AND
+            h = 0 AND
+            i = 0;",
+        )
+        .await
+    }
+
+    // Literal in this cases have incorrect type. This is not a good case
+    #[tokio::test]
+    async fn other_type_literal() -> Result<()> {

Review Comment:
   I think you can use the `arrow_cast` function to get specific types -- like `arrow_cast('foo', LargeUtf8)` for example



##########
datafusion/substrait/tests/roundtrip_logical_plan.rs:
##########
@@ -333,6 +405,23 @@ mod tests {
         Ok(())
     }
 
+    async fn roundtrip_all_types(sql: &str) -> Result<()> {

Review Comment:
   Does the following syntax work?
   
   ```sql
   select a::boolean from data work?
   ```



##########
datafusion/substrait/tests/roundtrip_logical_plan.rs:
##########
@@ -262,7 +262,79 @@ mod tests {
 
     #[tokio::test]
     async fn qualified_catalog_schema_table_reference() -> Result<()> {
-        roundtrip("SELECT * FROM datafusion.public.data;").await
+        roundtrip("SELECT a,b,c,d,e FROM datafusion.public.data;").await
+    }
+
+    #[tokio::test]
+    async fn read_all_types() -> Result<()> {
+        let mut ctx = create_all_type_context().await?;
+        let df = ctx
+            .sql(
+                "select * from data where 
+                a = TRUE AND
+                b = 0 AND
+                c = 0 AND
+                d = 0 AND
+                e = 0 AND
+                f = 0 AND
+                g = 0 AND
+                h = 0 AND
+                i = 0;",
+            )
+            .await?;
+        println!("{:?}", df.clone().collect().await.unwrap());
+        let plan = df.into_optimized_plan()?;
+        let proto = to_substrait_plan(&plan)?;
+        let plan2 = from_substrait_plan(&mut ctx, &proto).await?;
+        let plan2 = ctx.state().optimize(&plan2)?;
+
+        println!("{plan:#?}");
+        println!("{plan2:#?}");
+
+        let plan1str = format!("{plan:?}");
+        let plan2str = format!("{plan2:?}");
+        assert_eq!(plan1str, plan2str);
+        Ok(())
+    }
+
+    #[tokio::test]
+    async fn integer_type_literal() -> Result<()> {
+        roundtrip_all_types(
+            "select * from data where 
+            a = TRUE AND
+            b = 0 AND
+            c = 0 AND
+            d = 0 AND
+            e = 0 AND
+            f = 0 AND
+            g = 0 AND
+            h = 0 AND
+            i = 0;",

Review Comment:
   I wonder if there is any reason for not testing  `j` and `k` (f32 and f64) as well?



##########
datafusion/substrait/src/logical_plan/consumer.rs:
##########
@@ -910,20 +908,196 @@ fn from_substrait_bound(
     }
 }
 
+fn from_substrait_literal(lit: &Literal) -> Result<ScalarValue> {
+    let scalar_value = match &lit.literal_type {
+        Some(LiteralType::Boolean(b)) => ScalarValue::Boolean(Some(*b)),
+        Some(LiteralType::I8(n)) => match lit.type_variation_reference {
+            DEFAULT_TYPE_REF => ScalarValue::Int8(Some(*n as i8)),
+            UNSIGNED_INTEGER_TYPE_REF => ScalarValue::UInt8(Some(*n as u8)),
+            others => {
+                return Err(DataFusionError::Substrait(format!(
+                    "Unknown type variation reference {others}",
+                )));
+            }
+        },
+        Some(LiteralType::I16(n)) => match lit.type_variation_reference {
+            DEFAULT_TYPE_REF => ScalarValue::Int16(Some(*n as i16)),
+            UNSIGNED_INTEGER_TYPE_REF => ScalarValue::UInt16(Some(*n as u16)),
+            others => {
+                return Err(DataFusionError::Substrait(format!(
+                    "Unknown type variation reference {others}",
+                )));
+            }
+        },
+        Some(LiteralType::I32(n)) => match lit.type_variation_reference {
+            DEFAULT_TYPE_REF => ScalarValue::Int32(Some(*n)),
+            UNSIGNED_INTEGER_TYPE_REF => ScalarValue::UInt32(Some(unsafe {

Review Comment:
   The use of unsafe here seems strange to me for two reasons:
   1. It is inconsistent with Int16/UInt16 use `n as i16` / `n as u16`
   2. it doesn't seem necessary --it is perfectly safe to cast i32 to u32 -- for example https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=cfd7670d0675e2353f4f8c58616b3cec
   
   I realize you just moved this code around, but I think it would be good to get rid of transmute
   
   This comment applies to Int64 as well



-- 
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 diff in pull request #5775: feat: extend substrait type support, including type variations

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #5775:
URL: https://github.com/apache/arrow-datafusion/pull/5775#discussion_r1161758436


##########
datafusion/substrait/tests/roundtrip_logical_plan.rs:
##########
@@ -333,6 +405,23 @@ mod tests {
         Ok(())
     }
 
+    async fn roundtrip_all_types(sql: &str) -> Result<()> {

Review Comment:
   I think the `::boolean` syntax is in terms of SQL types (not Arrow types). The SQL --> Arrow type mapping are in 
   
   https://arrow.apache.org/datafusion/user-guide/sql/data_types.html



-- 
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 pull request #5775: feat: extend substrait type support, including type variations

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #5775:
URL: https://github.com/apache/arrow-datafusion/pull/5775#issuecomment-1501872722

   Thanks again @waynexia 


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