Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement stream-based input record decoder's instead of batch-based #52

Merged
merged 6 commits into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# v0.1.x
Copy link
Member

Choose a reason for hiding this comment

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

Good changelog 👍


## Release v0.1.0 - 2020/08/xx

### Breaking changes

- `Columnifier` interface stops supporting `io.WriterCloser`

### Enhancement

- #52 Implement stream-based input record decoder's to reduce memory consumption.


# v0.0.x

## Release v0.0.4 - 2020/07/29

### Bug fix

- Fix #49 Capture the first error caused by columnifier

... And some small improvements.

## Release v0.0.3 - 2020/06/02

Ready to publish columnify as an OSS.

## Release v0.0.2 - 2020/06/02

Ready for production.

## Release v0.0.1 - 2020/04/19

Initial release.
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{}
syucream marked this conversation as resolved.
Show resolved Hide resolved
c.w.MarshalFunc = parquet.MarshalMap
records, err := record.FormatToMap(data, c.schema, c.rt)
c.w.MarshalFunc = marshal.MarshalJSON
syucream marked this conversation as resolved.
Show resolved Hide resolved
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)
abicky marked this conversation as resolved.
Show resolved Hide resolved
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
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.

Loading