API docs: reference documentation for classes and functions of datarepo project.¶
Databases catalog module¶
Catalog
¶
A catalog that manages multiple databases and provides access to their tables.
Source code in src/datarepo/core/catalog/catalog.py
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 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
|
__init__(dbs)
¶
Initialize the Catalog.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dbs
|
dict[str, Database]
|
A dictionary of database names and their corresponding Database objects. |
required |
Source code in src/datarepo/core/catalog/catalog.py
188 189 190 191 192 193 194 195 |
|
db(db_name)
¶
Get a database from the catalog.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_name
|
str
|
The name of the database. |
required |
Raises:
Type | Description |
---|---|
KeyError
|
If the database is not found. |
Returns:
Name | Type | Description |
---|---|---|
Database |
Database
|
The requested database. |
Source code in src/datarepo/core/catalog/catalog.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
dbs()
¶
Get a list of database names in the catalog.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: A list of database names. |
Source code in src/datarepo/core/catalog/catalog.py
229 230 231 232 233 234 235 |
|
set_global_args(global_args)
¶
Set global arguments for all database queries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
global_args
|
dict[str, Any]
|
A dictionary of global arguments to apply to all database queries. |
required |
Source code in src/datarepo/core/catalog/catalog.py
197 198 199 200 201 202 203 |
|
Database
¶
Bases: Protocol
A protocol for a database that provides access to tables.
Source code in src/datarepo/core/catalog/catalog.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
get_tables(show_deprecated=False)
¶
Get a dictionary of tables in the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
show_deprecated
|
bool
|
Whether to include deprecated tables. Defaults to False. |
False
|
Source code in src/datarepo/core/catalog/catalog.py
12 13 14 15 16 17 18 |
|
table(name, *args, **kwargs)
¶
Get a table from the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the table. |
required |
Returns:
Name | Type | Description |
---|---|---|
NlkDataFrame |
NlkDataFrame
|
The requested table. |
Source code in src/datarepo/core/catalog/catalog.py
31 32 33 34 35 36 37 38 39 40 |
|
tables(show_deprecated=False)
¶
Get a list of table names in the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
show_deprecated
|
bool
|
Whether to include deprecated tables. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: A list of table names. |
Source code in src/datarepo/core/catalog/catalog.py
20 21 22 23 24 25 26 27 28 29 |
|
ModuleDatabase
¶
Bases: Database
A database that is implemented as a Python module.
Source code in src/datarepo/core/catalog/catalog.py
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 |
|
__init__(db)
¶
Initialize the ModuleDatabase.
Example usage
import my_database_module
db = ModuleDatabase(my_database_module)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db
|
ModuleType
|
The database module. |
required |
Source code in src/datarepo/core/catalog/catalog.py
46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
get_tables(show_deprecated=False)
¶
Get a dictionary of tables in the database.
Example usage
db = ModuleDatabase(my_database_module)
tables = db.get_tables(show_deprecated=True)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
show_deprecated
|
bool
|
Whether to include deprecated tables. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
dict[str, TableProtocol]
|
dict[str, TableProtocol]: A dictionary of table names and their corresponding TableProtocol objects. |
Source code in src/datarepo/core/catalog/catalog.py
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 |
|
table(name, *args, **kwargs)
¶
Get a table from the database.
Example usage
db = ModuleDatabase(my_database_module)
table = db.table("my_table")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the table. |
required |
Raises:
Type | Description |
---|---|
KeyError
|
If the table is not found. |
Returns:
Name | Type | Description |
---|---|---|
NlkDataFrame |
NlkDataFrame
|
The requested table. |
Source code in src/datarepo/core/catalog/catalog.py
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 |
|
Dataframes module¶
Tables module¶
DeltaCacheOptions
dataclass
¶
Source code in src/datarepo/core/tables/deltalake_table.py
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 |
|
to_storage_options()
¶
Convert the cache options to a dictionary of storage options.
Returns:
Type | Description |
---|---|
dict[str, Any]
|
dict[str, Any]: A dictionary of storage options that can be used with DeltaTable. |
Source code in src/datarepo/core/tables/deltalake_table.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
DeltalakeTable
¶
Bases: TableProtocol
A table that is backed by a Delta Lake table.
Source code in src/datarepo/core/tables/deltalake_table.py
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 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 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 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
|
__call__(filters=None, columns=None, boto3_session=None, endpoint_url=None, timeout=None, cache_options=None, **kwargs)
¶
Fetch a dataframe from the Delta Lake table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filters
|
DeltaInputFilters | None
|
filters to apply to the table. Defaults to None. |
None
|
columns
|
list[str] | None
|
columns to select from the table. Defaults to None. |
None
|
boto3_session
|
Session | None
|
boto3 session to use for S3 access. Defaults to None. |
None
|
endpoint_url
|
str | None
|
endpoint URL for S3 access. Defaults to None. |
None
|
timeout
|
str | None
|
timeout for S3 access. Defaults to None. |
None
|
cache_options
|
DeltaCacheOptions | None
|
cache options for the Delta Lake table. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
NlkDataFrame |
NlkDataFrame
|
a dataframe containing the data from the Delta Lake table, filtered and selected according to the provided parameters. |
Source code in src/datarepo/core/tables/deltalake_table.py
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 |
|
__init__(name, uri, schema, description='', docs_filters=[], docs_columns=None, roapi_opts=None, unique_columns=None, table_metadata_args=None, stats_cols=None, extra_cols=None)
¶
Initialize the DeltalakeTable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
table name, used as the table identifier in the DeltaTable |
required |
uri
|
str
|
uri of the table, e.g. "s3://bucket/path/to/table" |
required |
schema
|
Schema
|
schema of the table, used to define the table structure |
required |
description
|
str
|
description of the table, used for documentation. Defaults to "". |
''
|
docs_filters
|
list[Filter]
|
documentation filters, used to filter the table in the documentation. Defaults to []. |
[]
|
docs_columns
|
list[str] | None
|
documentation columns, used to define the columns in the documentation. Defaults to None. |
None
|
roapi_opts
|
RoapiOptions | None
|
ROAPI options, used to configure the ROAPI for the table. Defaults to None. |
None
|
unique_columns
|
list[str] | None
|
unique columns in the table, used to optimize the read performance. Defaults to None. |
None
|
table_metadata_args
|
dict[str, Any] | None
|
table metadata arguments, used to configure the table metadata. Defaults to None. |
None
|
stats_cols
|
list[str] | None
|
statistics columns, used to define the columns that have statistics. Defaults to None. |
None
|
extra_cols
|
list[tuple[Expr, str]] | None
|
extra columns to add to the table, where each tuple contains a Polars expression and its type annotation. Defaults to None. |
None
|
Source code in src/datarepo/core/tables/deltalake_table.py
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 |
|
construct_df(dt, filters=None, columns=None)
¶
Construct a dataframe from the Delta Lake table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
DeltaTable
|
The DeltaTable object representing the Delta Lake table. |
required |
filters
|
DeltaInputFilters | None
|
filters to apply to the table. Defaults to None. |
None
|
columns
|
list[str] | None
|
columns to select from the table. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
NlkDataFrame |
NlkDataFrame
|
a dataframe containing the data from the Delta Lake table, filtered and selected according to the provided parameters. |
Source code in src/datarepo/core/tables/deltalake_table.py
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 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
|
delta_table(storage_options=None, version=None)
¶
Get the DeltaTable object for this table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
storage_options
|
dict[str, Any] | None
|
Storage options for the DeltaTable, such as S3 access credentials. Defaults to None. |
None
|
version
|
int | None
|
Version of the Delta table to read. If None, the latest version is used. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
DeltaTable |
DeltaTable
|
The DeltaTable object representing the Delta Lake table. |
Source code in src/datarepo/core/tables/deltalake_table.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
|
get_schema()
¶
Generate and return the schema of the table, including partitions and columns.
Returns:
Name | Type | Description |
---|---|---|
TableSchema |
TableSchema
|
table schema containing partition and column information. |
Source code in src/datarepo/core/tables/deltalake_table.py
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 |
|
Filter
¶
Bases: NamedTuple
Filter represents a condition to be applied to a column in a table.
Source code in src/datarepo/core/tables/filters.py
20 21 22 23 24 25 |
|
ParquetTable
¶
Bases: TableProtocol
A table that is stored in Parquet format.
Source code in src/datarepo/core/tables/parquet_table.py
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 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 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 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 370 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 |
|
__call__(filters=None, columns=None, boto3_session=None, endpoint_url=None, **kwargs)
¶
Fetches data from the Parquet table based on the provided filters and columns.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filters
|
InputFilters | None
|
filters to apply to the data. Defaults to None. |
None
|
columns
|
Optional[list[str]]
|
columns to select from the data. Defaults to None. |
None
|
boto3_session
|
Session | None
|
boto3 session to use for S3 access. Defaults to None. |
None
|
endpoint_url
|
str | None
|
endpoint URL for S3 access. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
NlkDataFrame |
NlkDataFrame
|
A DataFrame containing the filtered data from the Parquet table. |
Source code in src/datarepo/core/tables/parquet_table.py
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 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
|
__init__(name, uri, partitioning, partitioning_scheme=PartitioningScheme.DIRECTORY, description='', docs_filters=[], docs_columns=None, roapi_opts=None, parquet_file_name='df.parquet', table_metadata_args=None)
¶
Initialize the ParquetTable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
name of the table, used for documentation and metadata. |
required |
uri
|
str
|
uri of the table, typically an S3 bucket path. |
required |
partitioning
|
list[Partition]
|
partitioning scheme for the table. This is a list of Partition objects, which define the columns and types used for partitioning |
required |
partitioning_scheme
|
PartitioningScheme
|
scheme used for partitioning. Defaults to PartitioningScheme.DIRECTORY. |
DIRECTORY
|
description
|
str
|
description of the table, used for documentation. Defaults to "". |
''
|
docs_filters
|
list[Filter]
|
documentation filters for the table. These filters are used to generate documentation and are not applied to the data. Defaults to []. |
[]
|
docs_columns
|
list[str] | None
|
docsumentation columns for the table. These columns are used to generate documentation and are not applied to the data. Defaults to None. |
None
|
roapi_opts
|
RoapiOptions | None
|
Read-only API options for the table. These options are used to configure the ROAPI endpoint for the table. Defaults to None. |
None
|
parquet_file_name
|
str
|
parquet file name to use when building file fragments. |
'df.parquet'
|
table_metadata_args
|
dict[str, Any] | None
|
additional metadata arguments for the table. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
if the partitioning_scheme is not a valid PartitioningScheme. |
Source code in src/datarepo/core/tables/parquet_table.py
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 |
|
build_file_fragment(filters)
¶
Returns a file path from the base table URI with the given filters. This will raise an error if the filter does not specify all partitions.
This is currently used to generate the file path used by ROAPI to infer schemas.
Source code in src/datarepo/core/tables/parquet_table.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|
get_schema()
¶
Generates the schema of the table, including partitions and columns.
Returns:
Name | Type | Description |
---|---|---|
TableSchema |
TableSchema
|
table schema containing partitions and columns. |
Source code in src/datarepo/core/tables/parquet_table.py
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 |
|
PartitioningScheme
¶
Bases: Enum
Defines the partitioning scheme for the table.
DIRECTORY - e.g. s3://bucket/5956/2024-03-24 HIVE - e.g. s3://bucket/implant_id=5956/date=2024-03-24
Source code in src/datarepo/core/tables/util.py
25 26 27 28 29 30 31 32 33 34 |
|
TableMetadata
dataclass
¶
Information about a table used for documentation generation.
Source code in src/datarepo/core/tables/metadata.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
TableProtocol
¶
Bases: Protocol
Source code in src/datarepo/core/tables/metadata.py
46 47 48 49 50 51 52 53 54 55 56 |
|
get_schema()
¶
Returns the schema of the table, used to generate the web catalog.
Source code in src/datarepo/core/tables/metadata.py
52 53 54 55 56 |
|
TableSchema
dataclass
¶
TableSchema represents the schema of a table, including partitions and columns.
Source code in src/datarepo/core/tables/metadata.py
38 39 40 41 42 43 |
|
table(*args, **kwargs)
¶
Decorator to define a table using a function.
Example uage
@table(description="This is a sample table.")
def my_table_function(param1, param2):
# Function logic to create a table
return NlkDataFrame(...)
Returns:
Type | Description |
---|---|
Callable[[U], U] | Callable[[Any], Callable[[U], U]]
|
Callable[[U], U] | Callable[[Any], Callable[[U], U]]: A decorator that wraps a function to create a table. |
Source code in src/datarepo/core/tables/decorator.py
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 |
|