-
Notifications
You must be signed in to change notification settings - Fork 241
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
[Data Store] My Sql - target, source and driver(storey) #2407
Closed
Closed
Changes from 81 commits
Commits
Show all changes
120 commits
Select commit
Hold shift + click to select a range
7f7899c
fix bug for loging extra data in all kinds of artifacts
davesh0812 484af50
fix bug for https://jira.iguazeng.com/browse/ML-1936
davesh0812 ddb83bd
Merge branch 'mlrun:development' into development
davesh0812 2c3ebf9
Merge branch 'mlrun:development' into development
davesh0812 97890dc
black+isort
davesh0812 ff6fe5e
Merge branch 'mlrun:development' into development
davesh0812 ea7438f
Merge branch 'mlrun:development' into development
davesh0812 a7f10ee
support filter for story engine
davesh0812 1287266
support filter for spark engine
davesh0812 c21b21f
Revert "support filter for spark engine"
davesh0812 184cbbc
Revert "support filter for story engine"
davesh0812 7ca059d
method to local function
davesh0812 4cd0189
Merge branch 'mlrun:development' into development
davesh0812 08574ff
mongodb (pandas engine only)
davesh0812 8c0625c
Revert "method to local function"
davesh0812 1dfbf60
undo del _id
davesh0812 62740c2
_id to string
davesh0812 5366114
_id to string + DB
davesh0812 4043de4
one line func
davesh0812 5be56f7
Merge remote-tracking branch 'origin/development' into development
davesh0812 4846ec8
to static method
davesh0812 6173ec6
to_step template
davesh0812 b85103b
mongodb
davesh0812 f3ad4bc
to_step works without time filter
davesh0812 3c40df5
comments
davesh0812 b92f853
lint
davesh0812 ddbd4a4
mongodb test
davesh0812 2a6c80d
pymongo to requirements.txt
davesh0812 78ffea9
imports
davesh0812 53b1bc2
imports
davesh0812 2461267
docs
davesh0812 3a2fcc3
Merge branch 'development' into mongodb
davesh0812 0fef892
mongodb target init
davesh0812 70a8114
mongodb target init - override option
davesh0812 295be8f
target to test
davesh0812 cb68f6e
target to test
davesh0812 015beda
comments
davesh0812 4113150
write_df
davesh0812 a26cea2
change names
davesh0812 a4cca77
change names
davesh0812 bfa604d
lint
davesh0812 0a358d8
revert steps.py
davesh0812 0606ba8
imports
davesh0812 396bf2b
lint
davesh0812 fe91801
lint
davesh0812 06ac2a9
test
davesh0812 f31159b
test
davesh0812 f39aaa7
system test
davesh0812 921cf4e
Merge branch 'development' into development
davesh0812 b52b087
lint
davesh0812 4eb30e9
lint
davesh0812 710ebfe
save attr
davesh0812 59795d6
save attr
davesh0812 19f7f95
test2
davesh0812 a718117
try
davesh0812 6c9e12f
try2
davesh0812 b57ebcd
try2
davesh0812 63e7788
Merge branch 'mlrun:development' into development
davesh0812 dbdcab2
is online
davesh0812 fdb869b
table
davesh0812 5f32605
Update tests/system/feature_store/test_feature_store.py
davesh0812 cb1af4e
review request commit
davesh0812 3b4f445
review request commit
davesh0812 3406ade
storey driver and target
davesh0812 04032c1
fix bug when using "as" if the feature list
davesh0812 f775d96
for driver without aggregate
davesh0812 fb344e7
test mongodb get online features
davesh0812 b7ec79c
lint
davesh0812 640e6a2
Merge branch 'development' into mongodb-target2
davesh0812 d7b0981
lint
davesh0812 9947c51
lint
davesh0812 aec1825
requirements
davesh0812 6a99c13
lint
davesh0812 e92e53b
req
davesh0812 7f1e421
req
davesh0812 e227791
req
davesh0812 a4f15b7
req
davesh0812 7ad38b7
Merge branch 'mlrun:development' into development
davesh0812 8708ec3
code review
davesh0812 4bbd570
code review 2
davesh0812 79ccc14
end day
davesh0812 fa02e6e
pr changes
davesh0812 a6b36f1
save
davesh0812 7b16655
Merge branch 'mlrun:development' into development
davesh0812 0f5f673
init test for sql
davesh0812 5eda29b
test and change storey driver
davesh0812 19cf7b4
comments + lint
davesh0812 5c80013
code style
davesh0812 2e4dcef
code style
davesh0812 15e93c4
Merge branch 'mlrun:development' into development
davesh0812 5935914
lint + comments (split temp from tempFromStorey.py to 2 diffrent files)
davesh0812 228127a
Merge branch 'development' into mongodb-target2
davesh0812 f9c722a
Copyright + lint
davesh0812 b912beb
Merge remote-tracking branch 'origin/mongodb-target2' into mongodb-ta…
davesh0812 b679520
lint
davesh0812 d7062ce
requirements.txt
davesh0812 3884740
Merge branch 'mlrun:development' into development
davesh0812 2131276
Merge branch 'mlrun:development' into development
davesh0812 b1dbedd
Merge branch 'mlrun:development' into development
davesh0812 5838380
Merge branch 'mlrun:development' into development
davesh0812 5bf8bc6
Merge branch 'mlrun:development' into development
davesh0812 f5b8da7
Merge branch 'development' into mongodb-target2
davesh0812 188fcdd
Merge branch 'mlrun:development' into development
davesh0812 25a3f87
review
davesh0812 5c44a62
only sql db
davesh0812 8bd2433
lint
davesh0812 8239217
review
davesh0812 3465111
review
davesh0812 00ac3e5
Merge branch 'mlrun:development' into development
davesh0812 084bdd4
test + create table not in the init
davesh0812 4e6f532
Merge branch 'development' into sql-target-and-driver
davesh0812 0cfec0c
del storey from mlrun
davesh0812 c6c79f6
test + update option
davesh0812 126f385
lint
davesh0812 f23603a
if_exists
davesh0812 923b525
del unnecessary function
davesh0812 8bd0c04
SqlDB -> Sql
davesh0812 61006b5
SqlDB -> SQL
davesh0812 6d4dab5
lint
davesh0812 69eadfc
SqlDB -> SQL
davesh0812 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,136 @@ | ||
# Copyright 2018 Iguazio | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from typing import List | ||
|
||
import storey | ||
|
||
|
||
class SqlDBDriver(storey.Driver): | ||
""" | ||
Database connection to Sql data basw. | ||
:param db_path: url string connection to sql database. | ||
:param primary_key: the primary key of the collection. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
primary_key: str, | ||
db_path: str, | ||
aggregation_attribute_prefix: str = "aggr_", | ||
aggregation_time_attribute_prefix: str = "_", | ||
): | ||
self._db_path = db_path | ||
self._sql_connection = None | ||
self._primary_key = primary_key | ||
self._mtime_name = "$_mtime_" | ||
self._storey_key = "storey_key" | ||
|
||
self._aggregation_attribute_prefix = aggregation_attribute_prefix | ||
self._aggregation_time_attribute_prefix = aggregation_time_attribute_prefix | ||
|
||
def _lazy_init(self): | ||
import sqlalchemy as db | ||
|
||
self._closed = False | ||
if not self._sql_connection: | ||
self._engine = db.create_engine(self._db_path) | ||
self._sql_connection = self._engine.connect() | ||
|
||
def collection(self, table_path): | ||
import sqlalchemy as db | ||
|
||
metadata = db.MetaData() | ||
return db.Table( | ||
table_path[3:].split("/")[1], | ||
metadata, | ||
autoload=True, | ||
autoload_with=self._engine, | ||
) | ||
|
||
async def _save_schema(self, container, table_path, schema): | ||
self._lazy_init() | ||
return None | ||
|
||
async def _load_schema(self, container, table_path): | ||
self._lazy_init() | ||
return None | ||
|
||
async def _save_key( | ||
self, container, table_path, key, aggr_item, partitioned_by_key, additional_data | ||
): | ||
import sqlalchemy as db | ||
|
||
self._lazy_init() | ||
|
||
collection = self.collection(table_path) | ||
return_val = None | ||
try: | ||
return_val = self._sql_connection.execute( | ||
collection.insert(), [additional_data] | ||
) | ||
except db.exc.IntegrityError: | ||
pass | ||
return return_val | ||
|
||
async def _load_aggregates_by_key(self, container, table_path, key): | ||
self._lazy_init() | ||
collection = self.collection(table_path) | ||
try: | ||
agg_val, values = await self._get_all_fields(key, collection) | ||
if not agg_val: | ||
agg_val = None | ||
if not values: | ||
values = None | ||
return [agg_val, values] | ||
except Exception: | ||
return [None, None] | ||
|
||
async def _load_by_key(self, container, table_path, key, attribute): | ||
self._lazy_init() | ||
collection = self.collection(table_path) | ||
if attribute == "*": | ||
_, values = await self._get_all_fields(key, collection) | ||
else: | ||
values = None | ||
return values | ||
|
||
async def close(self): | ||
pass | ||
|
||
async def _get_all_fields(self, key, collection): | ||
|
||
try: | ||
my_query = f"SELECT * FROM {collection} where {self._primary_key}={key}" | ||
results = self._sql_connection.execute(my_query).fetchall() | ||
except Exception as e: | ||
raise RuntimeError(f"Failed to get key {key}. Response error was: {e}") | ||
|
||
return None, { | ||
results[0]._fields[i]: results[0][i] for i in range(len(results[0])) | ||
} | ||
|
||
async def _get_specific_fields(self, key: str, collection, attributes: List[str]): | ||
try: | ||
my_query = f"SELECT {','.join(attributes)} FROM {collection} where {self._primary_key}={key}" | ||
results = self._sql_connection.execute(my_query).fetchall() | ||
except Exception as e: | ||
raise RuntimeError(f"Failed to get key {key}. Response error was: {e}") | ||
|
||
return None, { | ||
results[0]._fields[i]: results[0][i] for i in range(len(results[0])) | ||
} | ||
|
||
def supports_aggregations(self): | ||
return False |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why call a table a "collection"? Where does this terminology come from? It looks like the term collection only exists in Oracle's PL/SQL, and it doesn't mean a table there either.