<?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 Thulasitharan Govindaraj on Medium]]></title>
        <description><![CDATA[Stories by Thulasitharan Govindaraj on Medium]]></description>
        <link>https://medium.com/@thulasitharan-gt96?source=rss-ba4702c5727f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*y-xioxE-573IhMxF</url>
            <title>Stories by Thulasitharan Govindaraj on Medium</title>
            <link>https://medium.com/@thulasitharan-gt96?source=rss-ba4702c5727f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 15:01:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thulasitharan-gt96/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[How to run kafka inside docker containers and expose it to outer world]]></title>
            <link>https://thulasitharan-gt96.medium.com/how-to-run-kafka-inside-docker-containers-and-expose-it-to-outer-world-93018735dd4?source=rss-ba4702c5727f------2</link>
            <guid isPermaLink="false">https://medium.com/p/93018735dd4</guid>
            <category><![CDATA[zookeeper]]></category>
            <category><![CDATA[docker-network]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kafka]]></category>
            <dc:creator><![CDATA[Thulasitharan Govindaraj]]></dc:creator>
            <pubDate>Thu, 08 Sep 2022 06:16:33 GMT</pubDate>
            <atom:updated>2022-09-10T10:01:46.320Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi Folks,</p><p>Let’s see how to run kafka brokers and zookeeper inside separate docker containers and expose it to outer world.</p><p>Let’s create a base docker image</p><pre>FROM ubuntu:18.04<br>ARG KAFKAVERSION 0<br>ARG SCALAVERSION 0<br>ENV KAFKA_VERSION=$KAFKAVERSION<br>ENV SCALA_VERSION=$SCALAVERSION<br>RUN apt-get update -y<br>RUN apt-get install wget -y  <br>RUN apt-get install openjdk-8-jdk -y  <br>RUN mkdir -p /soft/tmp/kafka/<br>WORKDIR /soft/tmp/kafka/<br>RUN wget <a href="https://archive.apache.org/dist/kafka/$%7BKAFKA_VERSION%7D/kafka_$%7BSCALA_VERSION%7D-$%7BKAFKA_VERSION%7D.tgz">https://archive.apache.org/dist/kafka/${KAFKA_VERSION}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz</a> <br>RUN tar -xzvf kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz<br>RUN rm -r kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz<br>RUN mv -f kafka_${SCALA_VERSION}-${KAFKA_VERSION}/* ./<br>RUN rm -rf kafka_${SCALA_VERSION}-${KAFKA_VERSION}</pre><p>Build it using this command for appropriate version:</p><pre>docker build -t [baseImage:tag] --build-arg KAFKAVERSION=${Relevant version} --build-arg SCALAVERSION=${Relevant version} .</pre><p>Lets create an image for starting the zookeeper:</p><pre>#Zookeeper image</pre><pre>/*</pre><pre>Zookeeper_setup.sh # just replaces the log folder and port using sed command</pre><pre>sed -i &quot;s%dataDir=/tmp/zookeeper%dataDir=${LOGDIR}%g&quot; ./config/zookeeper.properties</pre><pre>sed -i &quot;s/clientPort=2181/clientPort=${ZOOKEEPERPORT}/g&quot; ./config/zookeeper.properties</pre><pre>sh ./bin/zookeeper-server-start.sh ./config/zookeeper.properties</pre><pre>*/</pre><pre>FROM [BaseImage]<br>COPY ./zookeeper_setup.sh  zookeeper_setup.sh<br>ENTRYPOINT [&quot;sh&quot;,&quot;zookeeper_setup.sh&quot;]</pre><pre>/*</pre><pre>Build it using</pre><pre>docker build -t ZookeeperImage . </pre><pre>*/</pre><p>Let’s use create an image for starting kafka and exposing it.</p><pre># broker image</pre><pre>/*</pre><pre>broker_setup.sh # sets listeners, ports, broker id, log dir and advertised listeners</pre><pre>echo `hostname`</pre><pre>export HOST_NAME_SH=`hostname`</pre><pre>sed -i &quot;s#log.dirs=/tmp/kafka-logs#log.dirs=${LOGDIR}#g&quot; ./config/server.properties</pre><pre>sed -i &quot;s#broker.id=0#broker.id=${BROKERID}#g&quot; ./config/server.properties</pre><pre>sed -i &quot;s@#listeners=PLAINTEXT://:9092@listeners=INTERNAL://:2${KAFKAPORT},EXTERNAL://:${KAFKAPORT}@g&quot; ./config/server.properties</pre><pre>sed -i &quot;s/zookeeper.connect=localhost:2181/zookeeper.connect=${ZOOKEEPERCONNECT}/g&quot; ./config/server.properties</pre><pre>echo -e &quot;\nlistener.security.protocol.map=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT&quot; &gt;&gt; ./config/server.properties</pre><pre>echo -e &quot;\ninter.broker.listener.name=INTERNAL&quot; &gt;&gt; ./config/server.properties</pre><pre>sed -i &quot;s~#advertised.listeners=PLAINTEXT://your.host.name:9092~advertised.listeners=INTERNAL://${HOST_NAME_SH}:2${KAFKAPORT},EXTERNAL://localhost:${KAFKAPORT}~g&quot; ./config/server.properties</pre><pre>sh ./bin/kafka-server-start.sh ./config/server.properties</pre><pre><br>*/</pre><pre>FROM base_image<br>COPY ./broker_setup.sh  broker_setup.sh<br>ENTRYPOINT [&quot;sh&quot;,&quot;broker_setup.sh&quot;]</pre><pre>/*</pre><pre>Build it using</pre><pre>docker build -t brokerImage .</pre><pre>*/</pre><p>Running the images:</p><pre>Zookeeper :</pre><pre>docker run -d -e LOGDIR=/kafka/logs/zookeeper/ -e ZOOKEEPERPORT=2181 -p 2181:2181 -v [HostLocation]:/kafka/logs/zookeeper/ --name zookeeper-client -t zookeeperImage</pre><pre>broker :</pre><pre>docker run -d --link zookeeper-client:zookeeper --name broker0 -e LOGDIR=/kafka/logs/kafka-logs-1/ -e BROKERID=0 -e KAFKAPORT=5053 -e ZOOKEEPERCONNECT=zookeeper:2181 -e ALLOW_PLAINTEXT_LISTENER=yes -p 5053:5053 -p 25053:25053 -v [hostDir]:/kafka/logs/kafka-logs-1/ -t brokerImage</pre><pre>Note: <br>-&gt; The port which you assign to kafka and the port which you expose it as external in advertised listeners must be the same, else the it wont work from outside.</pre><pre>-&gt; You can only link one one image to one container , so if you link the zookeeper to broker0 then you can&#39;t link it to another broker image. Meaning you can only bring up one broker.</pre><p>You can access this port from external binaries</p><pre>./bin/kafka-console-producer.sh --broker-list localhost:5053 --topic tmpTopic</pre><p>How to overcome the limitation of just able to connect with one broker:</p><p>Docker networks:</p><p>Docker networks creates a subnet to which your containers will be linked to and it will be east for your containers to communicate through the subnet to other containers in that subnet with their network alias or IP.</p><pre>docker network create app-network</pre><p><strong>app-network</strong> is the subnet which is going to serve as the proxy for our broker’s and zookeepers and other containers in that subnet to communicate.</p><p>Let’s run the containers within the network.</p><pre>docker run -d --network app-network --network-alias app-net-zoo -e LOGDIR=/kafka/logs/zookeeper/ -e ZOOKEEPERPORT=2181 -p 2181:2181 -v [externalDir]:/kafka/logs/zookeeper/ --name zookeeper-client -t ZookeeperImage</pre><pre>docker run -d --network app-network --network-alias app-net-broker0 --name broker0 -e LOGDIR=/kafka/logs/kafka-logs-0/ -e BROKERID=0 -e KAFKAPORT=5053 -e ZOOKEEPERCONNECT=app-net-zoo:2181 -e ALLOW_PLAINTEXT_LISTENER=yes -p 5053:5053 -v [externalDir]:/kafka/logs/kafka-logs-0/ -t brokerImage</pre><pre>docker run -d --network app-network --network-alias app-net-broker1 --name broker1 -e LOGDIR=/kafka/logs/kafka-logs-1/ -e BROKERID=1 -e KAFKAPORT=5054 -e ZOOKEEPERCONNECT=app-net-zoo:2181 -e ALLOW_PLAINTEXT_LISTENER=yes -p 5054:5054 -v [externalDir]:/kafka/logs/kafka-logs-1/ -t brokerImage</pre><p>This setup allows you to keep on adding brokers to your zookeepers according to your load. You can even automate the scale up and scale down using container orchestration tools like k8s.</p><p>If you wish to run all your containers in the subnet network and do not wish to expose them, then you can simply change the zookepper connect, listeners port and broker id alone in the server properties fie and start the containers exposing them to the same port in the network or different port . We can use a different network alias in for the broker containers to connect to the same port inside the network.</p><p>Checking it inside the network [Inside another container]:</p><pre>docker run --network app-network --network-alias app-net-it -it baseImage</pre><pre>//[Use the internal PORT for accessing inside network</pre><pre>./bin/kafka-console-producer.sh --broker-list app-net-broker1:25054,app-net-broker0:25053  --topic topicTmp</pre><p>Checking from outside the network [From host machine]:</p><pre>// Use the external IP and make sure that the IP which is being mapped from the inside and mapped to the outside is the same</pre><pre>./bin/kafka-console-consumer.sh --bootstrap.servers localhost:5053,localhost:5054 --topic topicTmp --from-beginning</pre><p>Note: The port to which it is being exposed must be the same.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93018735dd4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running spark on kubernetes (k8s)]]></title>
            <link>https://thulasitharan-gt96.medium.com/running-spark-on-kubernetes-k8s-9e613d64ae1d?source=rss-ba4702c5727f------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e613d64ae1d</guid>
            <category><![CDATA[minikube]]></category>
            <category><![CDATA[k8s]]></category>
            <category><![CDATA[storage]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[spark]]></category>
            <dc:creator><![CDATA[Thulasitharan Govindaraj]]></dc:creator>
            <pubDate>Wed, 17 Aug 2022 06:13:51 GMT</pubDate>
            <atom:updated>2022-08-17T06:15:00.711Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi Folks,</p><p>Let’s see how we can run spark in K8s.</p><p>The base utils for spark is created from the docker images in this blog. ( <a href="https://thulasitharan-gt96.medium.com/how-to-dynamically-pass-commands-to-docker-images-while-running-using-spark-submit-here-fb4f76406cee">https://thulasitharan-gt96.medium.com/how-to-dynamically-pass-commands-to-docker-images-while-running-using-spark-submit-here-fb4f76406cee</a> ) , we use the spark base util from this and create an executor and driver image for both.</p><p>I will be using minikube and running this example. Installing minikube is east and the steps for that will be given in their own documentation. Kubectl is used to interact with minikube and this must also be installed.</p><p>Image for executor and driver will be the same, they will have spark installed in it and the required application jar copied inside it.</p><pre>FROM spark-utils:v1<br>RUN mkdir -p /opt/spark/data-jars/<br>COPY jar.jar /opt/spark/data-jars/<br>ENTRYPOINT [&quot;/opt/spark/kubernetes/dockerfiles/spark/entrypoint.sh&quot;]</pre><p>The ENTRYPOINT is important asit is required for spark. The spark application will use the entrypoint.sh which comes packed with the spark application to launch the containers by itself.</p><pre>docker build -t spark-driver:v1<br>docker build -t spark-executor:v1</pre><p>You need the below prerequisites.</p><ul><li>Minikube</li><li>kubectl</li><li>kube proxy</li><li>spark binaries</li><li>A service account to be specifically configured for spark with required permissions</li></ul><p>Service account for spark :</p><pre>kubectl create serviceaccount spark # creation</pre><pre>kubectl create clusterrolebinding spark-role --clusterrole=edit --serviceaccount=default:spark --namespace=default #RBAC assignment</pre><p>Getting k8s URL:</p><pre>kubectl cluster-info</pre><p>Use the IP from the above command and submit the spark submit</p><pre>spark-submit — master k8s://<a href="https://192.168.59.101:8443/">https://I</a>P:PORT — deploy-mode cluster — name test-run-spark — conf spark.kubernetes.container.image=spark-executor:v1 — conf spark.kubernetes.driver.container.image=spark-driver:v1 — conf spark.kubernetes.executor.container.image=spark-executor:v1 — conf spark.kubernetes.driver.pod.name=test-run-spark — class [class] — conf spark.kubernetes.driver.volumes.hostPath.some-volume.mount.path=[PathInsidePodToWhichTheVolumeWillBeExposedTo] — conf spark.kubernetes.driver.volumes.hostPath.some-volume.options.path=[PathInsidePodToWhichTheVolumeWillBeExposedTo] — conf spark.kubernetes.executor.volumes.hostPath.some-volume.mount.path=[PathInsidePodToWhichTheVolumeWillBeExposedTo] — conf spark.kubernetes.executor.volumes.hostPath.some-volume.options.path=[PathInsidePodToWhichTheVolumeWillBeExposedTo] — num-executors 1 — executor-memory 512m — driver-memory 512m — driver-cores 2 — conf spark.kubernetes.namespace=default — executor-cores 2 — conf spark.kubernetes.driver.podTemplateFile=test-driver-spark.yml — conf spark.kubernetes.namespace=default — conf spark.kubernetes.executor.podNamePrefix=test-run-spark — conf spark.kubernetes.executor.podTemplateFile=test-executor-spark.yaml — conf spark.kubernetes.authenticate.driver.serviceAccountName=spark local:///opt/spark/data-jars/jar.jar [Args]</pre><p>I have provided the Pod template because this spark application will write output to a location and I am trying to write it to my local system from the pod. We can achieve this using mount’s. There needs to be amount name given in order to give the parameters for spark submit with respect to the path in which the mount must be exposed inside the pod. The spark configuration parameter must contain the volume mount’s name.</p><p>Template file:</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: test-driver-spark # change name for driver<br>spec:<br>  containers:<br>  - image: spark-driver:v1 # change name for driver<br>    name: test-driver # change name for driver<br>    volumeMounts:<br>    - mountPath: [LocalPath]<br>      name: some-volume #This name to be substituted in spark conf<br>  volumes:<br>  - name: some-volume #This name to be substituted in spark conf<br>    hostPath:<br>      path: [NodePath] # Mount path inside minikube VM</pre><p>The template file can also be used to set more k8s specific configs that are pod related.</p><p>Expose the local path to minikube.</p><pre>minikube mount [LocalPath]:[MinikubePath] #Dont kill this till the job is done</pre><p>More info on this : <a href="https://jaceklaskowski.github.io/spark-kubernetes-book/demo/spark-and-local-filesystem-in-minikube/">https://jaceklaskowski.github.io/spark-kubernetes-book/demo/spark-and-local-filesystem-in-minikube/</a></p><p>There can also be different kinds of FS exposed to spark inside K8s : <a href="https://spark.apache.org/docs/latest/running-on-kubernetes.html">https://spark.apache.org/docs/latest/running-on-kubernetes.html</a></p><p>Now the spark application will be able to read and write form local FS in the provided path.</p><p>If your minikube environment is not able to pull images from docker repo but your local system is able to do it , then you need to configure the proxy specifically for it, or pull the image to local and load the image using the below command.</p><pre>minikube image load [imageName]</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e613d64ae1d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Dynamically pass commands to docker images while running — using spark submit here]]></title>
            <link>https://thulasitharan-gt96.medium.com/how-to-dynamically-pass-commands-to-docker-images-while-running-using-spark-submit-here-fb4f76406cee?source=rss-ba4702c5727f------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb4f76406cee</guid>
            <category><![CDATA[dockerfiles]]></category>
            <category><![CDATA[spark-sql]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[spark]]></category>
            <dc:creator><![CDATA[Thulasitharan Govindaraj]]></dc:creator>
            <pubDate>Tue, 16 Aug 2022 06:28:51 GMT</pubDate>
            <atom:updated>2022-08-16T06:28:51.240Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Dynamically pass commands to docker images while running — using spark submit here</h3><p>HI folks,</p><p>Today we will see how to dynamically pass entire command to docker images on runtime. It is easy to do that while building using ( — build-arg) but that is more like hard coding. This will benefit the people who are trying to just create an environment as a docker image and use it to run commands for computing.</p><p>I will show you guys how to run a spark submit in local mode , as I have done for it. This can be applied in order to run java jar’s, python scripts or any similar scripts.</p><p>Creating a base docker image with JDK and the required libraries for spark [The additional libraries are for the spark , to run with k8s. Those can be ignored for this post]. I have used the official JDK image from docker as it comes packed within debian os, which also has the required packages for running spark with k8s[That will be covered in another post].</p><p>Note: I have split the env into separate modules for reusability. This can come inside a single docker file also.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZvxA1r1kKjgR3sy2.jpg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*c_wj72fpAG5hQa3J.png" /></figure><blockquote><strong>Dockerfile :</strong></blockquote><pre>FROM openjdk:8u342-jre<br>RUN sed -i s/http/https/ /etc/apt/sources.list &amp;&amp; apt-get -o Acquire::Check-Valid-Until=false update <br>RUN set -ex<br>RUN apt-get update -y<br>RUN ln -s /lib /lib64<br>RUN apt install -y bash  <br>RUN apt install -y tini<br>RUN apt install -y libc6<br>RUN apt install -y libpam-modules<br>RUN apt install -y libnss3<br>RUN apt install -y wget<br>RUN mkdir -p /opt/spark/work-dir<br>RUN touch /opt/spark/RELEASE<br>#RUN rm /bin/sh &amp;&amp; ln -sv /bin/bash /bin/sh<br>RUN echo &quot;auth required pam_wheel.so use_uid&quot; &gt;&gt; /etc/pam.d/su<br>RUN chgrp root /etc/passwd<br>RUN chmod ug+rw /etc/passwd<br>RUN rm -rf /var/cache/apt/*<br>WORKDIR /opt/spark/work-dir</pre><p>Build it using the below command in the same folder.</p><pre>docker build -t base_debian_utilities:v1 .</pre><blockquote><strong>Dockerfile for spark utility:</strong></blockquote><pre>FROM base_debian_utilities:v1<br>ARG SPARKVERSION=tmpsVersion #default value<br>ARG HADOOPVERSION=tmpHVersion #default value<br>ENV SPARK_VERSION=$SPARKVERSION<br>ENV HADOOP_VERSION=$HADOOPVERSION<br>RUN wget -O spark-${SPARK_VERSION}-bin-hadoop${HADOOP_VERSION}.tgz  <a href="https://archive.apache.org/dist/spark/spark-$%7BSPARK_VERSION%7D/spark-$%7BSPARK_VERSION%7D-bin-hadoop$%7BHADOOP_VERSION%7D.tgz">https://archive.apache.org/dist/spark/spark-${SPARK_VERSION}/spark-${SPARK_VERSION}-bin-hadoop${HADOOP_VERSION}.tgz</a><br>RUN tar -xzvf spark-${SPARK_VERSION}-bin-hadoop${HADOOP_VERSION}.tgz -C /opt/spark/<br>RUN rm -rf spark-${SPARK_VERSION}-bin-hadoop${HADOOP_VERSION}.tgz<br>RUN mv -f /opt/spark/spark-${SPARK_VERSION}-bin-hadoop${HADOOP_VERSION}/* /opt/spark/<br>RUN rm -rf /opt/spark/spark-${SPARK_VERSION}-bin-hadoop${HADOOP_VERSION}<br>ENV SPARK_HOME=/opt/spark<br>ENV PATH=&quot;${SPARK_HOME}/bin:${PATH}&quot;</pre><blockquote><strong>Build it using the below command in the same folder.</strong></blockquote><pre>docker build -t spark-utils:v1 --build-arg SPARKVERSION=2.4.7 --build-arg HADOOPVERSION=2.7 .</pre><p>We can now use this image as the env image and run the required spark sumbit commands, or directly interact with it (-it flag in docker run) and use the spark-shell for debugging too.</p><p>If we need to run any command in Docker on runtime , we either use CMD or ENTRYPOINT , detailed explaintion in this blog ( <a href="https://www.bmc.com/blogs/docker-cmd-vs-entrypoint/">https://www.bmc.com/blogs/docker-cmd-vs-entrypoint/</a> ). Basically if you use CMD or ENTRYPOINT whatever command is present in the docker file will run by default, but if you pass any other command from the outside while running the image, whatever is given in CMD is overridden whereas the ENTRYPOINT will never be overridden , ENTRYPOINT will be executed first then the command given from outside. CMD and ENTRYPOINT can both be given in the same docker file, the priority of execution being ENTRYPOINT then CMD.</p><blockquote><strong>CMD Example:</strong></blockquote><pre>FROM spark-utils:v1<br>RUN mkdir -p /opt/spark/data-jars/<br>COPY temp.jar /opt/spark/data-jars/<br>CMD spark-submit --class className --master local[*] --driver-memory 512m --driver-cores 2 /opt/spark/data-jars/temp.jar</pre><p>Build:</p><pre>docker build -t temp-run .</pre><p>Run with no Args :</p><pre>docker run -t temp-run. # spark-submit runs</pre><p>Run with Args:</p><pre>docker run docker4tg/temp_run pwd ##overrode the spark-submit</pre><pre>/opt/spark/work-dir</pre><pre>docker run cool-5 ls -ltr ##overrode the spark-submit</pre><pre>total 0</pre><blockquote><strong>Entrypoint DOCKERFILE:</strong></blockquote><pre>FROM spark-utils:v1<br>RUN mkdir -p /opt/spark/data-jars/<br>COPY tmp.jar /opt/spark/data-jars/<br>RUN echo &quot;date\n&quot; &gt;&gt; ./tmp.sh<br>RUN echo &quot;spark-submit --class tmpClass--master local[*] --driver-memory 512m --driver-cores 2 /opt/spark/data-jars/tmp.jar\n&quot; &gt;&gt; ./tmp.sh<br>RUN echo &quot;date\n&quot; &gt;&gt; ./tmp.sh<br>ENTRYPOINT [&quot;sh&quot;,&quot;./tmp.sh&quot;]</pre><p>Build it as temp-run-2</p><p>output:</p><p>Ran normally:</p><pre>docker run temp-run-2 # spark submit ran</pre><h4>With dynamic args:</h4><pre>docker run temp-run-2 pwd # spark submit ran , pwd was skipped as entrypoint is the priority</pre><blockquote><strong>Both CMD AND ENTRYPOINT:</strong></blockquote><pre>FROM spark-utils:v1<br>RUN mkdir -p /opt/spark/data-jars/<br>COPY tmp.jar /opt/spark/data-jars/<br>RUN echo &quot;date\n&quot; &gt;&gt; ./tmp.sh<br>RUN echo &quot;spark-submit --class class --master local[*] --driver-memory 512m --driver-cores 2 /opt/spark/data-jars/temp.jar\n&quot; &gt;&gt; ./tmp.sh<br>RUN echo &quot;date\n&quot; &gt;&gt; ./tmp.sh<br>CMD echo &quot;DONE $NAME&quot;<br>ENTRYPOINT [&quot;sh&quot;,&quot;./tmp.sh&quot;]</pre><p>Output:</p><p>CMD was never executed, neither did the pwd</p><pre>docker run -e NAME=tempUser  temp-image pwd</pre><p>I used another way to print the name instead.</p><pre>FROM spark-utils:v1<br>RUN mkdir -p /opt/spark/data-jars/<br>COPY tmp.jar /opt/spark/data-jars/<br>RUN echo &quot;date\n&quot; &gt;&gt; ./tmp.sh<br>RUN echo &quot;spark-submit --class class --master local[*] --driver-memory 512m --driver-cores 2 /opt/spark/data-jars/tmp.jar\n&quot; &gt;&gt; ./tmp.sh<br>RUN echo &quot;date\n&quot; &gt;&gt; ./tmp.sh<br>RUN echo &quot;``echo \&quot;DONE \$NAME\&quot;``&quot; &gt;&gt; ./tmp.sh<br>ENTRYPOINT [&quot;sh&quot;,&quot;./tmp.sh&quot;]</pre><p>Build and run this</p><pre>docker run -e NAME=tempUser temp-image pwd</pre><p>pwd is still skipped but the user name is printed.</p><p>The reason I have explained all of these is to show you how you can pass parameters dynamically. This can be used to play around for your requirement.</p><blockquote><strong>Env image</strong></blockquote><pre>FROM spark:utils:v1<br>CMD echo &#39;Provide spark submit&#39;</pre><p>Run it using</p><pre>docker run -v `pwd`:/volume/ -t test-run:v4 &quot;spark-submit&quot; &quot;--master&quot; &quot;local[*]&quot; &quot;--class&quot; &quot;class&quot; &quot;--driver-memory&quot; &quot;512m&quot; &quot;--driver-cores&quot; &quot;2&quot; &quot;/volume/temp.jar&quot; &quot;fileName=fileName.csv&quot;</pre><p>This ran, this can also be used to run java jar as Java is built in. So CMD is your way to run things dynamically and ENTRYPOINT is your way to make your image bind to only one way of execution.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb4f76406cee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spark Streaming Checkpoint Directory explained]]></title>
            <link>https://thulasitharan-gt96.medium.com/spark-streaming-checkpoint-directory-explained-3e9d927ebcff?source=rss-ba4702c5727f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e9d927ebcff</guid>
            <category><![CDATA[spark-streaming]]></category>
            <category><![CDATA[checkpoints]]></category>
            <dc:creator><![CDATA[Thulasitharan Govindaraj]]></dc:creator>
            <pubDate>Sun, 11 Jul 2021 13:19:33 GMT</pubDate>
            <atom:updated>2021-07-11T13:22:27.871Z</atom:updated>
            <content:encoded><![CDATA[<p>Spark streaming is one of the best way to process data as it arrives. Spark streaming is being used by the vast of the organizations to do streaming ETL. It is fault tolerant, efficient and reliable way of processing real time data as it arrives.</p><p>The fault tolerance of spark streaming is achieved by spark through saving it’s state in a location till micro-batch processed. This location is an external location ,usually HDFS, local file system or cloud storage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HneeWgsmu-mnb8-7.png" /><figcaption>Spark streaming flow</figcaption></figure><p>This checkpoint location has 3 directory and 1 file. Let’s see it with an example.</p><p>Let’s see how the streaming works for a directory with fixed schema txt file’s.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fNv6kBQiqhQic4evFbOwjg.png" /><figcaption>Batch 0</figcaption></figure><p>The checkpoint directory contains the below files and folder.</p><ul><li>metadata</li><li>commits</li><li>offsets</li><li>sources</li></ul><p>The metadata file contains the id of the streaming query .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2SSvzT75Btfl_Nx3I3s3nQ.png" /><figcaption>UI</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5DeiImRS4tZRWy0FRDp7mw.png" /><figcaption>Contents of metadata file</figcaption></figure><p>Lets place a file in the input location . Batch 0 get’s triggered. Let’s observe the contents of the folder now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oZ-66cNQpdi42hfq7ZfN2w.png" /><figcaption>contents of a checkpoint dir</figcaption></figure><p>Now we can see the batch 0 has created many files let’s understand the purpose of the file’s and then have a look at the content’s.</p><p>Sources folder has a batch wise segregation of the source for that batch.</p><p>Offsets folder has the batch wise segregation of the offset’s being processed in this batch in case of KAFKA, or the logOffset id for other sources. This is to instruct spark engine that source in batch 0 has been read and is being processed.</p><p>Commits folder has the batch wise segregation of the completely processed offsets per batch. If the job fail’s when processing batch n , then the offsets folder will have batch n and commits folder will not have batch n. (Where n is the batch which is in context) This way spark finds out which is the batch it has to start from in case the job is re-submitted with the same checkpoint location.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iIWxrAvM5_IW5OvxNWiXnw.png" /><figcaption>Sources and commits</figcaption></figure><p>Let’s pass some more files and see the directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vqdxdgxw9Z2rIrZPLYPD2Q.png" /><figcaption>after 4 batch’s</figcaption></figure><p>Lets see another example with source as kafka. Let’s see for a multiple partitioned topic and a topic with single partition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ue-5fsL2-K_SQ1nKyy9fBA.png" /><figcaption>kafka stream checkpoints</figcaption></figure><p>If the job is stop the job, delete the batch 9 folder in commits folder and then restart the job, the job resumes from end offset’s of 8th batch (i.e) job re-processes the batch 9 assuming there was a problem when processing batch 9 and it was not processed properly, it must be processed now.</p><p>Thanks for taking your time to read this blog. Appreciate it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e9d927ebcff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to add SSL security to your Kafka brokers and securely transmit receive data]]></title>
            <link>https://thulasitharan-gt96.medium.com/how-to-add-ssl-security-to-your-kafka-brokers-and-securely-transmit-receive-data-9aa00f1c5412?source=rss-ba4702c5727f------2</link>
            <guid isPermaLink="false">https://medium.com/p/9aa00f1c5412</guid>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[kafka-connect]]></category>
            <category><![CDATA[ssl-certificate]]></category>
            <dc:creator><![CDATA[Thulasitharan Govindaraj]]></dc:creator>
            <pubDate>Fri, 26 Feb 2021 15:49:54 GMT</pubDate>
            <atom:updated>2021-02-26T15:49:54.840Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi Folks,</p><p>I am going to explain how to add SSL to your kafka brokers and transmit/receive/access data securely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*D05fDHljkStoHuZ0" /><figcaption>Kafka</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/0*Ba2Hepr6d4GBPwIx.jpg" /><figcaption>SSL</figcaption></figure><p>You need to create a crt certificate, then using that a jks truststore file and a keystore file.</p><p>openssl genrsa -out root.key<br>openssl req -new -x509 -key root.key -out root.crt</p><p>#Country Name (2 letter code) [AU]: &lt;Country&gt;<br>#State or Province Name (full name) [Some-State]: &lt;State&gt;<br>#Locality Name (eg, city) []:&lt;city&gt;<br>#Organization Name (eg, company) [Internet Widgits Pty Ltd]:&lt;company&gt;<br>#Organizational Unit Name (eg, section) []:<br>#Common Name (e.g. server FQDN or YOUR name) []: &lt;FQDN&gt;<br>#Email Address []: &lt;Email&gt;</p><p># kafka jks <br>keytool -certreq -keystore kafka.truststore.jks -alias CARoot -import -file root.crt<br>#Pwd : test123<br> <br> <br>keytool -keystore kafka.keystore.jks -alias YourDNS -validity 365 -genkey -keyalg RSA -ext SAN=DNS:&lt;YourDNS&gt;</p><p>#Pwd : test123<br>#<br># What is your first and last name?<br># [Unknown]: YourDNS<br>#What is the name of your organizational unit?<br># [Unknown]: <br>#What is the name of your organization?<br># [Unknown]: &lt;organization&gt;<br>#What is the name of your City or Locality?<br># [Unknown]: &lt;City&gt;<br>#What is the name of your State or Province?<br># [Unknown]: &lt;State&gt;<br>#What is the two-letter country code for this unit?<br># [Unknown]: &lt;country&gt;<br>#Is CN=YourDNS, OU=Unknown, O=&lt;organization&gt;, L= &lt;City&gt;, ST=&lt;State&gt;, C=&lt;country&gt;correct?<br># [no]: yes<br>#<br>#Enter key password for &lt;localhost&gt;<br># (RETURN if same as keystore password): test123</p><p>keytool -keystore kafka.keystore.jks -alias YourDNS -certreq -file kafka.ssl.unsigned.crt</p><p>#Enter keystore password: <br>#<br>#Warning:<br>#The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using “keytool -importkeystore -srckeystore kafka.ssl.keystore.jks -destkeystore kafka.ssl.keystore.jks -deststoretype pkcs12”.</p><p>openssl x509 -req -CA root.crt -CAkey root.key -in kafka.ssl.unsigned.crt -out kafka.ssl.signed.crt -days 365 -CAcreateserial</p><p>keytool -keystore kafka.keystore.jks -alias CARoot -import -file root.crt<br>#Pwd : test123</p><p>keytool -keystore kafka.keystore.jks -alias YourDNS -import -file kafka.ssl.signed.crt<br>#Pwd : test123</p><p>#./bin/zookeeper-server-start.sh ./config/zookeeper.properties <br>#./bin/kafka-server-start.sh ./config/server.properties<br>#props for server.properties</p><p>#listeners=PLAINTEXT://YourDNS:9192,SSL://YourDNS:9194<br>#ssl.keystore.location=&lt;path&gt;/keys/kafka.keystore.jks<br>#ssl.keystore.password=test123<br>#ssl.key.password=test123<br>#ssl.truststore.location=&lt;path&gt;/keys/kafka.truststore.jks<br>#ssl.truststore.password=test123<br>#ssl.keystore.type=JKS<br>#ssl.truststore.type=JKS<br>#ssl.enabled.protocols=TLSv1.2,TLSv1.1,TLSv1<br>#ssl.client.auth=required<br>#ssl.endpoint.identification.algorithm=</p><p>/bin/kafka-console-producer.sh — broker-list YourDNS:9194 — topic tmpTopic — producer.config ./keys/keysForCLI.txt # works</p><p>/bin/kafka-console-producer.sh — broker-list YourDNS:9194 — topic tmpTopic # will fail due too handshake failure</p><p>./bin/kafka-console-consumer.sh — topic tmpTopic — bootstrap-server YourDNS:9194 — consumer.config ./keys/keysForCLI.txt # works</p><p>./bin/kafka-console-consumer.sh — topic tmpTopic — bootstrap-server YourDNS:9194 # will fail due to no keys</p><p># keysForCLI</p><p>ssl.keystore.location=&lt;path&gt;/kafka.keystore.jks<br>ssl.keystore.password=test123<br>ssl.key.password=test123<br>ssl.truststore.location=&lt;path&gt;/kafka.truststore.jks<br>ssl.truststore.password=test123<br>security.protocol=SSL</p><p>If you need a separate keystore for client machine from which you will access the data, then you need to generate one for your client’s DNS too.</p><p>keytool -keystore client.keystore.jks -alias ClientDNS -validity 365 -genkey -keyalg RSA -ext SAN=DNS:ClientDNS</p><p>#Pwd : test123<br>#<br># What is your first and last name?<br># [Unknown]: ClientDNS<br>#What is the name of your organizational unit?<br># [Unknown]: <br>#What is the name of your organization?<br># [Unknown]: &lt;organization&gt;<br>#What is the name of your City or Locality?<br># [Unknown]: &lt;City&gt;<br>#What is the name of your State or Province?<br># [Unknown]: &lt;State&gt;<br>#What is the two-letter country code for this unit?<br># [Unknown]: &lt;country&gt;<br>#Is CN=ClientDNS, OU=Unknown, O=&lt;organization&gt;, L= &lt;City&gt;, ST=&lt;State&gt;, C=&lt;country&gt;correct?<br># [no]: yes<br>#<br>#Enter key password for &lt;localhost&gt;<br># (RETURN if same as keystore password): test123</p><p>keytool -keystore client.keystore.jks -alias ClientDNS -certreq -file client.unsigned.cert</p><p>openssl x509 -req -CA root.crt -CAkey root.key -in client.unsigned.cert -out client.signed.cert -days 365 -CAcreateserial</p><p>keytool -keystore client.keystore.jks -alias CARoot -import -file root.crt</p><p>keytool -keystore client.keystore.jks -alias ClientDNS -import -file client.signed.cert</p><p>./bin/kafka-console-producer.sh — broker-list ClientDNS:9194 — topic tmpTopic — producer.config ./keys/keysForCLIClient.txt</p><p>./bin/kafka-console-consumer.sh — topic tmpTopic — bootstrap-server ClientDNS:9194 — consumer.config ./keys/keysForCLIClient.txt</p><p># keysForCLIClient , this must be in client system, the trust store is the same and must be copied from the broker, but the keystore must be generated in client system</p><p>ssl.keystore.location=&lt;path&gt;/client.keystore.jks<br>ssl.keystore.password=test123<br>ssl.key.password=test123<br>ssl.truststore.location=&lt;path&gt;/kafka.truststore.jks<br>ssl.truststore.password=test123<br>security.protocol=SSL</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9aa00f1c5412" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configuring Hive metastore for spark]]></title>
            <link>https://thulasitharan-gt96.medium.com/configuring-hive-metastore-for-spark-2c584e65a52d?source=rss-ba4702c5727f------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c584e65a52d</guid>
            <category><![CDATA[hive]]></category>
            <category><![CDATA[spark-sql]]></category>
            <category><![CDATA[hadoop]]></category>
            <category><![CDATA[spark]]></category>
            <dc:creator><![CDATA[Thulasitharan Govindaraj]]></dc:creator>
            <pubDate>Sun, 10 May 2020 13:42:56 GMT</pubDate>
            <atom:updated>2020-05-10T13:42:56.335Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi Folk’s ,</p><p>This post is going to be about how to configure hive metastore to access your hive table’s in spark sql.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5O9-hdqI2YTmx0t4QTCR4g.png" /><figcaption>Before Configuring</figcaption></figure><p>Defaults is spark’s default metastore respective to the session.</p><p>1)In Spark-env.sh Add your mysql connector jar path in the class path and hive home variable as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FhyKRbsWRa1gTnt-AeGTOA.png" /><figcaption>spark-env.sh</figcaption></figure><p>This is for spark to access your hive metastore i’m using Mysql as metastore , hence Mysql jar.</p><p>Copy hive-site.xml to $SPARK_HOME/conf directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Z7n0UqOmBMJZY-SGBHurw.png" /><figcaption>$SPARK_HOME/conf</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*haYFi4HfMCY4lkm6PuFFoA.png" /><figcaption>Hive</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HVUHH7gNlRIBJNHHMeduXA.png" /><figcaption>After Configuring</figcaption></figure><p>Note: spark 2.X will only support hive metastore versions ranging from 0.12.0 to 2.3.3 (As give in the documentation <a href="https://spark.apache.org/docs/latest/sql-data-sources-hive-tables.html">https://spark.apache.org/docs/latest/sql-data-sources-hive-tables.html</a>). Default one is 1.2.1 but i am going to use 1.2.0. Hive version 2.X is not supported by spark, i have tried but it didn’t work.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c584e65a52d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running a spark submit command on docker]]></title>
            <link>https://thulasitharan-gt96.medium.com/running-a-spark-submit-command-on-docker-d3ddf2852528?source=rss-ba4702c5727f------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3ddf2852528</guid>
            <category><![CDATA[pyspark]]></category>
            <category><![CDATA[dockerfiles]]></category>
            <category><![CDATA[docker-container]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Thulasitharan Govindaraj]]></dc:creator>
            <pubDate>Sun, 15 Mar 2020 08:04:30 GMT</pubDate>
            <atom:updated>2021-04-06T05:48:41.607Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi folks,</p><p>This blog is about how to run a spark submit on a docker container. I was spending some time on fixing an issue for running a spark submit inside a docker container. I have ran a pyspark application in docker playground, if you want you can build a jar and then run a spark-scala application in docker.</p><p>Sample docker file. (Used spark 2.4.5)</p><p>Explanation: Instaling ubuntu ,JDK(for spark),spark ,python and running the spark submit.</p><p>FROM ubuntu:latest<br>RUN apt-get update<br>RUN apt-get install -y openjdk-8-jdk<br>RUN apt-get update<br>RUN apt-get install git -y<br>RUN apt-get update<br>RUN apt-get install wget -y<br>RUN wget “<a href="https://downloads.apache.org/spark/spark-2.4.5/spark-2.4.5-bin-hadoop2.7.tgz">https://downloads.apache.org/spark/spark-2.4.5/spark-2.4.5-bin-hadoop2.7.tgz</a>&quot;<br>RUN tar -xzvf spark-2.4.5-bin-hadoop2.7.tgz <br>RUN rm spark-2.4.5-bin-hadoop2.7.tgz<br>RUN apt-get install -y python3-pip python3-dev<br>RUN apt-get update<br>RUN pip3 install — upgrade pip<br>RUN ln -s /usr/bin/python3 /usr/bin/python<br>RUN pip install pyspark<br>CMD ./spark-2.4.5-bin-hadoop2.7/bin/spark-submit — num-executors 1 — executor-cores 2 — executor-memory 1g — driver-cores 1 — driver-memory 1g /temp/test.py</p><p>Building an image:</p><p>==========</p><p>docker build -t [imageName]:[imageVersion] .</p><p>Running an image:</p><p>===========</p><p>docker run -t -i -v $(pwd):/temp [image id] — — — Mounted the present directory as a folder</p><p>whatever you give on test.py will be executed, test.py is the python file with pyspark code, similarly you can place you jar over here and run a spark shell with jar using — class attribute in spark submit.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3ddf2852528" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automatic loading of data to Snowflake using snow pipe from an external source when new files are…]]></title>
            <link>https://thulasitharan-gt96.medium.com/automatic-loading-of-data-to-snowflake-using-snow-pipe-from-an-external-source-when-new-files-are-4d7cb5ae028c?source=rss-ba4702c5727f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d7cb5ae028c</guid>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[snowflake]]></category>
            <category><![CDATA[snowpipe]]></category>
            <category><![CDATA[amazon]]></category>
            <dc:creator><![CDATA[Thulasitharan Govindaraj]]></dc:creator>
            <pubDate>Thu, 20 Feb 2020 04:48:13 GMT</pubDate>
            <atom:updated>2020-02-20T04:48:13.283Z</atom:updated>
            <content:encoded><![CDATA[<h3>Automatic loading of data to Snowflake using snow pipe from an external source when new files are pushed to the source</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/915/1*urluU0L0Z2cp6wgPZB0vCA.png" /></figure><p>Hi Folks,</p><p>I have done the the configuration if automatic load of data to Snowflake from an external source when new files are pushed to the source. Note there’s no screenshot for it , But you can refer the below video for reference.</p><p><a href="https://resources.snowflake.com/youtube-all-videos/automatically-ingesting-streaming-data-with-snowpipe">Automatically Ingesting Streaming Data with Snowpipe</a></p><p>Steps: (From S3 to snowflake)</p><p>1)Create a stage , Give the s3 basepath from which the data need’s to be loaded and with the key’s.</p><p>eg: s3://bucket//tablename/</p><p>2)Create a pipe pointing that stage with copy command. (external location’s cant directly be piped into snowflake.)​</p><p>3)Use show stages — use the ARN from your stage and add it to your S3 bucket’s event property with when file created event option (the s3 bucket given in the stage ).</p><p>After this is done, then if any file is created on the bucket an message is sent to ARN in the stage, and if it is created in the specifed URL in the stage then it’s loaded in the table specified.</p><p>Stage:</p><p>CREATE OR REPLACE STAGE first_pipe_Stage_for_sss​<br>URL=’s3://bucket/folder’​<br>CREDENTIALS = ( AWS_KEY_ID = ‘XXX’ AWS_SECRET_KEY = ‘YYY’ )​<br>COPY_OPTIONS = ( ON_ERROR = CONTINUE ) ​<br>COMMENT = ‘first_pipe_Stage_for_sss’ ​<br> ​<br>CREATE OR REPLACE PIPE first_pipe ​<br>AUTO_INGEST = TRUE ​ — for ARN<br>COMMENT = ‘first_pipe’ ​<br>AS copy into DestinationTable from <a href="http://twitter.com/first_pipe_Stage_for">@first_pipe_Stage_for</a>_sss​<br>FILE_FORMAT = (TYPE = ‘CSV’ field_optionally_enclosed_by=’\”’ RECORD_DELIMITER = ‘\n’ FIELD_DELIMITER = ‘|’ )​ — copy command except few exception’s which can’t be used like pattern, see the documentation for full detail’s</p><p><a href="https://docs.snowflake.net/manuals/sql-reference/sql/create-pipe.html">https://docs.snowflake.net/manuals/sql-reference/sql/create-pipe.html</a><br>​</p><p>Thanks for reading this folk’s , if you ave any doubt’s kindly let me know in the comment’s , so i can try and clarify it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d7cb5ae028c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Usage of Deequ Suite by Amazon for DQC(Data Quality Checks) for your data]]></title>
            <link>https://thulasitharan-gt96.medium.com/usage-of-deequ-suite-by-amazon-for-dqc-data-quality-checks-for-your-data-de1069f60cea?source=rss-ba4702c5727f------2</link>
            <guid isPermaLink="false">https://medium.com/p/de1069f60cea</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-quality]]></category>
            <category><![CDATA[check]]></category>
            <category><![CDATA[spark]]></category>
            <dc:creator><![CDATA[Thulasitharan Govindaraj]]></dc:creator>
            <pubDate>Thu, 20 Feb 2020 04:09:45 GMT</pubDate>
            <atom:updated>2020-02-20T04:09:45.139Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey folks,</p><p>Big data is becoming more and more trendier nowadays, as the technologies in the world tend to grow the collection of data in order to provide a good experience for the subscriber’s also tend to increase. In this kind of occasion’s there will be places where you don’t want to collect the wrong data unintentionally , which might affect your whole pipeline especially in production environment. So, it’s a good habit to add DQC’s in order to ensure the make sure of the data quality after processing(batch processing) and (frequent time interval’s) in streaming system’s [as Deequ doesn’t support streaming Data] and intimate the required team if some check fail’s.</p><p>Deequ is a additional framework provided by amazon to perform data quality checks on your data, it runs on top of spark. It cannot be used for streaming data as of now, currently it can only be applied for batch data.</p><p>More on it’s framework on the below link:</p><p><a href="https://aws.amazon.com/blogs/big-data/test-data-quality-at-scale-with-deequ/">Test data quality at scale with Deequ | Amazon Web Services</a></p><p>I won’t be going through the frame work again as it is already explained in the above link. I will be showing you some code example’s for your better understanding. Deequ framework allow’s you to perform DQC’s on your batch data and give’s you the result in a DataFrame. It is can be used by adding an additional dependency in Build.gradle(gradle) or POM.xml (Maven).</p><p>Let’s see some basic DQC’s given by Deequ on a sample data set.</p><p>For now we use REPL for learning purpose, later it can be integrated in your project and built as jar and ran in a spark submit.</p><p>//REPL with dependency in — packages</p><p><strong>This is just for measuring metric’s of DATA</strong></p><p>spark-shell — packages com.amazon.deequ:deequ:1.0.2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*YSMT5uU4WKrDFSPTgdmTFg.png" /><figcaption>Schema of the DataFrame i’m going to test</figcaption></figure><p>import com.amazon.deequ.analyzers.runners.{AnalysisRunner, AnalyzerContext}<br>import com.amazon.deequ.analyzers.runners.AnalyzerContext.successMetricsAsDataFrame<br>import com.amazon.deequ.analyzers.{Compliance, Correlation, Size, Completeness, Mean, ApproxCountDistinct,Entropy}</p><p>val analysisContextForResult = AnalysisRunner.onData(df) // gives analyser runner Object which should be used to apply DQC Scenario’s.</p><p>val analysisRunnerAddedWithAnalyzer= analysisContextForResult.addAnalyzer(Size()).addAnalyzer(Completeness(“Vehicle_id”)).addAnalyzer(ApproxCountDistinct(“Vehicle_id”)) .addAnalyzer(Mean(“miles”)).addAnalyzer(Compliance(“top miles”, “miles &gt;= 4000”)).addAnalyzer(Correlation(“model”, “brand”)).addAnalyzer(Correlation(“miles”, “number_of_owners”)).addAnalyzer(Correlation(“miles”, “year”)).addAnalyzer(Correlation(“miles”, “ ”)) // give’s you analysisContextForResult.type object which can be ran to get the result.</p><p>val analysisContextResult = analysisRunnerAddedWithAnalyzer.run() // Gives you an anayzer context.<br>val metrics = successMetricsAsDataFrame(spark, analysisContextResult) // converting the context to dataframe.</p><p>Note- Correlation can only be applied between two number type field’s.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*dEirrRB-9N5f4Fuh4tqp4w.png" /><figcaption>Result DF</figcaption></figure><p>Note- Correlation between two string’s have not been performed.</p><p>All these ojject’s can be written in a single line and passes to upcoming transformation . I’m just splitting it for you folks to understand.</p><p>Result explanation:</p><ul><li>vehicle id column has no empty column<br>* approximatelly 66 distinct vehicle id’s are present<br>* count of df is 83 <br>* Correlation between miles and number_of_owners is very less. (-ve means not corellated at all)<br>* Correlation between miles and year is 17%. (-ve means not corellated at all)<br>* avg of miles is 13024.096385542169</li></ul><p><strong>This is for performing DQC’s on data</strong></p><p>mport com.amazon.deequ.{VerificationSuite, VerificationResult}<br>import com.amazon.deequ.VerificationResult.checkResultsAsDataFrame<br>import com.amazon.deequ.checks.{Check, CheckLevel}</p><p>val verificationSuiteWithDfPassed= VerificationSuite().onData(df) //gives you a verification builder object<br>val verificationSuiteWithDfPassedAndCheckerAdded=verificationSuiteWithDfPassed.addCheck(Check(CheckLevel.Error, “Review Check”).hasSize(_ &gt;= 3000000).hasMin(“miles”, _ == 100).hasMax(“miles”, _ == 5000).isComplete(“Vehicle_id”).isUnique(“Vehicle_id”).isContainedIn(“number_of_owners”,Array(“2”,”3&quot;,”4&quot;)).isComplete(“month”).isContainedIn(“brand”, Array(“Lambhorghini”, “Konegzegg”, “Ferrari”, “Pagani”, “Jeep”)).isNonNegative(“year”)) // adding DQC’s for data</p><p>val analysisContextResult = verificationSuiteWithDfPassedAndCheckerAdded.run() // getting the result<br>val resultDataFrame = checkResultsAsDataFrame(spark, analysisContextResult) // converting the results as DF.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G-T0vrDTaLyb8TG0F1dA1g.png" /><figcaption>Result DF</figcaption></figure><p>Result explanation:</p><p>*df count is less than 3000000<br>*Minimum value for miles is not 100<br>*Maximum value for miles is not 5000<br>*Vehicle_id has no null’s or is not empty<br>*Vehicle_id is unique<br>*number_of_owners has values other than “2”,”3&quot;,”4&quot;<br>*month has no null’s or is not empty<br>*brand has values other than “Lambhorghini”, “Konegzegg”, “Ferrari”, “Pagani”, “Jeep”<br>*year has no -ve values</p><p><strong>Constraint Suggestion :</strong></p><p>Amazon give’s you another option of getting to know what are all the constraint’s which can be applied to the column’s on your data . To get the suggestion please find the code below.</p><p>import com.amazon.deequ.suggestions.{ConstraintSuggestionRunner, Rules}<br>import spark.implicits._ //for toDF</p><p>val suggestionResult =ConstraintSuggestionRunner().onData(df).addConstraintRules(Rules.DEFAULT).run() // Rule is set as default, feel free to explore other mode’s.</p><p>val suggestionDataFrame = suggestionResult.constraintSuggestions.flatMap{ case (column, suggestions) =&gt; suggestions.map ( constraint =&gt; (column, constraint.description, constraint.codeForConstraint) )}.toSeq.toDF(“columnName”,”constraintDescription”,”codeForConstraintImpementation”)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rZK87Oduk4NgS2ZRmSRSVg.png" /><figcaption>How it is applied</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*GIlOVZO13jiKz46K3-CmKg.png" /><figcaption>Gives you the description and the syntax to be used on analyzer object</figcaption></figure><p>Thanks for your time folk’s.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de1069f60cea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spark — hbase integration]]></title>
            <link>https://thulasitharan-gt96.medium.com/spark-hbase-integration-d18efc27af63?source=rss-ba4702c5727f------2</link>
            <guid isPermaLink="false">https://medium.com/p/d18efc27af63</guid>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[hbase]]></category>
            <category><![CDATA[integration]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[scala]]></category>
            <dc:creator><![CDATA[Thulasitharan Govindaraj]]></dc:creator>
            <pubDate>Sun, 16 Feb 2020 07:18:35 GMT</pubDate>
            <atom:updated>2020-02-16T07:56:31.638Z</atom:updated>
            <content:encoded><![CDATA[<h3>Spark — hbase integration</h3><p>Hey Folks</p><p>Thought of sharing a solution for an issue which took me a week or so to figure to the solution for it.</p><p>Hbase is a Nosql technology which runs over Hadoop, As huge amount’s of data are getting generated every minute some might be without schema, so it can be stored in no sql data base and later refined for data science purpose.</p><p>Ask: To read hbase table as a DataFrame in Spark.</p><p>Spark version: 2.4.0 — Hbase integration, 2.4.5 for orc/csv to parquet conversion</p><p>Hbase version: 1.4.12</p><p>Used the common syntax, catalog for column mapping and read with hbase as format. Took coludera’s spark dependency. As on the below link.</p><p><a href="https://docs.microsoft.com/en-us/azure/hdinsight/hdinsight-using-spark-query-hbase">https://docs.microsoft.com/en-us/azure/hdinsight/hdinsight-using-spark-query-hbase</a></p><p>Code:</p><p>===</p><p>spark-shell — packages com.hortonworks:shc-core:1.1.1–2.1-s_2.11,com.hortonworks:shc:1.1.1–2.1-s_2.11 — repositories <a href="https://repository.apache.org/content/repositories/releases">https://repository.apache.org/content/repositories/releases</a></p><p>import org.apache.spark.sql.DataFrame<br>import org.apache.spark.sql.execution.datasources.hbase.HBaseTableCatalog</p><p>def withCatalog(catalog:String): DataFrame =spark.read.options(Map(HBaseTableCatalog.tableCatalog-&gt;catalog)).format(“org.apache.spark.sql.execution.datasources.hbase”).load</p><p>def carCatalog = s”””{<br> “table”:{“namespace”:”default”, “name”:”cardata”},<br> “rowkey”:”key”,<br> “columns”:{<br> “vehicle_id”:{“cf”:”rowkey”, “col”:”key”, “type”:”string”},<br> “alloy_wheels”:{“cf”:”hardware”, “col”:”alloy_wheels”, “type”:”string”},<br> “anti_Lock_break”:{“cf”:”hardware”, “col”:”anti_Lock_break”, “type”:”string”},<br> “electronic_breakforce_distribution”:{“cf”:”software”, “col”:”electronic_breakforce_distribution”, “type”:”string”},<br> “terrain_mode”:{“cf”:”software”, “col”:”terrain_mode”, “type”:”string”},<br> “traction_control”:{“cf”:”software”, “col”:”traction_control”, “type”:”string”},<br> “stability_control”:{“cf”:”software”, “col”:”stability_control”, “type”:”string”},<br> “cruize_control”:{“cf”:”software”, “col”:”cruize_control”, “type”:”string”},<br> “make”:{“cf”:”other”, “col”:”make”, “type”:”string”},<br> “model”:{“cf”:”other”, “col”:”model”, “type”:”string”},<br> “variant”:{“cf”:”other”, “col”:”variant”, “type”:”string”}<br> }<br> }”””.stripMargin</p><p>val hbaseDf=withCatalog(spark,carCatalog)</p><p>Issue :</p><p>java.lang.NoSuchMethodError: org.json4s.jackson.JsonMethods$.parse(Lorg/json4s/JsonInput;Z)Lorg/json4s/JsonAST$JValue;</p><p>at org.apache.spark.sql.execution.datasources.hbase.HBaseTableCatalog$.apply(HBaseTableCatalog.scala:257)</p><p>at org.apache.spark.sql.execution.datasources.hbase.HBaseRelation.&lt;init&gt;(HBaseRelation.scala:80)</p><p>at org.apache.spark.sql.execution.datasources.hbase.DefaultSource.createRelation(HBaseRelation.scala:51)</p><p>at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:318)</p><p>at org.apache.spark.sql.DataFrameReader.loadV1Source(DataFrameReader.scala:223)</p><p>at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:211)</p><p>at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:167)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LGWcGBA7kBon2Za7JH4wpw.png" /><figcaption>Issue</figcaption></figure><p>Tried all the solutions in stack overflow, passing hbase’s conf file in spark submit, additional jar’s. Noting worked.</p><p>The issue is json4s jar’s.</p><p>json4s jar’s above 3.2.10 will throw the above error wile reading hbase table as DF.</p><p>Step’s to fix it. Take a back up of the below jar’s in SPARK_HOME/jars folder.</p><p>json4s-ast_2.11–3.5.3.jar<br> json4s-core_2.11–3.5.3.jar <br> json4s-ext_2.11–3.5.3.jar<br> json4s-jackson_2.11–3.5.3.jar<br> json4s-native_2.11–3.5.3.jar</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kdeWvD_EfpCbzJkTLFG6Yg.png" /><figcaption>Already existing jar’s</figcaption></figure><p>Remove all these jars.</p><p>Note: json4s-scalap_2.11–3.5.3.jar alone can remain.</p><p>Replace the deleted jar’s with below jar’s.</p><p>json4s-ast_2.11–3.2.10.jar<br>json4s-core_2.11–3.2.10.jar<br>json4s-ext_2.11–3.2.10.jar<br>json4s-jackson_2.11–3.2.10.jar<br>json4s-native_2.11–3.2.10.jar</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h4aQOg6wrM7hInzNzYMfmw.png" /><figcaption>Replaced one</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CqtO8ODeNnUhCt-f89SYrw.png" /><figcaption>Working now.</figcaption></figure><p>Basically any version of json4s other than 3.2.10 is not working while we read data from hbase, there exists an integration problem between these two tech’s. For knowing this i referred post in cloudera website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZJSz4yVoJZJXAx8cYU91EQ.png" /><figcaption>Visible data.</figcaption></figure><p>You can read/write from/to hbase now. :)</p><p>Note if you do this you won’t be able read or write any data frame as a parquet file. So think of another data source than parquet for saving this DF like orc and from another version of spark read it and convert it into Parquet or Delta table. I overcame this by using spark 2.4.5 and reading the ORC over there and converting it to parquet to suite for my data pipeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B4FIzW4CudWBtbGXTzSIXg.png" /><figcaption>Trying to write to parquet format</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QsgHOfxxUDRIA9E7Lg9pKw.png" /><figcaption>CSV Format</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lvovQvlj1ZDW8X_9PhiHdg.png" /><figcaption>ORC Format</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d18efc27af63" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>