Extracts

Extracts are transformations that generate output lines from something that is not one of the input channel. As it will yield all data for each input row, the input given is usually only one empty line.

Extract (base class and decorator)

class rdc.etl.transform.extract.Extract(extract=None)[source]

Base class for extract transforms.

extract[source]

Generator, iterable or iterable-typed callable that is used as the data source. Often used as a shortcut to make fast prototypes of ETL processes from a dictionary, before going further with real data sources.

Each iterator value should be something Hash.copy() can take as an argument.

Example using a dict:

>>> from rdc.etl.transform.extract import Extract

>>> data = ({'foo': 'bar'}, {'foo': 'baz'}, )
>>> my_extract = Extract(extract=data)

>>> list(my_extract({}))
[H{'foo': 'bar'}, H{'foo': 'baz'}]

Example using a callable:

>>> from rdc.etl.transform.extract import Extract

>>> @Extract
... def my_extract():
...     return (
...         {'bar': 'baz'},
...         {'bar': 'boo'},
...     )

>>> list(my_extract({}))
[H{'bar': 'baz'}, H{'bar': 'boo'}]

Example using a generator:

>>> from rdc.etl.transform.extract import Extract

>>> @Extract
... def my_extract():
...     yield {'bar': 'baz'}
...     yield {'bar': 'boo'}

>>> print list(my_extract({}))
[H{'bar': 'baz'}, H{'bar': 'boo'}]

Note

Whenever you can, prefer the generator approach so you’re not blocking anything while computing remaining elements.

DatabaseExtract

class rdc.etl.extra.db.extract.DatabaseExtract(engine, query=None, limit=None)[source]

Extract data from a database using some raw SQL and yield one output line per query result.

engine

The sqlalchemy engine to use for extraction.

query

The database query that will be used to extract data from database. Should not contain OFFSET/LIMIT, nor ”;”.

pack_size

The number of records to retrieve at a time (will be used to add OFFSET/LIMIT clauses to SQL).

FileExtract

class rdc.etl.transform.extract.file.FileExtract(uri=None, output_field=None)[source]

Extract data from a file into a field.

uri

The path for source file. Can be either an absolute/relative filesystem path or an HTTP/HTTPS resource.

output_field

The field that will contain file content. Use the topic (_) field by default.