Help to perform ETL process with Yii2 PHP

-5

Hello!

I am obliged to ask for your help, After a long wait at the end, I have to develop an ETL process (Extraction, Transformation and Loading of the data) using Yii2

I need to know if someone from the community has developed a project using Yii2 and has applied an ETL process (Extraction, Transformation and data loading). I am grateful if you can send me documentation or examples of how to carry out an ETL process in Yii2, I am waiting for any information that you can give me, it is an academic project.

    
asked by Sebastian Salazar 03.03.2018 в 02:41
source

1 answer

0

Install the component in your project yii2 (using composer composer require marquine/php-etl ), once that is done you can generate a command (console controller) and inside it, in the method init

You can initialize the use of Etl::config($params)

namespace app\commands;

use Marquine\Etl\Etl;
use Marquine\Etl\Job;
use yii\console\Controller;

class EtlController extends Controller
{
    public $file;
    public function init()
    {
        Etl::config([
            'path' => '/path/to/etl/files',
            'database' => [
                // Base de datos a utilizar
                'default' => 'sqlite',

                'connections' => [

                    'sqlite' => [
                        'driver' => 'sqlite',
                        'database' => '/path/to/database.sqlite',
                    ],

                    'mysql' => [
                        'driver' => 'mysql',
                        'host' => 'localhost',
                        'port' => '3306',
                        'database' => 'dbname',
                        'username' => 'user',
                        'password' => 'pass',
                        'charset' => 'utf8',
                        'collation' => 'utf8_unicode_ci',
                    ],

                    'pgsql' => [
                        'driver' => 'pgsql',
                        'host' => 'localhost',
                        'port' => '5432',
                        'database' => 'dbname',
                        'username' => 'user',
                        'password' => 'pass',
                        'charset' => 'utf8',
                        'schema' => 'public',
                    ],

                ],

            ],

        ]);
    }
    public function options($actionID)
    {
        return ['file'];
    }

    public function optionAliases()
    {
        return ['f' => 'file'];
    }

    public function actionIndex()
    {
        // ejecución de la tarea de etl
        Job::start()
        // datos a extraer
        ->extract('table', 'nombre_tabla_extraer', [
            'connection' => 'mysql' // Base de datos de donde obtendre los datos, si no viene seteado se utiliza el valor que tiene el campo 'default'
        ]) 
        // transformacion a aplicar a los datos
        ->transform('trim', ['columns' => ['name', 'email']])
        // donde cargare los datos
        ->load('table', 'users', [
            'connection' => 'pgsql' // Base de datos a donde voy a insertar los datos
        ]);
    }
}

data extractors link

data transformers link

data loaders link

in console you call it as ./yii etl

    
answered by 03.03.2018 в 03:49