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/06/03 12:53:33 UTC

[GitHub] [arrow] alexandreyc opened a new pull request, #13310: [Go] Fix pqarrow writer for null array

alexandreyc opened a new pull request, #13310:
URL: https://github.com/apache/arrow/pull/13310

   Hello world,
   
   When converting from Arrow to Parquet it looks like there is a bug with arrays of type `arrow.NULL`. Here is a snippet of code to reproduce the bug:
   ```go
   package main
   
   import (
   	"fmt"
   	"log"
   	"os"
   
   	"github.com/apache/arrow/go/v9/arrow"
   	"github.com/apache/arrow/go/v9/arrow/array"
   	"github.com/apache/arrow/go/v9/arrow/memory"
   	"github.com/apache/arrow/go/v9/parquet/pqarrow"
   )
   
   const n = 10
   
   func run() error {
   	schema := arrow.NewSchema(
   		[]arrow.Field{
   			{Name: "f1", Type: arrow.Null, Nullable: true},
   		},
   		nil,
   	)
   
   	rb := array.NewRecordBuilder(memory.DefaultAllocator, schema)
   	defer rb.Release()
   
   	for i := 0; i < n; i++ {
   		rb.Field(0).(*array.NullBuilder).AppendNull()
   	}
   
   	rec := rb.NewRecord()
   	defer rec.Release()
   
   	for i, col := range rec.Columns() {
   		fmt.Printf("column[%d] %q: %v\n", i, rec.ColumnName(i), col)
   	}
   
   	f, err := os.Create("output.parquet")
   	if err != nil {
   		return err
   	}
   	defer f.Close()
   
   	w, err := pqarrow.NewFileWriter(rec.Schema(), f, nil, pqarrow.DefaultWriterProps())
   	if err != nil {
   		return err
   	}
   	defer w.Close()
   
   	err = w.Write(rec)
   	if err != nil {
   		return err
   	}
   
   	return nil
   }
   
   func main() {
   	if err := run(); err != nil {
   		log.Fatal(err)
   	}
   }
   ```
   
   I'm not 100% sure if my fix is the best, so feel free to correct me.
   
   Thanks
   
   A
   


-- 
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] alexandreyc commented on pull request #13310: ARROW-16749: [Go] Fix pqarrow writer for null array

Posted by GitBox <gi...@apache.org>.
alexandreyc commented on PR #13310:
URL: https://github.com/apache/arrow/pull/13310#issuecomment-1150656943

   @zeroshade thanks for your answer.
   
   - I added a test to exercise the bug
   - I had to fix an issue with column writers (feel free to double check since I'm not very familiar with the parquet's code base)
   - I regenerate parquet's code (it looks like there has been modifications to metadata statistics that hasn't been taken into account)
   


-- 
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] alexandreyc commented on pull request #13310: ARROW-16749: [Go] Fix pqarrow writer for null array

Posted by GitBox <gi...@apache.org>.
alexandreyc commented on PR #13310:
URL: https://github.com/apache/arrow/pull/13310#issuecomment-1148146775

   Yes, it doesn't look like there is an equivalent Parquet type. Nonetheless, it seems that decision to convert Arrow's `Null` to Parquet's `Int32` has already been made in the code base. See [here](https://github.com/apache/arrow/blob/8c63788ff7d52812599a546989b7df10887cb01e/go/parquet/pqarrow/schema.go#L259). 
   
   The use case is quite simple: in real world databases there are columns which are full of `NULL` values and I guess that's why Arrow has `Null`. Some might say that's a bad practice but it exists...
   
   I don't see any reason why we should not allow converting record batches with `Null` arrays to Parquet.
   
   What do you think?
   
   In the mean time I will look into others implementations to see what's being done here.
   


-- 
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] zeroshade commented on a diff in pull request #13310: ARROW-16749: [Go] Fix pqarrow writer for null array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on code in PR #13310:
URL: https://github.com/apache/arrow/pull/13310#discussion_r893640554


##########
go/parquet/file/column_writer_types.gen.go.tmpl:
##########
@@ -137,13 +137,13 @@ func (w *{{.Name}}ColumnChunkWriter) WriteBatchSpaced(values []{{.name}}, defLev
 
     w.writeLevelsSpaced(batch, levelSliceOrNil(defLevels, offset, batch), levelSliceOrNil(repLevels, offset, batch))
     if values != nil {
-      vals = values[valueOffset:]
+      vals = values[valueOffset:][:info.numSpaced()]

Review Comment:
   why was this needed? also, if you're going to add this it should be `vals = values[valueOffset : info.numSpaced()]` no need for the extra set of brackets.



-- 
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] zeroshade commented on a diff in pull request #13310: ARROW-16749: [Go] Fix pqarrow writer for null array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on code in PR #13310:
URL: https://github.com/apache/arrow/pull/13310#discussion_r894776184


##########
go/parquet/file/column_writer_types.gen.go.tmpl:
##########
@@ -137,13 +137,13 @@ func (w *{{.Name}}ColumnChunkWriter) WriteBatchSpaced(values []{{.name}}, defLev
 
     w.writeLevelsSpaced(batch, levelSliceOrNil(defLevels, offset, batch), levelSliceOrNil(repLevels, offset, batch))
     if values != nil {
-      vals = values[valueOffset:]
+      vals = values[valueOffset:][:info.numSpaced()]
     }
 
     if w.bitsBuffer != nil {
-      w.writeValuesSpaced(vals[:info.numSpaced()], info.batchNum, w.bitsBuffer.Bytes(), 0)
+      w.writeValuesSpaced(vals, info.batchNum, w.bitsBuffer.Bytes(), 0)
     } else {
-      w.writeValuesSpaced(vals[:info.numSpaced()], info.batchNum, validBits, validBitsOffset+valueOffset)
+      w.writeValuesSpaced(vals, info.batchNum, validBits, validBitsOffset+valueOffset)

Review Comment:
   Gotcha, that would be my mistake actually i forgot that `numSpaced` would be the full number, not zero which would be fine. 



-- 
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] github-actions[bot] commented on pull request #13310: [Go] Fix pqarrow writer for null array

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #13310:
URL: https://github.com/apache/arrow/pull/13310#issuecomment-1145934275

   <!--
     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.
   -->
   
   Thanks for opening a pull request!
   
   If this is not a [minor PR](https://github.com/apache/arrow/blob/master/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on JIRA? https://issues.apache.org/jira/browse/ARROW
   
   Opening JIRAs ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project.
   
   Then could you also rename pull request title in the following format?
   
       ARROW-${JIRA_ID}: [${COMPONENT}] ${SUMMARY}
   
   or
   
       MINOR: [${COMPONENT}] ${SUMMARY}
   
   See also:
   
     * [Other pull requests](https://github.com/apache/arrow/pulls/)
     * [Contribution Guidelines - How to contribute patches](https://arrow.apache.org/docs/developers/contributing.html#how-to-contribute-patches)
   


-- 
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] alexandreyc commented on a diff in pull request #13310: ARROW-16749: [Go] Fix pqarrow writer for null array

Posted by GitBox <gi...@apache.org>.
alexandreyc commented on code in PR #13310:
URL: https://github.com/apache/arrow/pull/13310#discussion_r894120603


##########
go/parquet/file/column_writer_types.gen.go.tmpl:
##########
@@ -137,13 +137,13 @@ func (w *{{.Name}}ColumnChunkWriter) WriteBatchSpaced(values []{{.name}}, defLev
 
     w.writeLevelsSpaced(batch, levelSliceOrNil(defLevels, offset, batch), levelSliceOrNil(repLevels, offset, batch))
     if values != nil {
-      vals = values[valueOffset:]
+      vals = values[valueOffset:][:info.numSpaced()]
     }
 
     if w.bitsBuffer != nil {
-      w.writeValuesSpaced(vals[:info.numSpaced()], info.batchNum, w.bitsBuffer.Bytes(), 0)
+      w.writeValuesSpaced(vals, info.batchNum, w.bitsBuffer.Bytes(), 0)
     } else {
-      w.writeValuesSpaced(vals[:info.numSpaced()], info.batchNum, validBits, validBitsOffset+valueOffset)
+      w.writeValuesSpaced(vals, info.batchNum, validBits, validBitsOffset+valueOffset)

Review Comment:
   Yes that's the reason. I'm not sure it will change anything to replace the nil slice by an empty one because we are slicing out of bounds anyway.  `vals[:info.numSpaced()]` will panic in both cases (nil and empty) because in that case `info.numSpaced() > 0` (because null count > 0). 
   
   (Or maybe I misunderstood your message)



-- 
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] zeroshade commented on pull request #13310: ARROW-16749: [Go] Fix pqarrow writer for null array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on PR #13310:
URL: https://github.com/apache/arrow/pull/13310#issuecomment-1152604620

   @alexandreyc Looks good to me now! Thanks much for this!


-- 
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] zeroshade closed pull request #13310: ARROW-16749: [Go] Fix pqarrow writer for null array

Posted by GitBox <gi...@apache.org>.
zeroshade closed pull request #13310: ARROW-16749: [Go] Fix pqarrow writer for null array
URL: https://github.com/apache/arrow/pull/13310


-- 
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] zeroshade commented on a diff in pull request #13310: ARROW-16749: [Go] Fix pqarrow writer for null array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on code in PR #13310:
URL: https://github.com/apache/arrow/pull/13310#discussion_r893644440


##########
go/parquet/file/column_writer_types.gen.go.tmpl:
##########
@@ -137,13 +137,13 @@ func (w *{{.Name}}ColumnChunkWriter) WriteBatchSpaced(values []{{.name}}, defLev
 
     w.writeLevelsSpaced(batch, levelSliceOrNil(defLevels, offset, batch), levelSliceOrNil(repLevels, offset, batch))
     if values != nil {
-      vals = values[valueOffset:]
+      vals = values[valueOffset:][:info.numSpaced()]
     }
 
     if w.bitsBuffer != nil {
-      w.writeValuesSpaced(vals[:info.numSpaced()], info.batchNum, w.bitsBuffer.Bytes(), 0)
+      w.writeValuesSpaced(vals, info.batchNum, w.bitsBuffer.Bytes(), 0)
     } else {
-      w.writeValuesSpaced(vals[:info.numSpaced()], info.batchNum, validBits, validBitsOffset+valueOffset)
+      w.writeValuesSpaced(vals, info.batchNum, validBits, validBitsOffset+valueOffset)

Review Comment:
   I'm guessing this was needed cuz of passing nil? Hmm. It would be better to pass an empty slice so we can keep the `[:info.numSpaced()]` since i'm pretty sure `writeValuesSpaced` checks `len` of the first param.



-- 
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] alexandreyc commented on a diff in pull request #13310: ARROW-16749: [Go] Fix pqarrow writer for null array

Posted by GitBox <gi...@apache.org>.
alexandreyc commented on code in PR #13310:
URL: https://github.com/apache/arrow/pull/13310#discussion_r894121447


##########
go/parquet/file/column_writer_types.gen.go.tmpl:
##########
@@ -137,13 +137,13 @@ func (w *{{.Name}}ColumnChunkWriter) WriteBatchSpaced(values []{{.name}}, defLev
 
     w.writeLevelsSpaced(batch, levelSliceOrNil(defLevels, offset, batch), levelSliceOrNil(repLevels, offset, batch))
     if values != nil {
-      vals = values[valueOffset:]
+      vals = values[valueOffset:][:info.numSpaced()]

Review Comment:
   I made the change to use the following form: `vals = values[valueOffset:valueOffset+info.numSpaced()]`
   



-- 
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] zeroshade commented on pull request #13310: ARROW-16749: [Go] Fix pqarrow writer for null array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on PR #13310:
URL: https://github.com/apache/arrow/pull/13310#issuecomment-1150130749

   @alexandreyc Huh, I didn't even remember that I did that. Looks like parquet does have a `NULL` logical type so it makes sense.
   
   That said, instead of allocating an entire int32 slice for this. I believe the better solution would be to manually call `wr.WriteBatchSpaced(nil, defLevels, repLevels, learArr.NullBitmapBytes(), 0)` and then break. No need to allocate an entire int32 slice for this 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] github-actions[bot] commented on pull request #13310: ARROW-16749: [Go] Fix pqarrow writer for null array

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #13310:
URL: https://github.com/apache/arrow/pull/13310#issuecomment-1145937692

   https://issues.apache.org/jira/browse/ARROW-16749


-- 
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] github-actions[bot] commented on pull request #13310: ARROW-16749: [Go] Fix pqarrow writer for null array

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #13310:
URL: https://github.com/apache/arrow/pull/13310#issuecomment-1145937717

   :warning: Ticket **has not been started in JIRA**, please click 'Start Progress'.


-- 
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] zeroshade commented on pull request #13310: ARROW-16749: [Go] Fix pqarrow writer for null array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on PR #13310:
URL: https://github.com/apache/arrow/pull/13310#issuecomment-1147653763

   @alexandreyc I'm not sure if this is a bug or technically intended. I don't believe that there's any parquet type that would accurately map to Arrow's "Null" datatype, or would be even desireable to do. What's the use case here?


-- 
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] ursabot commented on pull request #13310: ARROW-16749: [Go] Fix pqarrow writer for null array

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

   Benchmark runs are scheduled for baseline = c563a005ede92c704ab363acb4cb53757deb6781 and contender = fd6a3ab9ef1830964ab4b0e7f8b3c0f4779bf4e4. fd6a3ab9ef1830964ab4b0e7f8b3c0f4779bf4e4 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Finished :arrow_down:0.0% :arrow_up:0.0%] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/8a53df7491b74bf7b5b9a83ded6dc56e...f1337e0a69654806a4137ce5417e94e4/)
   [Failed :arrow_down:0.91% :arrow_up:0.07%] [test-mac-arm](https://conbench.ursa.dev/compare/runs/723c2b2f4c524ed49111284163f1d811...dbcb0d8178b34643bcc2a068025094e6/)
   [Finished :arrow_down:0.0% :arrow_up:0.0%] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/9ad6158469ac40caab96de0104cf1df7...913b29feb86e47b8adbf466f2e867a68/)
   [Finished :arrow_down:0.15% :arrow_up:0.0%] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/68c43fd0c03f4f28a1d0e98dd02a3dad...9268140a2b154d66946e95bd80b322c2/)
   Buildkite builds:
   [Finished] [`fd6a3ab9` ec2-t3-xlarge-us-east-2](https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ec2-t3-xlarge-us-east-2/builds/932)
   [Failed] [`fd6a3ab9` test-mac-arm](https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-test-mac-arm/builds/932)
   [Finished] [`fd6a3ab9` ursa-i9-9960x](https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ursa-i9-9960x/builds/922)
   [Finished] [`fd6a3ab9` ursa-thinkcentre-m75q](https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ursa-thinkcentre-m75q/builds/935)
   [Finished] [`c563a005` ec2-t3-xlarge-us-east-2](https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ec2-t3-xlarge-us-east-2/builds/931)
   [Failed] [`c563a005` test-mac-arm](https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-test-mac-arm/builds/931)
   [Finished] [`c563a005` ursa-i9-9960x](https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ursa-i9-9960x/builds/921)
   [Finished] [`c563a005` ursa-thinkcentre-m75q](https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ursa-thinkcentre-m75q/builds/934)
   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