zeroshade commented on a change in pull request #9671:
URL: https://github.com/apache/arrow/pull/9671#discussion_r595195594



##########
File path: go/parquet/internal/testutils/random_arrow.go
##########
@@ -0,0 +1,475 @@
+// 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 testutils
+
+import (
+       "github.com/apache/arrow/go/arrow"
+       "github.com/apache/arrow/go/arrow/array"
+       "github.com/apache/arrow/go/arrow/memory"
+       "golang.org/x/exp/rand"
+)
+
+func RandomNonNull(dt arrow.DataType, size int) array.Interface {
+       switch dt.ID() {
+       case arrow.FLOAT32:
+               bldr := array.NewFloat32Builder(memory.DefaultAllocator)
+               defer bldr.Release()
+               values := make([]float32, size)
+               FillRandomFloat32(0, values)
+               bldr.AppendValues(values, nil)
+               return bldr.NewArray()
+       case arrow.FLOAT64:
+               bldr := array.NewFloat64Builder(memory.DefaultAllocator)
+               defer bldr.Release()
+               values := make([]float64, size)
+               FillRandomFloat64(0, values)
+               bldr.AppendValues(values, nil)
+               return bldr.NewArray()
+       case arrow.INT64:
+               bldr := array.NewInt64Builder(memory.DefaultAllocator)
+               defer bldr.Release()
+               values := make([]int64, size)
+               FillRandomInt64(0, values)
+               bldr.AppendValues(values, nil)
+               return bldr.NewArray()
+       case arrow.UINT64:
+               bldr := array.NewUint64Builder(memory.DefaultAllocator)
+               defer bldr.Release()
+               values := make([]uint64, size)
+               FillRandomUint64(0, values)
+               bldr.AppendValues(values, nil)
+               return bldr.NewArray()
+       case arrow.INT32:
+               bldr := array.NewInt32Builder(memory.DefaultAllocator)
+               defer bldr.Release()
+               values := make([]int32, size)
+               FillRandomInt32(0, values)
+               bldr.AppendValues(values, nil)
+               return bldr.NewArray()
+       case arrow.UINT32:
+               bldr := array.NewUint32Builder(memory.DefaultAllocator)
+               defer bldr.Release()
+               values := make([]uint32, size)
+               FillRandomUint32(0, values)
+               bldr.AppendValues(values, nil)
+               return bldr.NewArray()
+       case arrow.INT16:
+               bldr := array.NewInt16Builder(memory.DefaultAllocator)
+               defer bldr.Release()
+               values := make([]int16, size)
+               FillRandomInt16(0, 0, 64, values)
+               bldr.AppendValues(values, nil)
+               return bldr.NewArray()
+       case arrow.UINT16:
+               bldr := array.NewUint16Builder(memory.DefaultAllocator)
+               defer bldr.Release()
+               values := make([]uint16, size)
+               FillRandomUint16(0, 0, 64, values)
+               bldr.AppendValues(values, nil)
+               return bldr.NewArray()
+       case arrow.INT8:
+               bldr := array.NewInt8Builder(memory.DefaultAllocator)
+               defer bldr.Release()
+               values := make([]int8, size)
+               FillRandomInt8(0, 0, 64, values)
+               bldr.AppendValues(values, nil)
+               return bldr.NewArray()
+       case arrow.UINT8:
+               bldr := array.NewUint8Builder(memory.DefaultAllocator)
+               defer bldr.Release()
+               values := make([]uint8, size)
+               FillRandomUint8(0, 0, 64, values)
+               bldr.AppendValues(values, nil)
+               return bldr.NewArray()
+       case arrow.DATE32:
+               bldr := array.NewDate32Builder(memory.DefaultAllocator)
+               defer bldr.Release()
+               values := make([]int32, size)
+               FillRandomInt32Max(0, 24, values)
+
+               dates := make([]arrow.Date32, size)
+               for idx, val := range values {
+                       dates[idx] = arrow.Date32(val) * 86400000
+               }
+               bldr.AppendValues(dates, nil)
+               return bldr.NewArray()
+       case arrow.DATE64:
+               bldr := array.NewDate64Builder(memory.DefaultAllocator)
+               defer bldr.Release()
+               values := make([]int64, size)
+               FillRandomInt64Max(0, 24, values)
+
+               dates := make([]arrow.Date64, size)
+               for idx, val := range values {
+                       dates[idx] = arrow.Date64(val) * 86400000
+               }
+               bldr.AppendValues(dates, nil)
+               return bldr.NewArray()
+       case arrow.STRING:
+               bldr := array.NewStringBuilder(memory.DefaultAllocator)
+               defer bldr.Release()
+               for i := 0; i < size; i++ {
+                       bldr.Append("test-string")
+               }
+               return bldr.NewArray()
+       case arrow.BINARY:
+               bldr := array.NewBinaryBuilder(memory.DefaultAllocator, 
arrow.BinaryTypes.Binary)
+               defer bldr.Release()
+
+               buf := make([]byte, 12)
+               r := rand.New(rand.NewSource(0))
+               for i := 0; i < size; i++ {
+                       length := r.Intn(12-2+1) + 2
+                       r.Read(buf[:length])
+                       bldr.Append(buf[:length])
+               }
+               return bldr.NewArray()
+       case arrow.FIXED_SIZE_BINARY:
+               bldr := 
array.NewFixedSizeBinaryBuilder(memory.DefaultAllocator, 
&arrow.FixedSizeBinaryType{ByteWidth: 10})
+               defer bldr.Release()
+
+               buf := make([]byte, 10)
+               r := rand.New(rand.NewSource(0))
+               for i := 0; i < size; i++ {
+                       r.Read(buf)
+                       bldr.Append(buf)
+               }
+               return bldr.NewArray()
+       // case arrow.DECIMAL:

Review comment:
       See https://github.com/apache/arrow/pull/9671#discussion_r591668034 but 
long story short: these rely on a function that was exported in a later chunk 
of this change, so rather than delete them and then re-add it later, I just 
commented them out until i add that chunk. If you'd prefer these to be deleted 
for now and then added as part of that chunk, I can do that.




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

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


Reply via email to