-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
100 additions
and
17 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
clean: | ||
rm -fr build .databricks dlt_meta.egg-info | ||
|
||
dev: | ||
python3 -m venv .databricks | ||
.databricks/bin/python -m pip install -e . |
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,49 @@ | ||
import json | ||
import logging | ||
import sys | ||
|
||
from databricks.connect.session import DatabricksSession | ||
from discoverx import DX | ||
|
||
|
||
logger = logging.getLogger('databricks.labs.discoverx') | ||
|
||
def scan(spark, from_tables: str = '*.*.*', rules: str = '*', sample_size: str = '10000', what_if: str = 'false', locale='US'): | ||
logger.info(f'scan: from_tables={from_tables} rules={rules}') | ||
dx = DX(spark=spark, locale=locale) | ||
dx.scan(from_tables=from_tables, rules=rules, sample_size=int(sample_size), what_if='true' == what_if) | ||
print(dx.scan_result.head()) | ||
|
||
|
||
MAPPING = { | ||
'scan': scan, | ||
} | ||
|
||
|
||
def main(raw): | ||
console_handler = logging.StreamHandler(sys.stderr) | ||
console_handler.setLevel('DEBUG') | ||
logging.root.addHandler(console_handler) | ||
|
||
payload = json.loads(raw) | ||
command = payload['command'] | ||
if command not in MAPPING: | ||
raise KeyError(f'cannot find command: {command}') | ||
flags = payload['flags'] | ||
log_level = flags.pop('log_level') | ||
if log_level != 'disabled': | ||
databricks_logger = logging.getLogger("databricks") | ||
databricks_logger.setLevel(log_level.upper()) | ||
|
||
kwargs = {k.replace('-', '_'): v for k,v in flags.items()} | ||
|
||
try: | ||
spark = DatabricksSession.builder.getOrCreate() | ||
MAPPING[command](spark, **kwargs) | ||
except Exception as e: | ||
logger.error(f'ERROR: {e}') | ||
logger.debug(f'Failed execution of {command}', exc_info=e) | ||
|
||
|
||
if __name__ == "__main__": | ||
main(*sys.argv[1:]) |
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
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
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
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,24 @@ | ||
--- | ||
name: discoverx | ||
description: Multi-table operations over the Lakehouse | ||
entrypoint: discoverx/cli.py | ||
min_python: 3.10 | ||
commands: | ||
- name: scan | ||
description: Scans the lakehouse | ||
flags: | ||
- name: locale | ||
default: US | ||
description: Locale for scanning | ||
- name: from_tables | ||
default: '*.*.*' | ||
description: The tables to be scanned in format "catalog.schema.table", use "*" as a wildcard. Defaults to "*.*.*". | ||
- name: rules | ||
default: '*' | ||
description: The rule names to be used to scan the lakehouse, use "*" as a wildcard. Defaults to "*". | ||
- name: sample_size | ||
default: 10000 | ||
description: The number of rows to be scanned per table. Defaults to 10000. | ||
- name: what_if | ||
default: false | ||
description: Whether to run the scan in what-if mode and print the SQL commands instead of executing them. Defaults to False. |
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,3 +1,5 @@ | ||
# Databricks notebook source | ||
|
||
from discoverx import dx | ||
|
||
# COMMAND ---------- | ||
|
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