-
Notifications
You must be signed in to change notification settings - Fork 17
Notebook examples #89
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
edurdevic
wants to merge
8
commits into
master
Choose a base branch
from
notebook-examples
base: master
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.
+291
−1
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
93c6e14
Added slide deck examples
edurdevic a36098b
Updated scan and search examples
edurdevic 9771273
Updated slide deck examples
08f4eae
Merge branch 'master' into notebook-examples
edurdevic 3b4fa07
Added table freshness
d5abb7d
Added delta protocol version check
68da83a
Updated readme
eb3c322
Updated notebooks based on feedback
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,126 @@ | ||
# Databricks notebook source | ||
# MAGIC %pip install dbl-discoverx | ||
edurdevic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# COMMAND ---------- | ||
|
||
dbutils.widgets.text("from_tables", "sample_data_discoverx.*.*") | ||
from_tables = dbutils.widgets.get("from_tables") | ||
|
||
|
||
# COMMAND ---------- | ||
|
||
from discoverx import DX | ||
|
||
dx = DX() | ||
|
||
# COMMAND ---------- | ||
|
||
# MAGIC %md | ||
# MAGIC ## Which are the biggest 10 tables in the "sample_data_discoverx" catalog? | ||
# MAGIC | ||
# MAGIC | ||
|
||
# COMMAND ---------- | ||
|
||
from pyspark.sql.functions import col | ||
|
||
(dx | ||
.from_tables("sample_data_discoverx.*.*") | ||
.with_sql("DESCRIBE DETAIL {full_table_name}") | ||
.apply() | ||
.orderBy(col("sizeInBytes").desc()) | ||
.display() | ||
) | ||
|
||
# COMMAND ---------- | ||
|
||
# MAGIC %md | ||
# MAGIC ## Which tables have the most daily transactions? | ||
|
||
# COMMAND ---------- | ||
|
||
from pyspark.sql.functions import window | ||
|
||
(dx | ||
.from_tables("sample_data_discoverx.*.*") | ||
.with_sql("DESCRIBE HISTORY {full_table_name}") | ||
.apply() | ||
.groupBy("table_catalog", "table_schema", "table_name", window("timestamp", "1 day")) | ||
.count() | ||
.display() | ||
) | ||
|
||
# COMMAND ---------- | ||
|
||
# MAGIC %md | ||
# MAGIC ## Which tables have too many small files? | ||
|
||
# COMMAND ---------- | ||
|
||
from pyspark.sql.functions import col, lit | ||
|
||
(dx | ||
.from_tables("sample_data_discoverx.*.*") | ||
.with_sql("DESCRIBE DETAIL {full_table_name}") | ||
.apply() | ||
.withColumn("average_file_size", col("sizeInBytes") / col("numFiles")) | ||
.withColumn("has_many_small_files", | ||
(col("average_file_size") < 10000000) & (col("numFiles") > 100)) | ||
.orderBy("average_file_size") | ||
.display() | ||
) | ||
|
||
# COMMAND ---------- | ||
|
||
# MAGIC %md | ||
# MAGIC ## Which tables contain email addresses? | ||
|
||
# COMMAND ---------- | ||
|
||
result = (dx | ||
.from_tables("sample_data_discoverx.*.*") | ||
.scan() # Returns a Discovery object | ||
) | ||
|
||
# Ideally, this should look like this: | ||
edurdevic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# (dx | ||
# .from_tables("sample_data_discoverx.*.*") | ||
# .scan() # This should return a DataExplorerActions object | ||
# .apply() # This should return a Dataframe | ||
# ) | ||
|
||
# and optionally | ||
# classes = (dx | ||
# .from_tables("sample_data_discoverx.*.*") | ||
# .scan() # This should return a DataExplorerActions object | ||
# .apply() # This should return a Dataframe | ||
# ) | ||
# dx.apply_tags(classes) | ||
|
||
|
||
# COMMAND ---------- | ||
|
||
# MAGIC %md | ||
# MAGIC ## Which tables contain the email address “erni@databricks.com”? | ||
|
||
# COMMAND ---------- | ||
|
||
result.search("erni@databricks.com").display() | ||
|
||
# Ideally this should look like | ||
# (dx | ||
# .from_tables("sample_data_discoverx.*.*") | ||
# .search("erni@databricks.com") # This should return a DataExplorerActions object | ||
# .apply() # This should return a Dataframe | ||
# ) | ||
|
||
# and optionally | ||
# (dx | ||
# .from_tables("sample_data_discoverx.*.*") | ||
# .search("erni@databricks.com", in_columns_tagged_with=["email"]) # This should return a DataExplorerActions object | ||
# .apply() # This should return a Dataframe | ||
# ) | ||
|
||
# COMMAND ---------- | ||
|
||
|
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.