milden6 commented on code in PR #429: URL: https://github.com/apache/arrow-go/pull/429#discussion_r2178124352
########## parquet/example_write_read_pq_test.go: ########## @@ -0,0 +1,183 @@ +// 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 parquet_test + +import ( + "bytes" + "context" + "fmt" + "log" + + "github.com/apache/arrow-go/v18/arrow" + "github.com/apache/arrow-go/v18/arrow/array" + "github.com/apache/arrow-go/v18/arrow/memory" + "github.com/apache/arrow-go/v18/parquet" + "github.com/apache/arrow-go/v18/parquet/compress" + "github.com/apache/arrow-go/v18/parquet/file" + "github.com/apache/arrow-go/v18/parquet/pqarrow" +) + +// In a real project, this should be tuned based on memory usage and performance needs +const batchSize = 2 + +// List of fields to read +var colNames = []string{"intField", "stringField", "listField"} + +func Example_writeReadParquet() { + // --- Phase 1: Writing parquet file --- + + // Create an in-memory buffer to simulate a file + // For writing real file to disk, use os.Create instead + buffer := &bytes.Buffer{} + + // Create a schema with three fields + fields := []arrow.Field{ + {Name: "intField", Type: arrow.PrimitiveTypes.Int32, Nullable: false}, + {Name: "stringField", Type: arrow.BinaryTypes.String, Nullable: false}, + {Name: "listField", Type: arrow.ListOf(arrow.PrimitiveTypes.Float32), Nullable: false}, + } + + schema := arrow.NewSchema(fields, nil) + + // Create parquet writer props with snappy compression + writerProps := parquet.NewWriterProperties( + parquet.WithCompression(compress.Codecs.Snappy), + ) + + // Create arrow writer props to store the schema in the parquet file + arrowWriterProps := pqarrow.NewArrowWriterProperties( + pqarrow.WithStoreSchema(), + ) Review Comment: Yes, you are right, what about this comment? ```go // WithStoreSchema embeds the original Arrow schema into the Parquet file metadata, // allowing it to be accurately restored when reading. This ensures correct handling // of advanced types like dictionaries and preserves full type fidelity across write/read ``` -- 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]
