Skip to content

Commit

Permalink
WIP: MongoDB Discover and CDC Sync (#9)
Browse files Browse the repository at this point in the history
Signed-off-by: Piyush Singariya <[email protected]>
Co-authored-by: Piyush Singariya <[email protected]>
Co-authored-by: Piyush Singariya <[email protected]>
  • Loading branch information
3 people authored Dec 8, 2024
1 parent 9391b05 commit 0b1fdb7
Show file tree
Hide file tree
Showing 54 changed files with 5,315 additions and 750 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
g5
.vscode
test
.DS_Store
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function build_and_run() {
fi
cd $path || fail "Failed to navigate to path: $path"
go mod tidy
go build -ldflags="-w -s -X constants/constants.version=${GIT_VERSION} -X constants/constants.commitsha=${GIT_COMMITSHA} -X constants/constants.releasechannel=${RELEASE_CHANNEL}" -o g5 main.go
go build -ldflags="-w -s -X constants/constants.version=${GIT_VERSION} -X constants/constants.commitsha=${GIT_COMMITSHA} -X constants/constants.releasechannel=${RELEASE_CHANNEL}" -o g5 main.go || fail "build failed"

echo "============================== Executing connector: $connector with args [$joined_arguments] =============================="
./g5 $joined_arguments
Expand Down
1 change: 1 addition & 0 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/datazip-inc/olake/logger"
protocol "github.com/datazip-inc/olake/protocol"
"github.com/datazip-inc/olake/safego"
_ "github.com/datazip-inc/olake/writers/local"
)

func RegisterDriver(driver protocol.Driver) {
Expand Down
5 changes: 5 additions & 0 deletions constants/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package constants

const (
ParquetFileExt = "parquet"
)
50 changes: 42 additions & 8 deletions drivers/base/driver.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,74 @@
package base

import (
"sync"

"github.com/datazip-inc/olake/protocol"
"github.com/datazip-inc/olake/types"
"github.com/datazip-inc/olake/typeutils"
)

type Driver struct {
SourceStreams map[string]*types.Stream // locally cached streams; It contains all streams
GroupRead bool // Used in CDC mode
cachedStreams sync.Map // locally cached streams; It contains all streams
CDCSupport bool // Used in CDC mode
}

func (d *Driver) ChangeStreamSupported() bool {
return d.GroupRead
return d.CDCSupport
}

// Returns all the possible streams available in the source
func (d *Driver) GetStreams() []*types.Stream {
streams := []*types.Stream{}
d.cachedStreams.Range(func(key, value any) bool {
streams = append(streams, value.(*types.Stream))

return true
})

return streams
}

func (d *Driver) AddStream(stream *types.Stream) {
d.cachedStreams.Store(stream.ID(), stream)
}

func (d *Driver) UpdateState(stream protocol.Stream, data types.Record) error {
func (d *Driver) GetStream(streamID string) (bool, *types.Stream) {
val, found := d.cachedStreams.Load(streamID)
if !found {
return found, nil
}

return found, val.(*types.Stream)
}

func (d *Driver) UpdateStateCursor(stream protocol.Stream, data types.Record) error {
datatype, err := stream.Schema().GetType(stream.Cursor())
if err != nil {
return err
}

if cursorVal, found := data[stream.Cursor()]; found && cursorVal != nil {
// compare with current state
if stream.GetState() != nil {
state, err := typeutils.MaximumOnDataType(datatype, stream.GetState(), cursorVal)
if stream.GetStateCursor() != nil {
state, err := typeutils.MaximumOnDataType(datatype, stream.GetStateCursor(), cursorVal)
if err != nil {
return err
}

stream.SetState(state)
stream.SetStateCursor(state)
} else {
// directly update
stream.SetState(cursorVal)
stream.SetStateCursor(cursorVal)
}
}

return nil
}

func NewBase() *Driver {
return &Driver{
cachedStreams: sync.Map{},
CDCSupport: false,
}
}
17 changes: 13 additions & 4 deletions drivers/google-sheets/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,39 @@ require (
require (
cloud.google.com/go/compute v1.20.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/apache/arrow/go/arrow v0.0.0-20200730104253-651201b0f516 // indirect
github.com/apache/thrift v0.14.2 // indirect
github.com/brainicorn/ganno v0.0.0-20220304182003-e638228cd865 // indirect
github.com/brainicorn/goblex v0.0.0-20210908194630-cfe0cfdf87dd // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.22.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/joomcode/errorx v1.1.0 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mitchellh/hashstructure v1.1.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/pierrec/lz4/v4 v4.1.8 // indirect
github.com/piyushsingariya/relec v0.0.18 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
github.com/xitongsys/parquet-go v1.6.2 // indirect
github.com/xitongsys/parquet-go-source v0.0.0-20241021075129-b732d2ac9c9b // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.20.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.22.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit 0b1fdb7

Please sign in to comment.