-
Notifications
You must be signed in to change notification settings - Fork 1.3k
chore: Go Sql Online Store #2446
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
501f59d
Initial structure for go sqlite online store
kevjumba 0fbd8dc
Somewhat intermediate state
kevjumba 21c8900
Add sqlite online store for go for testing
kevjumba 01d9a1d
Revert
kevjumba 2c4fccd
Revert
kevjumba 34dcd15
Clean up
kevjumba 80f4579
Address review issues
kevjumba 17acc6a
Fix/address issues
kevjumba 64fa88b
lint
kevjumba 0601f0a
Fix
kevjumba 2233ff8
Fix
kevjumba 4de021b
Make integration test work
kevjumba e3f9970
Fix tests
kevjumba d9f5333
Fix tests
kevjumba a631c52
debugging
kevjumba 993ead4
Debug
kevjumba 63fbee6
Debug
kevjumba c325834
Debug
kevjumba f2202b8
Debug
kevjumba c242587
Debug
kevjumba 08e51fb
Debug
kevjumba b551639
Remove feature_repo files
kevjumba 0755e05
update gitignore
kevjumba eb8a320
Clean up code
kevjumba c3472bd
Update go mod
kevjumba a5b6607
Update makefile
kevjumba 5f68689
Fix gitignore issue
kevjumba 3896f99
Update makefile
kevjumba 111c2d0
Update makefile
kevjumba c6197ce
Update makefile
kevjumba a5d4d28
Update makefile
kevjumba 14d5602
Update makefile
kevjumba 02eda7a
Revert worfklow
kevjumba 14876a2
Update build path
kevjumba 3bfcfad
remove
kevjumba 8739e68
rename
kevjumba bd052a3
Address review
kevjumba 189d3d2
fix tests
kevjumba acc86bb
Fix
kevjumba 34ab63d
see if this fixes test
kevjumba fa0abf3
Fix
kevjumba 941aea8
revert
kevjumba 025a7e4
Will add in separate pr to update cryptography
kevjumba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Somewhat intermediate state
Signed-off-by: Kevin Zhang <kzhang@tecton.ai>
- Loading branch information
commit 0fbd8dc8590b24801ff89a7900904b7d7e1c826c
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Empty file.
This file contains hidden or 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,10 +1,14 @@ | ||
| package feast | ||
|
|
||
| import ( | ||
| "database/sql" | ||
| "errors" | ||
|
|
||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/feast-dev/feast/go/protos/feast/types" | ||
| _ "github.com/mattn/go-sqlite3" | ||
| ) | ||
|
|
||
| type SqliteOnlineStore struct { | ||
|
|
@@ -13,6 +17,7 @@ type SqliteOnlineStore struct { | |
| project string | ||
|
|
||
| path string | ||
| db *sql.DB | ||
| } | ||
|
|
||
| func NewSqliteOnlineStore(project string, onlineStoreConfig map[string]interface{}) (*SqliteOnlineStore, error) { | ||
|
|
@@ -23,25 +28,72 @@ func NewSqliteOnlineStore(project string, onlineStoreConfig map[string]interface | |
| return nil, fmt.Errorf("cannot find convert sqlite path to string %s", db_path) | ||
| } else { | ||
| store.path = dbPathStr | ||
| db, err := initializeConnection(dbPathStr) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| store.db = db | ||
| } | ||
| return &SqliteOnlineStore{ | ||
| project: project, | ||
| }, nil | ||
| return &store, nil | ||
| } | ||
|
|
||
| func (*SqliteOnlineStore) Destruct() { | ||
|
|
||
| func (s *SqliteOnlineStore) Destruct() { | ||
| s.db.Close() | ||
| } | ||
|
|
||
| func (*SqliteOnlineStore) OnlineRead(ctx context.Context, entityKeys []types.EntityKey, featureViewNames []string, featureNames []string) ([][]FeatureData, error) { | ||
| func (s *SqliteOnlineStore) OnlineRead(ctx context.Context, entityKeys []types.EntityKey, featureViewNames []string, featureNames []string) ([][]FeatureData, error) { | ||
| _, err := s.getConnection() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return nil, nil | ||
| } | ||
|
|
||
| // feature views, entities, dataframe? | ||
| func (*SqliteOnlineStore) WriteToOnlineStore(ctx context.Context, featureViewName string, data [][]FeatureData) error { | ||
| func (s *SqliteOnlineStore) WriteToOnlineStore(ctx context.Context, featureViewName string, data [][]FeatureData) error { | ||
| return nil | ||
| } | ||
|
|
||
| func (s *SqliteOnlineStore) Update(ctx context.Context, config *RepoConfig, tables_to_delete []*FeatureView, tables_to_keep []*FeatureView) error { | ||
| _, err := s.getConnection() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| project := config.Project | ||
| for _, table := range tables_to_keep { | ||
| s.db.Exec( | ||
| fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s (entity_key BLOB, feature_name TEXT, value BLOB, event_ts timestamp, created_ts timestamp, PRIMARY KEY(entity_key, feature_name))", tableId(project, table))) | ||
| s.db.Exec( | ||
| fmt.Sprintf("CREATE INDEX IF NOT EXISTS %s_ek ON %s (entity_key);", tableId(project, table), tableId(project, table))) | ||
| } | ||
| for _, table := range tables_to_delete { | ||
| s.db.Exec("DROP TABLE IF EXISTS %s", tableId(project, table)) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (*SqliteOnlineStore) initializeConnection(db_path string) { | ||
| func (s *SqliteOnlineStore) getConnection() (*sql.DB, error) { | ||
| if s.db == nil { | ||
| if s.path == "" { | ||
| return nil, errors.New("no database path available") | ||
| } | ||
| db, err := initializeConnection(s.path) | ||
| s.db = db | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
|
Comment on lines
123
to
132
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be guarded by a lock to prevent concurrent access creating multiple dangling connections
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added a mutex. |
||
| return s.db, nil | ||
| } | ||
|
|
||
| func tableId(project string, table *FeatureView) string { | ||
| return fmt.Sprintf("%s_%s", project, table.base.name) | ||
| } | ||
|
|
||
| func initializeConnection(db_path string) (*sql.DB, error) { | ||
| db, err := sql.Open("sqlite3", "./foo.db") | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return db, nil | ||
| } | ||
This file contains hidden or 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,54 @@ | ||
| package feast | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "log" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestSqliteSetup(t *testing.T) { | ||
| dir := "../test/selected_tetra" | ||
| config, err := NewRepoConfigFromFile(dir) | ||
| assert.Nil(t, err) | ||
| assert.Equal(t, "selected_tetra", config.Project) | ||
| assert.Equal(t, "data/registry.db", config.GetRegistryConfig().Path) | ||
| assert.Equal(t, "local", config.Provider) | ||
| assert.Equal(t, map[string]interface{}{ | ||
| "path": "data/online_store.db", | ||
| }, config.OnlineStore) | ||
| assert.Empty(t, config.OfflineStore) | ||
| assert.Empty(t, config.FeatureServer) | ||
| assert.Empty(t, config.Flags) | ||
| } | ||
|
|
||
| func TestSqliteUpdate(t *testing.T) { | ||
| dir := "../test/selected_tetra" | ||
| config, err := NewRepoConfigFromFile(dir) | ||
| assert.Nil(t, err) | ||
| store, err := NewSqliteOnlineStore("test", config.OnlineStore) | ||
| defer store.Destruct() | ||
| assert.Nil(t, err) | ||
| show_tables := `SELECT | ||
| * | ||
| FROM | ||
| selected_tetra_driver_hourly_stats;` | ||
| rows, err := store.db.Query(show_tables) | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| defer rows.Close() | ||
| for rows.Next() { | ||
| fmt.Println("in") | ||
| var id int | ||
| var name string | ||
| err = rows.Scan(&id, &name) | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| fmt.Println(id, name) | ||
| } | ||
| assert.False(t, true) | ||
|
|
||
| } |
Empty file.
Binary file not shown.
Binary file not shown.
This file contains hidden or 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,35 @@ | ||
| # This is an example feature definition file | ||
|
|
||
| from datetime import timedelta | ||
|
|
||
| from feast import Entity, Feature, FeatureView, FileSource, ValueType | ||
|
|
||
| # Read data from parquet files. Parquet is convenient for local development mode. For | ||
| # production, you can use your favorite DWH, such as BigQuery. See Feast documentation | ||
| # for more info. | ||
| driver_hourly_stats = FileSource( | ||
| path="/Users/kevinzhang/tecton-ai/offline_store/feast/go/internal/test/selected_tetra/data/driver_stats.parquet", | ||
| event_timestamp_column="event_timestamp", | ||
| created_timestamp_column="created", | ||
| ) | ||
|
|
||
| # Define an entity for the driver. You can think of entity as a primary key used to | ||
| # fetch features. | ||
| driver = Entity(name="driver_id", value_type=ValueType.INT64, description="driver id",) | ||
|
|
||
| # Our parquet files contain sample data that includes a driver_id column, timestamps and | ||
| # three feature column. Here we define a Feature View that will allow us to serve this | ||
| # data to our model online. | ||
| driver_hourly_stats_view = FeatureView( | ||
| name="driver_hourly_stats", | ||
| entities=["driver_id"], | ||
| ttl=timedelta(days=1), | ||
| features=[ | ||
| Feature(name="conv_rate", dtype=ValueType.FLOAT), | ||
| Feature(name="acc_rate", dtype=ValueType.FLOAT), | ||
| Feature(name="avg_daily_trips", dtype=ValueType.INT64), | ||
| ], | ||
| online=True, | ||
| batch_source=driver_hourly_stats, | ||
| tags={}, | ||
| ) |
This file contains hidden or 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,5 @@ | ||
| project: selected_tetra | ||
| registry: data/registry.db | ||
| provider: local | ||
| online_store: | ||
| path: data/online_store.db |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.