mapleFU commented on issue #38503:
URL: https://github.com/apache/arrow/issues/38503#issuecomment-1793392796

   After rethink the impl, I found it's the impl's problem rather than a bug.
   
   ```
        ctx := context.Background()
        numFields := len(arrowReader.Manifest.Fields)
        numRowGroups := fileReader.NumRowGroups()
        for rowGroupIndex := 0; rowGroupIndex < numRowGroups; rowGroupIndex += 
1 {
                rowGroupReader := arrowReader.RowGroup(rowGroupIndex)
                rowGroupWriter := fileWriter.AppendRowGroup()
                for fieldNum := 0; fieldNum < numFields; fieldNum += 1 {
                        arr, err := rowGroupReader.Column(fieldNum).Read(ctx)
                        fmt.Println("Read field: ", fieldNum)
                        if err != nil {
                                return nil, err
                        }
                        colWriter, err := pqarrow.NewArrowColumnWriter(arr, 0, 
int64(arr.Len()), arrowReader.Manifest, rowGroupWriter, fieldNum)
                        if err != nil {
                                return nil, err
                        }
                        if err := colWriter.Write(ctx); err != nil {
                                return nil, err
                        }
                }
        }
        if err := fileWriter.Close(); err != nil {
                return nil, err
        }
   ```
   
   ```
   colWriter, err := pqarrow.NewArrowColumnWriter(arr, 0, int64(arr.Len()), 
arrowReader.Manifest, rowGroupWriter, fieldNum)
   ```
   
   The code above is abit dangerous, the real code should be:
   
   ```
        numRowGroups := fileReader.NumRowGroups()
        for rowGroupIndex := 0; rowGroupIndex < numRowGroups; rowGroupIndex += 
1 {
                rowGroupReader := arrowReader.RowGroup(rowGroupIndex)
                rowGroupWriter := fileWriter.AppendRowGroup()
                colIdx := 0
                for fieldNum := 0; fieldNum < numFields; fieldNum += 1 {
                        arr, err := rowGroupReader.Column(fieldNum).Read(ctx)
                        fmt.Println("Read field: ", fieldNum)
                        for _, v := range arr.Chunks() {
                                fmt.Println("CHUNK:" , v)
                        }
                        if err != nil {
                                return nil, err
                        }
                        colWriter, err := pqarrow.NewArrowColumnWriter(arr, 0, 
int64(arr.Len()), arrowReader.Manifest, rowGroupWriter, colIdx)
                        if err != nil {
                                return nil, err
                        }
                        if err := colWriter.Write(ctx); err != nil {
                                return nil, err
                        }
                        colIdx += colWriter.LeafCount()
                }
        }
   ```
   
   `colWriter.LeafCount()` cannot be get now, maybe we need using other way.


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