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/11/23 16:09:52 UTC

[GitHub] [arrow-rs] tustvold opened a new pull request, #3174: Add RowParser

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

   # 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 #.
   
   # 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.
   -->
   
   I want to be able to spill rows from the row format to disk, currently this requires converting back to arrow, then to arrow IPC and back. Allowing users to parse rows as bytes opens up a large number of possibilities in this space.
   
   The only unsafe aspect of decoding is w.r.t UTF-8 validation, with all indexing, reads, etc... checked. Therefore to make this sound it is sufficient to optionally enable UTF-8 validation. Given this is a case where we have spilled to disk, I think this is an acceptable trade-off.
   
   _FWIW I couldn't work out a way to avoid this, as the nature of files is that their contents can be mutated by safe APIs, making it impossible to maintain an invariant over their contents_ 
   
   # 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 `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] ursabot commented on pull request #3174: Add RowParser

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

   Benchmark runs are scheduled for baseline = cea5146b69b3413a1d5caa946e0774ec8d834e95 and contender = 1d22fe3c23cc6ea1fb1df560c35f73cfdad96612. 1d22fe3c23cc6ea1fb1df560c35f73cfdad96612 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/8e193d8575de4553a36e0acbbdbf9e14...62d7285bf9164f8f80c47fd0c48ae060/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/6182336dfac14d5a9c3bb4a0052fb237...a32ce55df9144bca94ee6f232f8c15b2/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/3e71d029648a4aea8eb6bf0e08508a5f...2f17788612bf4f96848015810f631cb2/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/62263a24b2fa4ac4ba6c19815be7bca9...145a7f312fc642918846b438dc4bfebb/)
   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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3174: Add RowParser

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


##########
arrow/src/row/mod.rs:
##########
@@ -465,14 +470,15 @@ impl RowConverter {
     where
         I: IntoIterator<Item = Row<'a>>,
     {
+        let mut validate_utf8 = false;
         let mut rows: Vec<_> = rows
             .into_iter()
             .map(|row| {
                 assert!(
-                    Arc::ptr_eq(row.fields, &self.fields),
+                    Arc::ptr_eq(&row.config.fields, &self.fields),
                     "rows were not produced by this RowConverter"
                 );
-
+                validate_utf8 |= row.config.validate_utf8;

Review Comment:
   Indeed, potential future optimisation if it shows up in profiles. My hunch is the IO would dominate for that case



-- 
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] v1gnesh commented on pull request #3174: Add RowParser

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

   > I also think it would be very nice to have some `unsafe` way to skip the utf8 validation so that if we use this in datafusion, say, we could use that API to skip validation when reading in spill files
   
   What about using `bstr`?
   https://github.com/BurntSushi/bstr/issues/90#issuecomment-864174321


-- 
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] alamb commented on pull request #3174: Add RowParser

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

   I also think it would be very nice to have some `unsafe` way to skip the utf8 validation so that if we use this in datafusion, say, we could use that API to skip validation when reading in spill files


-- 
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 #3174: Add RowParser

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

   > could use that API to skip validation when reading in spill files
   
   In my benchmarks the performance hit of validation is fairly marginal, ~10%, and so I suspect will be dominated by IO. We can revisit if it starts to show up in profiles


-- 
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 #3174: Add RowParser

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


-- 
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] alamb commented on pull request #3174: Add RowParser

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

   > Also, where can I read up about the Row format and related functions, etc?
   
   I recommend
   https://arrow.apache.org/blog/2022/11/07/multi-column-sorts-in-arrow-rust-part-1/
   
   And https://docs.rs/arrow/27.0.0/arrow/row/index.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-rs] tustvold commented on a diff in pull request #3174: Add RowParser

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


##########
arrow/src/row/mod.rs:
##########
@@ -465,14 +470,15 @@ impl RowConverter {
     where
         I: IntoIterator<Item = Row<'a>>,
     {
+        let mut validate_utf8 = false;
         let mut rows: Vec<_> = rows
             .into_iter()
             .map(|row| {
                 assert!(
-                    Arc::ptr_eq(row.fields, &self.fields),
+                    Arc::ptr_eq(&row.config.fields, &self.fields),
                     "rows were not produced by this RowConverter"
                 );
-
+                validate_utf8 |= row.config.validate_utf8;

Review Comment:
   Consider the case of an ExternalSort where some batches have been spilled and some haven't. They all have the same row converter, but not all need validation. If you then merge them together you might need to do validation



-- 
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] alamb commented on a diff in pull request #3174: Add RowParser

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


##########
arrow/src/row/mod.rs:
##########
@@ -505,6 +518,43 @@ impl RowConverter {
     }
 }
 
+/// A [`RowParser`] can be created from a [`RowConverter`] and used to parse bytes to [`Row`]
+#[derive(Debug)]
+pub struct RowParser {
+    config: RowConfig,
+}
+
+impl RowParser {
+    fn new(fields: Arc<[SortField]>) -> Self {
+        Self {
+            config: RowConfig {
+                fields,
+                validate_utf8: true,
+            },
+        }
+    }
+
+    /// Creates a [`Row`] from the provided `bytes`.
+    ///
+    /// `bytes` must be a [`Row`] produced by the [`RowConverter`] associated with
+    /// this [`RowParser`], otherwise subsequent operations with the produced [`Row`] may panic
+    pub fn parse<'a>(&'a self, bytes: &'a [u8]) -> Row<'a> {
+        Row {
+            data: bytes,
+            config: &self.config,
+        }
+    }
+}
+
+/// The config of a given set of [`Row`]
+#[derive(Debug, Clone)]
+struct RowConfig {
+    /// The schema for these rows
+    fields: Arc<[SortField]>,
+    /// Whether to run UTF-8 validation when converting to arrow arrays

Review Comment:
   perhaps it would be wise to note here that utf8 validation will be required when reading bytes that may have been modified?
   
   



##########
arrow/src/row/mod.rs:
##########
@@ -465,14 +470,15 @@ impl RowConverter {
     where
         I: IntoIterator<Item = Row<'a>>,
     {
+        let mut validate_utf8 = false;
         let mut rows: Vec<_> = rows
             .into_iter()
             .map(|row| {
                 assert!(
-                    Arc::ptr_eq(row.fields, &self.fields),
+                    Arc::ptr_eq(&row.config.fields, &self.fields),
                     "rows were not produced by this RowConverter"
                 );
-
+                validate_utf8 |= row.config.validate_utf8;

Review Comment:
   This seems strange that some rows would have `validate_utf8` set and some would not if they came from the same row converter. Maybe we could assert they are all the same?



-- 
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] alamb commented on a diff in pull request #3174: Add RowParser

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


##########
arrow/src/row/mod.rs:
##########
@@ -465,14 +470,15 @@ impl RowConverter {
     where
         I: IntoIterator<Item = Row<'a>>,
     {
+        let mut validate_utf8 = false;
         let mut rows: Vec<_> = rows
             .into_iter()
             .map(|row| {
                 assert!(
-                    Arc::ptr_eq(row.fields, &self.fields),
+                    Arc::ptr_eq(&row.config.fields, &self.fields),
                     "rows were not produced by this RowConverter"
                 );
-
+                validate_utf8 |= row.config.validate_utf8;

Review Comment:
   But wound't this code effectively validate all rows in this case, even those that we know haven't been spilled? Maybe I misread it.
   
   
   
   



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