Skip to content

read

laktory.dlt.read ยค

read(*args, **kwargs)

When is_debug() is True read table from storage, else read table from pipeline with native Databricks dlt.read

RETURNS DESCRIPTION
SparkDataFrame

Ouput dataframe

Examples:

from laktory import dlt

dlt.spark = spark

def define_table():
    @dlt.table(name="slv_stock_prices")
    def get_df():
        df = dlt.read("dev.finance.brz_stock_prices")
        return df

    return get_df

define_table()
Source code in laktory/dlt/__init__.py
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
def read(*args, **kwargs) -> SparkDataFrame:
    """
    When `is_debug()` is `True` read table from storage, else read table from
    pipeline with native Databricks `dlt.read`

    Returns
    -------
    :
        Ouput dataframe

    Examples
    --------
    ```py
    from laktory import dlt

    dlt.spark = spark

    def define_table():
        @dlt.table(name="slv_stock_prices")
        def get_df():
            df = dlt.read("dev.finance.brz_stock_prices")
            return df

        return get_df

    define_table()
    ```
    """
    if is_debug():
        return spark.read.table(args[0])
    else:
        # Remove catalog and schema from naming space
        args = list(args)
        args[0] = args[0].split(".")[-1]
        return _read(*args, **kwargs)