<?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[Big Data Engineering - Medium]]></title>
        <description><![CDATA[Best technical posts about data (we love both small and big) - Medium]]></description>
        <link>https://medium.com/big-data-engineering?source=rss----f93e9b51fb56---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Big Data Engineering - Medium</title>
            <link>https://medium.com/big-data-engineering?source=rss----f93e9b51fb56---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 07:03:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/big-data-engineering" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Amazon Redshift CI/CD - How we did it and why you should do it too]]></title>
            <link>https://medium.com/big-data-engineering/redshift-cicd-how-we-did-it-and-why-you-should-do-it-to-e46ecf734eab?source=rss----f93e9b51fb56---4</link>
            <guid isPermaLink="false">https://medium.com/p/e46ecf734eab</guid>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[redshift]]></category>
            <dc:creator><![CDATA[Doron Vainrub]]></dc:creator>
            <pubDate>Mon, 03 Feb 2020 14:24:40 GMT</pubDate>
            <atom:updated>2020-02-18T07:06:53.927Z</atom:updated>
            <content:encoded><![CDATA[<h3>Amazon Redshift CI/CD — How we did it and why you should do it too</h3><h3>Databases CI/CD</h3><p>Database development should not be handled differently from application development. Database changes should be subject to the same activities (source control, continuous integration and continuous delivery) as application changes.</p><p>The goal of continuous integration and continuous delivery (CI/CD) is to reduce time-to-market and create a steady stream of end-user value with frequent, high-quality software releases.</p><p>Organizations without a Database CI/CD pipeline go through a very slow and manual process for each database change that needs to be made:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-nAV6Bu5xWFOAwSQWU1J7g.png" /></figure><p>In addition, scripts are often lost because they might be stored at each user’s or at the DBA’s local filesystem (if they are kept at all), making it hard to reproduce changes, keep track of them and debug issues.</p><blockquote>The aim of Database CI/CD is to bring the same integration, testing and deployment best practices to the database and enable SQL scripts to flow through the software release pipeline, synchronized with application code, enabling secure and faster deployments.</blockquote><p>At <a href="https://mobility.here.com/">HERE Mobility</a>, we wanted to enjoy all these benefits and went on a journey to implement a CI/CD pipeline for our Redshift code changes. This article describes what was required for our Data Engineers to build, for our Analysts to change and the challenges we faced and how we approached them.</p><h3>Our current CI/CD pipeline</h3><p>The Analytics team is in charge of writing PySpark ETLs that read from the Data Lake (S3) and write into Redshift, our Data Warehouse.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8qHjrWlijT7TvBhrrjNnJw.png" /></figure><p>They are also in charge of writing the SQL scripts to create the relevant tables, views, UDFs, and Stored Procedures in Redshift. As in any other DWH, this can range from dim/fact tables to enrichment or reporting tool-ready views (Tableau in our case).</p><h4>Applications’ CI/CD</h4><p>Spark code has a proper CI/CD pipeline:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*56SIAJ1igSlDJDFOCxB4gg.png" /></figure><h4>Database’s CI/CD</h4><p>But Redshift SQL Scripts were just pushed to Gerrit (our VCS) without testing nor versioning and were manually applied by the analysts (most of the time skipping the Redshift instance in DEV, generating a discrepancy between both DEV and PROD environments).</p><h4>ETL Projects’ Structure</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*jcuX-qnZ_84-me5pvaVokQ.png" /></figure><p>Each ETL project corresponds to a Redshift schema, therefore, each project contains both Spark code and Redshift Scripts.</p><p>The Scripts folder is divided into tables and views folders, where each folder contains the scripts that create the relevant database object.</p><p>For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sI3gbe70VDWBtCEu4Hc1kw.png" /></figure><p>As you can see, in addition to not having a proper CI/CD pipeline for the scripts, all table fixes are appended to the same file without an easy way of keeping track of changes.</p><h3>The journey begins</h3><p>The application code’s CI/CD pipeline was already robust so we thought about integrating Redshift’s scripts into the same CI/CD process.</p><p>We came up with a list of requirements and goals for this to happen:</p><h4>1. Database code is version controlled</h4><p>Database code changes should be tracked in the same version control system as application code. Some immediate benefits this will give us:</p><ul><li>Easier to keep track of changes.</li><li>Single source of truth.</li><li>Every change to the database is stored, allowing easy audit if any problems occur.</li><li>Prevent deployments where the database is out of sync with the application.</li><li>Changes can be easily rolled back.</li><li>New environments can be created from scratch by applying these scripts.</li></ul><p>All database changes are migrations, therefore, each code change needs a unique identification.</p><p>We will need to keep track of which migrations have been applied to each database.</p><h4>2. Database Code Validation</h4><p>Once database code is checked in, a series of automated tests are immediately triggered. That way, analysts can get immediate feedback on SQL code, just as they do with application code. Some of the things we want to automatically test are:</p><ul><li>Check all tables/views/functions are following the naming conventions set by the team and that they align with the requirements of the organization.</li><li>Check correct dependencies between tables and views (column names, views referencing table columns, etc.).</li><li>Validate Redshift/PSQL Syntax.</li><li>Run unit-test for complex views.</li><li>Test code changes in a clean instance before testing them on a real one to make sure if the deployment will work as intended.</li></ul><p>In addition, everybody gets their own database instance so the same tests can also be triggered locally while developing to get feedback even faster.</p><h4>3. CI/CD pipeline</h4><p>After validating the database changes, an immutable artifact should be created together with the application code so automated DB deployments can be consistent, repeatable and predictable as application code releases. All this pipeline should be integrated into our current Jenkins pipeline.</p><h4>4. Automatic Deployments</h4><p>Analysts used to have Redshift permissions to run DDL queries manually, these permissions should be removed and automatic DB deployments should be allowed instead.</p><p>The automated deployment should be applied first on our Redshift DEV instance so the database changes and ETLs can be tested before deploying the changes to production.</p><p>In addition, this should allow us to keep both DEV and PROD instances in sync.</p><h3>Meet redCI — Our Redshift CICD tool.</h3><p>We researched for a product that can answer our requirements above, and though some nice options came up, none of them were what we were looking for, and that’s how redCI was born.</p><p>redCI is a tool that allows running unit and integration tests on PSQL-compliant queries in addition to deploying the SQL scripts into Redshift in the relevant environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*2tusDssT6Kqz9MfqGXGGKg.png" /></figure><p>This is how redCI allowed us to change the way analysts at <a href="https://mobility.here.com/">HERE Mobility</a> test and deploy their database objects:</p><h3>The Tool</h3><p>redCI is a tool written in Python that can:</p><ul><li>Connect to Redshift and Postgres.</li><li>Read and run PSQL-compliant script files.</li><li>Keep track of the latest script deployed for each table, view and function on the Database.</li><li>Convert Redshift syntax into PSQL.</li><li>Run unit tests for complex views.</li></ul><p>The tool is used across all ETL projects in addition to some changes to the projects’ Jenkins pipeline and Makefile. The following are all the changes we had to make in the projects to solve the requirements listed above.</p><h3>1. Database code is version controlled</h3><p>SQL Scripts that create or modify tables used to be appended with new changes. Not any more! From now on, each table has its own folder and each change is a new script with the version number:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wS4wv031SBHSU6hsepVUgA.png" /></figure><p>Because database changes are migrations, each script name is prefixed with a sequential number to indicate the order in which code changes were made.</p><p>Every time the need to deploy a database change arises, we simply create a new SQL script with a version number higher than the current one. The next time redCI starts, it will find it and upgrade the database accordingly.</p><p>redCI tracks which migrations have been applied to each database by keeping a <strong>changelog</strong> table in Redshift.</p><h3>2. Database Code Validation</h3><p>To allow automated tests of the Redshift changes, we needed a new Redshift instance for each deployment. Ideally, we would have used a Redshift Docker Image, but it doesn’t exist (all the images with that name are just Postgres Images). We decided to use a<strong> Postgres Docker Image </strong>(because Redshift is based on Postgres 8, these bring some issues of their own and we will talk about them later).</p><p>We changed our ETL projects so each time they are tested (locally or in Jenkins), the <strong>Postgres Docker</strong> is executed and redCI deploys all the Scripts in the project in this new, sterile, environment, thus capturing SQL bugs as fast as we can.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t6Ufky6AEdvAE6C6Vwy89A.png" /></figure><h4>Catching bugs early</h4><p>Many bugs are caught in this stage (in the past they were caught in production), for example:</p><ul><li>Broken dependencies between tables and views.</li><li>Views referencing table columns that don’t exist.</li><li>Views referencing tables or columns with a typo.</li><li>Objects that are not following the naming conventions.</li><li>Tables that don’t have required columns as defined by the company.</li><li>Redshift SQL syntax errors.</li></ul><h4>But wait… Redshift is not Postgres</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T0XVQ6_SYz7wDiQB5q60WQ.png" /></figure><p>That’s right! Redshift is based on Postgres 8 but <a href="https://docs.aws.amazon.com/redshift/latest/dg/c_redshift-and-postgres-sql.html">there are many differences </a>you should be aware of. Some Postgres functions are not supported by Redshift and the opposite.</p><p>Take for example:</p><pre><em>datediff</em>(second, d1, d2)</pre><p>this Redshift function doesn’t exist in Postgres, but there’s an equivalent method:</p><pre><em>extract(epoch from (d2::timestamp - d1::timestamp))::int8</em></pre><p>Or for example:</p><pre>DISTSTYLE<br>DISTKEY<br>SORTKEY</pre><p>These Redshift keywords do not exist in Postgres.</p><p>This all means that Redshift-SQL scripts can’t be run as-is on our Postgres Docker. That’s where redCI comes into the picture, <strong>it will parse every SQL script before being executed in Postgres and convert Redshift-only syntax to its Postgres’ equivalent </strong>where possible (first example) or comment it out when there’s no equivalent (second example).</p><h4>Testing complex views</h4><p>Part of the suite of automated tests is composed of unit tests for database views.</p><p>Some of our database views can be very complex, and each change should be carefully checked. To help analysts with this hard challenge we added support for redCI to run special unit tests.</p><p>These tests are written as SQL scripts and can be used in one of the following three ways:</p><ul><li>An SQL script that runs a view and returns “TEST_SUCCEEDED” or “TEST_FAILED”. If running the view returns the last value, redCI will mark the test as failed.</li><li>An SQL script that fills an “expected output” table and some “input tables”. The view-to-test reads from these input tables and its output is compared with the “expected output” table. If they differ, the test will fail too, with an indicative error.</li><li>Sample data can be written into the tables to verify column types and schemas.</li></ul><p>This adds a new layer to our redCI tool since we can also catch database views logic errors before they are deployed into Redshift.</p><h3>3. CI/CD pipeline and Automatic Deployments</h3><h4>Pipeline Integration</h4><p>As explained above, the existing application code’s CI/CD pipeline was upgraded to include the Postgres Docker execution and the testing of database changes.</p><p>If the Jenkins pipeline finishes successfully and the code passes one of the team member’s Code Review, an artifact containing the application and database code will be deployed.</p><h4>Deploying to Redshift</h4><p>Each project has an equivalent Airflow DAG that runs the different ETLs inside the project and fills the relevant tables.</p><p>We added a new operator, called redci-operator to each of these DAGs. It’s the first thing that runs on each DAG and all other tasks depend on it.</p><p>This operator just calls our redCI package and deploys any new table or updates any edited view/function in Redshift.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y7UK8HieqsqHeLvyUuviQA.png" /></figure><p>Our Airflow instance running in DEV takes the latest ETL project deployed. After deploying our changes to our DEV Redshift instance and making sure no errors are found, we can update the ETL project’s artifact version for the Airflow instance in PROD and run the same redci-operator.</p><p>This change brings many benefits:</p><ul><li>Both environments remain synced all the time</li><li>Redshift deployments are always checked in DEV before being applied to PROD.</li><li>Individual users don’t have permission anymore to manually run DDL queries in PROD, reducing the risk for mistakes.</li></ul><h3>Conclusion</h3><p>It is important for you to treat database changes as application code changes. They should be tested and integrated into a robust CI/CD pipeline.</p><p>We hope this article together with redCI can help you solve your own challenges.</p><p>We’d love to hear about your own challenges and how you approached them! And of course, every suggestion is welcomed!</p><h4>Useful Resources</h4><ul><li><a href="https://martinfowler.com/articles/evodb.html">https://martinfowler.com/articles/evodb.html</a></li><li><a href="https://www.datical.com/database-continuous-integration-guide/">https://www.datical.com/database-continuous-integration-guide/</a></li><li><a href="https://www.red-gate.com/hub/product-learning/sql-source-control/strategy-implementing-database-source-control">https://www.red-gate.com/hub/product-learning/sql-source-control/strategy-implementing-database-source-control</a></li></ul><p>I’m also available on <a href="https://twitter.com/dvainrub">Twitter</a> and <a href="https://www.linkedin.com/in/dvainrub/">LinkedIn</a> ;)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e46ecf734eab" width="1" height="1" alt=""><hr><p><a href="https://medium.com/big-data-engineering/redshift-cicd-how-we-did-it-and-why-you-should-do-it-to-e46ecf734eab">Amazon Redshift CI/CD - How we did it and why you should do it too</a> was originally published in <a href="https://medium.com/big-data-engineering">Big Data Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hello Kafka World! The complete guide to Kafka with Docker and Python]]></title>
            <link>https://medium.com/big-data-engineering/hello-kafka-world-the-complete-guide-to-kafka-with-docker-and-python-f788e2588cfc?source=rss----f93e9b51fb56---4</link>
            <guid isPermaLink="false">https://medium.com/p/f788e2588cfc</guid>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Doron Vainrub]]></dc:creator>
            <pubDate>Thu, 06 Jun 2019 11:43:44 GMT</pubDate>
            <atom:updated>2019-06-06T15:18:45.316Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HpMCLWYWeEv_nOAWYwCLtg.png" /></figure><h3>What is Kafka? — A quick overview</h3><p>For a complete guide, the <a href="https://kafka.apache.org/documentation.html">Kafka documentation</a> does an excellent job. Below is just a quick overview.</p><h4>Pub/Sub system</h4><p>Apache Kafka is a <strong>distributed publish-subscribe messaging system</strong> that is designed to be fast, scalable, and durable.</p><p>Kafka stores streams of records (messages) in topics. <strong>Each record consists of a key, a value, and a timestamp</strong>.</p><p>Producers write data to topics and consumers read from topics.</p><h4>Topics and Logs</h4><p>A topic is a <strong>category to which records are published</strong>. It can have zero, one, or many consumers that subscribe to the data written to it.</p><p>For each topic, the Kafka <strong>cluster maintains a partitioned log</strong>. Since Kafka is a distributed system, topics are partitioned and <strong>replicated</strong> across multiple nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/0*k_fS6XwhUjldcmy4.png" /></figure><h4>Producers and Consumers</h4><p><strong>Producers</strong> publish data to the topics of their choice. It is <strong>responsible for choosing which record to assign to which partition within the topic</strong>. This is usually done in a round-robin fashion or partitioning by a key or value.</p><p><strong>Consumer groups</strong> can subscribe to one or more topics. Each one of these groups <strong>can be configured with multiple consumers.</strong></p><p><strong>Every message</strong> in a topic <strong>is delivered to one of the consumer instances</strong> inside the group subscribed to that topic. All messages with the same key arrive at the same consumer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/0*FzuJqsAzO-3jhFFb.png" /></figure><h3>Setting up Kafka (and Zookeeper) with Docker</h3><p><em>The following steps use bash commands. If you are on Windows use the equivalents.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*kxw-d738MV_wTTS7jO8wpg.png" /></figure><h4>Docker</h4><p>Install <a href="https://www.docker.io/gettingstarted/#h_installation">Docker</a> and <a href="http://docs.docker.com/compose/install/">Docker Compose</a>.</p><p>We are going to use these two docker images: <a href="https://hub.docker.com/r/wurstmeister/kafka">wurstmeister/kafka</a> and <a href="https://hub.docker.com/r/wurstmeister/zookeeper/">wurstmeister/zookeeper</a>.</p><h4>Setting up Kafka’s Docker</h4><p>Clone the <a href="https://github.com/wurstmeister/kafka-docker">Kafka’s git project</a> and initialize the docker image.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2ccf9c7fdede1bbaac2a8edcbaca138/href">https://medium.com/media/e2ccf9c7fdede1bbaac2a8edcbaca138/href</a></iframe><h3>Hello Kafka World!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/0*lQCdBdH9AacY48zl.jpg" /></figure><h4>Kafka Shell</h4><p>To start it just run the command:</p><pre>&gt; ./start-kafka-shell.sh &lt;DOCKER_HOST_IP/KAFKA_ADVERTISED_HOST_NAME&gt;</pre><pre># In my case:<br>&gt; ./start-kafka-shell.sh 172.17.0.1</pre><h4>Hello Topic</h4><p>From within the Kafka Shell, run the following to create and describe a topic:</p><pre>&gt; $KAFKA_HOME/bin/kafka-topics.sh --create --topic test \<br>--partitions 4 --replication-factor 2 \<br>--bootstrap-server `broker-list.sh`</pre><pre>&gt; $KAFKA_HOME/bin/kafka-topics.sh --describe --topic test \<br>--bootstrap-server `broker-list.sh`</pre><h4>Hello Producer</h4><p>Initialize the producer and write messages to Kafka’s brokers.</p><pre>&gt; $KAFKA_HOME/bin/kafka-console-producer.sh --topic=test \<br>--broker-list=`broker-list.sh`<br>&gt;&gt; Hello World!<br>&gt;&gt; I&#39;m a Producer writing to &#39;hello-topic&#39;</pre><h4>Hello Consumer</h4><p>Initialize the consumer from another Kafka terminal and it will start reading the messages sent by the producer.</p><pre>&gt; $KAFKA_HOME/bin/kafka-console-consumer.sh --topic=test \<br>--from-beginning --bootstrap-server `broker-list.sh`</pre><h3>Kafka and Python</h3><p>If you are inside the Kafka Shell, you’ll need to install python3:</p><pre>&gt; apk add python3</pre><p>Install Kafka’s python package and initialize python’s shell:</p><pre>&gt; pip3 install kafka<br>&gt; python3</pre><p>You can also try <a href="https://github.com/confluentinc/confluent-kafka-python">Confluent’s Kafka Python Package</a></p><h4>Python Kafka Consumer</h4><p>From one of the Kafka Shell’s instances, run python3 and write:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/320b5cbf5cf179cf4d75170eee9f92fd/href">https://medium.com/media/320b5cbf5cf179cf4d75170eee9f92fd/href</a></iframe><ul><li><strong><em>auto_offset_reset</em></strong>: Tells the consumer from where to start reading if it crashes. ‘earliest’ will move to the oldest available message, ‘latest’ will move to the most recent.</li><li><strong><em>enable_auto_commit</em></strong>: If True, the consumer’s offset will be periodically committed in the background</li><li><strong><em>value_deserializer:</em></strong> A method that defines how to deserialize the data. In this case, it will read the data coming in JSON format from the producer.</li><li><strong><em>bootstrap_servers:</em></strong> In my case, is the output of running ‘broker-list.sh’</li></ul><h4>Python Kafka Producer</h4><p>From another Kafka Shell’s instance, run python3 and write:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/807921161971f2cfca9a258329ee6e66/href">https://medium.com/media/807921161971f2cfca9a258329ee6e66/href</a></iframe><h3>Access Kafka from outside Docker</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*Ea7Qukeb_HqHHNMz.jpg" /><figcaption><a href="https://blog.docker.com/2016/05/docker-labs-docker-community/illus5-colorful-square/">https://blog.docker.com/2016/05/docker-labs-docker-community/illus5-colorful-square/</a></figcaption></figure><p>If you want to run the code above from outside Kafka’s shell (outside a Docker container) you’ll need to do some easy changes. Let’s start!</p><h4>Expose the Docker network and Kafka brokers</h4><p>You’ll need to edit the <strong>docker-compose.yml</strong> file so it looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/31990b834d2d78ea03c1de2fc14eff3c/href">https://medium.com/media/31990b834d2d78ea03c1de2fc14eff3c/href</a></iframe><p>We basically added some environment to expose Kafka brokers to the host machine, if you want to read more about this, you can read <a href="https://www.kaaproject.org/kafka-docker">this great explanation</a> or read more about <a href="https://github.com/wurstmeister/kafka-docker/wiki/Connectivity">docker and Kafka’s connectivity</a>.</p><h4>Consume/Produce from within a Docker container</h4><p>Previously, you had to start a Kafka Shell and then create a consumer/producer that connected to one of the servers in ‘broker-list.sh’.</p><p>With this new configuration, you’ll need to initialize the consumer/producer from within the Kafka docker and connect to the host <strong>kafka:9092.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c29b39993ee29baeb7577e3b53bc11f4/href">https://medium.com/media/c29b39993ee29baeb7577e3b53bc11f4/href</a></iframe><h4>Consume/Produce from Python in your host machine</h4><p>Same code as above, but you’ll need to change the <strong><em>bootstrap_servers</em></strong> to be ‘<strong>localhost:9092’</strong></p><h3>Sources and Useful Links</h3><ul><li><a href="https://kafka.apache.org/">Apache Kafka’s Official Guide</a></li><li><a href="https://github.com/wurstmeister/kafka-docker">Kafka Docker’s Git</a></li><li><a href="http://wurstmeister.github.io/kafka-docker/">Kafka Docker’s Wiki</a></li><li><a href="https://jaceklaskowski.gitbooks.io/apache-kafka/content/">The Internals of Apache’s Kafka by Jacek Laskowski</a></li><li><a href="https://kafka-python.readthedocs.io/en/master/usage.html">Kafka-Python’s Docs</a></li><li><a href="https://towardsdatascience.com/kafka-python-explained-in-10-lines-of-code-800e3e07dad1">Kafka-Python explained in 10 lines of code</a></li><li><a href="https://www.kaaproject.org/kafka-docker">Deploying a Kafka broker in a Docker container</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f788e2588cfc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/big-data-engineering/hello-kafka-world-the-complete-guide-to-kafka-with-docker-and-python-f788e2588cfc">Hello Kafka World! The complete guide to Kafka with Docker and Python</a> was originally published in <a href="https://medium.com/big-data-engineering">Big Data Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spark 2: How to install it on Windows in 5 steps]]></title>
            <link>https://medium.com/big-data-engineering/how-to-install-apache-spark-2-x-in-your-pc-e2047246ffc3?source=rss----f93e9b51fb56---4</link>
            <guid isPermaLink="false">https://medium.com/p/e2047246ffc3</guid>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[pyspark]]></category>
            <category><![CDATA[spark]]></category>
            <dc:creator><![CDATA[Doron Vainrub]]></dc:creator>
            <pubDate>Tue, 04 Jun 2019 10:30:24 GMT</pubDate>
            <atom:updated>2018-05-02T16:15:30.094Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a very easy tutorial that will let you install Spark in your Windows PC without using Docker.</p><p>By the end of the tutorial you’ll be able to use Spark with Scala or Python.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*gI65C1EJXR6nYFHR.png" /></figure><h4>Before we begin:</h4><p>It’s important that you replace all the paths that include the folder <em>“Program Files”</em> or <em>“Program Files (x86)”</em> as explained below to avoid future problems when running Spark.</p><p>If you have Java already installed, you still need to fix the <strong>JAVA_HOME </strong>and <strong>PATH</strong> variables</p><ul><li>Replace <em>“Program Files”</em> with <em>“Progra~1”</em></li><li>Replace <em>“Program Files (x86)”</em> with <em>“Progra~2”</em></li><li>Example: <em>“C:\Program FIles\Java\jdk1.8.0_161”</em> --&gt; <em>“C:\Progra~1\Java\jdk1.8.0_161”</em></li></ul><h3>1. Prerequisite — Java 8</h3><p>Before you start make sure you have Java 8 installed and the environment variables correctly defined:</p><ol><li>Download <strong>Java JDK 8 </strong>from <a href="http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html">Java’s official website</a></li><li>Set the following environment variables:</li></ol><ul><li><strong>JAVA_HOME </strong>= C:\Progra~1\Java\jdk1.8.0_161</li><li><strong>PATH </strong>+= C:\Progra~1\Java\jdk1.8.0_161\bin</li><li>Optional: <strong>_JAVA_OPTIONS </strong>= -Xmx512M -Xms512M <em>(To avoid common Java Heap Memory problems whith Spark)</em></li></ul><p><strong><em>Tip</em></strong>: Progra~1 is the shortened path for “Program Files”.</p><h3>2. Spark: Download and Install</h3><ol><li>Download Spark from <a href="http://spark.apache.org/downloads.html">Spark’s official website</a></li></ol><ul><li>Choose the newest release (<em>2.3.0</em> in my case)</li><li>Choose the newest package type (<em>Pre-built for Hadoop 2.7 or later</em> in my case)</li><li>Download the .<strong>tgz</strong> file</li></ul><p>2. Extract the <strong>.tgz</strong> file into D:\Spark</p><p><em>Note: In this guide I’ll be using my D drive but obviously you can use the C drive also</em></p><p>3. Set the environment variables:</p><ul><li><strong>SPARK_HOME </strong>= D:\Spark\spark-2.3.0-bin-hadoop2.7</li><li><strong>PATH </strong>+= D:\Spark\spark-2.3.0-bin-hadoop2.7\bin</li></ul><h3>3. Spark: Some more stuff (winutils)</h3><ol><li>Download winutils.exe from here: <a href="https://github.com/steveloughran/winutils">https://github.com/steveloughran/winutils</a></li></ol><ul><li>Choose the same version as the package type you choose for the Spark .tgz file you chose in section 2 <em>“Spark: Download and Install” (in my case: hadoop-2.7.1)</em></li><li>You need to navigate inside the <strong>hadoop-X.X.X folder</strong>, and inside the <strong>bin</strong> folder you will find <strong>winutils.exe</strong></li><li>If you chose the same version as me (hadoop-2.7.1) here is the direct link: <a href="https://github.com/steveloughran/winutils/blob/master/hadoop-2.7.1/bin/winutils.exe">https://github.com/steveloughran/winutils/blob/master/hadoop-2.7.1/bin/winutils.exe</a></li></ul><p>2. <strong>Move the winutils.exe file</strong> to the bin folder inside <strong>SPARK_HOME</strong>,</p><ul><li>In my case: D:\Spark\spark-2.3.0-bin-hadoop2.7\bin</li></ul><p>3. Set the folowing environment variable to be the same as <strong>SPARK_HOME</strong>:</p><ul><li><strong>HADOOP_HOME </strong>= D:\Spark\spark-2.3.0-bin-hadoop2.7</li></ul><h3>4. Optional: Some tweaks to avoid future errors</h3><p>This step is optional but <strong>I highly recommend you do it</strong>. It fixed some bugs I had after installing Spark.</p><h4>Hive Permissions Bug</h4><ol><li>Create the folder <strong>D:\tmp\hive</strong></li><li>Execute the following command in <strong>cmd</strong> started using the option <strong>Run as administrator</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*kxg6nRwqnVMPcQgjW7dsTA.png" /></figure><ul><li><em>cmd&gt; winutils.exe chmod -R 777 D:\tmp\hive</em></li></ul><p>3. Check the permissions</p><ul><li><em>cmd&gt; winutils.exe ls -F D:\tmp\hive</em></li></ul><h3>5. Optional: Install Scala</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/0*1gZqStPm2p9CmFde.png" /></figure><p>If you are planning on using Scala instead of Python for programming in Spark, follow this steps:</p><p>1. Download Scala from <a href="http://www.scala-lang.org/download/">their official website</a></p><ul><li>Download the Scala binaries for Windows (<em>scala-2.12.4.msi</em> in my case)</li></ul><p>2. Install Scala from the <strong>.msi</strong> file</p><p>3. Set the environment variables:</p><ul><li><strong>SCALA_HOME </strong>= C:\Progra~2\scala</li><li><strong>PATH </strong>+= C:\Progra~2\scala\bin</li></ul><p><strong><em>Tip</em></strong>: Progra~2 is the shortened path for “Program Files (x86)”.</p><p>4. Check if scala is working by running the following command in the <strong>cmd</strong></p><ul><li><em>cmd&gt; scala -version</em></li></ul><h3>Testing Spark</h3><h4>PySpark (Spark with Python)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*7hPBQfCk5ADz3ucK.png" /></figure><p>To test if Spark was succesfully installed, run the following code from <strong>pyspark’s shell</strong> (you can ignore the WARN messages):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9ae543aa2bc6b2e2b5627280418ba4d/href">https://medium.com/media/b9ae543aa2bc6b2e2b5627280418ba4d/href</a></iframe><h4>Scala-shell</h4><p>To test if Scala and Spark where succesfully installed, run the following code from <strong>spark-shell</strong> (Only if you installed Scala in your computer):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a17b1a01951e81d6ef45d28c495c43c/href">https://medium.com/media/9a17b1a01951e81d6ef45d28c495c43c/href</a></iframe><p><em>PD: The query will not work if you have more than one spark-shell instance open</em></p><h4>PySpark with PyCharm (Python 3.x)</h4><p>If you have PyCharm installed, you can also write a “Hello World” program to test PySpark</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f08799e88333fc216fadaece85abd156/href">https://medium.com/media/f08799e88333fc216fadaece85abd156/href</a></iframe><h4>PySpark with Jupyter Notebook</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/0*5eDzABGXBOx7ZY5G." /></figure><p>This tutorial was taken from: <a href="https://blog.sicara.com/get-started-pyspark-jupyter-guide-tutorial-ae2fe84f594f">Get Started with PySpark and Jupyter Notebook in 3 Minutes</a></p><p>You will need to use the findSpark package to make a Spark Context available in your code. This package is not specific to Jupyter Notebook, you can use it in you IDE too.</p><p>Install and launch the notebook from the cmd:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/718531ffeb861e70e9f6184adef4adc4/href">https://medium.com/media/718531ffeb861e70e9f6184adef4adc4/href</a></iframe><p>Create a new Python notebook and write the following at the beginning of the script:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9327652b6c55a62ead1602f2264b959/href">https://medium.com/media/d9327652b6c55a62ead1602f2264b959/href</a></iframe><p>Now you can add your code to the bottom of the script and run the notebook.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2047246ffc3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/big-data-engineering/how-to-install-apache-spark-2-x-in-your-pc-e2047246ffc3">Spark 2: How to install it on Windows in 5 steps</a> was originally published in <a href="https://medium.com/big-data-engineering">Big Data Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>