wjones127 commented on code in PR #34342: URL: https://github.com/apache/arrow/pull/34342#discussion_r1122163534
########## go/parquet/pqarrow/encode_dictionary_test.go: ########## @@ -0,0 +1,703 @@ +// 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. + +//go:build go1.18 + +package pqarrow_test + +import ( + "bytes" + "context" + "fmt" + "math" + "strings" + "testing" + + "github.com/apache/arrow/go/v12/arrow" + "github.com/apache/arrow/go/v12/arrow/array" + "github.com/apache/arrow/go/v12/arrow/compute" + "github.com/apache/arrow/go/v12/arrow/memory" + "github.com/apache/arrow/go/v12/parquet" + "github.com/apache/arrow/go/v12/parquet/file" + "github.com/apache/arrow/go/v12/parquet/internal/testutils" + "github.com/apache/arrow/go/v12/parquet/pqarrow" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" +) + +func (ps *ParquetIOTestSuite) TestSingleColumnOptionalDictionaryWrite() { + for _, dt := range fullTypeList { + // skip tests for bool as we don't do dictionaries for it + if dt.ID() == arrow.BOOL { + continue + } + + ps.Run(dt.Name(), func() { + mem := memory.NewCheckedAllocator(memory.DefaultAllocator) + defer mem.AssertSize(ps.T(), 0) + + bldr := array.NewDictionaryBuilder(mem, &arrow.DictionaryType{IndexType: arrow.PrimitiveTypes.Int16, ValueType: dt}) + defer bldr.Release() + + values := testutils.RandomNullable(dt, smallSize, 10) + defer values.Release() + ps.Require().NoError(bldr.AppendArray(values)) + + arr := bldr.NewDictionaryArray() + defer arr.Release() + + sc := ps.makeSimpleSchema(arr.DataType(), parquet.Repetitions.Optional) + data := ps.writeColumn(sc, arr) + ps.readAndCheckSingleColumnFile(data, values) + }) + } +} + +func TestPqarrowDictionaries(t *testing.T) { + suite.Run(t, &ArrowWriteDictionarySuite{dataPageVersion: parquet.DataPageV1}) + suite.Run(t, &ArrowWriteDictionarySuite{dataPageVersion: parquet.DataPageV2}) + testSuite := &ArrowReadDictSuite{} + for _, np := range testSuite.NullProbabilities() { + testSuite.nullProb = np + t.Run(fmt.Sprintf("nullprob=%.2f", np), func(t *testing.T) { + suite.Run(t, testSuite) + }) + } +} + +type ArrowWriteDictionarySuite struct { + suite.Suite + + dataPageVersion parquet.DataPageVersion +} + +func (ad *ArrowWriteDictionarySuite) fromJSON(mem memory.Allocator, dt arrow.DataType, data string) arrow.Array { + arr, _, err := array.FromJSON(mem, dt, strings.NewReader(data)) + ad.Require().NoError(err) + return arr +} + +func (ad *ArrowWriteDictionarySuite) TestStatisticsWithFallback() { + mem := memory.NewCheckedAllocator(memory.DefaultAllocator) + defer mem.AssertSize(ad.T(), 0) + + testDictionaries := []arrow.Array{ + ad.fromJSON(mem, arrow.BinaryTypes.String, `["b", "c", "d", "a", "b", "c", "d", "a"]`), + ad.fromJSON(mem, arrow.BinaryTypes.String, `["b", "c", "d", "a", "b", "c", "d", "a"]`), + ad.fromJSON(mem, arrow.BinaryTypes.Binary, `["ZA==", "Yw==", "Yg==", "YQ==", "ZA==", "Yw==", "Yg==", "YQ=="]`), + ad.fromJSON(mem, arrow.BinaryTypes.LargeString, `["a", "b", "c", "a", "b", "c"]`), + } + + testIndices := []arrow.Array{ + ad.fromJSON(mem, arrow.PrimitiveTypes.Int32, `[0, null, 3, 0, null, 3]`), + ad.fromJSON(mem, arrow.PrimitiveTypes.Int32, `[0, 1, null, 0, 1, null]`), + ad.fromJSON(mem, arrow.PrimitiveTypes.Int32, `[0, 1, 3, 0, 1, 3]`), + ad.fromJSON(mem, arrow.PrimitiveTypes.Int32, `[null, null, null, null, null, null]`), Review Comment: ```suggestion // ["b", null, "a", "b", null, "a"] ad.fromJSON(mem, arrow.PrimitiveTypes.Int32, `[0, null, 3, 0, null, 3]`), // ["b", "c", null, "b", "c", null] ad.fromJSON(mem, arrow.PrimitiveTypes.Int32, `[0, 1, null, 0, 1, null]`), // ["ZA==", "Yw==", "YQ==", "ZA==", "Yw==", "YQ=="] ad.fromJSON(mem, arrow.PrimitiveTypes.Int32, `[0, 1, 3, 0, 1, 3]`), ad.fromJSON(mem, arrow.PrimitiveTypes.Int32, `[null, null, null, null, null, null]`), ``` -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
