-
Notifications
You must be signed in to change notification settings - Fork 37
python demo example for reconciliation added #1427
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
Open
sriram251-code
wants to merge
3
commits into
main
Choose a base branch
from
feature/docs_recon_notebook
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,107 @@ | ||||||
# This is an example python code which can be used to perform reconciliation using remorph in Databricks notebook. | ||||||
# %pip install git+https://github.com/databrickslabs/remorph | ||||||
# dbutils.library.restartPython() | ||||||
from databricks.sdk import WorkspaceClient | ||||||
from pyspark.shell import spark | ||||||
|
||||||
from databricks.labs.remorph.config import ReconcileConfig, DatabaseConfig, ReconcileMetadataConfig | ||||||
from databricks.labs.remorph.config import TableRecon | ||||||
from databricks.labs.remorph.reconcile.exception import ReconciliationException | ||||||
from databricks.labs.remorph.reconcile.execute import recon | ||||||
from databricks.labs.remorph.reconcile.execute import reconcile_aggregates | ||||||
from databricks.labs.remorph.reconcile.recon_config import Table, ColumnMapping, Aggregate | ||||||
|
||||||
# Create a workspace client | ||||||
ws = WorkspaceClient(product="remorph", product_version="0.9.0") | ||||||
|
||||||
source_catalog = "" # Provide the source catalog name ex: hive_metastore | ||||||
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.
Suggested change
|
||||||
source_schema = "" # Provide the source schema name ex: default | ||||||
target_catalog = "" # Provide the target catalog name ex: users | ||||||
target_schema = "" # Provide the target schema name ex: remorph | ||||||
|
||||||
# Configure recon source and target | ||||||
reconcile_config = ReconcileConfig( | ||||||
data_source="databricks", # provide the data source name ex: snowflake | ||||||
report_type="row", # schema,row,data or all https://github.com/databrickslabs/remorph/tree/main/docs/recon_configurations#types-of-report-supported | ||||||
secret_scope="remorph_databricks", | ||||||
database_config=DatabaseConfig( | ||||||
source_catalog=source_catalog, | ||||||
source_schema=source_schema, | ||||||
target_catalog=target_catalog, | ||||||
target_schema=target_schema, | ||||||
), | ||||||
metadata_config=ReconcileMetadataConfig(catalog=target_catalog, schema=target_schema), | ||||||
) | ||||||
|
||||||
|
||||||
# Table recon configuration | ||||||
table_recon = TableRecon( | ||||||
source_schema=source_schema, | ||||||
target_catalog=target_catalog, | ||||||
target_schema=target_schema, | ||||||
tables=[ | ||||||
Table( | ||||||
source_name="source_employee_table", # Provide the source table name | ||||||
target_name="target_employee_table", # Provide the target table name | ||||||
column_mapping=[ | ||||||
ColumnMapping( | ||||||
source_name="emp_id", target_name="employee_id" | ||||||
), # Provide the source and target column name if they have different names | ||||||
ColumnMapping(source_name="salary", target_name="sal"), | ||||||
], | ||||||
join_columns=["emp_id"], # for recon type all join_columns is mandatory | ||||||
), | ||||||
Table(source_name="source_dept_table", target_name="target_dept_table", join_columns=["dept_id"]), | ||||||
], | ||||||
) | ||||||
|
||||||
|
||||||
# Performing reconciliation | ||||||
try: | ||||||
result = recon(ws, spark, table_recon, reconcile_config) | ||||||
print(f" Success : {result.recon_id}") | ||||||
print("***************************") | ||||||
except ReconciliationException as e: | ||||||
print(f"Exception : {str(e)}") | ||||||
print("***************************") | ||||||
except Exception as e: | ||||||
print(f"Exception : {str(e)}") | ||||||
print("***************************") | ||||||
|
||||||
|
||||||
# Check target_catalog.target_schema.details table for the reconciliation report | ||||||
|
||||||
# Table configuration for aggregated reconciliation | ||||||
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. Separate Notebook for Aggregates. |
||||||
table_recon_agg = TableRecon( | ||||||
source_schema=source_schema, | ||||||
target_catalog=target_catalog, | ||||||
target_schema=target_schema, | ||||||
tables=[ | ||||||
Table( | ||||||
source_name="source_employee_table", | ||||||
target_name="target_employee_table", | ||||||
aggregates=[ | ||||||
Aggregate( | ||||||
agg_columns=["emp_id"], type="count" | ||||||
), # Provide the column name and aggregation type https://github.com/databrickslabs/remorph/tree/main/docs/recon_configurations#supported-aggregate-functions | ||||||
Aggregate(agg_columns=["salary"], type="min"), | ||||||
Aggregate(agg_columns=["salary"], type="max"), | ||||||
], | ||||||
join_columns=["emp_id"], # for recon type all join_columns is mandatory | ||||||
), | ||||||
], | ||||||
) | ||||||
|
||||||
try: | ||||||
result = reconcile_aggregates(ws, spark, table_recon_agg, reconcile_config) # _aggregates | ||||||
recon_id = result.recon_id | ||||||
print(f" Success : {recon_id}") | ||||||
print("***************************") | ||||||
except ReconciliationException as e: | ||||||
print(f"Exception : {str(e)}") | ||||||
print("***************************") | ||||||
except Exception as e: | ||||||
print(f"Exception : {str(e)}") | ||||||
print("***************************") | ||||||
|
||||||
# Check target_catalog.target_schema.aggregate_details table for the aggregated reconciliation |
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.
use it from the
__version__
variable from__about__.py