Coder Social home page Coder Social logo

treetl's Introduction

treetl: Running ETL tasks with tree-like dependencies

Pipelines of batch jobs don't need to be linear. Sometimes there are shared intermediate transformations that can feed future steps in the process. treetl manages and runs collections of dependent ETL jobs by storing and registering them as a polytree.

This package was put together with Spark jobs in mind, so caching intermediate and carrying results forward is top of mind. Due to this, one of the main benefits of treetl is that partial job results can be shared in memory.

Example

The following set of jobs will all run exactly once and pass their transformed data (or some reference to it) to the jobs dependent upon them.

from treetl import (
  Job, JobRunner, JOB_STATUS
)

class JobA(Job):
  def transform(self, **kwargs):
    self.transformed_data = 1
    return self

# JobB.transform can take a kwarg named
# a_param that corresponds to JobA().transformed_data
@Job.dependency(a_param=JobA)
class JobB(Job):
  def transform(self, a_param=None, **kwargs):
    self.transformed_data = a_param + 1
    return self

  def load(self, **kwargs):
    # could save intermediate result self.transformed_data here
    pass

@Job.dependency(some_b_param=JobB)
class JobC(Job):
  pass

@Job.dependency(input_param=JobA)
class JobD(Job):
  def transform(self, input_param=None, **kwargs):
    self.transformed_data = input_param + 1
    return self

@Job.dependency(in_one=JobB, in_two=JobD)
class JobE(Job):
  def transform(self, in_one=None, in_two=None, **kwargs):
    # do stuff with in_one.transformed_data and in_two.transformed_data
    self.transformed_data = in_one + in_two

# order submitted doesn't matter
jobs = [ JobD(), JobC(), JobA(), JobB(), JobE() ]
job_runner = JobRunner(jobs)
if job_runner.run().status == JOB_STATUS.FAILED:
  # to see this section in action add the following to
  # def transform(self): raise ValueError()
  # to the definition of JobD
  print('Jobs failed')
  print('Root jobs that caused the failure : {}'.format(job_runner.failed_job_roots()))
  print('Paths to sources of failure       : {}'.format(job_runner.failed_job_root_paths()))
else:
  print('Success!')
  print('JobE transformed data: {}'.format(jobs[4].transformed_data))

TODO

  • Set parameters common to multiple jobs via the top level JobRunner
  • Set/pass state parameters to job methods
  • Support submitting a JobRunner as a job for nested job dependency graphs.
  • Run from a specific point in the tree. Allow for parents of starting point to retrieve last loaded data instead of recomputing the whole set of dependencies.
  • Ability to pass job attributes to component functions used in the decorator based definition of a job

treetl's People

Contributors

robhowley avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.