Git Product home page Git Product logo

clickhouse_plugin's Introduction

clickhouse-plugin for Airflow

Install

First we need to get the dependencies installed with:

pip3 install -r requirements.txt

Next step is to add the $AIRFLOW_HOME/plugins to the PYTHONPATH.

export PYTHONPATH="$PYTHONPATH:$AIRFLOW_HOME/plugins"

this also works: PYTHONPATH=$AIRFLOW_HOME/plugins airflow webserver Put the files from this repository on the Airflow Plugins directory

cp -rf ~/devel/clickhouse_plugin/ $AIRFLOW_HOME/plugins

Getting started

Using the clickhouse-client CLI (or whatever) create a table like this:

CREATE TABLE test (x Int32) ENGINE = Memory

Once we have a table, here comes an example of DAG loading data using the operator:

from datetime import datetime, timedelta
from airflow import DAG
from airflow.models import Variable
from clickhouse_plugin.operators.clickhouse_load_operator import (
    ClickHouseLoadCsvOperator)

DAG_ID = 'testing_clickhouse_plugin'


default_args = {
    'owner': 'airflow',
    'depends_on_past': False,
    'start_date': datetime(2018, 11, 9),
    'retries': 1,
    'retry_delay': timedelta(minutes=2),
    'provide_context': True,
}

dag = DAG(DAG_ID, **{
    'default_args': default_args,
    'schedule_interval': '@daily',
    'catchup': False,
})


with dag:
    ClickHouseLoadCsvOperator(**{
        'task_id': 'load_csv',
        'clickhouse_conn_id': 'clickhouse_localhost',
        'filepath': '/path/to/some/sample.csv',
        'database': 'default',
        'table': 'test',
        'schema': {
            'x': lambda x: int(float(x))
        },
    })

sample.csv

x
1
2
3
4

Setup the clickhouse_conn_id on Airflow > Admin > Connections creating a HTTP connection, filling the following fields:

  • Host: localhost
  • Port: 9000
  • Login: default
  • Password: (set a password on ClickHouse's users.xml)

clickhouse_plugin's People

Contributors

wesleybatista avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

forestlzj

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.