Skip to main content

Delta Lake

Data Lake Target Long Term Storage

Synopsis​

The Delta Lake target writes records to Delta Lake tables. A table can be on a local disk, in Amazon S3 or in Azure Blob Storage. Search, Spark, Microsoft Fabric and Databricks can read the tables that the target writes.

The target writes each record as a row of a Parquet data file, and adds the file to its table with a Delta commit. One target can write several tables, and a route chooses the table for each record.

note

The web interface has no card for the Delta Lake target. Configure it in a Director configuration file.

Schema​

- name: <string>
description: <string>
type: deltalake
status: <boolean>
properties:
location: <string>
unity_catalog:
url: <string>
catalog: <string>
schema: <string>
token: <string>
client_id: <string>
client_secret: <string>
token_url: <string>
scope: <string>
table: <string>
schema: <string>
partition_by: <string[]>
compression: <string>
iceberg: <boolean>
tables:
- table: <string>
location: <string>
schema: <string>
retention: <string>
retention_column: <string>
compaction: <boolean>
partition_by: <string[]>
compression: <string>
iceberg: <boolean>
max_open_files: <numeric>
transaction_retention: <string>
retention: <string>
retention_column: <string>
maintenance_interval: <string>
compaction: <boolean>
batch_size: <numeric>
max_size: <numeric>
max_rows_per_rowgroup: <numeric>
timeout: <numeric>
interval: <numeric>
cron: <string>
field_format: <string>
key: <string>
secret: <string>
session: <string>
region: <string>
endpoint: <string>
use_path_style: <boolean>
connection_string: <string>
tenant_id: <string>
client_id: <string>
client_secret: <string>
account: <string>
debug:
status: <boolean>
dont_send_logs: <boolean>

Configuration​

The following fields are used to define the target:

FieldRequiredDefaultDescription
nameYTarget name
descriptionN-Optional description
typeYMust be deltalake
pipelinesN-Optional post-processor pipelines
statusNtrueEnable/disable the target

Tables​

FieldRequiredDefaultDescription
locationY*-Where the tables are: a directory, s3://bucket/path or az://container/path. A relative directory starts at the Director's root directory. Each table is a directory below the location, named after the table
tableN**-The table for every record whose route names no other table
schemaY-The table's columns: a Parquet schema from the Library, a JSON schema, or a column list such as TimeGenerated:datetime,Computer:string. See Columns
partition_byN-The columns that partition the table. Each must be a column of schema. See Partitions
compressionNsnappyThe compression of the data files: snappy, zstd, gzip or none
tablesN**-More tables. Each item sets table, and can set its own location, schema, partition_by and compression. A setting that an item leaves out comes from the target

* = Required unless the target writes the tables of a Unity Catalog catalog (unity_catalog).

** = Set table, tables, or both. A target without a table doesn't start.

A table name can hold letters, digits, _, - and ..

Commits​

FieldRequiredDefaultDescription
batch_sizeN100000A table's batch is committed early once it holds this many records
max_sizeN33554432A table's batch is committed early once its data files, and the records still held in memory, reach this many bytes (32 MB)
max_open_filesN1024The most data files that one table's batch writes at once, one for each partition. A record for one partition more makes the target commit the batch first
max_rows_per_rowgroupN10000The rows of each row group in a data file
timeoutN300How long one commit may take, in seconds, uploads of its data files included
transaction_retentionN1hHow long a table that the target creates remembers each payload that it committed. See No Duplicates on Retry. 0 keeps the record for good
field_formatN-Data normalization format. See applicable Normalization section

Scheduling​

The target commits what it has buffered once a minute. To commit on another schedule, set interval (seconds between commits) or cron. See Scheduling and Pool Behavior.

Amazon S3​

The target signs in to S3 as the Amazon S3 target does.

FieldRequiredDefaultDescription
keyN-AWS access key ID. Without key and secret, the target uses the AWS SDK's default credentials, such as the environment or an instance role
secretN-AWS secret access key
sessionN-Session token for temporary credentials
regionN-AWS region of the bucket
endpointN-The endpoint of an S3-compatible store
use_path_styleNfalseUse path-style addressing. Set it for an endpoint without virtual-host DNS, such as MinIO or LocalStack

Azure Blob Storage​

The target signs in to Azure Blob Storage as the Azure Blob Storage target does: with a connection string, or with a service principal and the storage account.

FieldRequiredDefaultDescription
connection_stringN*-Azure Storage connection string
tenant_idN*-Azure tenant ID of the service principal
client_idN*-Client ID of the service principal
client_secretN*-Client secret of the service principal
accountN*-Storage account name

* = Set connection_string, or the service principal and the account.

Debug Options​

FieldRequiredDefaultDescription
debug.statusNfalseEnable debug logging
debug.dont_send_logsNfalseProcess logs but don't write them to the tables (testing)

Details​

Where Tables Live​

location names where the tables are, and each table is a directory below it, named after the table. For example, with location: s3://my-bucket/lake, the table events is in s3://my-bucket/lake/events.

  • A local directory: a path such as /var/lib/lake or lake. A relative path starts at the Director's root directory.
  • Amazon S3: s3://bucket/path. The bucket can also be in an S3-compatible store.
  • Azure Blob Storage: az://container/path. The container must exist before the target starts.

A table under tables can set its own location, so one target can write tables in more than one place.

The target reads each table when it starts. If it can't reach the storage, or a table can't take its records, the target doesn't start, and its error names the table.

Tables and Routing​

table is the catch-all table. It takes every record whose route names no other table, or names a table that the target doesn't have.

tables lists more tables. A route sends a record to one of them when it sets _vmetric.table to the table's name. Without a catch-all table, a record for a table that the target doesn't have is refused.

The target creates a table that doesn't exist yet, with the columns of schema and the partitions of partition_by.

Columns​

schema gives a table its columns. It takes one of these:

  • The name of a Parquet schema in the Library.
  • A JSON schema, as described on the Parquet page.
  • A column list, such as TimeGenerated:datetime,Computer:string,EventID:int.

The columns can be STRING, BOOLEAN, DOUBLE, FLOAT, INT32, INT64 or DATETIME. A partition column can also be a DATE. The target refuses a list, a group or a dotted column name.

Each record is a JSON object, and its fields fill the columns of the same name. A record that is JSON but not an object, such as an array, is refused. A field that the schema doesn't list is not written.

VARIANT Columns​

A column can also be a VARIANT. A VARIANT column holds semi-structured data, such as a JSON object, in a binary form that queries can read field by field.

  • In a Parquet schema, a field of type VARIANT becomes a VARIANT column. It must be optional: the target refuses a required VARIANT field.
  • In a column list, a dynamic column becomes a VARIANT column, as in TimeGenerated:datetime,Properties:dynamic.

The target shreds a VARIANT column when the table allows it: the data files also store the fields that most documents have in columns of their own, so a query that reads one of those fields reads only that column. A table that the target creates with a VARIANT column allows shredding. Where a table doesn't allow it, the target writes the column unshredded. See VARIANT Columns in Delta Tables on the Search page for the readers that can open each kind of table.

A VARIANT column can't partition a table.

Partitions​

partition_by names the columns that partition a table. A partition column can be STRING, BOOLEAN, INT32, INT64, DATE or DATETIME. A table needs at least one column that doesn't partition it.

Choose partition columns with few values, such as a day or a region. A partition is one combination of the partition columns' values. Each commit writes a data file of its own for every partition that it has records for. A column with many values, such as a host name, makes many small files.

max_open_files limits how many data files one batch writes at once. When a record would open one more, the target commits the batch first.

A partition column's values are kept in the table's log and in the names of the files' directories, not in the data files.

Iceberg Metadata​

With iceberg: true, each table that the target creates also carries Apache Iceberg metadata, as Delta's UniForm writes it. Readers of Iceberg tables then read the table's data files in place, so the data is stored once. Set it for the whole target, or for one table under tables.

FieldRequiredDefaultDescription
icebergNfalsetrue makes each table that the target creates also an Iceberg table. Each item of tables can set its own
targets:
- name: lake
type: deltalake
properties:
location: "s3://my-bucket/lake"
region: "us-east-1"
table: events
schema: "TimeGenerated:datetime,Computer:string,Day:date"
partition_by: [Day]
iceberg: true
tables:
- table: audit
iceberg: false
  • New tables only. The setting applies to the tables that the target creates. A table that was there already keeps its properties: the target logs a warning once and writes no Iceberg metadata for it. To turn the metadata on for such a table, run Search's ALTER TABLE ... SET TBLPROPERTIES ('delta.universalFormat.enabledFormats' = 'iceberg') on it. See Iceberg Metadata for Delta Tables on the Search page.
  • Tables made UniForm elsewhere. A table that another writer made a UniForm table gets its Iceberg metadata whatever the setting says.
  • When it is written. The target writes the metadata after each commit, without making the commit wait. If writing it fails, the commit still stands: the target logs a warning, and the table's next commit or its next maintenance writes what is missing.
  • What changes in the table. Such a table maps its columns by name and tracks its rows' IDs. Each data file also holds the values of the table's partition columns. Readers of the table as a Delta table must support column mapping by name.
  • Maintenance. The target's scheduled VACUUM also brings the metadata up to date and expires its old snapshots.
  • Azure Blob Storage. The metadata names the files by abfss://<container>@<account>.dfs.core.windows.net/... URLs.
  • Unity Catalog. A table of a Unity Catalog catalog can't set iceberg: the target refuses to start. Turn on UniForm in the catalog instead.

Commits​

The target buffers records for each table, and commits them once a minute, or on the schedule that interval or cron sets. A table's batch is also committed early when it reaches batch_size records or max_size bytes.

Each commit adds a data file for each partition that it wrote, and a new version of the table. Readers see the rows once the commit lands.

When a commit fails, the target sends the batch's records again. Other tables of the same target are still committed.

No Duplicates on Retry​

A payload that the Director sends again doesn't add its rows twice. Each commit records which payloads it holds. When a payload comes back, the target leaves out the records that the table already holds.

A table that the target creates keeps this record for transaction_retention, one hour by default. The hour counts while the table is written to: a pause in its commits, such as a Director that was down for a day, counts 10 minutes at most. A payload that keeps coming back has its record renewed, for up to the Director's persistent_storage.max_age (48 hours by default).

Keep transaction_retention short. The table's log, each of its checkpoints and the Director's memory hold about one record for each payload of that period.

Another engine that writes a checkpoint of the table, such as Spark with OPTIMIZE, counts the time by the clock. If the Director is down for longer than transaction_retention while such an engine writes a checkpoint, a payload that comes back after that can add its rows twice.

A table that the target creates also writes a checkpoint every 100 commits (delta.checkpointInterval) and keeps its log for 2 days (delta.logRetentionDuration). A table that was there before keeps its own properties. To give it the same behaviour, set delta.setTransactionRetentionDuration, delta.checkpointInterval and delta.logRetentionDuration on it with ALTER TABLE ... SET TBLPROPERTIES. If such a table has no delta.setTransactionRetentionDuration, the target logs a warning, because the table then keeps the record of every payload.

Table Maintenance​

The target maintains the tables it writes, on a schedule. Maintenance is on by default and runs every hour, so nobody has to run OPTIMIZE or VACUUM by hand.

Upgrading

A target that was set up before maintenance existed starts maintaining its tables every hour as soon as the Director is upgraded. It merges small data files, and deletes data files and log files that the tables no longer need, by each table's own Delta retention settings. It removes rows only when retention is set. To keep the old behaviour, set maintenance_interval: 0.

FieldRequiredDefaultDescription
retentionN-How long a table keeps its rows, such as 30d, 2w or 12h. Empty or 0 keeps every row. A value under one hour is refused, because 30m means 30 minutes, not 30 months. Each item of tables can set its own
retention_columnNsee belowThe DATE or DATETIME column that says how old a row is. Each item of tables can set its own
maintenance_intervalN1hHow often maintenance runs, such as 1h or 1d. It must be at least one minute. 0 turns maintenance off
compactionNtrueMerges the small data files of each partition during maintenance. false turns it off for the target's tables, or, set on an item of tables, for that table

Without retention_column, the target takes the table's first DATE or DATETIME partition column. If there is none, it takes the table's only DATE or DATETIME column. If the table has several such columns and none partitions it, set retention_column: the target doesn't start until it knows which one to use.

The target checks these settings when it starts. A wrong value stops the target with an error that says what to fix. retention together with maintenance_interval: 0 is refused, because nothing would then remove the old rows.

What a Run Does​

Each run does these things to each table, in this order:

  1. Removes old rows. Where the table has a retention, the run removes the rows older than it, in one commit that the table's history shows as a DELETE. A table partitioned by its retention column loses whole partitions: a day goes once all of it is older than retention. Any other table loses the data files whose rows are all older. A row that shares a data file with newer rows can stay a while longer. A row whose retention column is NULL always stays, and so do the rows of a data file that has no statistics for that column, as some other engines write such files.
  2. Merges small files. The run merges the small data files of each partition into larger ones, as OPTIMIZE does. The merge keeps every row as it was, and never blocks the target's commits. The merged files stay in storage until VACUUM deletes them.
  3. Writes a checkpoint when the table's newest checkpoint is delta.checkpointInterval versions or more behind, as after a checkpoint that failed. That interval is 100 for a table the target creates, and 10 for other tables by default.
  4. Deletes old log files: the files of the table's log that are older than its delta.logRetentionDuration. That is 2 days for a table the target creates, and 30 days for other tables by default.
  5. Runs VACUUM, which deletes the data files that no version of the table needs, once the table's delta.deletedFileRetentionDuration has passed (7 days by default). It never deletes a file younger than one hour, or younger than the target's commit timeout if that is longer. So the files of a commit that is still being written stay.

A step that fails is logged as a warning, and the next run tries it again. The other steps still run.

The target keeps appending while a run commits. Appends and the removal of old rows don't conflict, so both land.

The first run comes about a minute after the target starts.

Which Director Runs It​

In a Director cluster, only the cluster's leader maintains the tables. A Director that isn't in a cluster maintains them itself. A Director that can't tell whether it leads its cluster skips that run and logs a warning.

Before You Set Retention​

  • Removed rows can't be brought back once VACUUM's retention has passed. A retention that is too short deletes data for good.
  • Large tables take longer. Each run lists every file of each table, its log included. On a very large table in S3 that is slow, so choose a longer maintenance_interval for it.

This example keeps the catch-all table's rows for 30 days, and the auth_events table's rows for 90 days:

targets:
- name: lake_with_retention
type: deltalake
properties:
location: "s3://my-bucket/lake"
region: "us-east-1"
table: "events"
schema: "TimeGenerated:datetime,Computer:string,Message:string"
retention: 30d
maintenance_interval: 1h
tables:
- table: auth_events
schema: "TimeGenerated:datetime,Account:string,Result:string,Day:date"
partition_by: [Day]
retention: 90d

Sign-In​

Amazon S3: the target uses key, secret and session, or the AWS SDK's default credentials. region, endpoint and use_path_style work as on the Amazon S3 target.

An S3-compatible store must support conditional writes (If-None-Match), as Amazon S3 does. The target relies on them so that two writers can't both write the same version of a table. It checks the store when it starts, and refuses to start on a store that doesn't support them.

Azure Blob Storage: the target uses connection_string, or tenant_id, client_id and client_secret with account.

Credential fields take plain text, ${VARIABLE} or $secret{...}.

Unity Catalog​

With a unity_catalog block, the target writes the Delta tables of a Unity Catalog catalog instead of tables at a storage location. The catalog can be on Databricks or on the open-source Unity Catalog server, version 0.5.0 or later. Databricks, Spark and the catalog's other clients then read what the target writes as part of the catalog's tables.

targets:
- name: lake
type: deltalake
properties:
unity_catalog:
url: "https://<workspace>.cloud.databricks.com"
catalog: main
schema: security
token: "$secret{databricks-token}"
table: events
schema: "TimeGenerated:datetime,Computer:string,EventID:int,Message:string"
tables:
- table: firewall
- table: archive
location: "s3://my-bucket/archive"
FieldRequiredDefaultDescription
unity_catalog.urlY-The catalog's server: a Databricks workspace's URL, or the open-source server's URL, such as http://localhost:8080
unity_catalog.catalogY-The catalog that holds the target's tables
unity_catalog.schemaNdefaultThe catalog's schema that holds the tables
unity_catalog.tokenN*-A Databricks personal access token, or the open-source server's token
unity_catalog.client_idN*-The application ID of an OAuth service principal. Set it together with client_secret
unity_catalog.client_secretN*-The service principal's secret. Set it together with client_id
unity_catalog.token_urlN<url>/oidc/v1/tokenWhere the service principal's access token comes from
unity_catalog.scopeNall-apisThe scope of the service principal's access token

* = Sign in with token, or with client_id and client_secret. The open-source server needs no sign-in by default.

unity_catalog.schema is a schema of the catalog: a namespace that holds tables. The target's own schema is still the tables' columns. They are different settings.

Leave the target's location out when you set unity_catalog. A table under tables that sets its own location is written there, outside the catalog, as archive is in the example above. The target signs in to the catalog once, and all of its tables in the catalog share that sign-in.

How the Target Writes a Catalog's Tables​

  • When it starts, the target looks up each of its tables in the catalog's schema: table, and each item of tables that doesn't set its own location. It creates a table that doesn't exist yet as a managed table, with the target's columns and partition_by.
  • The catalog hands out short-lived credentials for each table's files in S3 or Azure Blob Storage. The target renews them before they expire. If the catalog hands out none, the target signs in to the storage with its own S3 or Azure settings.
  • In S3, region, endpoint and use_path_style still apply. Without region, the target asks Amazon S3 for the bucket's region. In Azure, endpoint replaces the storage account's endpoint.
  • A managed table's commits go through the catalog. A payload that the Director sends again still adds no row twice, as with a table at a storage location.
  • The target also writes the catalog's external tables.
  • If someone drops a table and creates another under the same name, the target starts again on the new table.

What the Target Refuses​

The target refuses to start in these cases, with an error that names the setting or the table:

CaseWhat to do
Both location and unity_catalog are set at the target levelLeave location out. To write one table outside the catalog, set location on that table under tables
unity_catalog has no url or no catalog, or an empty schemaSet the setting the error names
client_id is set without client_secret, or the other way roundSet both, or neither
A table name holds a dot, such as sales.eventsName the table alone, and set the schema under unity_catalog
Two of the catalog's tables have names that differ only by caseRename one. Unity Catalog doesn't tell table names apart by case
A table is in Google Cloud Storage, or on a local disk of the catalog's serverWrite the table in S3 or Azure Blob Storage. The target doesn't write tables in those places
A table's location holds a user name or a passwordGive the table a location without them
A managed table's commits don't go through the catalogWrite to a managed table whose commits the catalog manages (the Delta table feature catalogManaged), or to an external table

Maintenance of a Catalog's Tables​

Databricks doesn't let the target run VACUUM or delete the old log files of its managed tables, and runs that maintenance itself. The target's scheduled maintenance skips both, and it doesn't merge the small files of a catalog's tables either. It says so once in its log when it starts.

The target still removes the rows older than a table's retention, with a commit through the catalog. Their data files stay in storage until the catalog's own maintenance deletes them, and the target logs a warning saying so.

Permissions on Databricks​

The principal that the target signs in as needs these Unity Catalog privileges:

  • USE CATALOG on the catalog.
  • USE SCHEMA, CREATE TABLE and EXTERNAL USE SCHEMA on the schema.
  • SELECT and MODIFY on each table that already exists.

The metastore must also allow external data access.

Existing Tables​

The target appends to a table that is already there, when the table's columns and partitions match the target's:

  • The table must be partitioned by the columns of partition_by, in the same order.
  • Each column of schema must be a column of the table, with the same name and type. Names must match in case too.
  • A column of the table that the schema leaves out reads as empty (NULL) in the rows the target adds.
  • A table column that takes no NULL needs a required column in the schema.

The target refuses to start on a table that doesn't match, and its error says what to change.

Tables That Spark and Databricks Created​

The target also appends to tables that Spark and Databricks created. Such tables often turn on Delta features that ask a writer for more than its rows. Databricks turns several of them on for its managed tables. The target writes these features:

FeatureWhat the target does
Column mapping, by name or by idWrites each column under the physical name and the field ID that the table's schema gives it
Row trackingGives the rows their IDs, and keeps the table's row IDs unique, also when two writers commit at once
Liquid clusteringKeeps the table's clustering columns. An append doesn't cluster its own rows, as Spark's appends don't
CHECK constraints and NOT NULL invariantsChecks each record before writing it
Generated columnsAlways writes the value of the column's expression, also over a value that the record gives
Default valuesFills in a column that the record leaves out or holds as null
Identity columnsNumbers the rows when it commits. A column GENERATED ALWAYS gives every row its value. A column GENERATED BY DEFAULT keeps a value that the record gives, and numbers only the rows that have none

The target's schema doesn't need to list the columns that the target fills in. A partition column that a rule fills in, such as a day generated from a time, must stay in schema and partition_by. The target computes the rules with Search's SQL, in UTC.

Records That Break a Rule​

  • The record is left out. A record that fails a CHECK constraint or an invariant is not written. So is a record that, after the target filled in its columns, still has no value for a column that the target fills in and that takes no NULL. The batch's other records are still written.
  • It counts as dropped in the target's statistics.
  • The target logs a warning for each table and rule: at once, and then at most once a minute, with a count. The warning names the table and the rule, and never shows the record's values.
  • No duplicates. A payload that the Director sends again leaves the same records out.

A NOT NULL column of the target's schema that a record has no value for gets the column type's zero value, such as empty text. A partition column is the exception: the target refuses a record that has no value for a partition column that takes no NULL.

Tables the Target Refuses​

The target refuses these tables when it starts, with an error that names the table and what to do. Usually the answer is to let the target create its own table, or to write to another table.

  • A table that turns on a Delta feature the target doesn't write, such as Iceberg compatibility V1 or V2 (delta.enableIcebergCompatV1, delta.enableIcebergCompatV2).
  • A rule that calls a function that Search doesn't have, such as Spark's date_format, to_date, nvl or RLIKE.
  • A rule that holds text in double quotes. Spark reads such text as a string, and Search reads it as a column name. Write the text in single quotes.
  • A rule that casts a value that is not an integer to an integer type. Spark and Search compute such casts differently.
  • A rule that reads an identity, decimal, binary, VARIANT or nested column, and an invariant of a nested field.
  • A generated, default or identity column of a decimal, binary or nested type.

Identity Columns and Several Writers​

A table with identity columns takes its commits one writer at a time. When another writer gives the column values at the same time, one of the two commits fails, and the target sends its records again. Several Directors that write one such table therefore retry each other's commits.

Examples​

Local Directory​

A table on the Director's own disk, partitioned by day:

targets:
- name: local_lake
type: deltalake
properties:
location: "lake"
table: "events"
schema: "TimeGenerated:datetime,Computer:string,EventID:int,Message:string,Day:date"
partition_by: [Day]

Amazon S3​

targets:
- name: s3_lake
type: deltalake
properties:
location: "s3://my-bucket/lake"
key: "AKIAIOSFODNN7EXAMPLE"
secret: "$secret{aws-secret}"
region: "us-east-1"
table: "events"
schema: "TimeGenerated:datetime,Computer:string,EventID:int,Message:string"

Azure Blob Storage​

targets:
- name: azure_lake
type: deltalake
properties:
location: "az://lake-container/tables"
tenant_id: "00000000-0000-0000-0000-000000000000"
client_id: "11111111-1111-1111-1111-111111111111"
client_secret: "$secret{lake-sp-secret}"
account: "mystorageaccount"
table: "events"
schema: "TimeGenerated:datetime,Computer:string,EventID:int,Message:string"

Several Tables​

A catch-all table and two more. The auth_events table has its own columns and partitions, and the dns table is in another container:

targets:
- name: multi_lake
type: deltalake
properties:
location: "az://lake-container/tables"
connection_string: "$secret{lake-connection-string}"
table: "events"
schema: "TimeGenerated:datetime,Computer:string,Message:string"
tables:
- table: auth_events
schema: "TimeGenerated:datetime,Account:string,Result:string,Day:string"
partition_by: [Day]
- table: dns
location: "az://other-container/lake"