Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions columnifier/columnifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import "io"

// Columnifier is the interface that converts input file to columnar format file.
type Columnifier interface {
io.WriteCloser

WriteFromReader(reader io.Reader) (int, error)
WriteFromFiles(paths []string) (int, error)
Close() error
}

// NewColumnifier creates a new Columnifier.
Expand Down
42 changes: 21 additions & 21 deletions columnifier/parquet.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package columnifier

import (
"io"
"io/ioutil"
"os"

"github.com/reproio/columnify/record"

"github.com/reproio/columnify/parquet"
"github.com/reproio/columnify/schema"
"github.com/xitongsys/parquet-go-source/local"
"github.com/xitongsys/parquet-go/marshal"
parquetSource "github.com/xitongsys/parquet-go/source"
"github.com/xitongsys/parquet-go/writer"
)
Expand Down Expand Up @@ -65,36 +68,32 @@ func NewParquetColumnifier(st string, sf string, rt string, output string, confi
}

// Write reads, converts input binary data and write it to buffer.
func (c *parquetColumnifier) Write(data []byte) (int, error) {
func (c *parquetColumnifier) WriteFromReader(reader io.Reader) (int, error) {
// Intermediate record type is map[string]interface{}
Comment thread
syucream marked this conversation as resolved.
Outdated
c.w.MarshalFunc = parquet.MarshalMap
records, err := record.FormatToMap(data, c.schema, c.rt)
c.w.MarshalFunc = marshal.MarshalJSON
Comment thread
syucream marked this conversation as resolved.
Outdated
decoder, err := record.NewJsonDecoder(reader, c.schema, c.rt)
if err != nil {
return -1, err
}

beforeSize := c.w.Size
for _, r := range records {
if err := c.w.Write(r); err != nil {
for {
var v string
err = decoder.Decode(&v)
Comment thread
abicky marked this conversation as resolved.
Outdated
if err != nil {
if err == io.EOF {
break
} else {
return -1, err
}
}

if err := c.w.Write(v); err != nil {
return -1, err
}
}
afterSize := c.w.Size

// Intermediate record type is wrapped Apache Arrow record
// It requires Arrow Golang implementation more logical type supports
// ref. https://github.com/apache/arrow/blob/9c9dc2012266442d0848e4af0cf52874bc4db151/go/arrow/array/builder.go#L211
/*
c.w.MarshalFunc = parquet.MarshalArrow
records, err := record.FormatToArrow(data, c.schema, c.rt)
if err != nil {
return err
}
if err := c.w.Write(&records); err != nil {
return err
}
*/

return int(afterSize - beforeSize), nil
}

Expand All @@ -103,11 +102,12 @@ func (c *parquetColumnifier) WriteFromFiles(paths []string) (int, error) {
var n int

for _, p := range paths {
data, err := ioutil.ReadFile(p)
f, err := os.Open(p)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this PR makes iterating processes reading some blocks of the file instead of reading the whole file. That's good.

if err != nil {
return -1, err
}
if n, err = c.Write(data); err != nil {

if n, err = c.WriteFromReader(f); err != nil {
return -1, err
}
}
Expand Down
12 changes: 0 additions & 12 deletions parquet/doc.go

This file was deleted.

266 changes: 0 additions & 266 deletions parquet/marshal_arrow.go

This file was deleted.

Loading