<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tejas Marvadi on Medium]]></title>
        <description><![CDATA[Stories by Tejas Marvadi on Medium]]></description>
        <link>https://medium.com/@tmarvadi?source=rss-aec09b3f2c57------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*pNt6Em_UxNFbWVlb</url>
            <title>Stories by Tejas Marvadi on Medium</title>
            <link>https://medium.com/@tmarvadi?source=rss-aec09b3f2c57------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 23:17:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tmarvadi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Data Reliability with Soda Core]]></title>
            <link>https://medium.com/codex/data-reliability-with-soda-core-a6dd32574b16?source=rss-aec09b3f2c57------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6dd32574b16</guid>
            <category><![CDATA[data-quality]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[soda]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Tejas Marvadi]]></dc:creator>
            <pubDate>Sun, 21 Aug 2022 21:48:53 GMT</pubDate>
            <atom:updated>2022-08-22T13:58:46.893Z</atom:updated>
            <content:encoded><![CDATA[<p>Data is critical for all organizations and yet many struggles with getting quality data. The most common reasons are either lack of documentation on data reliability or tribal knowledge to validate assumptions. Often time, there is no concrete solution established at the organization level and this results in unreliable data. Unfortunately, this can have a significant financial impact on many organizations because they are not getting the right insights from their data.</p><p>There are plenty of solutions out there to mitigate data reliability and data observability issues. <a href="https://www.soda.io/core">Soda Core</a> is one of the less known yet powerful tools that are available in the open-source market. In this article, I am going to briefly explain what Soda Core is and demonstrate how to leverage this open-source tool to improve data quality testing both in and out of your pipeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*hKDJXWt990h86NcV.jpg" /></figure><h4>What is Soda Core?</h4><p>Soda Core is a command-line interface (CLI) tool that enables you to scan the data in your data source to surface invalid, missing or unexpected data. It is for data quality testing both in and out of your pipeline, data observability, and data monitoring. It works on both SQL tables and Spark DataFrames, and consists of several components like metric collection, data classification, check evaluation, and alerting. Soda Core uses the Soda Checks Language (SodaCL), a human-readable domain-specific language for data reliability.</p><p>Soda Core supports the following data sources, and you can find their configuration information on their <a href="https://docs.soda.io/soda-core/configure.html">official documentation page</a>.</p><ul><li>Amazon Athena</li><li>Amazon Redshift</li><li>Apache Spark DataFrames</li><li>GCP Big Query</li><li>IBM DB2</li><li>MS SQL Server</li><li>MySQL</li><li>PostgreSQL</li><li>Snowflake</li></ul><h4>Get Started with Soda Core</h4><p>To get started, you must have Python 3.8 or greater on your system. It is also recommended to use Python virtual environment to install the Soda Core. So let’s first create a virtual environment and activate it using the following commands:</p><pre>python -m venv .venv<br>source .venv/bin/activate</pre><p>Now that your virtual environment is ready, let’s upgrade its Python package manager, pip, to the latest version:</p><pre>pip install --upgrade pip</pre><p>Lastly, we need to install the Soda Core package depending on the type of data sources you need to work with. For this demo, I am going to use the soda-core-snowflake.</p><pre>pip install soda-core-snowflake</pre><p>Now we need to create the following two YAML files:</p><ul><li><strong>configuration.yml</strong></li></ul><p>This file contains connection details for your data source. Soda Core uses this file to access your data source. It is recommended to leverage system variables to securely retrieve the value, especially sensitive data like passwords.</p><pre>data_source your_datasource_name:<br>  type: snowflake<br>  connection:<br>    username: &quot;YOUR_USER_ID&quot;<br>    password: ${SNOWFLAKE_PASSWORD}<br>    account: you_account.us-east-1<br>    database: YOUR_DATABASE<br>    warehouse: YOUR_WAREHOUSE<br>    connection_timeout: 300<br>    role: YOUR_ROLE<br>    client_session_keep_alive:<br>    session_parameters:<br>      QUERY_TAG: soda-queries<br>      QUOTED_IDENTIFIERS_IGNORE_CASE: false<br>  schema: YOUR_SCHEMA_NAME</pre><ul><li><strong>checks.yml</strong></li></ul><p>This file contains a test that Soda Core performs when it scans a dataset in your data source. These checks are written using the <a href="https://docs.soda.io/soda-cl/soda-cl-overview.html">Soda Check Language</a> (SodaCL). There are plenty of built-in metrics available for us to use and you can even define your own using the SQL queries. In this demo, we are performing two checks.</p><ol><li>Iterating through each table, whose name ends with _DIMENSIONS in YOUR_SCHEMA_NAME schema and checking whether they are empty or not. We are excluding any table names that begin with TEMP_.</li><li>The second check is to ensure that the date_id column is not NULL in the DATE_DIMENSION table.</li></ol><pre>for each dataset T:<br>  datasets:<br>    - include %_DIMENSION<br>    - exclude TEMP_%<br>  checks:<br>    - row_count &gt; 0</pre><pre>checks for DATE_DIMENSION:<br>  - missing_count(date_id) = 0</pre><p>Finally, you are ready to run a scan against the data source by issuing the following command. You can find scan command options and their descriptions <a href="https://docs.soda.io/soda-core/scan-core.html#add-scan-options">here</a>.</p><pre>soda scan -d your_datasource_name -c configuration.yml checks.yml</pre><p>Once the above command is executed successfully, you should see the output as shown below.</p><pre>Soda Core 3.0.4<br>Instantiating for each for [&#39;CUSTOMER_DIMENSION&#39;,&#39;DATE_DIMENSION&#39;,&#39;PRODUCT_DIMENSION&#39;]<br>Scan summary:<br>4/4 checks PASSED:<br>   DATE_DIMENSION in YOUR_SCHEMA_NAME<br>     missing_count(date_id) = 0 [PASSED]<br>   CUSTOMER_DIMENSION in YOUR_SCHEMA_NAME<br>     row_count &gt; 0 [PASSED]<br>   DATE_DIMENSION in YOUR_SCHEMA_NAME<br>     row_count &gt; 0 [PASSED]<br>   PRODUCT_DIMENSION in YOUR_SCHEMA_NAME<br>     row_count &gt; 0 [PASSED]<br>All is good. No failures. No warnings. No errors.</pre><h4>Where to Go from Here?</h4><p>Now that you have working data quality checks with Soda Core, you can integrate it with a data orchestration tool like Airflow to automate and schedule your search for bad data. You can even extend the functionality by connecting it to the <a href="https://docs.soda.io/soda-cloud/overview.html">Soda Cloud</a>, which allows you to use a metric store, collaborate with others, and use an issue resolution workflow. The growing SodaCL offers many built-in human-readable checks and its ability to define our own metrics to customize checks using SQL queries.</p><h4>Conclusion</h4><p>I feel this project has a lot of potential, especially since it allows you to run data quality checks against multiple data sources with minimal effort. It offers simple integration with orchestration tools, and it allows you to check for a variety of known and unknown root causes with ease. It is lightweight in terms of dependencies and the learning curve is straightforward. I am excited about the future of Soda Core.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6dd32574b16" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/data-reliability-with-soda-core-a6dd32574b16">Data Reliability with Soda Core</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Setup a Local MWAA Development Environment]]></title>
            <link>https://medium.com/codex/how-to-setup-a-local-mwaa-development-environment-92e4e7557ecb?source=rss-aec09b3f2c57------2</link>
            <guid isPermaLink="false">https://medium.com/p/92e4e7557ecb</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[airflow]]></category>
            <category><![CDATA[developer-tools]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[mwaa]]></category>
            <dc:creator><![CDATA[Tejas Marvadi]]></dc:creator>
            <pubDate>Sun, 10 Oct 2021 19:04:39 GMT</pubDate>
            <atom:updated>2021-10-11T01:36:30.286Z</atom:updated>
            <content:encoded><![CDATA[<p>Apache Airflow is an open-source tool to programmatically author, schedule, and monitor workflows. It is one of the most robust platforms used by Data Engineers for orchestrating workflows or pipelines. Setting up and managing this tool along with underlying infrastructure requires quite an effort. This is where the Amazon Managed Workflow for Apache Airflow (MWAA) shines. The MWAA makes it easier to set up and operate end-to-end data pipelines in the cloud at scale. With MWAA, a lot of management and underlying infrastructure goes away, but it makes it difficult for Data Engineers to develop on their local machine. This article is going to demonstrate how you can replicate an MWAA environment locally, so the development activities can be easily conducted without frequently needing to push your code and DAGs to your AWS S3 bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mkqcKfQMQtg34S4a.png" /></figure><h3>Prerequisites:</h3><ul><li>Linux (64-bit)</li><li>Docker</li><li>Docker-Compose</li></ul><h3>Step 1: Structure Setup</h3><p>In order to mimic the infrastructure, we are going to spin up four different docker containers using docker-compose, as depicted below. We are leveraging the <a href="https://hub.docker.com/r/localstack/localstack">Locastack</a> docker image, which is a cloud emulator that runs in a single container. We are leveraging an Amazon-provided local MWAA docker image, which is similar to an MWAA production image. For the backend data for MWAA metadata, we are using a publicly available <a href="https://hub.docker.com/_/postgres">Postgres</a> docker image. Finally, a <a href="https://hub.docker.com/r/mesosphere/aws-cli/">containerized AWS CLI</a> to initialize and set up any services in the Localstack container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*PzXLH0CuGIpXp_UaZM7edw.png" /></figure><p>Before we get started, let’s first review our folder structure for this project. The parent folder mwaa contains four folders — .aws, dags, plugins, and landing bucket, and one file — docker-compose.yml. The dags folder contains a sample DAG — sample_dag.py, which we will execute at the end to demonstrate our local MWAA environment. The remaining folders are there for supporting the MWAA configuration setup.</p><pre>mwaa<br>|__.aws<br>   |__config<br>   |__credentials<br>|__dags<br>   |__sample_dag.py<br>|__plugins<br>   |__plugins.zip<br>|__landing_bucket<br>   |__customer.csv<br>|__docker-compose.yml</pre><h3>Step 2: Define Localstack Service</h3><p>Localstack is a cloud service emulator, and it offers a wide variety of services so you can run your AWS applications entirely on your local machine without connecting to an actual cloud provider. For this demonstration, we are going to use only three services — S3, IAM, and SecretsManager. You can refer to the Localstack official <a href="https://github.com/localstack/localstack">Github</a> for a complete list of supported services. Let’s begin creating a docker-compose.yml file as indicated below. We are exposing port 4566 so we can interact with services like S3 and SecretsManager.</p><pre>version: &quot;3&quot;</pre><pre>services:<br>  localstack:<br>    image: localstack/localstack:latest<br>    container_name: &quot;localstack&quot;<br>    ports:<br>      - &quot;4566:4566&quot;<br>    environment:<br>      - SERVICES=s3,iam,secretsmanager,ec2<br>      - DOCKER_HOST=unix:///var/run/docker.sock<br>      - DEFAULT_REGION=us-east-1<br>    volumes:<br>      - &quot;/var/run/docker.sock:/var/run/docker.sock&quot;<br>      - &quot;/tmp/localstack:/tmp/localstack&quot;</pre><h3>Step 3: Define Postgres Service</h3><p>MWAA uses an Aurora PostgreSQL database as a backend for Airflow metadatabase, where DAG runs and task instances are stored. This Postgres container fulfills the metadatabase need to emulate our MWAA environment locally. Let’s append the following code to the docker-compose.yml file.</p><pre>postgres:<br>      image: postgres:10-alpine<br>      environment:<br>          - POSTGRES_USER=airflow<br>          - POSTGRES_PASSWORD=airflow<br>          - POSTGRES_DB=airflow<br>      volumes:<br>          - &quot;${PWD}/db-data:/var/lib/postgresql/data&quot;</pre><h3>Step 4: Define Amazon Local MWAA Service</h3><p>This Amazon Local MWAA docker image allows you to run a local Apache Airflow environment to develop and test DAGs, custom plugins, and dependencies before deploying to MWAA. Add the following code to the docker-compose.yml file.</p><pre>local-runner:<br>      image: amazon/mwaa-local:2.0.2<br>      user: 1000:1000<br>      restart: always<br>      depends_on:<br>          - postgres<br>      environment:<br>          - LOAD_EX=n<br>          - EXECUTOR=Local<br>          - AIRFLOW_CONN_AWS_DEFAULT=aws://a:a@?host=<a href="http://localstack:4566&amp;region_name=us-east-1">http://localstack:4566&amp;region_name=us-east-1</a><br>          - AWS_DEFAULT_REGION=us-east-1<br>          - AWS_PROFILE=default<br>      volumes:<br>          - &quot;${PWD}/dags:/usr/local/airflow/dags&quot;<br>          - &quot;${PWD}/plugins:/usr/local/airflow/plugins&quot;<br>          - &quot;${PWD}/.aws:/usr/local/airflow/.aws&quot;<br>      ports:<br>          - &quot;8080:8080&quot;<br>      command: local-runner<br>      healthcheck:<br>          test: [&quot;CMD-SHELL&quot;, &quot;[ -f /usr/local/airflow/airflow-webserver.pid ]&quot;]<br>          interval: 30s<br>          timeout: 30s<br>          retries: 3</pre><h3>Step 5: Define AWS CLI Service</h3><p>We are using mesosphere/aws-cli docker image, which contains the aws-cli and allows us to easily create mock resources in the Localstack by issuing CLI commands. We are mapping a local landing folder from our host to this container, so we can push a CSV file to an S3 bucket my-landing-bucket, which we are creating in this container. This is a short-lived container, and it will terminate soon after it’s done creating a bucket and copying a file into the S3 bucket.</p><pre>aws-cli:<br>    image: mesosphere/aws-cli<br>    container_name: &quot;aws-cli&quot;<br>    volumes:<br>      - ./landing:/tmp/landing:ro<br>    environment:<br>      - AWS_ACCESS_KEY_ID=dummyaccess<br>      - AWS_SECRET_ACCESS_KEY=dummysecret<br>      - AWS_DEFAULT_REGION=us-east-1<br>    entrypoint: /bin/sh -c<br>    command: &gt;<br>      &quot;<br>        echo Waiting for localstack service start...;<br>        while ! nc -z localstack 4566;<br>        do<br>          sleep 1;<br>        done;     <br>        echo Connected!;<br>     <br>      aws s3api create-bucket --bucket my-landing-bucket --endpoint-url <a href="http://localstack:4566/">http://localstack:4566</a></pre><pre>      aws s3 cp /tmp/landing s3://my-landing-bucket --recursive --endpoint-url <a href="http://localstack:4566/">http://localstack:4566</a></pre><pre>&quot;<br>    depends_on:<br>      - localstack</pre><h3>Step 6: Create a DAG &amp; Data File for Testing</h3><p>This is a sample DAG file to demonstrate our working MWAA environment using the S3 service. We are using a PythonOperator to execute a read_file method, which reads data directly from an S3 bucket. Use the following code to create sample_dag.py and place it under the dags folder.</p><pre>from airflow import DAG<br>from airflow.operators.python_operator import PythonOperator<br>from airflow.hooks.S3_hook import S3Hook<br>from datetime import datetime</pre><pre>default_args = {<br>    &quot;owner&quot;: &quot;airflow&quot;,<br>    &quot;start_date&quot;: datetime(2021, 10, 1),<br>}</pre><pre>def read_file():<br>    hook = S3Hook()<br>    file_content = hook.read_key(<br>        key=&quot;customer.csv&quot;, bucket_name=&quot;my-landing-bucket&quot;<br>    )    <br>    print(file_content)</pre><pre>with DAG(&quot;sample_dag&quot;, schedule_interval=None, catchup=False, default_args=default_args) as dag:</pre><pre>t1 = PythonOperator(<br>        task_id=&#39;read_s3_file&#39;,<br>        python_callable=read_file<br>    )</pre><p>Let’s create a new file, customer.csv, which we are using in the DAG to read data.</p><pre>id,firstname,lastname,email,email2,profession<br>100,Anestassia,Yate,Anestassia.Yate@opmail.com,Anestassia.Yate@gmail.com,police officer<br>101,Demetris,Taima,Demetris.Taima@opmail.com,Demetris.Taima@gmail.com,police officer<br>102,Neila,Karylin,Neila.Karylin@opmail.com,Neila.Karylin@gmail.comworker<br>....</pre><h3>Step 7: Create a Credentials File for localstack</h3><p>Create the following credentials file under .aws folder so our local MWAA can use it to interact with Localstack resources.</p><pre>[default]<br>aws_access_key_id = dummyaccess<br>aws_secret_access_key = dummysecret</pre><h3>Step 8: Deploy Local MWAA</h3><p>If everything is configured correctly, you should be able to execute the following command from the mwaa directory. If you encounter any issue starting the docker containers, then check your configuration files.</p><pre>docker-compose up -d</pre><p>Let’s confirm all containers are up and running by executing the following command:</p><pre>docker ps</pre><p>If you see all three containers running, then you have successfully deployed your MWAA environment on your local machine. Please note that our fourth aws-cli container may not appear in the list because it terminates soon after it completes executing CLI commands defined in our docker-compose.yml file. Now let’s verify it is working by executing our sample DAG file. Navigate to the Airflow UI at <a href="http://localhost:8080/">http://localhost:8080</a> and login with the username adminand password test.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rEeXIVjRPHuOwqvUAAqDCg.png" /></figure><p>If it runs successfully, you should check the log for the task and you should see the content of the CSV file from the S3 bucket as indicated below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*cHbk7JD6SKoq6V9YCLASNg.png" /></figure><p>If you made it this far, then you have successfully deployed a local MWAA environment on your machine. Congratulations!</p><h3>Conclusion</h3><p>In this article, I explained how to quickly stand up an MWAA development environment by using docker on your local machine. This setup will help you during your workflow development and testing phase. I hope all scripts from this article will help you as a starting point to quickly stand up an environment for your need. Hope you find these step-by-step instructions useful. Please leave your comment below for this article.</p><p>You can read my article <a href="https://medium.com/codex/how-to-scale-out-apache-airflow-2-0-with-redis-and-celery-3e668e003b5c">How to Scale-out Apache Airflow 2.0 with Redis and Celery</a> if you like to stand up a distributed Airflow environment with Redis and Celery on your local machine.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92e4e7557ecb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/how-to-setup-a-local-mwaa-development-environment-92e4e7557ecb">How to Setup a Local MWAA Development Environment</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Version Control your Data Lake with LakeFS]]></title>
            <link>https://medium.com/codex/version-control-your-data-lake-with-lakefs-e38316c70eea?source=rss-aec09b3f2c57------2</link>
            <guid isPermaLink="false">https://medium.com/p/e38316c70eea</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-lake]]></category>
            <category><![CDATA[version-control]]></category>
            <category><![CDATA[data-engineering]]></category>
            <dc:creator><![CDATA[Tejas Marvadi]]></dc:creator>
            <pubDate>Thu, 01 Apr 2021 22:54:02 GMT</pubDate>
            <atom:updated>2021-04-02T01:11:57.767Z</atom:updated>
            <content:encoded><![CDATA[<p>Data Lake brings revolution to the data world, it allows you to store relational data from business applications and operational databases, and non-relational data from mobile apps, IoT devices, and social media at any scale. Having all your data in this centralized repository (Data Lake) opened up a new way to perform analytics — from building a basic dashboard to complex machine learning that helps businesses make better decisions.</p><p>The data lake solves many problems that were once challenging to solve, for example, storing data at scale, storing both structured and unstructured data in one place, and running analytics and machine learning on large data. This is a huge advancement; however, there is still a big gap in a data lake and that is data management. Without the use of proper cataloging mechanisms, the data lake would result in a “data swamp”. I would like to introduce you to an open-source platform — l<a href="https://lakefs.io/">akeFS</a> that may help you avoid turning your data lake into a “data swamp”. It delivers resilience and manageability to your existing data lake. It allows you to build repeatable, atomic and versioned data lake operations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ycy5tIBZwWZBY0Nafdb7_g.jpeg" /></figure><h3>What is lakeFS?</h3><p>lakeFS is an open-source platform that enables you to manage your data lake the way you manage your code. It transforms your object storage into a Git-like repository. As a result, you can run parallel pipelines for experimentation and CI/CD for your data. It works seamlessly with all modern data frameworks such as Spark, Kafka, Presto, Databricks, Airflow, Delta Lake, and many more. You can deploy it on any S3 compatible storage solution either in the cloud or on-prem. lakeFS is distributed as a single binary that comprises several logical services. The complete architecture information can be found on their <a href="https://docs.lakefs.io/architecture/overview.html">official website</a>.</p><p>lakeFS is format-agnostic so you can perform Git-like operations over any object storage. It uses a relational database (Postgres) to store its metadata. This keeps the metadata separate from your object storage, which in turn saves costs because this avoids duplicating data. In a Data Lake, there is no easy way to isolate data. The only option is to copy the data into a different bucket. This is where the lakeFS shines because it allows you to isolate data without copying it. So you can have a single file in your data lake that can have many pointers to it.</p><h3>Why you need lakeFS?</h3><p>lakeFS provides a Git-like branching and committing model that allows changes to happen in isolation. It would be a perfect solution for your development environment for data. You can manipulate production data by creating a branch. It gives you an isolated snapshot that you can experiment with while not risking actual production data. It also provides different versions of the same data over time and allows you to do a time travel between those different versions. You can also read from the data lake at any point in time, compare changes, and safely roll back if necessary.</p><p>Data Engineers would find the lakeFS helpful especially when they are working on ingesting new data or performing any sort of validation operations. Instead of ingesting data directly in the main branch, the data can be ingested in an isolated branch first. This allows them to perform validation (data format &amp; schema enforcement) before introducing the new data into the data lake. Ingesting data to an isolated branch can also minimize data corruptions in your production due to either upstream changes or recently deployed code changes.</p><p>In the event of low-quality data, lakeFS allows you to revert the data to its previous version instantly with one atomic action. The ability to move between the version of data using lakeFS can be a useful to Data Scientist. They can create multiple versions of their machine learning models and compare their accuracy with ease without duplicating the data set in a data lake.</p><p>lakeFS allows multiple developers or teams to work in isolation with the same data without stepping on each other toes. It also minimizes duplicating the data in your data lake, which can significantly reduce the usage cost if you are using cloud storage. Finally, it helps avoid turning your data lake into a “data swamp”.</p><h3>Conclusion</h3><p>lakeFS is a very interesting project and one that provides a lot of value and flexibility for teams who are working on the data lake. It enables your data lake with Git-like operations: branching, merging, committing, reverting, and rolling back. Like any other open-source technologies, the lakeFS is evolving and adding new features as more people are joining their community to contribute. I briefly highlighted some use cases of the lakeFS in this article. What other use cases do you foresee benefit from the lakeFS? Please share your thoughts and ideas with me in the comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e38316c70eea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/version-control-your-data-lake-with-lakefs-e38316c70eea">Version Control your Data Lake with LakeFS</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build Data Pipeline with Apache Hop]]></title>
            <link>https://medium.com/codex/build-data-pipeline-with-apache-hop-62417ecee303?source=rss-aec09b3f2c57------2</link>
            <guid isPermaLink="false">https://medium.com/p/62417ecee303</guid>
            <category><![CDATA[etl]]></category>
            <category><![CDATA[apache]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Tejas Marvadi]]></dc:creator>
            <pubDate>Sun, 31 Jan 2021 20:29:14 GMT</pubDate>
            <atom:updated>2021-02-11T03:04:45.973Z</atom:updated>
            <content:encoded><![CDATA[<h4><a href="http://medium.com/codex">CODEX</a></h4><p>Apache Airflow has become a de facto tool for Data Engineering, but don’t overlook other tools out there that can boost your productivity. <a href="https://hop.apache.org/">Hop</a> (<strong>H</strong>op <strong>O</strong>rchestration <strong>P</strong>latform) project is one of the less known yet powerful tools that is incubating at Apache. In this article, I am going to briefly explain what Apache Hop is and will demonstrate how to create a simple pipeline without writing any code with Hop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*-dW-QeJc1b6JPOLRp6X9HQ.png" /><figcaption>Official Apache Hop Project Logo</figcaption></figure><h4>What is Apache Hop?</h4><p>Hop is an open-source data integration tool, which is a fork of Pentaho Data Integration (PDI) or Kettle. It offers a visual development tool that can make developers more productive and less daunting for those who prefer building their pipelines without writing any code. Hop workflow and pipeline can be run on various engines including its own native Hop engine, Spark, Flink, Google Dataflow, or AWS EMR through Beam. Hop is one of the first GUI based designers out there for building Apache Beam pipeline.</p><h4>Hop Components</h4><p>Hop is composed of the following three primary components:</p><ul><li><strong>Hop GUI. </strong>It is a graphical interface editor for building pipelines (transformations) and workflows (jobs). It allows you to build a complex ETL (Extract Transformation and Load) jobs without writing any code. It provides a drag-and-drop interface that allows you to author, edit, run or debug a pipeline or workflow.</li><li><strong>Hop Run. </strong>It is a standalone CLI utility that can be used to execute both pipeline and workflow.</li><li><strong>Hop Server. </strong>It is a lightweight Web container that allows you to execute your pipeline and workflow on a remote server. This can be deployed on multiple servers. It also provides a REST API to remotely invoke your workflow and pipeline.</li></ul><h4>Get Started with Hop</h4><p>To get started, you can download a recent build from its official <a href="https://hop.apache.org/download/">Apache Hop</a> project. You need to unzip the file once it is downloaded and start the Hop GUI with the following command:</p><p>On Linux:</p><pre>./hop-gui.sh</pre><p>On Windows:</p><pre>hop-gui.bat</pre><p>After starting the Hop GUI, you’ll be presented with the following window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-QjOGmVNWbihgqWD7l38RA.png" /><figcaption>Hop GUI Editor</figcaption></figure><p>This editor allows you to build a complex data pipeline with just a drag-and-drop interface. To give you a better understanding of how Hop works, let me walk through a real-world example.</p><h4>Real-World Example with Hop</h4><p>I am going to show a real-world example of how you can bring currency exchange data using API and store them in a MySQL database table. For this demonstration, I’m going to use <a href="https://openexchangerates.org/">Open Exchange Rates</a> API that offers a free plan with USD as a base currency. Before we start building the pipeline using Hop, let’s first understand how we are going to build this pipeline.</p><p>First, we will send an API request to Open Exchange Rates endpoint to retrieve the latest currency exchange data. Upon successful request, the endpoint will send back a JSON object similar to the one below.</p><pre>{<br>  &quot;disclaimer&quot;: &quot;Usage subject to terms: https://openexchangerates.org/terms&quot;,<br>  &quot;license&quot;: &quot;https://openexchangerates.org/license&quot;,<br>  &quot;timestamp&quot;: 1611871200,<br>  &quot;base&quot;: &quot;USD&quot;,<br>  &quot;rates&quot;: {<br>    &quot;AED&quot;: 3.672995,<br>    &quot;AFN&quot;: 77.503946,<br>    &quot;ALL&quot;: 102.210542,<br>    &quot;AMD&quot;: 519.485125,<br>    &quot;ANG&quot;: 1.794941,<br>    &quot;AOA&quot;: 655.668,<br>    &quot;ARS&quot;: 87.146455,<br>    &quot;AUD&quot;: 1.302647,<br>     /* .... */<br>  }<br>} </pre><p>We will parse (without writing any code) this JSON object, which contains a UNIX timestamp (UTC seconds), a base currency (3-letter ISO code), and a rates object with “symbol: value” pairs, relative to the USD currency. Subsequently, we will clean up unnecessary data before inserting them into a MySQL database. The end result should fit into a MySQL database table with three columns — Exchange_Date, Exchange_Currency, and Exchange_Rate.</p><p>Let’s begin by creating a new pipeline by clicking the ‘New’ icon in the upper left corner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UxdfZjZGapWiFIYHV_rqyg.png" /></figure><p>Once you have created a new pipeline we can start building by clicking anywhere on the editor. Upon clicking on the editor, you will be presented with the dialog shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*IrvA5zQS_CsnnOYATzFqHQ.png" /></figure><p>This dialog box shows a list of transforms that allows you to build your pipeline. It appears the Hop team has not yet officially published their documentation for them, but I hope they will be available soon. In the meanwhile, you can access them <a href="https://hop.apache.org/manual/latest/plugins/transforms/">here</a>.</p><p>Let’s add the following transforms to our pipeline by searching them using the search box and subsequently clicking on them.</p><ul><li>Generate Rows</li><li>JSON Input</li><li>Calculator</li><li>Select values</li><li>Row Normaliser</li><li>Insert / Update</li></ul><p>After adding them all to your pipeline, you can arrange them as indicated below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*Z4r9NkrgEOb_LnqWUxx08g.png" /></figure><p>These are the only six transforms are required to build our pipeline. Let’s configure them one at a time, and connect each of these transforms by creating a hop between them.</p><ul><li><strong>Generate rows: </strong>It generates a specified number of rows as output. In our case, we will use this transform to pass the API endpoint for Open Exchange Rates as indicated below. The output of this step will become an input for the next transform (JSON Input).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XueR87ap8RxStkGM5LlCiA.png" /></figure><ul><li><strong>JSON Input: </strong>This transform reads data from JSON objects, files, or incoming fields using a JSONPath expression to extract data and output rows. We are going to use this transform to extract data from the URL that was defined in the ‘Generate rows’ transform.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hgnv9qlgLdQoWbr_Sg336Q.png" /></figure><p>To keep this demonstration simple, we are going to extract only selected currency as indicated below. We provide JSONPath expression to extract data from JSON response and we provide the name of the field associated with each of those expressions. In addition, we also need to define the data type for each of these fields.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*889Xpmb8WwUzdcVuc2QePQ.png" /></figure><ul><li><strong>Calculator: </strong>We are using this transform to convert a UNIX timestamp from seconds to milliseconds by multiplying it with 1000. Eventually, we will use this in the next transform (Select value) to convert it to a human-readable date.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dNp_WsvIceS44J55hFNTSw.png" /></figure><ul><li><strong>Select values: </strong>This transform helps us selecting, removing, renaming, changing data types as well as configuring the length and precision of the fields on the stream. We are using this transform to remove unnecessary fields (URL, timestamp, and CONSTANT) that we created in our previous transforms.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*-QpLwy3oSZmMsPEHdHINiw.png" /></figure><p>Now let’s use this same transform to convert the UNIX timestamp from milliseconds to a normal date.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NPTiHJllAJIpNzLBHe75YA.png" /></figure><p>At this point, let’s preview our pipeline to see what our output would look like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*hDjC69fao8TZfg9qyRoYUw.png" /></figure><p>In order to store them in the MySQL database, let’s normalize the stream so we can store them in three columns as shown below.</p><pre>Exchange_Date | Exchange_Currency | Exchange_Rate |<br>--------------|-------------------|---------------|<br> 2021-01-28   |        CAD        |     1.283072  |<br> 2021-01-28   |        AUD        |     1.303642  |<br> 2021-01-28   |        GBP        |     0.728617  |<br> 2021-01-28   |        EUR        |     0.825002  |<br> 2021-01-28   |        INR        |     72.93905  |<br> 2021-01-28   |        SGD        |      1.32905  |<br> 2021-01-28   |        NZD        |      1.39401  |</pre><ul><li><strong>Row Normaliser: </strong>We are using this transform to convert columns into rows, so we can store them in a table.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*qRYh8DXmLF-uR_2BT-N-9w.png" /></figure><ul><li><strong>Insert / Update:</strong></li></ul><p>Now let’s use this transform to create a new database connection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*3ixxGAr9OrrDo58WzbF1LQ.png" /></figure><p>Click on the database icon to open up a window and fill in the information as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*KY8m_UbWmDWgG_P6ajKVOg.png" /></figure><p>Once you fill out the information, you can click on the “Test” button to ensure the connection is working before hitting the “OK” button.</p><p>Now we need to define the table and schema information as well as key and update fields as indicated below. This allows us to run our pipeline multiple times per day without creating duplicate records in a table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*J8Vh9Z7ZIBLhiepIYrbgjQ.png" /></figure><p>Now it’s time to create a table in the database by clicking on the “SQL” button, which will open up a new window with a SQL statement. You can modify the script as you would like before clicking on the Execute button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*XdlN8AJ51a5HlbL4ctl1-g.png" /></figure><p>Once it successfully creates a table, you can come back to the main editor window by closing all pop-up transform windows.</p><p>Finally, you are ready to run your first pipeline in Apache Hop. Let’s click on the play button on the top left corner and you’ll be prompted with a Run Options window as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*TLUp3SDriMjLA1AjaWg-8Q.png" /></figure><p>Click on the Launch button and your pipeline will start executing on your local machine. Once your pipeline is run successfully, you’ll see a green checkmark on top of each transform. The bottom “Execution Results” panel displays metrics as well as logging information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fbpZ0yZfuvZgw5D46JtOhQ.png" /></figure><p>Let’s verify the result in the MySQL database table.</p><pre>mysql&gt; SELECT * FROM TEST.currency_exchange;<br>+---------------+-------------------+---------------+<br>| Exchange_Date | Exchange_Currency | Exchange_Rate |<br>+---------------+-------------------+---------------+<br>| 2021-01-28    | CAD               |      1.283072 |<br>| 2021-01-28    | AUD               |      1.303642 |<br>| 2021-01-28    | GBP               |      0.728617 |<br>| 2021-01-28    | EUR               |      0.825002 |<br>| 2021-01-28    | INR               |      72.93905 |<br>| 2021-01-28    | SGD               |       1.32905 |<br>| 2021-01-28    | NZD               |       1.39401 |<br>+---------------+-------------------+---------------+<br>7 rows in set (0.00 sec)</pre><h4><strong>Where to Go from Here?</strong></h4><p>Now that you have a working pipeline, you can create other pipelines and orchestrate them by creating a workflow. You may also want to run your workflow or pipeline using Hop Server on a headless machine. Lastly, you can also deploy it on AWS EC2 instance. You can do all of these; however, keep in mind that the Apache Hop project is still in an incubation phase, so be cautious before deploying any of your pipeline in your production environment.</p><h4>Conclusion</h4><p>Apache Hop is a new open-source data integration platform that is still under the incubation phase. I feel this project has a lot of potentials, especially it allows you to run your pipeline on different engines — such as Spark, Flink, Google Dataflow, or AWS EMR through Beam. I believe this platform will be a game-changer for data pipeline development because it allows you to visually developed for many platforms like Spark, Flink, and Google Dataflow. I am excited about the future of Apache Hop.</p><p>[<strong><em>Feb 10, 2021 Update</em></strong>: The official documentation is now available at <a href="https://hop.apache.org/manual/latest/index.html">https://hop.apache.org/manual/latest/index.html</a>]</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62417ecee303" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/build-data-pipeline-with-apache-hop-62417ecee303">Build Data Pipeline with Apache Hop</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Scale-out Apache Airflow 2.0 with Redis and Celery]]></title>
            <link>https://medium.com/codex/how-to-scale-out-apache-airflow-2-0-with-redis-and-celery-3e668e003b5c?source=rss-aec09b3f2c57------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e668e003b5c</guid>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[airflow]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Tejas Marvadi]]></dc:creator>
            <pubDate>Tue, 19 Jan 2021 20:59:48 GMT</pubDate>
            <atom:updated>2021-01-20T01:27:26.601Z</atom:updated>
            <content:encoded><![CDATA[<h4><a href="http://medium.com/codex">CODEX</a></h4><p>Apache Airflow has become one of the most prevalent tools in the Data Engineering space. It is a platform that offers you to programmatically author, schedule, and monitor workflows. Airflow can be configured to run with different executors such as <a href="https://airflow.apache.org/docs/apache-airflow/stable/executor/sequential.html">Sequential</a>, <a href="https://airflow.apache.org/docs/apache-airflow/stable/executor/debug.html">Debug</a>, <a href="https://airflow.apache.org/docs/apache-airflow/stable/executor/local.html">Local</a>, <a href="https://airflow.apache.org/docs/apache-airflow/stable/executor/dask.html">Dask</a>, <a href="https://airflow.apache.org/docs/apache-airflow/stable/executor/celery.html">Celery</a>, <a href="https://airflow.apache.org/docs/apache-airflow/stable/executor/kubernetes.html">Kubernetes</a>, and <a href="https://airflow.apache.org/docs/apache-airflow/stable/executor/celery_kubernetes.html">CeleryKubernetes</a>. As a data engineer, you would generally configure Apache Airflow on your local machine to run with either Sequential or Local Executor for your development work. However, this setup would preclude you from testing your workflow in a distributed environment. In this article, I will walk you through a step-by-step process to put together a docker-compose, which would allow you to resemble a distributed environment on your local machine. We will be setting up Airflow with a Celery Executor, which will distribute the load to worker nodes. The method I discuss here can be extended to deploy in a distributed production environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JUQlFLtTS_E9_K5I4FlLvQ.jpeg" /></figure><h3>Prerequisites:</h3><ul><li>Linux (64-bit)</li><li>Docker</li><li>Docker-Compose</li></ul><h3>Step 1: Structure Setup</h3><p>Let’s first clarify how we are going to set up a distributed Airflow using Docker. In this setup, we will be using Postgres as a backend to store our metadata, and Redis as the message broker. We have an option to use RabbitMQ instead of Redis; however, Redis is easier to deploy and maintain than RabbitMQ. The latter requires extra effort to maintain, and it is difficult to debug crashes.</p><p>As depicted below, we are going to spin-up six different docker containers using docker-compose. The Airflow webserver and its scheduler are going to share the same container. We will use publicly available docker images for Postgres and Redis. The two containers will be used for the worker nodes and the last container will be dedicated to monitoring worker nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*JQUBRf6OscKNdrXpk8XTfQ.png" /><figcaption>Airflow Components in Multiple Docker Containers</figcaption></figure><p>To get started, let’s first take a look at our folder structure for this project. The parent folder, airflow-docker, contains two folders — dags and config, and three files — docker-compose.yml, Dockerfile, and entrypoint.sh. The dags folder contains a sample DAG — sample_dag.py, which we will execute at the end to demonstrate our distributed environment. The config folder contains a file for environment variables and several files for supporting Airflow configuration setup.</p><pre>airflow-docker<br>|__dags<br>   |__sample-dag.py<br>|__config<br>   |__common.env<br>   |__connections.yml<br>   |__requirements.txt<br>   |__setup_connections.py<br>   |__variables.json<br>|__docker-compose.yml<br>|__Dockerfile<br>|__entrypoint.sh</pre><h3>Step 2: Define Environment Variables &amp; Additional Python Packages</h3><p>Let’s first define the environment variables that we will be using within our docker-compose.yml file for Postgres, Redis, and Airflow. I choose to use a single environment file for simplification reasons; however, you can split them out into separate files or directly define them within a docker-compose file.</p><ul><li><strong>common.env</strong></li></ul><pre># Postgres DB <br>POSTGRES_USER=airflow<br>POSTGRES_PASSWORD=airflow<br>POSTGRES_DB=airflow<br>POSTGRES_PORT=5432<br>POSTGRES_HOST=postgres</pre><pre># Redis<br>REDIS_HOST=redis<br>REDIS_PORT=6379</pre><pre># Airflow User <br>AF_USER_NAME=airflow<br>AF_USER_PASSWORD=airflow<br>AF_USER_FIRST_NAME=Tejas<br>AF_USER_LAST_NAME=M<br>AF_USER_EMAIL=test@test.com<br>AF_USER_ROLE=Admin</pre><p>Use this requirements.txt file to install any additional python packages that you may need.</p><ul><li><strong>requirements.txt</strong></li></ul><pre>snowflake-connector-python==2.3.8</pre><h3>Step 3: Define Connections and Variables for Airflow</h3><p>All your needed connections for Airflow can be defined in this YAML file.</p><ul><li><strong>connections.yml</strong></li></ul><pre>SAMPLE_DB:<br>  conn_type: mysql<br>  host: 192.168.254.210<br>  login: myuser<br>  password: mypassword<br>  schema: sample_db<br>  port: 3306<br>SAMPLE_HTTP:<br>  conn_type: http<br>  login: myuser<br>  password: mypassword</pre><p>Any required variables can be added in a variable.json file.</p><ul><li><strong>variables.json</strong></li></ul><pre>{<br>    &quot;NOTIFICATION_EMAILS&quot;: &quot;test@test.com&quot;,<br>    &quot;sample_api_secret&quot;: &quot;abc123&quot;<br>}</pre><h3>Step 4: Python Script to Create Connections in Airflow</h3><p>We will use the following python script to create all connections that are defined in the previous step.</p><ul><li><strong>setup_connections.py</strong></li></ul><pre>import yaml<br>from airflow import settings<br>from airflow.models import Connection<br><br>with open(&quot;connections.yml&quot;, &quot;r&quot;) as f:<br>    connection_dict = yaml.safe_load(f.read())</pre><pre>for connection_name, connection in connection_dict.items():<br>    conn = Connection(<br>        conn_id=connection_name,<br>        conn_type=connection.get(&#39;conn_type&#39;),<br>        host=connection.get(&#39;host&#39;),<br>        login=connection.get(&#39;login&#39;),<br>        password=connection.get(&#39;password&#39;),<br>        port=connection.get(&#39;port&#39;),<br>        schema=connection.get(&#39;schema&#39;),<br>        extra=connection.get(&#39;extra&#39;)<br>    ) <br>    session = settings.Session<br>    session.add(conn)<br>    session.commit()</pre><h3>Step 5: Create a DAG File for Testing</h3><p>This is a sample DAG file to demonstrate our working distributed Airflow environment. We are using two BashOperators and each of these will run on separate worker nodes.</p><ul><li><strong>sample-dag.py</strong></li></ul><pre>from airflow import DAG<br>from airflow.operators.bash_operator import BashOperator<br>from datetime import datetime, timedelta</pre><pre>default_args = {<br>  &#39;owner&#39;: &#39;airflow&#39;,<br>  &#39;depends_on_past&#39;: False,<br>  &#39;start_date&#39;: datetime(2021, 1, 15),<br>  &#39;email&#39;: [&#39;<a href="/service/mailto:airflow@example.com">airflow@example.com</a>&#39;],<br>  &#39;email_on_failure&#39;: False,<br>  &#39;email_on_retry&#39;: False,<br>  &#39;retries&#39;: 1,<br>  &#39;retry_delay&#39;: timedelta(minutes=5),<br>}</pre><pre>dag = DAG(  &#39;dist_example&#39;,<br>        schedule_interval=&#39;0 0 * * *&#39; ,<br>                catchup=False,<br>        default_args=default_args<br>    )<br>create_command = &#39;echo $(hostname)&#39;</pre><pre>t1 = BashOperator(<br>  task_id=&#39;task_for_q1&#39;,<br>  bash_command=create_command,<br>  queue=&#39;queue_1&#39;,<br>  dag=dag<br>)</pre><pre>t2 = BashOperator(<br>  task_id= &#39;task_for_q2&#39;,<br>  bash_command=create_command,<br>  queue=&#39;queue_2&#39;,<br>  dag=dag<br>)</pre><pre>t1 &gt;&gt; t2</pre><h3>Step 6: Prepare Dockerfile to Create a Base Image</h3><p>We are going to use the <strong>python:3.8-slim-buster</strong> image for the Airflow webserver, scheduler, worker nodes, and worker monitor. We are installing netcat, which will be used in the entrypoint.sh script to check the service status for Postgres and Redis. We are also installing vim editor in case if you have to view any config files in docker for debugging purposes.</p><p>Finally, we use pip to install the apache-airflow with selected packages. You can also define any additional python packages in requirements.txt in Step 2.</p><ul><li><strong>Dockerfile</strong></li></ul><pre>FROM python:3.8-slim-buster<br>RUN apt-get update &amp;&amp; \<br>    apt-get install -y netcat &amp;&amp; \<br>    apt-get install vim -y &amp;&amp; \<br>    pip3 install apache-airflow[celery,redis,postgres,crypto]==2.0.0<br>WORKDIR /root/airflow<br>COPY config/variables.json variables.json<br>COPY config/connections.yml connections.yml<br>COPY config/setup_connections.py setup_connections.py<br>COPY config/requirements.txt requirements.txt<br>COPY entrypoint.sh entrypoint.sh<br>COPY dags/ dags<br>ENTRYPOINT [&quot;./entrypoint.sh&quot;]</pre><h3>Step 7: Define Entrypoint for Airflow Docker Images</h3><p>We will use this parameterize shell-script to start the web server, worker nodes, and worker monitor thru docker-compose.yml.</p><ul><li><strong>entrypoint.sh</strong></li></ul><pre>#!/usr/bin/env bash<br>TRY_LOOP=&quot;20&quot;<br>wait_for_port() {<br>  local name=&quot;$1&quot; host=&quot;$2&quot; port=&quot;$3&quot;<br>  local j=0<br>  while ! nc -z &quot;$host&quot; &quot;$port&quot; &gt;/dev/null 2&gt;&amp;1 &lt; /dev/null; do<br>    j=$((j+1))<br>    if [ $j -ge $TRY_LOOP ]; then<br>      echo &gt;&amp;2 &quot;$(date) - $host:$port still not reachable, giving up&quot;<br>      exit 1<br>    fi<br>    echo &quot;$(date) - waiting for $name $host... $j/$TRY_LOOP&quot;<br>    sleep 5<br>  done<br>}<br>create_airflow_user() {<br>  airflow users create \<br>  --username &quot;$AF_USER_NAME&quot; \<br>  --firstname &quot;$AF_USER_FIRST_NAME&quot; \<br>  --lastname &quot;$AF_USER_LAST_NAME&quot; \<br>  --role &quot;$AF_USER_ROLE&quot; \<br>  --email &quot;$AF_USER_EMAIL&quot; \<br>  --password &quot;$AF_USER_PASSWORD&quot;<br>}<br>setup_airflow_variables() {<br>    if [ -e &quot;variables.json&quot; ]; then<br>      echo &quot;Start importing Airflow variables&quot;<br>      airflow variables import variables.json<br>    fi<br>}<br>setup_airflow_connections() {<br>    if [ -e &quot;connections.yml&quot; ]; then<br>      echo &quot;Start setting up Airflow connections&quot;<br>      python3 setup_connections.py<br>    fi<br>}<br>install_python_packages() {<br>    if [ -e &quot;requirements.txt&quot; ]; then<br>      echo &quot;Installing additional Python packages&quot;<br>      pip3 install -r requirements.txt<br>    fi<br>}<br>wait_for_port &quot;Postgres&quot; &quot;$POSTGRES_HOST&quot; &quot;$POSTGRES_PORT&quot;<br>wait_for_port &quot;Redis&quot; &quot;$REDIS_HOST&quot; &quot;$REDIS_PORT&quot;</pre><pre>export AIRFLOW__CORE__SQL_ALCHEMY_CONN \<br>AIRFLOW__CELERY__RESULT_BACKEND \<br>AIRFLOW__CORE__FERNET_KEY \<br>AIRFLOW__CORE__LOAD_EXAMPLES \<br>AIRFLOW__CORE__EXECUTOR</pre><pre>AIRFLOW__CORE__SQL_ALCHEMY_CONN=&quot;postgres+psycopg2://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB&quot;<br>AIRFLOW__CELERY__RESULT_BACKEND=&quot;db+postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB&quot;<br>AIRFLOW__CORE__LOAD_EXAMPLES=False<br>AIRFLOW__CORE__EXECUTOR=CeleryExecutor<br>AIRFLOW__CORE__FERNET_KEY=&quot;wVKXj_gUFi0scVsP-HARZYyxxihQCpj3B2gA_ERaIBE=&quot;</pre><pre>case &quot;$1&quot; in<br>    webserver)<br>        airflow db init<br>        sleep 10<br>        create_airflow_user<br>        setup_airflow_variables<br>        setup_airflow_connections<br>        install_python_packages<br>        exec airflow scheduler &amp;<br>        exec airflow webserver<br>        ;;<br>    worker)<br>        airflow db init<br>        sleep 10<br>        install_python_packages<br>        exec airflow celery &quot;$@&quot; -q &quot;$QUEUE_NAME&quot;<br>        ;;<br>    flower)<br>        airflow db init<br>        sleep 10<br>        exec airflow celery &quot;$@&quot;<br>        ;;<br>    *)<br>        exec &quot;$@&quot;<br>        ;;<br>esac</pre><h3>Step 8: Put Together into a Docker-Compose</h3><p>This is the final-step to package everything together before we can spin-up our distributed Airflow environment. We have six different services, which match what I graphically depicted in Step 1. The Redis container will run on port 6379, and the Postgres container on port 5432. We are also passing required values through our environment file, common.env, to the Postgres image. Both the Redis and Postgres can start independently.</p><p>The Airflow webserver requires Postgres for the metadata, thus we have added dependency by adding a “depends_on” tag in the docker-compose file. The webserver is available through port 8080. The two workers are available on a separate port, the first worker is available on port 8081, and the second one is available on 8082. Each worker is associated with a queue. The name of the queue is defined under an environment variable called QUEUE_NAME. Finally, the worker monitor, Celery Flower, will be available on port 5555.</p><ul><li><strong>docker-compose.yml</strong></li></ul><pre>version: &#39;3.7&#39;<br>services:</pre><pre>redis:<br>    image: redis:latest<br>    ports:<br>      - &quot;6379:6379&quot;<br>  <br>  postgres:<br>    image: postgres:9.6<br>    env_file:<br>      - config/common.env<br>    ports:<br>      - &quot;5432:5432&quot;<br>    healthcheck:<br>      test: [ &quot;CMD-SHELL&quot;, &quot;pg_isready -U airflow&quot; ]<br>      interval: 10s<br>      timeout: 5s<br>      retries: 5</pre><pre>airflow-webserver:<br>      build: .<br>      restart: always<br>      command: webserver<br>      depends_on:<br>        postgres:<br>          condition: service_healthy<br>      ports:<br>        - &quot;8080:8080&quot;<br>      env_file: <br>        - config/common.env<br>      healthcheck:<br>        test: [ &quot;CMD-SHELL&quot;, &quot;[ -f /airflow/airflow-webserver.pid ]&quot; ]<br>        interval: 30s<br>        timeout: 30s<br>        retries: 3</pre><pre>airflow-worker-1:<br>      build: .<br>      command: worker<br>      restart: always<br>      depends_on:<br>        - airflow-webserver<br>      ports:<br>        - &quot;8081:8080&quot;<br>      env_file: <br>        - config/common.env<br>      environment:<br>        - QUEUE_NAME=queue_1</pre><pre>airflow-worker-2:<br>      build: .<br>      command: worker<br>      restart: always<br>      depends_on:<br>        - airflow-webserver<br>      ports:<br>        - &quot;8082:8080&quot;<br>      env_file: <br>        - config/common.env<br>      environment:<br>        - QUEUE_NAME=queue_2</pre><pre>airflow-flower:<br>      build: .<br>      command: flower<br>      restart: always<br>      depends_on:<br>        - airflow-worker-1<br>        - airflow-worker-2<br>      ports:<br>        - &quot;5555:5555&quot;<br>      env_file: <br>        - config/common.env</pre><h3>Step 9: Deploy Distributed Airflow</h3><p>If everything is configured correctly, you should be able to execute the following command from the airflow-docker directory. If you encounter any issue starting the docker containers, then check your configuration files.</p><pre>docker-compose up -d --build</pre><p>Let’s confirm all your containers are up and running by executing the following command:</p><pre>docker ps</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SNqDBZUImZ2ZMlqwfep28Q.png" /><figcaption>List of Running Containers</figcaption></figure><p>If you see all your six containers running, then you have successfully deployed your distributed Airflow environment on your local machine. Now let’s verify it is working in a distributed mode by executing our sample DAG file. Navigate to the Airflow UI at <a href="http://localhost:8080/">http://localhost:8080</a> and login with the username and password you defined in your common.env file. Once you log in, you should see a DAG called, “dist_example”. It will execute it after a few seconds once you unpause it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jafs42T2A4iMDBPPffLw2A.png" /><figcaption>Airflow UI DAGs View</figcaption></figure><p>If it runs successfully, you should check the log for each of its tasks to ensure both tasks ran on a different worker node. You should see a different hostname for both logs as indicated below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*U_ezT9WdDyvlqBKyziceXQ.png" /><figcaption>Log for Task 1 (task_for_q1)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*BEKhHlU4LtGqTcqezfXBFg.png" /><figcaption>Log for Task 2 (task_for_q2)</figcaption></figure><p>You can also confirm this by navigating to Worker Monitor (Celery Flower) at <a href="http://localhost:5555/dashboard">http://localhost:5555/dashboard</a>. You should see similar output as indicated below screenshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1GrqmmpRAWBo79Ya1cVqFg.png" /></figure><p>If you made it this far, then you have successfully deployed a distributed Airflow environment. Congratulations!</p><h3>Conclusion</h3><p>In this article, I explained how to quickly stand up a distributed Airflow environment with Redis and Celery on your local machine. This setup will help you during your workflow development and testing phase. I hope all scripts from this article will help you as a starting point to quickly stand up an environment for your need. I hope you find these step-by-step instructions useful. Please leave your comment below for this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e668e003b5c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/how-to-scale-out-apache-airflow-2-0-with-redis-and-celery-3e668e003b5c">How to Scale-out Apache Airflow 2.0 with Redis and Celery</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modern Data Platform Using Open Source Technologies]]></title>
            <link>https://medium.com/codex/modern-data-platform-using-open-source-technologies-212ba8273eab?source=rss-aec09b3f2c57------2</link>
            <guid isPermaLink="false">https://medium.com/p/212ba8273eab</guid>
            <category><![CDATA[minio]]></category>
            <category><![CDATA[data-warehouse]]></category>
            <category><![CDATA[presto]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-lake]]></category>
            <dc:creator><![CDATA[Tejas Marvadi]]></dc:creator>
            <pubDate>Mon, 11 Jan 2021 23:09:00 GMT</pubDate>
            <atom:updated>2021-01-12T16:00:35.535Z</atom:updated>
            <content:encoded><![CDATA[<h4><a href="https://medium.com/codex">CODEX</a></h4><h3>Modern Data Platform using Open Source Technologies</h3><p>Are you looking to build a modern data warehouse or a data lake for your organization? If so, should you build one from the ground up or use off-the-shelf from the market? It’s a tough question to answer. In this article, I am going to share some detail on a couple of open source technologies — <a href="https://trino.io/">Trino</a> and <a href="https://min.io/">MinIO</a> — that can be leveraged to build this modern data warehouse either on-premises or on a public cloud. I briefly shared a step-by-step process in my previous article (<a href="https://tmarvadi.medium.com/how-to-build-a-modern-data-lake-with-minio-db0455eec053">How to Build a Data Lake with MinIO</a>) on how to set it up. These two powerful yet lightweight and scalable tools have so much to offer. It’s worth looking at them before you decide to shell out money to a cloud-based data-warehousing company. This article is going to give you an overview of Trino and MinIO, and it also touches upon some features that they can offer once you implement them together as a data platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UGemxMoj7FiqbvRrNlqX3A.jpeg" /></figure><h3>What is Trino?</h3><p>Trino is really fast and proven at scale with performance. It is a distributed SQL query engine designed to handle a large volume of data over heterogeneous data sources. It can perform a cross-platform query — meaning you can join data across multiple databases that are on separate servers, and they do not need to be within the same data center. It supports both structured and semi-structured data. This gives advantages to data analysts and data scientists because the data is readily available for them to use.</p><p>Trino architecture is very similar architecture as MPP (Massively Parallel Processing) database management system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*RjFyL16WKY-qOZqYmsJfMw.png" /><figcaption>Trino Architecture</figcaption></figure><p>It has a coordinator node working in-sync with multiple worker nodes. When users submit their SQL query to the coordinator, which uses a custom query and execution engine to parse, plan, and schedule a distributed query plan across the worker nodes. It is designed to support standard ANSI SQL semantics, including complex queries, aggregations, joins, sub-queries, window functions, distinct counts, and approximate percentiles.</p><p>No matter where your data lives, Trino uniformly allows access to data through its SQL abstraction layer. The query result returns are extremely fast because of in-memory processing. The intermediate data is pipelined across nodes in the MPP fashion, thus it leads to highly interactive query performance. Trino allows querying data where it lives, and this works for both NoSQL and SQL databases. A single query can combine data from multiple sources allowing you to analyze the data across your entire organization. Trino offers a wide range of connectors such as MySQL, Oracle, SQL Server, Redshift, Kafka, Elasticseach, and many more (see <a href="https://trino.io/docs/current/connector.html">complete list</a>).</p><h3><strong>What is MinIO?</strong></h3><p>MinIO is a high performance distributed object storage server, which is compatible with Amazon S3. It can store unstructured data such as photos, videos, log files, backups, and container images. It can be deployed on different hardware. The power of MinIO unleased when you deploy it as a cluster in multiple nodes. It is designed to be minimal and scalable. It is light enough to be bundled along with other application stacks. It protects against data corruption and hardware failure using <a href="https://docs.min.io/docs/minio-erasure-code-quickstart-guide">erasure code</a> and<a href="https://github.com/minio/minio/blob/master/docs/erasure/README.md#what-is-bit-rot-protection"> bit-rot protection</a>. It offers a wide range of authentication integration such as Active Directory and Okta. It provides both high-performance and strict read after write consistency for all I/O operations. It is an open-source distributed object storage solution that runs on commodity servers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BzJjAuu1egLoEvgQ" /><figcaption>MinIO Architecture</figcaption></figure><h3>Trino + MinIO = Modern Data Platform</h3><p>Trino and MinIO together can create a modern data platform or you can call it a modern data warehouse. The implementation of MinIO provides a storage solution, whereas Trino serves as a compute. The separation of both the storage and compute provide a scalable platform without any disruption. With this implementation, you have full flexibility to scale out the MinIO cluster without impacting the Trino cluster and vice versa. You can even deploy Trino and MinIO on a public cloud platform in Kubernetes or in a managed service Kubernetes, and it would provide an ultimate solution for your data platform.</p><p>The combination of Trino and MinIO provide essentially similar functionalities as what cloud-based data-warehousing companies have to offer. You do not have to worry about data ingress and egress cost with this setup. It also eliminates the vendor lock-in and allows us much-needed flexibility. If you have the right staff and expertise in your team, it’s worth exploring these technologies. The benefit includes having all your data in your private cloud if you decide to deploy it on-premises.</p><p>Here are some arbitrary examples demonstrating some of the operations that can be performed when you build your data platform with both Trino and MinIO.</p><ul><li>Create a schema-on-read on top of the data files that are in the MinIO bucket. You can essentially create schema-on-read on a variety of file types including ORC, Parquet, JSON, and many more.</li></ul><pre>CREATE TABLE datalake.first_schema.customer <br>(customer_id VARCHAR, <br> name VARCHAR, <br> full_name VARCHAR<br>)<br>WITH (external_location=&#39;s3a://raw-data/&#39;,format = &#39;csv&#39;, skip_header_line_count=1);</pre><ul><li>Running a query across disparate source systems without moving any data into the MinIO cluster. With a predicate push-down support, the performance of your query would be lightning fast.</li></ul><pre>SELECT erp_account.id, erp_account_name, sum(crm_customer.amount) <br>FROM <br>oracle_erp.erp_schema.account erp_account,   # Oracle<br>mysql_crm.crm_schema.customer crm_customer,  # MySQL datalake.first_schema.customer csv_customer  # CSV File<br>WHERE erp_account.cmr_id = crm_customer.id<br>  AND crm_customer.id = csv_customer.id<br>GROUP BY erp_account.id, erp_account_name;</pre><ul><li>The Machine Learning plugin provides ML functionality that can train Support Vector Machine (SVM) based classifiers and regressors for the supervised learning problems using SQL.</li></ul><pre>SELECT<br>classify(features(2.9, 3, 5.1, 1.8), model) AS predicted_label<br>FROM <br>(SELECT learn_classifier(species, features(sepal_length, sepal_width, petal_length, petal_width)) AS model <br>FROM <br>datalake.data_analytics.iris<br>) t;</pre><ul><li>Trino provides a client interface for different languages such as <a href="https://github.com/trinodb/trino-python-client">Python</a> and <a href="https://github.com/trinodb/trino-go-client">GO</a> to connect Trino. Please refer to their <a href="https://github.com/trinodb">Github</a> for more details. Here’s a Python code example of connecting to Trino using Basic Authentication.</li></ul><pre>import trino<br>conn = trino.dbapi.connect(<br>    host=&#39;coordinator url&#39;,<br>    port=8443,<br>    user=&#39;the-user&#39;,<br>    catalog=&#39;the-catalog&#39;,<br>    schema=&#39;the-schema&#39;,<br>    http_scheme=&#39;https&#39;,<br>    auth=trino.auth.BasicAuthentication(&quot;principal id&quot;, &quot;password&quot;),<br>)<br>cur = conn.cursor()<br>cur.execute(&#39;SELECT * FROM system.runtime.nodes&#39;)<br>rows = cur.fetchall()</pre><h3>Conclusion</h3><p>In this article, I share detail on two powerful open-source technologies — Trino and MinIO. Together they allow you to build a modern data platform either on-premises or on a public cloud. If you have the right resources in your team, I recommend considering this setup because it provides flexibility and full control over your data.</p><p>If you are interested in building this platform, you can refer to the step-by-step basic implementation guide in my previous article (<a href="https://tmarvadi.medium.com/how-to-build-a-modern-data-lake-with-minio-db0455eec053">How to Build a Data Lake with MinIO</a>).</p><p>I hope you find this article useful. Please leave your comment below for this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=212ba8273eab" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/modern-data-platform-using-open-source-technologies-212ba8273eab">Modern Data Platform Using Open Source Technologies</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build a Modern Data Lake with MinIO]]></title>
            <link>https://medium.com/codex/how-to-build-a-modern-data-lake-with-minio-db0455eec053?source=rss-aec09b3f2c57------2</link>
            <guid isPermaLink="false">https://medium.com/p/db0455eec053</guid>
            <category><![CDATA[data-lake]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[minio]]></category>
            <category><![CDATA[presto]]></category>
            <category><![CDATA[how-to]]></category>
            <dc:creator><![CDATA[Tejas Marvadi]]></dc:creator>
            <pubDate>Sun, 10 Jan 2021 00:09:37 GMT</pubDate>
            <atom:updated>2021-01-12T16:07:21.311Z</atom:updated>
            <content:encoded><![CDATA[<h4><a href="https://medium.com/codex">CODEX</a></h4><p>In this article, the focus is to build a modern data lake using only open source technologies. I will walk-through a step-by-step process to demonstrate how we can leverage an S3-Compatible Object Storage (<a href="https://min.io/">MinIO</a>) and a Distributed SQL query engine (<a href="https://trino.io/">Trino</a>) to achieve this. This setup can be used for development by data engineers and developers. The method I discuss here can also be extended to deploy in a distributed production environment at your organization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x34kpls1wPa8kHVmR2L77Q.jpeg" /></figure><h3>Prerequisite</h3><ol><li>Linux OS (64-bit)</li><li>Python 2.6.x, 2.7.x, or 3.x</li><li>Java JDK</li></ol><h3>Step 1: Download MinIO and MinIO Client</h3><p>Let’s download the executable from MinIO using <strong>wget</strong> and make these files executable using the following commands.</p><pre><strong>$ wget</strong> <a href="https://dl.min.io/server/minio/release/linux-amd64/minio">https<strong>://</strong>dl.min.io<strong>/</strong>server<strong>/</strong>minio<strong>/</strong>release<strong>/</strong>linux-amd64<strong>/</strong>minio</a><br><strong>$ chmod</strong> <strong>+x</strong> minio<strong><br>$ wget</strong> <a href="https://dl.min.io/client/mc/release/linux-amd64/mc">https<strong>://</strong>dl.min.io<strong>/</strong>client<strong>/</strong>mc<strong>/</strong>release<strong>/</strong>linux-amd64<strong>/</strong>mc</a><br>$ <strong>chmod</strong> <strong>+x</strong> mc</pre><h3>Step 2: Create storage and Start MinIO Server</h3><p>For MinIO to work, a local directory is required to store the data. Let’s create a directory in a local file system, and start the MinIO server pointing to that local directory.</p><pre><strong>$ mkdir</strong> minio_storage<strong><br>$ ./minio server</strong> /home/demo/minio_storage</pre><p>Once you execute the above commands, you should see the output in your terminal as shown below. Please note down the Endpoint IP address, AccessKey, and SecretKey in order to access the MinIO through a web browser. Let’s keep this terminal window open, so the MinIO server can continue to run and we can use it for the remaining of our steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NJGuLPyCXOFz_l-spEokmA.png" /><figcaption>MinIO Server Terminal Output</figcaption></figure><h3>Step 3: Access the Web UI</h3><p>You should be able to access the MinIO Web UI using the Endpoint IP address from the previous step. This confirms that our MinIO instance up and running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*M69BYlKKfsS-NDe2RgF_eg.png" /><figcaption>MinIO Web UI Login Page</figcaption></figure><p>Once you submit your access key and secret key at the login page, you should have access to the MinIO home page, where you can create new buckets and upload new files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VjE7ZTNPyB3drUnuHu-uDQ.png" /><figcaption>MinIO Landing Page</figcaption></figure><p>Instead of creating buckets through Web UI, let’s look at the MinIO client that we downloaded in Step 1, and we will utilize it to create a bucket from there.</p><h3>Step 4: Set up an alias for MinIO using MinIO Client</h3><p>Before we start interacting with our MinIO instance, it is important that we set up an alias for it. MinIO alias would be helpful, especially when you’re using MinIO clients. Let’s create an alias called “myminio” for our MinIO instance by executing the following command in a new terminal window.</p><pre><strong>$ ./mc config host add</strong> myminio <a href="http://127.0.0.1:9000/">http://127.0.0.1:9000</a> minioadmin minioadmin</pre><p>Once you execute the above command, you should get the following success message “<strong>Added ‘myminio’ successfully</strong>”.</p><h3>Step 5: Create an S3 bucket in MinIO</h3><p>Let’s utilize the MinIO client to create your first S3 bucket called “<strong>datalake</strong>”.</p><pre><strong>$ ./mc mb</strong> myminio/datalake</pre><p>Let’s confirm that your S3 bucket has been successfully created by executing the following command:</p><pre><strong>$ ./mc ls</strong> myminio</pre><p>You should see a “datalake” as your S3 object in the list. You can also confirm this using the MinIO web console by navigating to <a href="http://127.0.0.1:9000/">http://127.0.0.1:9000</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*ghMTbcnMeBCNepZdgPzuUg.png" /></figure><p>There are many other commands available for MinIO client, which can be helpful in managing your environment. You can refer to a comprehensive list of commands available on the <a href="https://docs.min.io/docs/minio-client-complete-guide.html">MinIO Client documentation</a>.</p><p>Yay! The MinIO service is up and running. If you need to set up the MinIO in a distributed-mode, please refer to this <a href="https://docs.min.io/docs/distributed-minio-quickstart-guide.html">documentation</a>. We’re halfway there now with our data lake setup. We just need to set up one more tool — Trino (previously known as PrestoSQL), which would enable us to interact with our MinIO environment that we just created.</p><h3>Step 6: Download Trino Server</h3><p>To better organize let’s create a parent folder called trino with the following commands.</p><pre><strong>$ cd</strong> /opt<br><strong>$ mkdir</strong> trino<strong><br>$ cd trino</strong></pre><p>Let’s grab the Trino server file and uncompress it. I like to drop the version from the folder for convenience.</p><pre><strong>$ wget</strong> <a href="https://repo1.maven.org/maven2/io/trino/trino-server/351/trino-server-351.tar.gz">https://repo1.maven.org/maven2/io/trino/trino-server/351/trino-server-351.tar.gz</a><br><strong>$ tar xvf</strong> trino-server-351.tar.gz<br><strong>$ mv</strong> trino-server-351 server</pre><h3>Step 6: Configuring Trino Server</h3><p>Trino needs a data directory for storing logs, etc. Trino recommends creating a data directory outside of the installation directory, which allows it to be easily preserved when upgrading Trino. So let’s create a data directory under the /opt/trino folder.</p><pre><strong>$ mkdir</strong> data</pre><p>Create the following two directories under the /opt/trino/server folder to hold configuration files.</p><pre><strong>$ mkdir</strong> etc <strong><br>$ mkdir</strong> catalog</pre><p>Now we need to create four new files as following:</p><ul><li><strong>etc/node.properties</strong>: environment configuration specific to each node</li><li><strong>etc/jvm.config</strong>: command-line options for JVM</li><li><strong>etc/config.properties</strong>: configuration for the Trino server</li><li><strong>catalog/datalake.properties</strong>: configuration for MinIO data sources</li><li><strong>catalog/mysql.properties</strong>: configuration for MySQL (This file is not required. Just adding this to demonstrate the usage of the data lake. You can create your own configuration for different databases. Refer to Trino documentation for <a href="https://trino.io/docs/current/connector.html">supported connectors</a>.)</li></ul><p><strong>node.properties:</strong></p><pre>node.environment=development<br>node.id=0bc6c957-0404-490f-8f6a-8db6e8f3cf2b<br>node.data-dir=/opt/trino/data</pre><p><strong><em>Note: </em></strong><em>you can pick any name you like for the node.environment. For node.id, you can generate your own uuid using uuidgen tool.</em></p><p><strong>config.properties:</strong></p><pre>coordinator=true<br>node-scheduler.include-coordinator=true<br>http-server.http.port=8080<br>query.max-memory=1GB<br>query.max-memory-per-node=1GB<br>query.max-total-memory-per-node=2GB<br>discovery-server.enabled=true<br>discovery.uri=http://127.0.0.1:8080<br>http-server.authentication.type=PASSWORD</pre><p><strong>jvm.config:</strong></p><pre>-server<br>-Xmx16G<br>-XX:-UseBiasedLocking<br>-XX:+UseG1GC<br>-XX:G1HeapRegionSize=32M<br>-XX:+ExplicitGCInvokesConcurrent<br>-XX:+ExitOnOutOfMemoryError<br>-XX:+HeapDumpOnOutOfMemoryError<br>-XX:ReservedCodeCacheSize=512M<br>-XX:PerMethodRecompilationCutoff=10000<br>-XX:PerBytecodeRecompilationCutoff=10000<br>-Djdk.attach.allowAttachSelf=true<br>-Djdk.nio.maxCachedBufferSize=2000000</pre><p><strong>datalake.properties:</strong></p><pre>connector.name=hive-hadoop2<br>hive.metastore=file<br>hive.s3-file-system-type=TRINO<br>hive.metastore.catalog.dir=s3://datalake/<br>hive.s3.aws-access-key=minioadmin<br>hive.s3.aws-secret-key=minioadmin<br>hive.s3.endpoint=127.0.0.1:9000<br>hive.s3.path-style-access=true<br>hive.s3select-pushdown.enabled=true<br>hive.s3.ssl.enabled=false</pre><p><strong>mysql.properties:</strong></p><pre>connector.name=mysql<br>connection-url=jdbc:mysql://192.168.254.210:3306<br>connection-user=myuser<br>connection-password=mypassword<br>case-insensitive-name-matching=true</pre><p>For all configuration options, please refer to <a href="https://trino.io/docs/current/index.html">Trino Documentation</a>.</p><h3>Step 7: Run Trino Server</h3><p>If everything is configured correctly, you should be able to execute the following command from the /opt/presto/server directory. If you encounter any issue starting the Trino server, then check your configuration files.</p><pre>bin/launcher run</pre><h3><strong>Step 8: Testing our Data Lake</strong></h3><p>We will need a Trino command-line client to run queries and test our data lake, so let’s download it. Open up a new terminal and run the following command from the /opt/trino folder.</p><pre><strong>$ wget</strong> <a href="https://repo1.maven.org/maven2/io/trino/trino-cli/351/trino-cli-351-executable.jar">https://repo1.maven.org/maven2/io/trino/trino-cli/351/trino-cli-351-executable.jar</a></pre><p>Run the following command to connect to Trino.</p><pre><strong>$ java -jar</strong> trino-cli-351-executable.jar</pre><p>You should be now in a Trino console, you can type show catalogs and you should see three catalog names: datalake, mysql, and system.</p><pre><strong>trino&gt;</strong> SHOW CATALOGS;<br> Catalog  <br>----------<br> datalake <br> mysql    <br> system   <br>(3 rows)</pre><p>Before we start creating anything in our data lake, we need to create a schema.</p><pre><strong>trino&gt;</strong> CREATE SCHEMA datalake.myschema;<br>CREATE SCHEMA</pre><p>Now that we have the schema created, let’s replicate a table from MySQL to our data lake using just a SQL statement.</p><pre><strong>trino&gt;</strong> CREATE TABLE datalake.myschema.category AS SELECT * FROM mysql.homedb.category;<br>CREATE TABLE: 22 rows</pre><p>We just created a table in our data lake with just a plain SQL statement. We did not need any ETL tool or write any Python or Java code. Let’s just confirm the data is available in the data lake.</p><pre><strong>trino&gt;</strong> SELECT * FROM datalake.myschema.category;<br>  id   |            name            <br>-------+----------------------------<br>  1900 | Beer                       <br>  1901 | Beverages                  <br>  1902 | Deli                       <br>  1903 | Floral                     <br>  1904 | Health and Beauty Care     <br>  1905 | Delivered Fresh Daily      <br>  1906 | From Our Kitchen           <br>  1907 | Meal Makers                <br>  1908 | Canned goods &amp; Soup        <br>  1909 | Pet care                   <br>  1910 | Condiments Spices &amp; Baking <br>  1911 | Baby                       <br>  1912 | Dairy Eggs &amp; Cheese        <br>  1913 | Paper Cleaning &amp; Home      <br>  1914 | Cookies Snacks &amp; Candy     <br>  1915 | Breakfast &amp; Cereal         <br>  1916 | General merchandise        <br>  1917 | Bread &amp; Bakery             <br>  4628 | Meat                       <br>  4629 | Seafood                    <br>  4630 | Produce                    <br>  4634 | Frozen food                <br>(22 rows)</pre><h3>Conclusion</h3><p>In this article, I explained how to stand up a data lake quickly on your local machine or VM. This setup can be extended to deploy an on-premise data lake in your organization, without going to a third-party vendor like AWS or GCP. Both MinIO and Trino are scalable solutions and they provide comprehensive documentation on their website.</p><p>You can read my article <a href="https://tmarvadi.medium.com/modern-data-platform-using-open-source-technologies-212ba8273eab">Modern Data Platform Using Open Source Technologies</a> if you would like to learn more about Trino and MinIO. I hope you find this article useful. Please leave your comment below for this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db0455eec053" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/how-to-build-a-modern-data-lake-with-minio-db0455eec053">How to Build a Modern Data Lake with MinIO</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>