Syntax Flashcards
Search for database
show databases like ‘*name*’
Search for table
show tables in attribution like ‘*tablename*’
Query files under table
select distinct input_file_name() from database.tablename
Query table metadata (2 types)
describe table [extended] database.tablename
describe detail database.tablename
Get table history
describe history database.tablename
Get Point in time for table
select * from database.table timestamp as of ‘2023-04-12T13:43:30’
Search file system
dbutils.fs.ls(“/”)
Return X number of records in sql query
Select * from database.tablename Limit X
Use data frame to build temporary view
df.createOrReplaceTempView(“database.viewname”
Move file data into dataframe
df = (
spark.read
.format(“csv”)
.option(“delimter”,”,”)
.option(“header”,”true”)
.load(“/mnt/folder”)
)
List secrets in scope
dbutils.secrets.list(“scopename”)
View all scopes
dbutils.secrets.listscopes()
Filter rows in data frame
df = df.filter(
(df.city == “Ki”) & (df.province == “Zu”)
)
Execute notebook with widgets
dbutils.notebook.run( path=”/Users/”,
timeout_seconds=12,
{
“mountPoint”:”/mnt/”
}
)
Activate intellisense
Tab