sfc-gh-mbojanczyk commented on code in PR #344:
URL: https://github.com/apache/arrow-go/pull/344#discussion_r2064842943


##########
parquet/variants/util.go:
##########
@@ -0,0 +1,154 @@
+// 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.
+
+package variants
+
+import (
+       "fmt"
+       "io"
+       "reflect"
+       "time"
+)
+
+// Reads a little-endian encoded uint (betwen 1 and 8 bytes wide) from a raw 
buffer at a specified
+// offset and returns its value. If any part of the read would be out of 
bounds, this returns an error.
+func readUint(raw []byte, offset, size int) (uint64, error) {
+       if size < 1 || size > 8 {
+               return 0, fmt.Errorf("invalid size, must be in range [1,8]: 
%d", size)
+       }
+       if maxPos := offset + size; maxPos > len(raw) {
+               return 0, fmt.Errorf("out of bounds: trying to access position 
%d, max position is %d", maxPos, len(raw))
+       }
+       var ret uint64
+       for i := range size {
+               ret |= uint64(raw[i+offset]) << (8 * i)
+       }
+       return ret, nil
+}

Review Comment:
   Ah, I see where your confusion is coming from (the spec doesn't make it easy 
to find all these in one place).
   
   There are _so many places_ where widths are set, `is_large` is solely one 
place. In this case `is_large` indicates whether `num_elements` in the [Object 
Data](https://github.com/apache/parquet-format/blob/master/VariantEncoding.md#value-data-for-object-basic_type2)
 is 1 or 4 bytes. I'm talking about `field_id` and `field_offset` sizes. From 
the header documentation:
   
   > `field_offset_size_minus_one` and `field_id_size_minus_one` are 2-bit 
values that represent the number of bytes used to encode the field offsets and 
field ids.
   
   In this case, `field_id` and `field_offset` can be 1-4 bytes.
   
   Perhaps a better example here is in the 
[header](https://github.com/apache/parquet-format/blob/master/VariantEncoding.md#value-header-for-short-string-basic_type1)
 for `Short String`:
   
   > When `basic_type` is 1, value_header is a 6-bit `short_string_header` ... 
The `short_string_header` value is the length of the string.
   
   So a short string's length can be represented by 1-6 bytes inclusive.



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

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

Reply via email to