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
Print table schema in DB initialization test #5248
Merged
Merged
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8978467
Print out table schemas in DB initialization check
harupy c47dba7
rename
harupy 1926377
fix arg name
harupy 77b65bc
rename to run_logging_operations
harupy 3d74401
remove COPY log.py
harupy 9285ade
move assert
harupy b6dbab5
print schema after logging
harupy 6759b73
fix
harupy f20817b
add sqlite
harupy d9a71b2
update step
harupy ef56686
move parse_args
harupy 13578eb
separate step
harupy e7681fc
pull
harupy 4e8a2fb
remove comments
harupy 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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
** | ||
|
||
!dist/*.whl | ||
!log.py | ||
!init-mssql-db.sh | ||
!init-mssql-db.sql |
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 @@ | ||
schemas |
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 |
---|---|---|
|
@@ -13,6 +13,8 @@ services: | |
- postgres | ||
build: | ||
context: . | ||
volumes: | ||
- .:/tmp/mlflow | ||
environment: | ||
MLFLOW_TRACKING_URI: postgresql://mlflowuser:mlflowpassword@postgres:5432/mlflowdb | ||
|
||
|
@@ -30,6 +32,8 @@ services: | |
- mysql | ||
build: | ||
context: . | ||
volumes: | ||
- .:/tmp/mlflow | ||
Comment on lines
+35
to
+36
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. Use volumes for faster development cycle instead of copying scripts in the docker image. |
||
environment: | ||
MLFLOW_TRACKING_URI: mysql://mlflowuser:mlflowpassword@mysql:3306/mlflowdb | ||
|
||
|
@@ -46,5 +50,7 @@ services: | |
build: | ||
context: . | ||
dockerfile: Dockerfile.mssql | ||
volumes: | ||
- .:/tmp/mlflow | ||
environment: | ||
MLFLOW_TRACKING_URI: mssql+pyodbc://mlflowuser:Mlfl*wpassword1@mssql/mlflowdb?driver=ODBC+Driver+17+for+SQL+Server |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import os | ||
import argparse | ||
|
||
import sqlalchemy | ||
from sqlalchemy.schema import MetaData, CreateTable | ||
|
||
import mlflow | ||
from mlflow.tracking._tracking_service.utils import _TRACKING_URI_ENV_VAR | ||
|
||
assert _TRACKING_URI_ENV_VAR in os.environ | ||
|
||
|
||
class MockModel(mlflow.pyfunc.PythonModel): | ||
def load_context(self, context): | ||
pass | ||
|
||
def predict(self, context, model_input): | ||
pass | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--schema-output", required=True, help="Output path of DB schema") | ||
return parser.parse_args() | ||
|
||
|
||
def run_logging_operations(): | ||
with mlflow.start_run() as run: | ||
print("Tracking URI:", mlflow.get_tracking_uri()) | ||
mlflow.log_param("p", "param") | ||
mlflow.log_metric("m", 1.0) | ||
mlflow.set_tag("t", "tag") | ||
mlflow.pyfunc.log_model( | ||
artifact_path="model", | ||
python_model=MockModel(), | ||
registered_model_name="mock", | ||
) | ||
print(mlflow.get_run(run.info.run_id)) | ||
|
||
|
||
def get_db_schema(): | ||
engine = sqlalchemy.create_engine(mlflow.get_tracking_uri()) | ||
created_tables_metadata = MetaData(bind=engine) | ||
created_tables_metadata.reflect() | ||
# Write out table schema as described in | ||
# https://docs.sqlalchemy.org/en/13/faq/metadata_schema.html#how-can-i-get-the-create-table-drop-table-output-as-a-string | ||
lines = [] | ||
for ti in created_tables_metadata.sorted_tables: | ||
lines += list(map(str.rstrip, str(CreateTable(ti)).splitlines())) | ||
return "\n".join(lines) | ||
|
||
|
||
def main(): | ||
args = parse_args() | ||
schema = get_db_schema() | ||
title = "Schema" | ||
print("=" * 10, title, "=", 10) | ||
print(schema) | ||
print("=" * (20 + 2 + len(title))) | ||
os.makedirs(os.path.dirname(args.schema_output), exist_ok=True) | ||
with open(args.schema_output, "w") as f: | ||
f.write(schema) | ||
|
||
run_logging_operations() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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.
Dump the table schema to make it easier to debug locally.