-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instead of #15. Plugin V3 Protocol client/server regenerated from cloudquery/plugin-pb#1
- Loading branch information
1 parent
ba7d275
commit 50ec9d9
Showing
11 changed files
with
2,523 additions
and
15 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package managedplugin | ||
|
||
import "sync/atomic" | ||
|
||
type Metrics struct { | ||
Errors uint64 | ||
Warnings uint64 | ||
} | ||
|
||
func (m *Metrics) incrementErrors() { | ||
atomic.AddUint64(&m.Errors, 1) | ||
} | ||
|
||
func (m *Metrics) incrementWarnings() { | ||
atomic.AddUint64(&m.Warnings, 1) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package plugin | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/apache/arrow/go/v13/arrow" | ||
"github.com/apache/arrow/go/v13/arrow/ipc" | ||
) | ||
|
||
func SchemaToBytes(sc *arrow.Schema) ([]byte, error) { | ||
var buf bytes.Buffer | ||
wr := ipc.NewWriter(&buf, ipc.WithSchema(sc)) | ||
if err := wr.Close(); err != nil { | ||
return nil, err | ||
} | ||
return buf.Bytes(), nil | ||
} | ||
|
||
func NewSchemaFromBytes(b []byte) (*arrow.Schema, error) { | ||
rdr, err := ipc.NewReader(bytes.NewReader(b)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return rdr.Schema(), nil | ||
} | ||
|
||
func RecordToBytes(record arrow.Record) ([]byte, error) { | ||
var buf bytes.Buffer | ||
wr := ipc.NewWriter(&buf, ipc.WithSchema(record.Schema())) | ||
if err := wr.Write(record); err != nil { | ||
return nil, err | ||
} | ||
if err := wr.Close(); err != nil { | ||
return nil, err | ||
} | ||
return buf.Bytes(), nil | ||
} | ||
|
||
func NewRecordFromBytes(b []byte) (arrow.Record, error) { | ||
rdr, err := ipc.NewReader(bytes.NewReader(b)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for rdr.Next() { | ||
rec := rdr.Record() | ||
rec.Retain() | ||
return rec, nil | ||
} | ||
return nil, nil | ||
} |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package plugin | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/apache/arrow/go/v13/arrow" | ||
"github.com/apache/arrow/go/v13/arrow/array" | ||
"github.com/apache/arrow/go/v13/arrow/memory" | ||
) | ||
|
||
func TestSchemaRoundTrip(t *testing.T) { | ||
md := arrow.NewMetadata([]string{"foo", "bar"}, []string{"baz", "quux"}) | ||
sc := arrow.NewSchema([]arrow.Field{ | ||
{Name: "a", Type: arrow.PrimitiveTypes.Int64}, | ||
{Name: "b", Type: arrow.PrimitiveTypes.Float64}, | ||
}, &md) | ||
b, err := SchemaToBytes(sc) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
sc2, err := NewSchemaFromBytes(b) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if !sc.Equal(sc2) { | ||
t.Errorf("expected %v, got %v", sc, sc2) | ||
} | ||
} | ||
|
||
func TestRecordRoundTrip(t *testing.T) { | ||
md := arrow.NewMetadata([]string{"foo", "bar"}, []string{"baz", "quux"}) | ||
sc := arrow.NewSchema([]arrow.Field{ | ||
{Name: "a", Type: arrow.PrimitiveTypes.Int64}, | ||
{Name: "b", Type: arrow.PrimitiveTypes.Float64}, | ||
}, &md) | ||
bldr := array.NewRecordBuilder(memory.DefaultAllocator, sc) | ||
bldr.Field(0).(*array.Int64Builder).AppendValues([]int64{1, 2, 3}, nil) | ||
bldr.Field(1).(*array.Float64Builder).AppendValues([]float64{1.1, 2.2, 3.3}, nil) | ||
rec := bldr.NewRecord() | ||
defer rec.Release() | ||
|
||
b, err := RecordToBytes(rec) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
rec2, err := NewRecordFromBytes(b) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if !array.RecordEqual(rec, rec2) { | ||
t.Errorf("expected %v, got %v", rec, rec2) | ||
} | ||
} |
Oops, something went wrong.