<?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 Ajay Thakur on Medium]]></title>
        <description><![CDATA[Stories by Ajay Thakur on Medium]]></description>
        <link>https://medium.com/@ajaychandthakur?source=rss-6968c17ade90------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2yTAE7seQU2UHtZTK4Xiyg.png</url>
            <title>Stories by Ajay Thakur on Medium</title>
            <link>https://medium.com/@ajaychandthakur?source=rss-6968c17ade90------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 16:48:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ajaychandthakur/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[Apache Kafka for Anyone]]></title>
            <link>https://medium.com/@ajaychandthakur/apache-kafka-for-anyone-4be7fa1b94e?source=rss-6968c17ade90------2</link>
            <guid isPermaLink="false">https://medium.com/p/4be7fa1b94e</guid>
            <category><![CDATA[realtime]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[apache-kafka]]></category>
            <category><![CDATA[data-product-manager]]></category>
            <category><![CDATA[kafka]]></category>
            <dc:creator><![CDATA[Ajay Thakur]]></dc:creator>
            <pubDate>Thu, 18 Jul 2024 14:08:24 GMT</pubDate>
            <atom:updated>2024-07-18T14:10:58.246Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>What to expect from this article?</strong></p><p>If you are entirely new to the term Kafka or have heard of it but don’t know what it is, then by the end of this blog, you will have a basic understanding of what Kafka is, why it was developed, and the problem it solves.</p><p><strong>What not to expect from this article?</strong></p><p>If you are already using Kafka or any versions of it, and trying to learn deeper nuances of it, this post might be too basic for you. But please keep an eye out for my upcoming blog posts on this topic.</p><p><strong>What is Kafka?</strong></p><p>Before we dive into Kafka, let&#39;s understand data processing. Data can be processed in 2 ways - in batches or in real-time. And yes, as the name suggests, real-time data processing is faster than batch processing.</p><p>Let me give you an example, let’s say you want to send a message to your friend living across the country and you decide to post your friend a letter. You write a letter and deliver it to your local post office. Now the post office guys won’t deliver the letter straight away as they receive it. They would collect all the letters received during the day and at a particular time towards the end of the day, they would start processing all the letters — sorting all letters per zip code and sending them out accordingly in batches. This is batch processing. The other way to communicate the same message to your friend would be to call your friend. This is real-time, without any lag. You just stream your message in real time.</p><p>Similarly in the data world, examples of batch processing would be payrolls processed bi-weekly or monthly, bills processed at the end of month, etc</p><p>Examples of stream processing are FB/Instagram feeds, Netflix streaming, etc.</p><blockquote>Kafka is a platform that supports real-time data streaming.</blockquote><p>Now, let’s get a little more precise..</p><blockquote>Kafka is a highly scalable and distributed platform for creating and processing real-time data streams</blockquote><p>Kafka was developed by folks at Linkedin for LinkedIn’s internal data streaming capabilities. Later it was open-sourced and given to the Apache Foundation to maintain. So, you can use the open-source version of Kafka which is Apache Kafka. Some organisations have built add-on features on top of open-source Kafka and these are available for purchase as enterprise versions like Confluent Kafka, etc</p><p><strong>Ok, but what problems does Kafka solve?</strong></p><p>Imagine a small organization where you want to send data in real time from source systems to destination systems. Now every source will have to establish a data connection for every destination. In this example, a combination of 4 sources and 3 destinations will require us to create 12 data connections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o2WDUw8MTOzbpY_Qo928dg.png" /></figure><p>Now imagine that you are managing a consumer-facing app that receives data from tens of front-end and backend source systems and then forwards it to another bunch of downstream consumers. This scenario can easily become chaotic, as in the image below. I shudder at the thought of a day when some of these pipelines, carrying continuously flowing terabytes of data, fail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZU2XBh8lDS5lKf8epdEORw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mt4Chi9Djz7FUzYcENDZ6Q.png" /></figure><p>Here comes our savior, Kafka, who acts as a broker between the publishers of data and subscribers of data. Now both the publishers and consumers of data need not worry about creating n number of individual 1:1 data pipelines. Instead, publishers of data can simply publish their data onto the Kafka server(broker), and any consumer, given it has permissions, can subscribe to the published stream of data and consume it.</p><p><strong>How does Kafka work?</strong></p><p>Kafka has 3 components — Producer(publisher), Broker, and Consumer(subscriber)</p><p>i) Producer is an application that sends data in the form of messages</p><p>ii) Broker acts as a middle-person between the producers and consumers since they do not interact directly with each other. Kafka server acts as a broker.</p><p>iii) Consumer is an application that receives messages.</p><p>While sending information using Kafka, we need to ensure that it is structured. To help with this, Kafka has this concept of Kafka topic.</p><p><strong>A Kafka topic</strong> is a unique dataset containing a list of data points/attributes/key-value pairs. It is similar to a database table in the SQL world. We can design the topics as per our design considerations. You could club a bunch of similar data points within a topic. For example, I could add all user subscription-related information like subscription start date, end date, subscription status, and subscription type within a topic.</p><p><strong>Topic partitions: </strong>Brokers can face storage capacity challenges with huge volumes of streaming data. To address this, we can partition the topic into smaller segments and distribute these partitions across different machines using vertical sharding. We have the flexibility to decide the number of partitions within a topic while designing our system.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4be7fa1b94e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Catalog for your Org]]></title>
            <link>https://medium.com/@ajaychandthakur/data-catalog-for-your-org-84719adb503c?source=rss-6968c17ade90------2</link>
            <guid isPermaLink="false">https://medium.com/p/84719adb503c</guid>
            <category><![CDATA[data-platforms]]></category>
            <category><![CDATA[data-catalog-tool]]></category>
            <category><![CDATA[data-catalog]]></category>
            <category><![CDATA[datahub]]></category>
            <category><![CDATA[data-lineage]]></category>
            <dc:creator><![CDATA[Ajay Thakur]]></dc:creator>
            <pubDate>Wed, 22 Mar 2023 12:28:27 GMT</pubDate>
            <atom:updated>2023-03-22T12:28:27.547Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>I keep hearing this confusing term. What is a Data Catalog?</strong></p><p>Let’s say you want to read a book on a fairly complex topic. Before starting with chapter 1, you will most likely browse through the index, see all the listed chapters, and then check the topics under each chapter. This gives you a high-level view of the contents of that book. Now you can easily navigate to any particular section of the book without having to read all contents from page 1 to page n.</p><p>Similarly, a data catalog is an index for all the metadata that resides within your organisation. It is a one-stop shop to get information on all the databases, schemas, tables, and columns. Even better, data catalogs can also be leveraged to provide you with lineage information (visualise a data flow chart) between these systems.</p><p><strong>So what is metadata?</strong></p><p>Metadata is data about data. Metadata can be technical or business metadata. The following items are examples of metadata:</p><p>A) Technical metadata:</p><ol><li>A list of all database(DB) names</li><li>A list of all table/dataset names within those DBs</li><li>A list of all columns/keys(in the case of NoSQL) within the table/dataset</li><li>Tags to denote whether a column is a primary key column</li><li>The data type of the column (eg. string, numeric, etc)</li><li>A list of any feature tables, features, or models used by ML teams</li></ol><p>B) Business metadata</p><ol><li>Business descriptions of these tables/datasets</li><li>Business descriptions of these columns/keys</li><li>Business descriptions of models or underlying features</li><li>Any tagging such as PII/sensitive data/deprecated data</li></ol><p><strong>Tools used for Data Cataloging</strong></p><p>Alation, Atlan, Atlas, Collibra, DataHub, Glue(AWS), etc are some popular ones.</p><p>Oh, so many options! Which tool should I use for my organisation&#39;s Data Cataloging needs?</p><p>Below(refer to chart) is an exercise I did for comparing the different data cataloging tools. This is my personal opinion and the actual features might differ due to constant product updates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*y17nm66ttUS_N_7TVHAkYQ.png" /></figure><p>If you are a budget-conscious startup, you might want to go with open-source Datahub. If you are looking at rich features like the ability to build and display lineage or have email notifications, you might want to go for Atlan. If your org only deals with SQL data, you might not need a data catalog with multiple connectors. If you have a plethora of data sources like MySQL, Cassandra, MongoDB, Kafka, etc, and the data catalog tool does not support built-in connectors with these systems, building and testing a reliable custom connector is another time and resource-consuming task. So you might need to keep this under consideration before selecting a tool. For example, in one of my organisations we used Cassandra heavily and at that point in time, Datahub did not have a built-in connector for Cassandra. So it took us 2 weeks of additional effort to build a custom connector, while for other DB’s built-in connectors, you can establish a connection, test it, and start consuming data within a day</p><p><strong>Data Lineage</strong></p><p>Below is an example how what data lineage looks like. Data Lineage is graphical information that shows how the data flows in the organisation — from source systems to intermediate tables to destination reports/models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*VqEF87G5KzUFOguujmFX6g.png" /></figure><p><strong>Challenges while implementing Data Catalog</strong></p><ol><li><strong>Stakeholder Buy-in</strong>: Data Catalogs are generally implemented by a central data governance team for different business units within an organisation. So it is important to get stakeholder buy-in. It takes engineering, program, and product efforts to successfully implement a Data Cataloging solution. You need to evangelise the value of this solution for them to commit resources to this data product. In my experience, I did this by connecting with stakeholders and explaining to them the value proposition like cost savings, effort optimisation, and long-term integrations with other platforms like Access Control systems, Data Privacy systems, PII Data Classification systems, etc.</li><li><strong>Updating business metadata</strong>: Data Catalogs almost always come in after the data in an org is in a mess. For example, it takes days to reach the root cause of a data issue, there is little to no knowledge of data that exists within the organisation when some data owner leaves the organisation, etc. Because of these issues, all historical context of business metadata information needs to be filled in one-time manually. For new data getting onboarded, one can set up automatic processes to capture this business metadata at the time of data onboarding. But historical backfill is a time and effort-consuming activity.</li><li><strong>Maintenance and upkeep</strong>: The Data team will implement a Data Catalog solution once and set up processes for maintenance and upkeep. But these processes have to be followed. For example, we can set up a process to have a business metadata column, let’s say table description, be filled in mandatorily. But data owners could workaround this by filling in dummy values like NA. Data quality checks need to be set in place to avoid such issues.</li></ol><p>Do let me know about how you implemented Data Catalog in your organisation, or if you want to discuss anything related to Data Catalog implementation. I am reachable at ajaychandthakur@gmail.com, or you can comment on this article.</p><p>Have a great Data Cataloging journey!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84719adb503c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What are Knowledge Graphs?]]></title>
            <link>https://medium.com/@ajaychandthakur/what-are-knowledge-graphs-b77bfc140f36?source=rss-6968c17ade90------2</link>
            <guid isPermaLink="false">https://medium.com/p/b77bfc140f36</guid>
            <category><![CDATA[knowledge-graph]]></category>
            <category><![CDATA[graphdb]]></category>
            <category><![CDATA[graph-data-structure]]></category>
            <category><![CDATA[google-knowledge-graph]]></category>
            <category><![CDATA[graph-database]]></category>
            <dc:creator><![CDATA[Ajay Thakur]]></dc:creator>
            <pubDate>Mon, 09 Jan 2023 20:35:36 GMT</pubDate>
            <atom:updated>2023-01-09T20:35:36.057Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*okrfDyRcnGxm43RrDhhWlQ.png" /></figure><p><strong>Definition</strong></p><p><strong>Knowledge Graphs </strong>are a<strong> network of facts</strong> connected via <strong>explicitly defined relationships</strong> from which <strong>new knowledge can be inferred</strong>. A knowledge graph may have an <strong>underlying structure</strong>(schema) called ontology.</p><p>Lets break down this definition,</p><p>Network of facts: Visually, think of it as 2 nodes connected via an edge. In knowledge graph terms, consider 2 facts connected by a relationship called triples.</p><p>Explicitly defined relationship: In a knowledge graph, relation has direction. Relations are as important as the data they bind.</p><p>New inferable knowledge: These can be derived through deductive and automated reasoning through rules. For example, Winston Churchill is an enemy of Adolf Hitler. Charles de Gaulle is also an enemy of Adolf Hitler. We can derive that Winston Churchill and Charles de Gaulle are friends with each other.</p><p>Let’s take a more practical example — How does LinkedIn know if a person is a 1st or 2nd or 3rd connection? This is derived by path traversal algorithms applied on knowledge graphs.</p><p>Other Applications of knowledge graphs are Customer behaviour analytics, Marketing analytics, Fraud detecting, etc</p><p><strong>Knowledge Graph Technology</strong></p><p>To build a knowledge graph, we need sources of information - structured or unstructured data.</p><p>We can use various techniques to build triples out of these sources of data. In case of documents DBs, you can use document mining or text mining.</p><p>For other DBs, you can use data ingestion or data virtualisation or ETL methods. Using these transformation, we can create a data graph and define explicitly defined relationships to bring meaning to the data graph. Both data graph and ontology are deployed to a graph database which is a scalable repository that allows to read or write graph information.</p><p>Using APIs and graph queries, we can surface a graph information to expose this knowledge to end user applications.</p><p>In terms of ownership, Data Engineers are reposnible for the ETL stage. SME’s will help with ontology creation process.</p><p><strong>Graph DBs vs RDBMS</strong></p><p>Graphs DBs have better performance while querying, storage and retrieval. Their structure is flexible, easily extendable, and agile. Though access control practices for Graph DBs are just emerging, and are not as mature as relationship databases.</p><p><strong>Tech Landscape</strong></p><p>Knowledge graph solutions: AllegroGraph, Maana, Refinitiv, MissionGraph, ClearGraph, etc.</p><p>Graph DBs: AWS Neptune, Apache Jena, MariaDB, Velocity DB, etc.</p><p>Graph Processing Engines: Gradoop, Mapr, Flink, etc.</p><p>Visual Analytics Tools: Cambridge Semantics, Graphlytic, Lumify, etc.</p><p><strong>Knowledge Graph Development Cycle</strong></p><ol><li>Product manager defines the requirements which form the basis for knowledge graph backlog</li><li>Dev team will develop features required in the next sprint</li><li>Data sources are identified and secured.</li><li>Ontology is defined on top of data</li><li>Knowledge graph implementation is showcased to users</li></ol><p><strong>Approaches for Defining Ontologies</strong></p><ol><li>Schema-first: Ontology is decided first before data is exposed</li><li>Schema-light: Data graph is first exposed before ontology is developed</li><li>Schema-on-demand: Ontology is developed in parallel with data graph</li></ol><p><strong>Application of Knowledge Graphs</strong></p><ol><li>Linked data: Relates data from different sources on the web to expose richer connected data that can be made useful using semantic queries eg. Geonames.com</li><li>Semantic search: Intelligent search with ‘Google-like’ capabilities and powerful search filters. This is achieved through content tagging with relevant metadata to provide rich contextual information.</li><li>Semantic federation: Manage the data and metadata as a part of data management strategy. eg. data catalogs, data glossaries, data dictionaries</li><li>Enterprise knowledge graphs: Application of knowledge graphs at enterprise levels to deeply understand the business at a macro level</li><li>Other use cases can be i)Publishing and education sector use knowledge graphs for content tagging, curation of bibliographic databases, intelligent search, etc; ii) Financial services — risk management, upselling, customer targeting, iii) Recommendation engines, iv)Network analysis, etc.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b77bfc140f36" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Crash Course on PySpark]]></title>
            <link>https://medium.com/@ajaychandthakur/a-crash-course-on-pyspark-77fe1f113adf?source=rss-6968c17ade90------2</link>
            <guid isPermaLink="false">https://medium.com/p/77fe1f113adf</guid>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[pyspark-training]]></category>
            <category><![CDATA[spark-sql]]></category>
            <category><![CDATA[pyspark]]></category>
            <category><![CDATA[pyspark-dataframes]]></category>
            <dc:creator><![CDATA[Ajay Thakur]]></dc:creator>
            <pubDate>Sun, 06 Nov 2022 19:54:15 GMT</pubDate>
            <atom:updated>2022-11-15T16:28:46.748Z</atom:updated>
            <content:encoded><![CDATA[<h4>What would you get from spending 3mins reading this article?</h4><p>If you work in the world of data, you would have come across the term/technology — PySpark. If you are curious to understand it, keep reading. This article aims to explain:</p><p>i) What is PySpark?</p><p>ii) Why are data professionals gung-ho about it?</p><p>iii) How can you use it? (With examples for using it for basic data operations)</p><p>iv) Why do we use PySpark (over other options)?</p><p>This article has been written from a point of view that a reader has no prior knowledge or experience with this topic, but has a basic knowledge of coding (no specific language, though Python would be good to have)</p><h4>What is PySpark?</h4><p>Before going into mundane technical definitions, let&#39;s take a walk down the annals of history. It was the early 2000s and big organizations were struggling to keep up with massive quantities of data. This was a time when search engines were novelty, the term ‘big data’ was not yet coined, and social networks were limited to text messages, no images or video. Organizations were just vertically stacking up storage and computation resources (RAM, storage disks) to cope up with ever increasing volumes of data and it still was not enough.</p><p>Then in 2003–04, Google, our knight in shining armor, published a paper on ‘The Google File System’ and later ‘MapReduce’. ‘The first paper discussed how Google had implemented a scalable and distributed file storage system using traditional hardware. The second paper discussed simplified data processing on these large clusters of storage systems.</p><p>MapReduce split huge amounts of data (read petabytes) into smaller chunks and allowed parallel processing, thus speeding up the computation on these large datasets. Map splits and maps the data; Reduce shuffles and produces a reduced output. If needed, more details here: <a href="https://en.wikipedia.org/wiki/MapReduce#Overview">MapReduce — Wikipedia</a></p><p>Inspired by these Google papers, developers at Apache developed Hadoop ecosystem, which can be main broken down into parts viz.</p><p>i) HDFS(Hadoop Distributed File System) — distributed file storage that can store petabytes of data by distributing data across multiple storage devices</p><p>ii) Hadoop MapReduce — data processing engine</p><p>iii) Hadoop YARN (Yet Another Resource Negotiator) — Replaced MapReduce in later versions of Hadoop</p><p>To overcome some limitations of Hadoop, Spark was developed around 2012. Long story short, Spark is based on RDD (Resilient Distributed Dataset)</p><p>Resilient: Spark architecture has data lineage information to recover lost data automatically on failure. This introduces fault tolerance. Even if your system fails, your data is safe.</p><p>Distributed: You can horizontally scale your storage. Data can be logically divided into multiple logical partitions and stored on different machines. eg. You can store data for user ids 1–10000, 10001–20000, 20001–30000, and so on on different machines.</p><p>Spark performs in-memory (RAM) calculations, so it can be upto 100 times faster than Hadoop MapReduce. When you perform operations on a 100TB file with 1TB of RAM, this makes a huge difference in performance.</p><p>Spark supports various languages — Scala, Python, R, and Java. When you use Python API for using Apache Spark, you are essentially using PySpark.</p><p>So if you are a data professional who wants to use Python APIs for data manipulation operations using Spark, you need to know PySpark.</p><h4>Why do we use PySpark (over other options)?</h4><ol><li>If you compare PySpark to Hadoop, PySpark gives you upto 100x better performance. You can observe a significant difference if you are dealing with terabytes and petabytes of big data.</li><li>Spark supports various languages — Scala, Python, R, Java. It even has an SQL API. So you don’t need to learn a new language altogether to start working on it.</li><li>Spark has other layers like Spark Streaming — to handle live streaming data, Spark MLib — machine learning library, GraphX — for processing graph data. This adds to its utility.</li></ol><h4>Common Spark Operations</h4><p>Let’s learn some common PySpark data manipulation, data cleaning operations that are very used for analyzing datasets.</p><ol><li><strong>Reading data from a csv file</strong></li></ol><pre>#Reads data from my_csv_file.csv and includes header/first row<br>spark.read.csv(&quot;my_csv_file.csv&quot;, header=True)</pre><blockquote><strong><em>2. Inspecting a data frame</em></strong></blockquote><pre>#returns top 5 rows of your dataframe<br>df.head(5) <br><br>#returns the first row<br>df.first() <br><br>#returns stats for all columns in your dataframe<br>#stats like count, mean, stddev, min, max<br>df.describe().show()<br><br>#returns all column names in your dataframe<br>df.columns<br><br>#returns the total number of rowsin your dataframe<br>df.count()<br><br>#Total number of unique rows in your dataframe<br>#A quick way to see if you have duplicate rows...<br>#...is by comparing outputs of df.count() and df.distinct().count()<br>df.distinct().count()</pre><p><strong>3. Handling Null values</strong></p><pre>#Drop all rows where there is a NA or null value in any of the columns<br>df.na.drop()<br><br>#Drop rows with null values in a specific column<br>df.filter(df.column_name.isNotNull())<br><br>#Replace nulls with a value. In below example, we replaced null with &#39;Unknown&#39;<br>df.withColumn(&quot;New Column&quot;, when(df.columns_old isNull(), &#39;Unknown&#39;).otherwise(df.column_old))<br><br>#Drop duplicate rows (entire row is identical to another row in dataframe)<br>df.dropDuplicates()</pre><p><strong>4. Selecting and filtering</strong></p><pre>#Filter rows where column &#39;name&#39; has value &#39;Ajay&#39; <br>df.filter((df.name == &quot;Ajay&quot;))<br><br>#Filter rows where column &#39;name&#39; has values containing &#39;jay&#39;. eg. Ajay, Vijaya, etc. <br>df.filter((df.name.like(&quot;%jay%&quot;)))<br><br>#Filter rows where column &#39;name&#39; has values ending with &#39;jay&#39;. eg. Apeejay<br>df.filter((df.name.endswith(&quot;%jay%&quot;)))<br><br>#Filter rows where column &#39;name&#39; has values starting with &#39;jay&#39;. eg. jaywalk<br>df.filter((df.name.startswith(&quot;%jay%&quot;)))<br><br>#Filter rows where column &#39;name&#39; has values &#39;Ajay&#39; or &#39;John&#39;<br>df.filter((df.name.isin(&#39;Ajay&#39;, &#39;John&#39;)))<br><br>#Filter rows where (column &#39;name&#39; has values &#39;Ajay&#39; or &#39;John&#39;) and (column &#39;city&#39; has value &#39;London&#39;)<br>df.filter((df.name.isin(&#39;Ajay&#39;,&#39;John&#39;) &amp; (df.city == &quot;London&quot;)))<br><br>#Filter rows where column &#39;id&#39; has a value greater than 10 but less than 100<br>df.filter((df.id &gt; 10) &amp; (df.id&lt;100))</pre><p><strong>5. Running SQL on data frames</strong></p><pre>#Writing an SQL query in PySpark<br>from pyspark.sql.types.import *<br>query1 = spark.sql(&#39;select * from original&#39;)<br>query1.show()</pre><p><strong>6. Calculated columns</strong></p><pre>#Add a new column &#39;is penguin&#39;. If value in column bird_name is Penguin, populate &#39;is penguin&#39; with &#39;Yes&#39;, else &#39;No&#39; otherwise.<br>df.withColumn(&#39;is penguin&#39;, when(df.bird_name == &#39;Penguin&#39;, &#39;Yes&#39;). otherwise(&#39;No&#39;))<br><br>#Group data by values in &#39;Gender&#39; column. Add a calculated column - sum of salary. Give this column an alias &#39;Total Salary&#39;<br>df1 = df.groupBy(&#39;gender&#39;).agg(sqlfunc.sum(&#39;salary&#39;).alias(&#39;Total Salary&#39;))</pre><p><strong>7. Writing dataframes into files</strong></p><pre>#Write dataframe df to a csv file named &#39;df1.csv&#39;<br>df.write.csv(&#39;df1.csv&#39;)<br><br>#Write dataframe df to a json file named &#39;df2.json&#39;<br>df.write.json(&#39;df2.json&#39;)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77fe1f113adf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>