<?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 Hemanth Kumar M on Medium]]></title>
        <description><![CDATA[Stories by Hemanth Kumar M on Medium]]></description>
        <link>https://medium.com/@hemanth-kumarm?source=rss-ae015e783a40------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ar3EefkYk8YdpzR35IHOmg.jpeg</url>
            <title>Stories by Hemanth Kumar M on Medium</title>
            <link>https://medium.com/@hemanth-kumarm?source=rss-ae015e783a40------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 23:18:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hemanth-kumarm/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[Hive Metastore Service on EKS]]></title>
            <link>https://towardsaws.com/hive-metastore-service-on-eks-5409f96f98ed?source=rss-ae015e783a40------2</link>
            <guid isPermaLink="false">https://medium.com/p/5409f96f98ed</guid>
            <category><![CDATA[big-data-analytics]]></category>
            <category><![CDATA[apache-hive]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[aws-eks]]></category>
            <dc:creator><![CDATA[Hemanth Kumar M]]></dc:creator>
            <pubDate>Thu, 01 Sep 2022 08:13:50 GMT</pubDate>
            <atom:updated>2022-09-01T08:13:50.969Z</atom:updated>
            <content:encoded><![CDATA[<h4>Running highly available and scalable Hive Metastore service on EKS</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rS2CmzgzKMDsUzGM" /><figcaption>Photo by <a href="https://unsplash.com/@sharonmccutcheon?utm_source=medium&amp;utm_medium=referral">Alexander Grey</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Apache Hive is an open source Datawarehousing software for Big Data, which provides Distributed Data management, MetaData management and Query engine using SQL. The MetaData management is handled by Hive Metastore service, which provides an interface via thrift protocol to read, write and update metadata for frameworks like Apache Spark, Presto etc.</p><p>This blog explains a simple way of running a highly available and scalable Hive Metastore service on EKS.</p><p><strong>Requirement:</strong></p><p>We are using multiple tools like Apache Spark on AWS EMR &amp; Databricks, Presto, Hive Server2 etc for processing and querying Big Data. For all these tools, we are using a central metadata management service, the Hive Metastore Service which running on EMR cluster with single master node.</p><p>As we move towards the server-less architecture of processing the data, we need not maintain a physical cluster for compute. Having an EMR cluster just for running Hive Metastore service is costlier as we are charged for EMR service and EC2 of master node and also this is not scalable as it runs on a single EC2.</p><p>We wanted a simple, scalable and highly available way of hosting Hive Metastore service. We also want to use AWS complied version of Hive.</p><p><strong>Solution:</strong></p><p>We are already running an EKS cluster to host Apache Airflow, we can just containerise the Hive Metastore service and run scalable Kubernetes pods that hosts the Metastore Service.</p><figure><img alt="Hive Metastore Service on EKS Architecture" src="https://cdn-images-1.medium.com/max/1024/1*dbtRPM2gm_e8LJcDC5TLMw.jpeg" /><figcaption>Hive Metastore Service on EKS Architecture</figcaption></figure><p>The above picture represent the architecture of running Hive Metastore service as a containerised application in EKS. Below are the details of how this architecture works.</p><p>1. Create a Docker Image for Hive Metastore service</p><p>The Dockerfile installs AWS compiled version of Hive from AWS EMR repo and exposes 9083 thrift port. We can get these repo details from an EMR cluster in /etc/yum.repos.d/ location.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dbe17faf3d3c28a4e156d10cba091136/href">https://medium.com/media/dbe17faf3d3c28a4e156d10cba091136/href</a></iframe><p>The entry point script, exports the necessary environment variables and dynamically creates hive-site.xml from a json file that contains the necessary hive configurations and starts the metastore service.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d651b31375fc1079907e6c671a07de86/href">https://medium.com/media/d651b31375fc1079907e6c671a07de86/href</a></iframe><p>This script takes a json file that contains key as hive configuration name and value as the hive configuration value to generates hive-site.xml dynamically at runtime which makes the application config driven.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c725ce8468559ff300a9e6e94752186/href">https://medium.com/media/3c725ce8468559ff300a9e6e94752186/href</a></iframe><p>2. Create a Kubernetes deployment</p><p>In this deployment, the hive configurations are provided as an parameterised input to the container by mounting the Kubernetes config map <em>hive-config </em>as a file in the container which contains the hive configurations as a json file. The MYSQL Database username and password is injected as an environment variable to the container from the Kubernetes secret <em>hive-metastore-secret.</em></p><p>We can scale the number of pods in the deployment based on the load which makes it more scalable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0be9d3549ab1923f5d2a7f7eba05254/href">https://medium.com/media/d0be9d3549ab1923f5d2a7f7eba05254/href</a></iframe><p>3. Autoscale the deployment</p><p>Scale the number of Metastore service pods based on the load by using <a href="https://docs.aws.amazon.com/eks/latest/userguide/horizontal-pod-autoscaler.html">Horizontal pod scaler</a></p><pre>kubectl autoscale deployment hive-metastore-deployment --cpu-percent=70 --min=1 --max=10</pre><p>4. Create a Load balancer service</p><p>Since we are using AWS EKS, Kubernetes creates an AWS Classic Load balancer. We can add appreciate security group to have inbound security for production environment.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a51732e2a4d2ef8005fecb23f81dd5e0/href">https://medium.com/media/a51732e2a4d2ef8005fecb23f81dd5e0/href</a></iframe><p>5. Create a Route53 DNS record for the Classic Load balancer</p><p>6. Use the DNS record created in Step4 in the necessary applications or frameworks.</p><p>pyspark --name my-spark-session --conf &quot;spark.hive.metastore.uris=&lt;dns_for_hive_metastore&gt;:9083</p><p>This is a simple example of running highly available and scalable Hive Metastore service on EKS by containerising the Hive Metastore application.</p><p>Happy Containerisation!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5409f96f98ed" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/hive-metastore-service-on-eks-5409f96f98ed">Hive Metastore Service on EKS</a> was originally published in <a href="https://towardsaws.com/">Towards AWS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes CronJob: Automate Administrative tasks in EKS]]></title>
            <link>https://hemanth-kumarm.medium.com/kubernetes-cronjob-automate-administrative-tasks-in-eks-be09cb340802?source=rss-ae015e783a40------2</link>
            <guid isPermaLink="false">https://medium.com/p/be09cb340802</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[aws-eks]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[airflow]]></category>
            <dc:creator><![CDATA[Hemanth Kumar M]]></dc:creator>
            <pubDate>Mon, 29 Aug 2022 12:50:50 GMT</pubDate>
            <atom:updated>2022-09-12T04:54:27.436Z</atom:updated>
            <content:encoded><![CDATA[<h4>A simple use case of Automating administrative tasks in EKS using Kubernetes Cron job</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*T3CmcDgEUNBCGar5" /><figcaption>Photo by <a href="https://unsplash.com/@viazavier?utm_source=medium&amp;utm_medium=referral">Laura Ockel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Kubernetes is one of the most widely used open source container orchestration platforms. The easy, quick and handy way of automating tasks in Unix for most DevOps Engineers is to schedule a script with Unix crontab.</p><p>Similarly, Kubernetes provides a native way of scheduling tasks at a fixed schedule. This blog explains a simple use case of automating an administrative task using the Kubernetes Cron job.</p><h4><strong>Requirement:</strong></h4><p>We are running Apache Airflow on Kubernetes (EKS). In the Dev environment, each developer has been provisioned a dedicated Airflow instance running as a Kubernetes deployment with a dedicated Scheduler and Web-server in a dedicated Kubernetes Namespace. These deployments will be inactive during weekends (Non-Working Days) and some of the deployments are not used very frequently.</p><p>We do not want to run any pods for Scheduler and Web-server which is not doing anything (not actively scheduling jobs) during weekends, which will save us significant compute cost during weekends accounting the fact that each developers in the medium sized team has a dedicated Airflow Deployment. There should be a simple way to disable / hibernate Airflow deployments during weekends and enable them back when required by users.</p><h4><strong>Solution:</strong></h4><p>The solution is to scale down all the deployments of airflow to 0 replica during weekends.</p><pre>kubectl scale deployment -n my-airflow-namespace --all --replicas=0</pre><p>On the weekdays if a user requires the airflow deployment back, they just have to scale up the deployment with replica 1, which is the original value of the replica.</p><pre>kubectl scale deployment -n my-airflow-namespace --all --replicas=1</pre><p>This way no pods will be running during weekends and all infrequently used Airflow deployments will not run any unnecessary pods until user needs it on-demand.</p><p>Now to schedule this task on weekends, we can use a Kubernetes Cron Job that can perform this administrative task.</p><p><strong>Implementation:</strong></p><ul><li>Created a Docker image that has kubectl installed so that the the script in the image can interact with AWS EKS Cluster with help of kubectl command.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0c0a3f9baa747e316e327b86ea756f5/href">https://medium.com/media/c0c0a3f9baa747e316e327b86ea756f5/href</a></iframe><ul><li>Created a Kubernetes namespace where the automation Cronjob will run. The access to this namespace is restricted to only Admin users via Kubernetes RBAC.</li><li>Created a Kubernetes service account attached to an AWS IAM role that provides necessary access for the cron job to run necessary kubectl commands on EKS cluster. Reference: <a href="https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html">IAM Role For EKS Service account</a></li><li>Created a Kubernetes cronjob scheduled to run at 7AM UTC on every Saturday. Below is the definition of the cron job. Reference: <a href="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/">Creating Kubernetes Cron Job</a></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30402766efc328489cafed09ac4617f0/href">https://medium.com/media/30402766efc328489cafed09ac4617f0/href</a></iframe><p>This is just a simple example of automating an administrative in EKS using Kubernetes Cron job. Similarly, We can automate any task with Kubernetes ConJob.</p><p>Happy Automation!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be09cb340802" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spark remote job submission to Yarn running on AWS EMR]]></title>
            <link>https://hemanth-kumarm.medium.com/spark-remote-job-submission-to-yarn-running-on-aws-emr-5d6ffd8cb373?source=rss-ae015e783a40------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d6ffd8cb373</guid>
            <category><![CDATA[aws-emr]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[yarn]]></category>
            <category><![CDATA[big-data-analytics]]></category>
            <dc:creator><![CDATA[Hemanth Kumar M]]></dc:creator>
            <pubDate>Sun, 12 Dec 2021 18:16:41 GMT</pubDate>
            <atom:updated>2021-12-13T11:21:24.671Z</atom:updated>
            <content:encoded><![CDATA[<h4>Spark remote job submission allows client to submit Spark jobs to Yarn cluster from anywhere, decoupling the client from the Yarn cluster.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xWPZCsDLcmZeRRij" /><figcaption>Photo by <a href="https://unsplash.com/@ffstop?utm_source=medium&amp;utm_medium=referral">Fotis Fotopoulos</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Spark remote job submission allows clients to submit Spark jobs to the Yarn cluster from anywhere. This can also be leveraged to submit Spark jobs to different Yarn clusters running different versions of Hadoop and Spark.</p><h3>Problem Statement</h3><p>We are using AWS EMR cluster with Yarn as a resource manager to run our Spark jobs. We want to submit jobs to the EMR cluster remotely without ssh to the master node or without running the spark-submit command directly on the master node.</p><h3>Solution</h3><p>Leverage remote job submission feature of Spark to submit jobs to Yarn cluster from anywhere remotely.</p><h4><strong>Basic Requirements of the remote instance:</strong></h4><p><strong>1. Java and Python runtime</strong></p><p><strong>2. Hadoop and Spark binary</strong></p><p>The binaries should be present on the remote host (need not be installed). The version of binaries in remote machine and target EMR cluster should match.</p><p>The binaries can be downloaded <a href="https://spark.apache.org/downloads.html">here</a> or can be copied from the EMR master node from the following locations <strong><em>/usr/lib/hadoop</em></strong> &amp; <strong><em>/usr/lib/spark</em></strong>. If binaries are not copied from the EMR cluster, make sure to copy emrfs-hadoop-assembly jar from the EMR cluster.</p><p>Place the binaries in the remote instance and set the following environment variables.</p><ul><li><em>export</em> HADOOP_HOME=<em>&lt;</em>path to hadoop binary folder<em>&gt;</em></li><li><em>export</em> SPARK_HOME=<em>&lt;</em>path to spark binary folder<em>&gt;</em></li></ul><p><strong>3. Hadoop and Spark Config files of EMR cluster</strong></p><p>Copy Hadoop config files yarn-site.xml, core-site.xml, mapred-site.xml from /etc/hadoop/conf and copy spark config file hive-site.xml from /etc/spark/conf.</p><p>These config files will give information to Spark about the EMR cluster like which is the master node, resource manager, and hive metastore to connect to on running spark-submit. Store the config files in a folder of the remote instance and set the following environment variables.</p><ul><li><em>export</em> HADOOP_CONF_DIR=<em>&lt;</em>path to hadoop configs folder<em>&gt;</em></li><li><em>export</em> SPARK_HIVE_XML_CONF_DIR=<em>&lt;</em>path to spark configs folder<em>&gt;</em></li></ul><h4><strong>Running Spark Submit</strong></h4><p>Run the spark-submit command as shown below, with spark deploy mode set to cluster mode.</p><pre><em>$</em>SPARK_HOME/bin/spark-submit --master yarn --deploy-mode cluster --conf spark.yarn.dist.files=<em>${</em>SPARK_HIVE_XML_CONF_DIR<em>}</em>/hive-site.xml sample-spark-code.py</pre><p>Now the spark-submit runs on the remote instance, submitting the actual spark job to the EMR cluster.</p><h3>Conclusion</h3><ul><li>By leveraging the remote job submission feature of Spark we can submit spark jobs to the Yarn cluster from anywhere remotely without SSH to the master node or directly running spark-submit on the master node.</li><li>The remote instance can have different versions of Hadoop and Spark binary. By setting the environment variable per session pointing to a specific version of the binary folder based on the requirement at the runtime, we can submit Spark jobs with multiple versions of Spark &amp; Hadoop.</li><li>We can store Spark and Hadoop config files of different EMR clusters in the remote instance and choose different EMR clusters at run time by setting the environment variable per session pointing to a specific cluster config folder.</li><li>The remote instance can be a Docker container or Kubernetes pod whose image will have the Hadoop and Spark binaries embedded into the image.</li><li>With this, we can decouple the client that submits Spark job from the EMR cluster. Enable the client to submit Spark jobs with multiple versions of Spark &amp; Hadoop and to multiple EMR clusters.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d6ffd8cb373" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Compare PySpark DataFrames based on Grain]]></title>
            <link>https://medium.com/data-science/compare-pyspark-dataframes-based-on-grain-e963e0a8aacf?source=rss-ae015e783a40------2</link>
            <guid isPermaLink="false">https://medium.com/p/e963e0a8aacf</guid>
            <category><![CDATA[pyspark]]></category>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[big-data-analytics]]></category>
            <category><![CDATA[data-engineering]]></category>
            <dc:creator><![CDATA[Hemanth Kumar M]]></dc:creator>
            <pubDate>Sun, 08 Aug 2021 22:28:14 GMT</pubDate>
            <atom:updated>2021-08-20T05:59:35.118Z</atom:updated>
            <content:encoded><![CDATA[<h4>A simple approach to compare Pyspark DataFrames based on grain and to generate reports with data samples</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*phbOluCX5OLNntz5" /><figcaption>Photo by <a href="https://unsplash.com/@mjessier?utm_source=medium&amp;utm_medium=referral">Myriam Jessier</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Comparing two datasets and generating accurate meaningful insights is a common and important task in the BigData world. By running parallel jobs in Pyspark we can efficiently compare huge datasets based on <a href="http://www.datamartist.com/dimensional-tables-and-fact-tables#:~:text=The%20GRAIN%20or%20GRANULARITY%20of,one%20line%20for%20some%20orders)."><strong>grain</strong></a> and generate efficient reports to pinpoint the difference at each column level.</p><p><strong>Requirement:</strong></p><p>We have a huge dataset ingested from Salesforce. The dataset has more than 600 columns and around 20 million rows. Dev and validation datasets have to be compared to generate a report that can pinpoint the difference at the column level based on <a href="http://www.datamartist.com/dimensional-tables-and-fact-tables#:~:text=The%20GRAIN%20or%20GRANULARITY%20of,one%20line%20for%20some%20orders)."><strong>grain</strong></a>.</p><p>Below are the insights to be generated along with data samples containing grain columns, that can be used to query and analyze it further.</p><ul><li>Duplicate records.</li><li>Missing records.</li><li>Capture the difference between the column value in the dev and validation dataset.</li></ul><p><strong>Approach:</strong></p><p>We can use the subtract method of the data frame to subtract two data frames that will generate the records that are not matching, but it would be difficult to identify which out of 600 columns is actually changing and the actual value that is different. Below is a simple approach to tackle this.</p><p>From here on ill be referring validation dataset as the source data frame (src_df) and the dev dataset as the target data frame (tar_df). Since the same two data frames are being used again and again for different analytical queries, we can persist the two data frames in memory for faster analysis.</p><p>In the below approach it is assumed that both the data frames are having the same schema, i.e both data frames have the same number of columns, same column names, and same data type for all the columns.</p><p><strong>Identify duplicate and missing grain records:</strong></p><p>To identify duplicate records, we can write a small group by query using Pyspark functions. The grainDuplicateCheck() function does the same.</p><p>To identify missing grains, we can select grain columns from both data frames and subtract them directly.</p><p>It&#39;s important to note that we need to perform both src_df - tar_df which would get us the valid missing grains and tar_df - src_df which would get us the grain of extra records that are invalid.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aa07664ff511bb6c27cf8ebaa53a04f2/href">https://medium.com/media/aa07664ff511bb6c27cf8ebaa53a04f2/href</a></iframe><p><strong>Compare column values:</strong></p><p>Now we have to compare the column values between the data frames and generate the report column by column, with both expected value and invalid value found for a particular grain.</p><p>Since we have already identified the missing records, now we shall join the two data frames on the grain columns and compare the column values for all the records which have matching grain in both data frames.</p><p>It is important to note that</p><ul><li>Grain columns can have null values and we have to perform <strong>null safe join </strong>otherwise, those records won’t join and the records will be skipped. I’m using the <a href="https://spark.apache.org/docs/3.1.1/api/python/reference/api/pyspark.sql.Column.eqNullSafe.html"><strong>eqNullSafe()</strong></a> built-in Pyspark function for this purpose.</li><li>The columns that contain double values like amount, will not match exactly as different calculations might generate values with a small difference in decimal precision. Hence for these types of columns, we have to subtract the values and flag those records which has a difference ≥ threshold.</li></ul><p>In the below compareDf() function, using the joined data frame, we select grain and specific column to be validated and compare them.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0cb7e02efe1231f9bf559ff651dd343/href">https://medium.com/media/c0cb7e02efe1231f9bf559ff651dd343/href</a></iframe><p><strong>Compare column values by running parallel jobs:</strong></p><p>The limitation of the above function is that we are comparing the two data frames column by column sequentially, iterating over each column of the data frame.</p><p>Let’s look at some stats now. With 600+ columns and around 20 million rows, it is taking 15 seconds for each column to be compared. For all 600 columns, it comes around 150 minutes (~2.5hrs).</p><p>The column comparison tasks are independent of each other and hence we can parallelize them. If we compare 8 columns in parallel then the time taken would be around 19 minutes. This is a huge difference as it&#39;s 8x times faster.</p><p>In the below function compareDfParallel(), I’m creating a thread pool of specified size using multiprocessing built-in python package. With <em>parallel_thread_count =</em> 8, 8 columns will be compared parallelly. compareDFColumn() is the actual comparison function that will be executed by each thread for a specific column.</p><p>Parallel thread count has to be chosen based on the capacity of the nodes in the cluster. We can use the number of driver cores specified in spark-submit as the parallel thread count.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0f12df16e0ccdf9066b9f9268d507ed/href">https://medium.com/media/e0f12df16e0ccdf9066b9f9268d507ed/href</a></iframe><p>Assuming all the above functions are present in the pyspark_utils.py file, below is an example of the usage with the sample data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b379c4961f1a20941aaa356541be0161/href">https://medium.com/media/b379c4961f1a20941aaa356541be0161/href</a></iframe><p>The output of compareDfParallel() will have the columns with prefix <em>_src</em> for the column value referring to the source data frame and <em>_tar</em> for the column value referring to the target data frame.</p><p>In the above example, <em>billing_amount_src</em> is 1100 which is the value of billing_amount in the source data frame, whereas <em>billing_amount_tar</em> is 1000 which is the value of billing_amount in the target data frame.</p><p>The output of the script can be piped to a file to get a consolidated report. The function can be modified to generate an HTML report instead of a text file report.</p><p>This is one of the simple approaches to efficiently compare Pyspark data frames based on grain and to generate reports with data samples.</p><p>Happy Datawarehousing!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e963e0a8aacf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/compare-pyspark-dataframes-based-on-grain-e963e0a8aacf">Compare PySpark DataFrames based on Grain</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple AWS S3 Logging in Python3 Using Boto3]]></title>
            <link>https://hemanth-kumarm.medium.com/simple-aws-s3-logging-in-python3-using-boto3-cfbd345ef65b?source=rss-ae015e783a40------2</link>
            <guid isPermaLink="false">https://medium.com/p/cfbd345ef65b</guid>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[aws-s3]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Hemanth Kumar M]]></dc:creator>
            <pubDate>Tue, 03 Aug 2021 10:59:12 GMT</pubDate>
            <atom:updated>2021-12-13T03:05:37.052Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TfpIaPVlP_8T8o69" /><figcaption>Photo by <a href="https://unsplash.com/@sveninho?utm_source=medium&amp;utm_medium=referral">Sven Scheuermeier</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Simple way of implementing S3 logging in Python3</h4><p>One of the Key aspects of a software framework is to log necessary information and persist them. Using boto3 and native python logger its easy to persist logs into AWS S3 within a python program.</p><p>Logs would be helpful to debug, monitor, audit and understand the behaviour of the framework at any given point of time. When it comes to applications in cloud, we don’t store important information in local machine, instead we would store it in cloud storage service like AWS S3.</p><p>Recently i’ve been working on a framework to automate Big Data ETL deployments using python. The requirement was to persist the logs to S3 for future reference, without using complex code or much code changes. The requirement was not to have the logs in realtime in S3.</p><p>My intention was to leverage existing Python logger that i’ve been using all along for all python codes and Boto3 SDK to interact with AWS S3. Here is a simple approach of storing logs generated by Python logger into S3.</p><h3>Approach</h3><p><strong>Create String I/O Logger:</strong></p><p>Python logger allows us to add different kinds of handlers. We can leverage this to add a String I/O Stream handler which is basically a string buffer that would store all the logs generated by logger.info or logger.error function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1609fbbc9f1fd4ddb2b88f5a68f45738/href">https://medium.com/media/1609fbbc9f1fd4ddb2b88f5a68f45738/href</a></iframe><p><strong>Put Content to S3:</strong></p><p>Boto3 is a python SDK to interact with AWS Services. Here i have created a function put_content_to_s3() to put given content in specified s3 path. This function also takes backup key as parameter and if in case the file already exists in the specified S3 location, it will backup the old content in either backup folder or backup file based on specified backup strategy. This backup strategy can be customised as required based on the requirement.</p><p>The instance on which the code is running should have read and write access to specified S3 path.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0693df59152b8f3a836c80a86e8f14fd/href">https://medium.com/media/0693df59152b8f3a836c80a86e8f14fd/href</a></iframe><p><strong>How to use S3 logging:</strong></p><p>The main function of the code will create a String I/O buffer and string I/O logger. The code will have a normal flow with logger.info and logger.error.</p><p>In the finally block put_content_to_s3() function is called to put the logs content from String I/O buffer to S3.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dfd1cb337b70452f093498c01a395a46/href">https://medium.com/media/dfd1cb337b70452f093498c01a395a46/href</a></iframe><p>This is one of the simple and easy way of implementing S3 logging in Python3 using existing python logger and Boto3. There are few libraries available in open source for this purpose, but here the intention was not to use any untrusted python libraries and not to over complicate things.</p><p>Happy Coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cfbd345ef65b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>