A partition is composed of a subset of rows in a table that share the same value for a predefined subset of columns
called the partitioning columns.
Using partitions can speed up queries against the table as well as data manipulation.
To use partitions, you define the set of partitioning column when you create a table by including the PARTITIONED BY clause.
When inserting or manipulating rows in a table Azure Databricks automatically dispatches rows into the appropriate partitions.
You can also specify the partition directly using a PARTITION clause.
This syntax is also available for tables that don’t use Delta Lake format, to DROP, ADD or RENAME partitions quickly by using the ALTER TABLE statement.
PARTITIONED BY
The PARTITIONED BY clause specified a list of columns along which the new table is partitioned.
An identifier may reference a column_identifier in the table. If you specify more than one column there must be no duplicates.
If you reference all columns in the table’s column_specification an error is raised.
Unless the partition_column refers to a column_identifier in the table’s column_specification, column_type defines the data type of the partition_column.
Not all data types supported by Databricks SQL are supported by all data sources.
Notes
Unless you define a Delta Lake table partitioning columns referencing the columns in the column specification are always moved to the end of the table.
PARTITION
You use the PARTITION clause to identify a partition to be queried or manipulated.
A partition is identified by naming all its columns and associating each with a value.
You need not specify them in a specific order.
Unless you are adding a new partition to an existing table you may omit columns or values to indicate that the operation applies to the all matching partitions matching the subset of columns.
A column named as a partition column of the table.
You may not specify the same column twice.
= partition_value
A literal of a data type matching the type of the partition column.
If you omit a partition value the specification will match all values for this partition column.
Matches the string representation of partition_column to pattern.
pattern must be a string literal as used in LIKE.
Examples
SQL
-- Use the PARTTIONED BY clause in a table definition
> CREATETABLE student(university STRING,
major STRING,
nameSTRING)
PARTITIONED BY(university, major)
> CREATETABLE professor(nameSTRING)
PARTITIONED BY(university STRING,
department STRING);
-- Use the PARTITION specification to INSERT into a table
> INSERTINTO student
PARTITION(university= 'TU Kaiserslautern') (major, name)
SELECT major, nameFROM freshmen;
-- Use the partition specification to add and drop a partition
> CREATETABLElog(dateDATE, idINT, eventSTRING)
USING CSV
PARTITIONED BY (date);
> ALTERTABLElogADDPARTITION(date = DATE'2021-09-10');
> ALTERTABLElogDROPPARTITION(date = DATE'2021-09-10');
-- Drop all partitions from the named university, independent of the major.
> ALTERTABLE student DROPPARTITION(university = 'TU Kaiserslautern');
Tables in a Microsoft Fabric lakehouse are based on the Delta Lake technology commonly used in Apache Spark. By using the enhanced capabilities of delta tables, you can create advanced analytics solutions.
Demonstrate understanding of common data engineering tasks to implement and manage data engineering workloads on Microsoft Azure, using a number of Azure services.