-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: Move to Arrow implementation (#120)
* Move to Apache Arrow in-memory representation
- Loading branch information
1 parent
a5deffa
commit b4fb660
Showing
37 changed files
with
539 additions
and
2,999 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,25 @@ | ||
package csv | ||
|
||
import ( | ||
"encoding/csv" | ||
"errors" | ||
"fmt" | ||
"io" | ||
|
||
"github.com/cloudquery/plugin-sdk/schema" | ||
"github.com/apache/arrow/go/v12/arrow" | ||
"github.com/apache/arrow/go/v12/arrow/csv" | ||
) | ||
|
||
func (cl *Client) Read(r io.Reader, table *schema.Table, sourceName string, res chan<- []any) error { | ||
reader := csv.NewReader(r) | ||
reader.Comma = cl.Delimiter | ||
sourceNameIndex := table.Columns.Index(schema.CqSourceNameColumn.Name) | ||
if sourceNameIndex == -1 { | ||
return fmt.Errorf("could not find column %s in table %s", schema.CqSourceNameColumn.Name, table.Name) | ||
} | ||
if cl.IncludeHeaders { | ||
_, err := reader.Read() | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
for { | ||
record, err := reader.Read() | ||
if err != nil { | ||
if errors.Is(err, io.EOF) { | ||
break | ||
} | ||
return err | ||
} | ||
if record[sourceNameIndex] != sourceName { | ||
continue | ||
} | ||
values := make([]any, len(record)) | ||
for i, v := range record { | ||
values[i] = v | ||
func (cl *Client) Read(r io.Reader, arrowSchema *arrow.Schema, _ string, res chan<- arrow.Record) error { | ||
reader := csv.NewReader(r, arrowSchema, | ||
csv.WithComma(cl.Delimiter), | ||
csv.WithHeader(cl.IncludeHeaders), | ||
csv.WithNullReader(true, ""), | ||
) | ||
for reader.Next() { | ||
if reader.Err() != nil { | ||
return reader.Err() | ||
} | ||
res <- values | ||
rec := reader.Record() | ||
rec.Retain() | ||
res <- rec | ||
} | ||
return nil | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.