HiveMetastoreDataSink
laktory.models.datasinks.HiveMetastoreDataSink
¤
Bases: TableDataSink
Data sink writing to a Hive Metastore data table.
PARAMETER | DESCRIPTION |
---|---|
dataframe_backend
|
Type of DataFrame backend
TYPE:
|
dataframe_api
|
DataFrame API to use in DataFrame Transformer nodes. Either 'NATIVE' (backend-specific) or 'NARWHALS' (backend-agnostic).
TYPE:
|
variables
|
Dict of variables to be injected in the model at runtime |
checkpoint_path
|
Path to which the checkpoint file for which a streaming dataframe should be written.
TYPE:
|
is_quarantine
|
Sink used to store quarantined results from a pipeline node expectations.
TYPE:
|
type
|
Sink Type
TYPE:
|
merge_cdc_options
|
Merge options to handle input DataFrames that are Change Data Capture (CDC). Only used when
TYPE:
|
mode
|
Write mode. Spark¤
Spark Streaming¤
Polars Delta¤
Laktory¤
TYPE:
|
writer_kwargs
|
Keyword arguments passed directly to dataframe backend writer. Passed to
TYPE:
|
writer_methods
|
DataFrame backend writer methods.
TYPE:
|
catalog_name
|
Sink table catalog name
TYPE:
|
format
|
Storage format for data table.
TYPE:
|
schema_name
|
Sink table schema name
TYPE:
|
table_name
|
Sink table name. Also supports fully qualified name (
TYPE:
|
table_type
|
Type of table. 'TABLE' and 'VIEW' are currently supported.
TYPE:
|
view_definition
|
View definition of 'VIEW'
TYPE:
|
Examples:
import laktory as lk
df = spark.createDataFrame([{"x": 1}, {"x": 2}, {"x": 3}])
sink = lk.models.HiveMetastoreDataSink(
schema_name="default",
table_name="my_table",
mode="APPEND",
)
# sink.write(df)
METHOD | DESCRIPTION |
---|---|
as_source |
Generate a table data source with the same properties as the sink. |
inject_vars |
Inject model variables values into a model attributes. |
inject_vars_into_dump |
Inject model variables values into a model dump. |
model_validate_json_file |
Load model from json file object |
model_validate_yaml |
Load model from yaml file object using laktory.yaml.RecursiveLoader. Supports |
purge |
Delete sink data and checkpoints |
push_vars |
Push variable values to all child recursively |
read |
Read dataframe from sink. |
validate_assignment_disabled |
Updating a model attribute inside a model validator when |
write |
Write dataframe into sink. |
ATTRIBUTE | DESCRIPTION |
---|---|
data_sources |
Get all sources feeding the sink
|
dlt_apply_changes_kwargs |
Keyword arguments for dlt.apply_changes function |
full_name |
Table full name {catalog_name}.{schema_name}.{table_name}
TYPE:
|
upstream_node_names |
Pipeline node names required to write sink |
data_sources
property
¤
Get all sources feeding the sink
dlt_apply_changes_kwargs
property
¤
Keyword arguments for dlt.apply_changes function
full_name
property
¤
Table full name {catalog_name}.{schema_name}.{table_name}
upstream_node_names
property
¤
Pipeline node names required to write sink
as_source(as_stream=None)
¤
Generate a table data source with the same properties as the sink.
PARAMETER | DESCRIPTION |
---|---|
as_stream
|
If
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
TableDataSource
|
Table Data Source |
Source code in laktory/models/datasinks/tabledatasink.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
|
inject_vars(inplace=False, vars=None)
¤
Inject model variables values into a model attributes.
PARAMETER | DESCRIPTION |
---|---|
inplace
|
If
TYPE:
|
vars
|
A dictionary of variables to be injected in addition to the model internal variables.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Model instance. |
Examples:
from typing import Union
from laktory import models
class Cluster(models.BaseModel):
name: str = None
size: Union[int, str] = None
c = Cluster(
name="cluster-${vars.my_cluster}",
size="${{ 4 if vars.env == 'prod' else 2 }}",
variables={
"env": "dev",
},
).inject_vars()
print(c)
# > variables={'env': 'dev'} name='cluster-${vars.my_cluster}' size=2
References
Source code in laktory/models/basemodel.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
|
inject_vars_into_dump(dump, inplace=False, vars=None)
¤
Inject model variables values into a model dump.
PARAMETER | DESCRIPTION |
---|---|
dump
|
Model dump (or any other general purpose mutable object) |
inplace
|
If
TYPE:
|
vars
|
A dictionary of variables to be injected in addition to the model internal variables. |
RETURNS | DESCRIPTION |
---|---|
Model dump with injected variables. |
Examples:
from laktory import models
m = models.BaseModel(
variables={
"env": "dev",
},
)
data = {
"name": "cluster-${vars.my_cluster}",
"size": "${{ 4 if vars.env == 'prod' else 2 }}",
}
print(m.inject_vars_into_dump(data))
# > {'name': 'cluster-${vars.my_cluster}', 'size': 2}
References
Source code in laktory/models/basemodel.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
|
model_validate_json_file(fp)
classmethod
¤
Load model from json file object
PARAMETER | DESCRIPTION |
---|---|
fp
|
file object structured as a json file
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Model
|
Model instance |
Source code in laktory/models/basemodel.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
|
model_validate_yaml(fp)
classmethod
¤
Load model from yaml file object using laktory.yaml.RecursiveLoader. Supports
reference to external yaml and sql files using !use
, !extend
and !update
tags.
Path to external files can be defined using model or environment variables.
Referenced path should always be relative to the file they are referenced from.
PARAMETER | DESCRIPTION |
---|---|
fp
|
file object structured as a yaml file
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Model
|
Model instance |
Examples:
businesses:
apple:
symbol: aapl
address: !use addresses.yaml
<<: !update common.yaml
emails:
- jane.doe@apple.com
- extend! emails.yaml
amazon:
symbol: amzn
address: !use addresses.yaml
<<: update! common.yaml
emails:
- john.doe@amazon.com
- extend! emails.yaml
Source code in laktory/models/basemodel.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
purge()
¤
Delete sink data and checkpoints
Source code in laktory/models/datasinks/tabledatasink.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
|
push_vars(update_core_resources=False)
¤
Push variable values to all child recursively
Source code in laktory/models/basemodel.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
|
read(as_stream=None)
¤
Read dataframe from sink.
PARAMETER | DESCRIPTION |
---|---|
as_stream
|
If
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
AnyFrame
|
DataFrame |
Source code in laktory/models/datasinks/basedatasink.py
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
|
validate_assignment_disabled()
¤
Updating a model attribute inside a model validator when validate_assignment
is True
causes an infinite recursion by design and must be turned off
temporarily.
Source code in laktory/models/basemodel.py
323 324 325 326 327 328 329 330 331 332 333 334 335 |
|
write(df=None, mode=None, full_refresh=False)
¤
Write dataframe into sink.
PARAMETER | DESCRIPTION |
---|---|
df
|
Input dataframe.
TYPE:
|
full_refresh
|
If
TYPE:
|
mode
|
Write mode overwrite of the sink default mode.
TYPE:
|
Source code in laktory/models/datasinks/basedatasink.py
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 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
|