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/09/23 14:01:22 UTC

[GitHub] [arrow-rs] tustvold opened a new pull request, #2774: Fix schema for non-list repeated fields (#1915)

tustvold opened a new pull request, #2774:
URL: https://github.com/apache/arrow-rs/pull/2774

   # 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 #1915
   
   # 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.
   -->
   
   As described in https://github.com/apache/parquet-format/blob/master/LogicalTypes.md#backward-compatibility-rules there are various backwards compatibility rules for converting parquet schema to lists. This logic is applied by the schema inference logic added in https://github.com/apache/arrow-rs/pull/1682, which "promotes" bare-repeated fields to be ListArray in the generated arrow schema.
   
   This works well, however, the mechanism by which array_reader is constructed would perform this inference again, using the an inferred arrow schema, as opposed to any schema embedded in the parquet metadata. Aside from being potentially inefficient, this causes issues if the provided arrow schema no longer matches the parquet schema, e.g. a field has been promoted to a different arrow representation.
   
   # 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.
   -->
   
   This pushes projection into the array reader construction, in addition to being more efficient, this avoids the double-inference issues. We infer the schema once, and then project this.
   
   # Are there any user-facing changes?
   
   No
   
   <!--
   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 `breaking 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-rs] thinkharderdev commented on a diff in pull request #2774: Fix Backwards Compatible Parquet List Encodings (#1915)

Posted by GitBox <gi...@apache.org>.
thinkharderdev commented on code in PR #2774:
URL: https://github.com/apache/arrow-rs/pull/2774#discussion_r979271132


##########
parquet/src/arrow/array_reader/builder.rs:
##########
@@ -26,40 +26,43 @@ use crate::arrow::array_reader::{
     ListArrayReader, MapArrayReader, NullArrayReader, PrimitiveArrayReader,
     RowGroupCollection, StructArrayReader,
 };
-use crate::arrow::schema::{convert_schema, ParquetField, ParquetFieldType};
+use crate::arrow::schema::{ParquetField, ParquetFieldType};
 use crate::arrow::ProjectionMask;
 use crate::basic::Type as PhysicalType;
 use crate::data_type::{
     BoolType, DoubleType, FloatType, Int32Type, Int64Type, Int96Type,
 };
-use crate::errors::Result;
+use crate::errors::{ParquetError, Result};
 use crate::schema::types::{ColumnDescriptor, ColumnPath, Type};
 
 /// Create array reader from parquet schema, projection mask, and parquet file reader.
 pub fn build_array_reader(
-    arrow_schema: SchemaRef,
-    mask: ProjectionMask,
+    field: Option<&ParquetField>,
+    mask: &ProjectionMask,
     row_groups: &dyn RowGroupCollection,
 ) -> Result<Box<dyn ArrayReader>> {
-    let field = convert_schema(&row_groups.schema(), mask, Some(arrow_schema.as_ref()))?;
+    let reader = field
+        .and_then(|field| build_reader(field, mask, row_groups).transpose())
+        .transpose()?
+        .unwrap_or_else(|| make_empty_array_reader(row_groups.num_rows()));

Review Comment:
   Not a comment on this PR per se, but I don't understand why we swallow the error here and return and empty array reader



-- 
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-rs] thinkharderdev commented on a diff in pull request #2774: Fix Backwards Compatible Parquet List Encodings (#1915)

Posted by GitBox <gi...@apache.org>.
thinkharderdev commented on code in PR #2774:
URL: https://github.com/apache/arrow-rs/pull/2774#discussion_r979271264


##########
parquet/src/arrow/array_reader/builder.rs:
##########
@@ -26,40 +26,43 @@ use crate::arrow::array_reader::{
     ListArrayReader, MapArrayReader, NullArrayReader, PrimitiveArrayReader,
     RowGroupCollection, StructArrayReader,
 };
-use crate::arrow::schema::{convert_schema, ParquetField, ParquetFieldType};
+use crate::arrow::schema::{ParquetField, ParquetFieldType};
 use crate::arrow::ProjectionMask;
 use crate::basic::Type as PhysicalType;
 use crate::data_type::{
     BoolType, DoubleType, FloatType, Int32Type, Int64Type, Int96Type,
 };
-use crate::errors::Result;
+use crate::errors::{ParquetError, Result};
 use crate::schema::types::{ColumnDescriptor, ColumnPath, Type};
 
 /// Create array reader from parquet schema, projection mask, and parquet file reader.
 pub fn build_array_reader(
-    arrow_schema: SchemaRef,
-    mask: ProjectionMask,
+    field: Option<&ParquetField>,
+    mask: &ProjectionMask,
     row_groups: &dyn RowGroupCollection,
 ) -> Result<Box<dyn ArrayReader>> {
-    let field = convert_schema(&row_groups.schema(), mask, Some(arrow_schema.as_ref()))?;
+    let reader = field
+        .and_then(|field| build_reader(field, mask, row_groups).transpose())
+        .transpose()?
+        .unwrap_or_else(|| make_empty_array_reader(row_groups.num_rows()));

Review Comment:
   Actually, nvm was misreading the code. We are unwrapping the `Option` not the `Result>



-- 
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-rs] tustvold commented on a diff in pull request #2774: Fix schema for non-list repeated fields (#1915)

Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #2774:
URL: https://github.com/apache/arrow-rs/pull/2774#discussion_r978711220


##########
parquet/src/arrow/arrow_reader/mod.rs:
##########
@@ -82,15 +84,17 @@ impl<T> ArrowReaderBuilder<T> {
             false => metadata.file_metadata().key_value_metadata(),
         };
 
-        let schema = Arc::new(parquet_to_arrow_schema(
+        let (schema, fields) = parquet_to_array_schema_and_fields(

Review Comment:
   Here we can see that we perform the inference logic once, and keep the ParquetField around to later project



-- 
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-rs] tustvold merged pull request #2774: Fix Backwards Compatible Parquet List Encodings (#1915)

Posted by GitBox <gi...@apache.org>.
tustvold merged PR #2774:
URL: https://github.com/apache/arrow-rs/pull/2774


-- 
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-rs] tustvold commented on a diff in pull request #2774: Fix schema for non-list repeated fields (#1915)

Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #2774:
URL: https://github.com/apache/arrow-rs/pull/2774#discussion_r978709306


##########
parquet/src/arrow/arrow_reader/mod.rs:
##########
@@ -2313,4 +2328,66 @@ mod tests {
         assert_ne!(1024, num_rows);
         assert_eq!(reader.batch_size, num_rows as usize);
     }
+
+    #[test]

Review Comment:
   This is based on the test by @liyongjing, thank you for the great reproducer. I had to tweak the levels a little for the generated parquet to be valid, but the spirit remains the same :smile: 



-- 
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-rs] tustvold commented on pull request #2774: Fix Backwards Compatible Parquet List Encodings (#1915)

Posted by GitBox <gi...@apache.org>.
tustvold commented on PR #2774:
URL: https://github.com/apache/arrow-rs/pull/2774#issuecomment-1257006710

   Oops I accidentally included a test parquet file, will remove


-- 
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-rs] tustvold commented on a diff in pull request #2774: Fix schema for non-list repeated fields (#1915)

Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #2774:
URL: https://github.com/apache/arrow-rs/pull/2774#discussion_r978712013


##########
parquet/src/arrow/arrow_reader/mod.rs:
##########
@@ -420,9 +432,11 @@ impl<T: ChunkReader + 'static> ArrowReaderBuilder<SyncReader<T>> {
                     break;
                 }
 
-                let projection = predicate.projection().clone();
-                let array_reader =
-                    build_array_reader(Arc::clone(&self.schema), projection, &reader)?;
+                let array_reader = build_array_reader(

Review Comment:
   We no longer do potentially expensive schema inference for every filter :tada:
   
   FYI @thinkharderdev 



-- 
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-rs] ursabot commented on pull request #2774: Fix Backwards Compatible Parquet List Encodings (#1915)

Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #2774:
URL: https://github.com/apache/arrow-rs/pull/2774#issuecomment-1257040902

   Benchmark runs are scheduled for baseline = d52cae0df1d7ba651d2c9a7d4904666363f40a76 and contender = cf1e778b8c34155e7b598907a829ff6c8e52a1ea. cf1e778b8c34155e7b598907a829ff6c8e52a1ea is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/aa135154092044f68c214b79549e97cc...36cbfde896144168bb944cc929b59e1a/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/ba881af257e943e8b7916e032e58252a...1021e4088c364f87b49da977c55fa117/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/b712c9d1db154c18be8529d56f2e4ebd...ed667960a05547fca5dd3ad585ffa1fc/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/70f674700aeb4d29b257fb5290becb81...afa1eef8414a4746b15ae45a8334681a/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


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