emkornfield commented on a change in pull request #10951:
URL: https://github.com/apache/arrow/pull/10951#discussion_r699824796



##########
File path: go/parquet/metadata/metadata_test.go
##########
@@ -0,0 +1,325 @@
+// 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 metadata_test
+
+import (
+       "context"
+       "testing"
+       "unsafe"
+
+       "github.com/apache/arrow/go/parquet"
+       "github.com/apache/arrow/go/parquet/metadata"
+       "github.com/apache/arrow/go/parquet/schema"
+       "github.com/stretchr/testify/assert"
+       "github.com/stretchr/testify/require"
+)
+
+func generateTableMetaData(schema *schema.Schema, props 
*parquet.WriterProperties, nrows int64, statsInt, statsFloat 
metadata.EncodedStatistics) (*metadata.FileMetaData, error) {
+       fbuilder := metadata.NewFileMetadataBuilder(schema, props, nil)
+       rg1Builder := fbuilder.AppendRowGroup()
+       // metadata
+       // row group 1
+       col1Builder := rg1Builder.NextColumnChunk()
+       col2Builder := rg1Builder.NextColumnChunk()
+       // column metadata
+       dictEncodingStats := 
map[parquet.Encoding]int32{parquet.Encodings.RLEDict: 1}
+       dataEncodingStats := 
map[parquet.Encoding]int32{parquet.Encodings.Plain: 1, parquet.Encodings.RLE: 1}
+       statsInt.Signed = true
+       col1Builder.SetStats(statsInt)
+       statsFloat.Signed = true
+       col2Builder.SetStats(statsFloat)
+
+       col1Builder.Finish(nrows/2, 4, 0, 10, 512, 600, true, false, 
dictEncodingStats, dataEncodingStats, nil)
+       col2Builder.Finish(nrows/2, 24, 0, 30, 512, 600, true, false, 
dictEncodingStats, dataEncodingStats, nil)
+
+       rg1Builder.SetNumRows(nrows / 2)
+       rg1Builder.Finish(1024, -1)
+
+       // rowgroup2 metadata
+       rg2Builder := fbuilder.AppendRowGroup()
+       col1Builder = rg2Builder.NextColumnChunk()
+       col2Builder = rg2Builder.NextColumnChunk()
+       // column metadata
+       col1Builder.SetStats(statsInt)
+       col2Builder.SetStats(statsFloat)
+       col1Builder.Finish(nrows/2, 6, 0, 10, 512, 600, true, false, 
dictEncodingStats, dataEncodingStats, nil)
+       col2Builder.Finish(nrows/2, 16, 0, 26, 512, 600, true, false, 
dictEncodingStats, dataEncodingStats, nil)
+
+       rg2Builder.SetNumRows(nrows / 2)
+       rg2Builder.Finish(1024, -1)
+
+       return fbuilder.Finish()
+}
+
+func assertStatsSet(t *testing.T, m *metadata.ColumnChunkMetaData) {
+       ok, err := m.StatsSet()
+       assert.NoError(t, err)
+       assert.True(t, ok)
+}
+
+func assertStats(t *testing.T, m *metadata.ColumnChunkMetaData) 
metadata.TypedStatistics {
+       s, err := m.Statistics()
+       assert.NoError(t, err)
+       assert.NotNil(t, s)
+       return s
+}
+
+func TestBuildAccess(t *testing.T) {
+       props := parquet.NewWriterProperties(parquet.WithVersion(parquet.V2))
+
+       fields := schema.FieldList{
+               schema.NewInt32Node("int_col", parquet.Repetitions.Required, 
-1),
+               schema.NewFloat32Node("float_col", 
parquet.Repetitions.Required, -1),
+       }
+       root, err := schema.NewGroupNode("schema", 
parquet.Repetitions.Repeated, fields, -1)
+       require.NoError(t, err)
+       schema := schema.NewSchema(root)
+
+       var (
+               nrows      int64   = 1000
+               intMin     int32   = 100
+               intMax     int32   = 200
+               floatMin   float32 = 100.100
+               floatMax   float32 = 200.200
+               statsInt   metadata.EncodedStatistics
+               statsFloat metadata.EncodedStatistics
+       )
+
+       statsInt.SetNullCount(0).
+               SetDistinctCount(nrows).
+               SetMin((*(*[4]byte)(unsafe.Pointer(&intMin)))[:]).
+               SetMax((*(*[4]byte)(unsafe.Pointer(&intMax)))[:])
+
+       statsFloat.SetNullCount(0).
+               SetDistinctCount(nrows).
+               SetMin((*(*[4]byte)(unsafe.Pointer(&floatMin)))[:]).
+               SetMax((*(*[4]byte)(unsafe.Pointer(&floatMax)))[:])
+
+       faccessor, err := generateTableMetaData(schema, props, nrows, statsInt, 
statsFloat)
+       require.NoError(t, err)
+       serialized, err := faccessor.SerializeString(context.Background())
+       assert.NoError(t, err)
+       faccessorCopy, err := metadata.NewFileMetaData([]byte(serialized), nil)
+       assert.NoError(t, err)
+
+       for _, accessor := range []*metadata.FileMetaData{faccessor, 
faccessorCopy} {
+               assert.Equal(t, nrows, accessor.NumRows)
+               assert.Len(t, accessor.RowGroups, 2)
+               assert.EqualValues(t, parquet.V2, accessor.Version)
+               assert.Equal(t, parquet.DefaultCreatedBy, 
accessor.GetCreatedBy())
+               assert.Equal(t, 3, accessor.NumSchemaElements())
+
+               rg1Access := accessor.RowGroup(0)
+               assert.Equal(t, 2, rg1Access.NumColumns())
+               assert.Equal(t, nrows/2, rg1Access.NumRows())
+               assert.Equal(t, int64(1024), rg1Access.TotalByteSize())
+
+               rg1Col1, err := rg1Access.ColumnChunk(0)
+               assert.NoError(t, err)
+               rg1Col2, err := rg1Access.ColumnChunk(1)
+               assert.NoError(t, err)
+               assertStatsSet(t, rg1Col1)
+               assertStatsSet(t, rg1Col2)
+               assert.Equal(t, statsInt.Min, assertStats(t, 
rg1Col1).EncodeMin())

Review comment:
       its a little hard to grok/review if all of these tests are correct.  I'm 
glad there are tests, but I'm wondering if there might be a better way to 
express the tests so that is it easier to verify the assertions align with 
reality?




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


Reply via email to