You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "xinlifoobar (via GitHub)" <gi...@apache.org> on 2024/06/17 10:15:08 UTC

[PR] User/xinli/substriat init [datafusion]

xinlifoobar opened a new pull request, #10949:
URL: https://github.com/apache/datafusion/pull/10949

   ## 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.
   -->
   
   Parts of #9347. To close this ticket, at least the translations between substrait types to arrow types translations and statistics support should be added which will make this PR giant. I'd keep the as following tasks.
   
   ## 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.
   -->
   
   Yes, but substrait for physical plans is not functional yet.
   
   <!--
   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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Substrait support for ParquetExec round trip for simple select [datafusion]

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


##########
datafusion/substrait/tests/testdata/Readme.md:
##########
@@ -0,0 +1,51 @@
+<!---
+  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.
+-->
+
+# Apache DataFusion Substrait Test Data

Review Comment:
   ❤️ 



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Substrait support for ParquetExec round trip for simple select [datafusion]

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


##########
datafusion/substrait/src/physical_plan/producer.rs:
##########
@@ -55,15 +60,56 @@ pub fn to_substrait_rel(
             }
         }
 
+        let mut names = vec![];
+        let mut types = vec![];
+
+        for field in base_config.file_schema.fields.iter() {
+            match to_substrait_type(field.data_type(), field.is_nullable()) {
+                Ok(t) => {
+                    names.push(field.name().clone());
+                    types.push(t);
+                }
+                Err(e) => return Err(e),
+            }
+        }
+
+        let type_info = Struct {
+            types,
+            // FIXME: duckdb doesn't set this field, keep it as default variant 0.
+            // https://github.com/duckdb/substrait/blob/b6f56643cb11d52de0e32c24a01dfd5947df62be/src/to_substrait.cpp#L1106-L1127
+            type_variation_reference: 0,
+            nullability: Nullability::Required.into(),
+        };
+
+        let mut select_struct = None;
+        if let Some(projection) = base_config.projection.as_ref() {
+            let struct_items = projection
+                .iter()
+                .map(|index| StructItem {
+                    field: *index as i32,
+                    // FIXME: duckdb sets this to None, but it's not clear why.
+                    // https://github.com/duckdb/substrait/blob/b6f56643cb11d52de0e32c24a01dfd5947df62be/src/to_substrait.cpp#L1191
+                    child: None,
+                })
+                .collect();
+
+            select_struct = Some(StructSelect { struct_items });
+        }
+
         Ok(Box::new(Rel {
             rel_type: Some(RelType::Read(Box::new(ReadRel {
                 common: None,
-                base_schema: None,
+                base_schema: Some(NamedStruct {
+                    names,
+                    r#struct: Some(type_info),
+                }),
                 filter: None,
                 best_effort_filter: None,
                 projection: Some(MaskExpression {
-                    select: None,
-                    maintain_singular_struct: false,
+                    select: select_struct,
+                    // FIXME: duckdb set this to true, but it's not clear why.

Review Comment:
   > 		// fixme: whatever this means
   
   😆 



##########
datafusion/substrait/tests/testdata/data.parquet:
##########


Review Comment:
   Can you please put a README in that directory with this information? It is important context but would likely be hard to find after this PR
   
   Perhaps https://github.com/apache/datafusion/tree/main/datafusion/substrait/tests/testdata/README.md



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Substrait support for ParquetExec round trip for simple select [datafusion]

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


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Substrait support for ParquetExec round trip for simple select [datafusion]

Posted by "xinlifoobar (via GitHub)" <gi...@apache.org>.
xinlifoobar commented on code in PR #10949:
URL: https://github.com/apache/datafusion/pull/10949#discussion_r1644423508


##########
datafusion/substrait/tests/testdata/data.parquet:
##########


Review Comment:
   Done



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Substrait support for ParquetExec round trip for simple select [datafusion]

Posted by "xinlifoobar (via GitHub)" <gi...@apache.org>.
xinlifoobar commented on code in PR #10949:
URL: https://github.com/apache/datafusion/pull/10949#discussion_r1642573978


##########
datafusion/substrait/tests/testdata/data.parquet:
##########


Review Comment:
   Those are generated from `data.csv` under the same folder using `pandas`, e.g.,
   
   ```
   dataset = pd.read_csv("datafusion/substrait/tests/testdata/data.csv")
   dataset.to_parquet("datafusion/substrait/tests/testdata/data.parquet")
   ```



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org