Delta File Relations¶
deltaFile relation is used for creating Delta Lake tables stored only in some Hadoop
compatible file system, without registering the table in the Hive metastore. If you want to use a Delta Lake table,
and you also want to store its meta data in Hive, then use the deltaFile relation instead.
relations: some_delta_table: kind: deltaFile # Specify the physical location where the data files should be stored at. location: /warehouse/default/financial_transactions # Optional add partition column partitions: - name: business_date type: string # Specify the default key to use in upsert operations. Normally this should match the primary key # (except partition columns, which will be added implicitly) mergeKey: - id # Specify a schema, which is mandatory for creating the table during CREATE phase schema: kind: inline fields: - name: id type: string - name: amount type: double
schema(optional) (schema) (default: empty): Explicitly specifies the schema of the Delta Lake table. Alternatively Flowman will automatically use the schema of the Delta relation, if it already exists.
description(optional) (string) (default: empty): A description of the relation. This is purely for informational purpose.
options(optional) (map:string) (default: empty): All key-value pairs specified in options are directly passed to Apache Spark for reading and/or writing to this relation. The
optionswill not be persisted in the Hive metastore. If that is what you want, then have a closer look at
location(mandatory) (string) (default: empty): Specifies the location of where the Delta files will be created.
partitions(optional) (list:partition) (default: empty): Specifies all partition columns. This is used both for creating Hive tables, but also for writing and reading to and from them. Therefore if you are working with partitioned Hive tables you have to specify partition columns, even if Flowman is not used for creating the table. Normally the partition columns are separate from the schema, but you may also include the partition column in the schema, although this is not considered to be best practice. But it turns out to be quite useful in combination with dynamically writing to multiple partitions.
properties(optional) (map:string) (default: empty): Specifies additional properties of the Hive table. This setting is only used when Flowman is used to create the Delta table and is ignored otherwise.
mergeKey(optional) (list:string) (default: empty): List of column names specifying the key to identify matching records on
Flowman supports some automatic migrations, specifically with the migration strategies
REPLACE (those can be set via the global config variable
see configuration for more details).
The migration strategy
ALTER supports the following alterations:
- Changing nullability
- Changing the comment
- Adding new columns
Other changes (like changing the data type or dropping columns) is not supported in the
ALTER strategy and
will require either
ALTER_REPLACE - but this will remove all existing data in that table!
The Delta file relation fully supports automatic schema conversion on input and output operations as described in the corresponding section of relations.
deltaFile relation supports the following output modes in a relation target:
||yes||Throw an error if the Delta table already exists|
||yes||Do nothing if the Delta table already exists|
||yes||Overwrite the whole table or the specified partitions|
||yes||Overwrites all partitions where records are provided in the input data. Other partitions remain untouched|
||yes||Append new records to the existing table|
||yes||Updates existing records, either using
In addition, the
deltaFile relation also supports complex merge operations in a merge target.
Note that support
overwrite_dynamic is not perfect and is implemented in a two phase approach: First all partition
values are calculated, then the data is inserted. This implies that the input data is scanned twice, which might be an
expensive operation depending on the computational complexity and the amount of data.
In addition to batch writing, the Delta file relation also supports stream writing via the stream target with the following semantics:
||yes||Append new records from the streaming process once they don't change any more|
||yes||Append records every time they are updated|
Note that Flowman will rely on schema inference in some important situations, like mocking and generally for describing the schema of a relation. This might create unwanted connections to the physical data source, particular in case of self-contained tests. To prevent Flowman from creating a connection to the physical data source, you simply need to explicitly specify a schema, which will then be used instead of the physical schema in all situations where only schema information is required.
Writing to Dynamic Partitions¶
Beside explicitly writing to a single Hive partition, Flowman also supports to write to multiple partitions where
the records need to contain values for the partition columns. Note that currently Delta table do not support the
relation output mode
dynamic_overwrite with dynamic partitions, instead you can only use
This means, that whenever you write to a partitioned Delta table without explicitly specifying the target partition
in the relation target, then the table is truncated first and all normally unchanged partitions
will be lost.