Tables
kelp.tables
¶
Generic model metadata API for use in any Spark job.
MaterializedContext
dataclass
¶
Execution context optionally injected into materialized functions.
Attributes:
| Name | Type | Description |
|---|---|---|
spark |
SparkSession
|
Active SparkSession. |
this |
str
|
Fully qualified target table name (or provided name when unresolved). |
target_exists |
bool
|
Whether the target table exists before materialization. |
full_refresh |
bool
|
Whether a full refresh was requested by the caller. |
is_incremental
¶
init
¶
init(
project_file_path=None,
target=None,
init_vars=None,
manifest_file_path=None,
refresh=False,
store_in_global=True,
run_policy_checks=False,
log_level=None,
)
Initialize kelp runtime context from current directory.
When manifest_file_path is provided (or resolved from KELP_MANIFEST_FILE
environment variable), the context is loaded directly from a pre-built
manifest JSON file, skipping all project discovery, Jinja rendering, and
metadata loading.
When policy_config.enabled is True in the project settings, metadata
governance policies are evaluated immediately after loading. Warn-severity
violations are logged; error-severity violations raise a RuntimeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_file_path
|
str | None
|
Path to project file or directory. |
None
|
target
|
str | None
|
Target environment name. |
None
|
init_vars
|
dict[str, Any] | None
|
Runtime variable overrides. |
None
|
manifest_file_path
|
str | None
|
Path to a manifest JSON file. When provided, skips source file loading. Also resolved from KELP_MANIFEST_FILE env var. |
None
|
refresh
|
bool
|
If True, recreate context even if one already exists. |
False
|
store_in_global
|
bool
|
Whether to store context globally. |
True
|
run_policy_checks
|
bool
|
Whether to run policy checks. |
False
|
log_level
|
str | None
|
Optional log level to configure. |
None
|
Returns:
| Type | Description |
|---|---|
MetaRuntimeContext
|
The initialized MetaRuntimeContext. |
Source code in src/kelp/config/config.py
columns
¶
ddl
¶
func
¶
Get the fully qualified name for a Unity Catalog function.
get_model
¶
ref
¶
schema
¶
Get the Spark schema DDL for a model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Model name. |
required |
exclude
|
list[str] | None
|
Column names to exclude from the schema. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
Spark schema DDL string, or |
Source code in src/kelp/tables/api.py
schema_lite
¶
Get the raw Spark schema without constraints or generated columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Model name. |
required |
exclude
|
list[str] | None
|
Column names to exclude from the schema. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
Spark schema DDL string, or |
Source code in src/kelp/tables/api.py
source
¶
source_options
¶
materialize
¶
materialize(
*,
dataframe,
name,
config=None,
full_refresh=False,
sync_metadata=True,
apply_vacuum=True,
vacuum_lite=True,
apply_optimize=True,
apply_quality_checks=True,
spark=None,
)
Materialize a DataFrame to Delta Lake based on materialization config.
Strategy: - Resolve model metadata by table name (if available). - Merge metadata materialization config with passed runtime config. - Dispatch to append/overwrite or merge materializers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe
|
DataFrame
|
DataFrame to materialize. |
required |
name
|
str
|
Kelp model name or fully qualified table name. |
required |
config
|
ModelMaterializationConfig | None
|
Optional runtime override materialization config. |
None
|
full_refresh
|
bool
|
Whether to perform a full refresh, which may be prevented by model config. |
False
|
sync_metadata
|
bool
|
Whether to perform metadata sync after materialization. |
True
|
apply_vacuum
|
bool
|
Whether to apply VACUUM after materialization. |
True
|
vacuum_lite
|
bool
|
Whether to use VACUUM LITE (if False, full VACUUM is applied). Only applicable if apply_vacuum is True. |
True
|
apply_optimize
|
bool
|
Whether to apply OPTIMIZE after materialization. |
True
|
spark
|
SparkSession | None
|
Optional SparkSession to use for materialization. If not provided, the active SparkSession will be used. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The same input DataFrame (for chaining). |
Source code in src/kelp/tables/materialization/factory.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
materialized
¶
materialized(
func=None,
*,
name=None,
config=None,
depends_on=None,
full_refresh=False,
apply_vacuum=True,
vacuum_lite=True,
apply_optimize=True,
apply_quality_checks=True,
)
Decorator that materializes the returned DataFrame.
Model matching uses name when provided; otherwise the wrapped function
name is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Optional kelp model/table name. |
None
|
config
|
ModelMaterializationConfig | dict | None
|
Optional materialization override config. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[..., DataFrame]], Callable[..., DataFrame]]
|
Decorated callable returning the same DataFrame after materialization. |
Source code in src/kelp/tables/materialization/decorator.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
kelp.service.model_manager.KelpModel
dataclass
¶
KelpModel(
name,
table_type=None,
comment=None,
table_properties=None,
spark_conf=None,
path=None,
partition_cols=None,
cluster_by_auto=None,
cluster_by=None,
row_filter=None,
auto_ttl=None,
fqn=None,
schema=None,
schema_lite=None,
dqx_quality=None,
validation_table=None,
quarantine_table=None,
target_table=None,
root_model=None,
materialization=None,
meta=None,
)
build_ddl
¶
Build a CREATE TABLE DDL statement directly from this model's properties.
Unlike :meth:get_ddl, this does not require root_model — it uses
schema, fqn, table_type, table_properties,
cluster_by, partition_cols, path, and comment
directly from the dataclass fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
if_not_exists
|
bool
|
Emit |
True
|
Returns:
| Type | Description |
|---|---|
str | None
|
DDL string, or |
Source code in src/kelp/service/model_manager.py
get_ddl
¶
Source code in src/kelp/service/model_manager.py
kelp.service.model_manager.KelpSdpModel
dataclass
¶
KelpSdpModel(
name,
table_type=None,
comment=None,
table_properties=None,
spark_conf=None,
path=None,
partition_cols=None,
cluster_by_auto=None,
cluster_by=None,
row_filter=None,
auto_ttl=None,
fqn=None,
schema=None,
schema_lite=None,
dqx_quality=None,
validation_table=None,
quarantine_table=None,
target_table=None,
root_model=None,
materialization=None,
meta=None,
expect_all=None,
expect_all_or_fail=None,
expect_all_or_drop=None,
expect_all_or_quarantine=None,
)
Bases: KelpModel
params
¶
Source code in src/kelp/service/model_manager.py
params_raw
¶
params_cst
¶
Source code in src/kelp/service/model_manager.py
get_sdp_params
¶
Source code in src/kelp/service/model_manager.py
get_ddl
¶
Source code in src/kelp/service/model_manager.py
build_ddl
¶
Build a CREATE TABLE DDL statement directly from this model's properties.
Unlike :meth:get_ddl, this does not require root_model — it uses
schema, fqn, table_type, table_properties,
cluster_by, partition_cols, path, and comment
directly from the dataclass fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
if_not_exists
|
bool
|
Emit |
True
|
Returns:
| Type | Description |
|---|---|
str | None
|
DDL string, or |