<?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 Mert Tunç on Medium]]></title>
        <description><![CDATA[Stories by Mert Tunç on Medium]]></description>
        <link>https://medium.com/@merttunc96?source=rss-d36546e05204------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3I-dVXDo32bqhB7CSyIX_A.png</url>
            <title>Stories by Mert Tunç on Medium</title>
            <link>https://medium.com/@merttunc96?source=rss-d36546e05204------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 11:27:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@merttunc96/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[Quantum String Matching, A tutorial]]></title>
            <link>https://medium.com/@merttunc96/quantum-string-matching-a-tutorial-70dc822334ae?source=rss-d36546e05204------2</link>
            <guid isPermaLink="false">https://medium.com/p/70dc822334ae</guid>
            <category><![CDATA[quantum-computing-tutor]]></category>
            <category><![CDATA[string-search]]></category>
            <category><![CDATA[quantum-computing]]></category>
            <category><![CDATA[grover]]></category>
            <category><![CDATA[string-matching]]></category>
            <dc:creator><![CDATA[Mert Tunç]]></dc:creator>
            <pubDate>Sat, 10 Jun 2023 18:36:12 GMT</pubDate>
            <atom:updated>2023-06-10T19:17:14.816Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<h3>String Matching on Quantum Computer, A tutorial</h3><h4>Using Grover’s Algorithm to solve the string search problem</h4><p>In this blog post, we will implement <a href="https://learn.qiskit.org/course/ch-algorithms/grovers-algorithm">Grover’s algorithm</a> for solving <a href="https://en.wikipedia.org/wiki/String-searching_algorithm">string matching problem</a> (also called string searching) in a quantum computer using Python and <a href="https://qiskit.org/">Qiskit</a>.</p><p>The string matching problem is defined as follows:</p><blockquote>Given a string w, and a pattern p, find all starting positions of p in w.</blockquote><h4>A high-level look at Grover’s Algorithm</h4><p>Grover’s search algorithm shares a framework with us on how to implement unstructured search with a time complexity of O(√N). We will utilize Grover’s Algorithm to solve our problem.</p><p>The framework is as follows:</p><ol><li>Initialize the state |s› to a uniform superposition of all possible states</li><li>Repeat the 3rd and the 4th steps O(√N) times</li><li>Apply Grover’s oracle U_f to the state |s›</li><li>Apply Grover’s diffusion operator U_sto the state |s›</li><li>Measure the state |s› to gather your solution(s).</li></ol><p>The following image is an illustration of the steps of Grover’s Algorithm</p><figure><img alt="Grovers Illustration" src="https://cdn-images-1.medium.com/max/1024/0*tG9qMAJJ82KusDy1.png" /><figcaption>The illustration is taken from <a href="https://learn.qiskit.org/course/ch-algorithms/grovers-algorithm">https://learn.qiskit.org/course/ch-algorithms/grovers-algorithm</a></figcaption></figure><p>What I understand is, defining the oracle is the hard part when you want to implement Grover’s Algorithm to your problem since it is very problem specific. When you have an oracle that negates the amplitude of the states you are searching for, you are pretty much done with thinking 😄</p><blockquote>If you would like to learn more and see some additional tutorials on applications of Grover’s Algorithm, I would recommend you to take a look at <a href="https://learn.qiskit.org/course/ch-algorithms/grovers-algorithm">Qiskit’s Grover’s Algorithm page</a>.</blockquote><h4>Defining the circuit and setting qubits for the given input</h4><p>Let’s start by importing the required libraries.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07d339f3204023a83c1d84332c30efc4/href">https://medium.com/media/07d339f3204023a83c1d84332c30efc4/href</a></iframe><p>As in the problem statement, we have w and p as the string and the pattern respectively. For our application, we’ll use <em>w</em> and <em>p</em> as binary strings.<br>In the implementation, it is assumed that the <em>w</em> and <em>p</em> have a length of power 2 for ease of implementation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/750cc7e05de26f314b425c23e19229fb/href">https://medium.com/media/750cc7e05de26f314b425c23e19229fb/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aad750262b0c58c6c66050982343815f/href">https://medium.com/media/aad750262b0c58c6c66050982343815f/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9dab2b84aae9fe3e7d5815be66672b4b/href">https://medium.com/media/9dab2b84aae9fe3e7d5815be66672b4b/href</a></iframe><p>Now, we define the circuit and initialize the <em>s</em> with Hadamard gates.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a104e99fc61158db043b667181601962/href">https://medium.com/media/a104e99fc61158db043b667181601962/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d09afdc1b76ae36d9aaf4430ffd9b7f6/href">https://medium.com/media/d09afdc1b76ae36d9aaf4430ffd9b7f6/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c55add040791ddbd27ced82ec608f41d/href">https://medium.com/media/c55add040791ddbd27ced82ec608f41d/href</a></iframe><h4>Defining the Grover’s Oracle for String Matching Problem</h4><p>Let’s have a broad look and try to understand the search here and we’ll build an oracle using the conditions we deduce.</p><p>In our application, the states that we want to search consist of the starting index of the pattern in the string. The challenge in the string search problem is that each state brings more than one constraint.</p><p>Considering the values we have, <em>w</em> = 1101 and <em>p</em> = 01, the states we will be searching are “00”, “01”, “10”. These binary strings represent the possible starting position of <em>p</em> inside <em>w</em>.</p><p>For example, state “01”(decimal 1, as the start index of <em>p</em> in <em>w</em>) asserts the following equivalencies to be a starting point of a match:</p><ul><li><em>w</em>[1] = <em>p</em>[0]</li><li><em>w</em>[2] = <em>p</em>[1]</li></ul><p>Observing that the starting position acts as an offset to the indexes we built on <em>w</em>, we can try to generalize the constraints we generate for any <em>w</em> and <em>p</em> as follows:</p><p>Given:</p><ul><li>A state s in binary form representing the start position of the match</li><li>A <em>p</em> of length <em>k</em></li></ul><p>Constraints to check if the state s is a match:</p><ul><li><em>w</em>[s+0]= <em>p</em>[0]</li><li><em>w</em>[s+1]= <em>p</em>[1]</li><li>…</li><li><em>w</em>[s+k-1]= <em>p</em>[k-1]</li></ul><p>Grover’s Oracle is the part where we check and flip the “result” qubit if the state is the one satisfying the search conditions.</p><p>Let’s try to implement what we observed above:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6adf8adeb5f179cb4db0880663379bc1/href">https://medium.com/media/6adf8adeb5f179cb4db0880663379bc1/href</a></iframe><p>Following our observations, we use<em> multi controlled and gates</em> to check if the added offset of given <em>s</em> to <em>w</em> causes us to end up with corresponding characters of <em>p</em> and <em>w</em> becoming equal. If that equalities hold for all characters for <em>p</em>, we then negate a qubit named match and will build a diffuser using that qubit.</p><p>During the implementation of our oracle, we also had to do some additional tweaks:</p><ul><li>Checking if a bit in <em>w </em>and <em>p</em> is equal requires these bits to be flipped to 1 before the operation and after the operation if these bits are 0(Since we’ll use <em>multi-input and gates</em>, <a href="https://qiskit.org/documentation/stubs/qiskit.circuit.QuantumCircuit.mcx.html">mcx</a>).</li><li>Similarly, we’ll need to flip the bits of <em>s</em> if the bits are 0.</li><li>For each constraint, we’ll store the value of the equivalence(e.g <em>w</em>[s+1] = <em>p</em>[1]) in an intermediate qubit, then use a <em>multi-controlled and gate</em> to <em>and</em> all of them to a single qubit. We’ll call these intermediate qubits bit_matches, having a total length of <em>len(p)</em>, and the final qubit as match.</li></ul><h4>Defining the Grover’s Diffusion Operator for String Matching Problem</h4><p>Now, the hard part is done and we can move to the implementation of our second building block, the diffusion operator. <br>The diffusion operator is defined as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee708ee90f5e2e00a7bb4508c34805cd/href">https://medium.com/media/ee708ee90f5e2e00a7bb4508c34805cd/href</a></iframe><p>We are almost done. We need to apply these oracle and diffusion operators O(√N) times, where N is 2 to the power of length(s).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a269d3681b68faaccebf978e9d68dc41/href">https://medium.com/media/a269d3681b68faaccebf978e9d68dc41/href</a></iframe><p>To measure what we got on s as the output, we define a measurement and append that to the circuit.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/375bae894cfe11f1b18755532f430748/href">https://medium.com/media/375bae894cfe11f1b18755532f430748/href</a></iframe><p>Then, run the circuit on a simulator and plot the results.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d153fb2c97b4e27118a6ab06e3b70651/href">https://medium.com/media/d153fb2c97b4e27118a6ab06e3b70651/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76b12ae3b7132c870369f8337872327e/href">https://medium.com/media/76b12ae3b7132c870369f8337872327e/href</a></iframe><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*HDKnv-5zJw9mzGrL2ou9yg.png" /><figcaption>Histogram of the observed states from the register “<em>s”</em></figcaption></figure><p>In the above histogram, we can see that on 100 shots on the simulator, we got only the “10” match, which is 2 in decimal notation. (Qiskit uses little-endian notation, so we read the value “01” as “10”, and convert it to decimal notation). <br>Our <em>w</em> was “1101” and <em>p</em> was “01”, and we got the correct result from our circuit. There is indeed a match for <em>p</em> starting from the index 2 in <em>w</em>(Using 0-based indexing).</p><p>Now, let’s see the limits of the implementation. We’ll try to search for a pattern of length 2 in a string of length 8. We’ll also try the code with more than one occurrence of <em>p</em> inside <em>w</em>.</p><p>Let’s re-define <em>w</em> and <em>p</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2774a52da6d1c7b3f741daa1244b4008/href">https://medium.com/media/2774a52da6d1c7b3f741daa1244b4008/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95c8d0720d0afe28f486c96c77fe986a/href">https://medium.com/media/95c8d0720d0afe28f486c96c77fe986a/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d27c6cf0ba704996ce7d4aaef4285b4e/href">https://medium.com/media/d27c6cf0ba704996ce7d4aaef4285b4e/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5550ba12a9daede1d4e2170bde9b37ad/href">https://medium.com/media/5550ba12a9daede1d4e2170bde9b37ad/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f6c5d8042677be1e71022c86c962b62/href">https://medium.com/media/0f6c5d8042677be1e71022c86c962b62/href</a></iframe><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*8r-_H2pU1pLUG-r71GYK0w.png" /><figcaption>Histogram of the observed states from the register “s”</figcaption></figure><p>It is clearly visible that the states “0001”(1 in decimal) and “0110”(6 in decimal) are the most probable states, which are the correct answers for our input <em>w</em> = “10110001” and <em>p</em> = “01”.</p><h4>A small story behind this blog post</h4><p>This implementation started as a term project for the graduate course offered by the CEng department at Middle East Technical University, Turkey.</p><p>During my project, I realized that one of the papers I’m trying to replicate had some issues, and I tried to fix these issues. While doing so, I ended up with an easy-to-follow and well-generalized solution for the problem and decided to publish it.</p><p>The algorithm we walked through in this post is (at least relatively) a simple one and aims to be a tutorial for how we can approach string search problem using a quantum computer, utilizing Grover’s Algorithm.</p><p>If you wish to find something more performant, the following two papers seem like good sources to navigate:</p><p>[1] <a href="https://doi.org/10.1038/s41534-021-00369-3">https://doi.org/10.1038/s41534-021-00369-3</a><br>[2] <a href="https://www.sciencedirect.com/science/article/pii/S1570866703000108">https://www.sciencedirect.com/science/article/pii/S1570866703000108</a></p><p>You can also follow the latest state and reach me and the original code from <a href="https://github.com/mmmeeedddsss/ceng798">GitHub</a>.</p><p>Thank you for bearing with me until the end 🎊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70dc822334ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Supporting Multiple Time Zones on Hive with Single Data Source]]></title>
            <link>https://medium.com/udemy-engineering/supporting-multiple-time-zones-on-hive-with-single-data-source-b884cba46451?source=rss-d36546e05204------2</link>
            <guid isPermaLink="false">https://medium.com/p/b884cba46451</guid>
            <category><![CDATA[hive]]></category>
            <category><![CDATA[timezone]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[external-tables]]></category>
            <category><![CDATA[data-lake]]></category>
            <dc:creator><![CDATA[Mert Tunç]]></dc:creator>
            <pubDate>Mon, 20 Jul 2020 08:08:19 GMT</pubDate>
            <atom:updated>2021-10-05T11:15:54.084Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*9WidMUkF29tD_9atNYPNgg.png" /><figcaption>The same “present” being represented with different times using different time zones</figcaption></figure><p>At Udemy, most internal analytics dashboards rely on data residing in Pacific Time (PT) partitioned Hive tables. However, data collected from our event tracking system is partitioned based on Coordinated Universal Time (UTC). To enable efficient analysis of these datasets while avoiding both complicated joins and unnecessary data duplication, we used custom code in order to create a “view” of UTC data as PT within Hive.</p><p>In this blog post, I will be sharing our experience with supporting multiple partitions on Hive while keeping one copy of data on our data lake.</p><h3>What is the Event Tracking System?</h3><p>The Event Tracking framework at Udemy is a scalable and highly available event ingestion system for collecting user behavioral data. The overall data flow consists of three stages:</p><ol><li>Data is prepared and sent to the system via provided client libraries.</li><li>Event Tracking System consists of 4 microservices to process collected data from clients. Data transfer between those services is done through Kafka.</li><li>Data is synced to AWS S3 and Hive metadata is updated for long term storage and batch processing.</li></ol><h3>High-Level View of Data Storages of Event Tracking</h3><p>In this blog post, the focus will be on the third stage of the system.</p><p>The journey of the data on the Event Tracking System after arrival and processing consists of two main steps: syncing the Kafka with AWS S3 and registering the new data partitions to Hive external tables.</p><p>Event Tracking uses Kafka as its real-time source of truth of data. At the end of the journey on Kafka, events are copied from Kafka to AWS S3 by an open-source component named <a href="https://docs.confluent.io/current/connect/index.html">Kafka Connect</a>. We use hourly UTC partitions while storing data on S3. Hourly partitions reduce the query time by limiting the range of data with relevant partitions, thus reducing the amount of I/O. For this, both Kafka Connect is configured accordingly and Hive tables are created with four partition columns: year, month, day and hour.</p><p>When the data for a new partition appears on S3, Hive external tables require registration of these new partitions to tables metadata. For this purpose, a simple workflow querying Hive for partition registration is executed hourly. After that operation, newly arrived data can be queried from Hive.</p><h3>Problems</h3><p>For context, this is how Event Tracking System handles time information:</p><ul><li>All timestamp fields are stored as <a href="https://en.wikipedia.org/wiki/Unix_time">UNIX timestamp</a>s. UNIX timestamp fields can be easily converted to different time zones. Note that the four partition columns (i.e., year, month, day, and hour) are stored as string fields, instead of UNIX timestamp fields since they are not actually storing timestamps but rather discretized sections of it.</li><li>Kafka Connect creates hourly S3 prefixes for the data while syncing the Kafka with data lake on S3. Kafka Connect is configured to use hourly UTC partitioning while writing data to our data lake, so the source of truth data is stored UTC partitioned. Using UTC is beneficial because it’s the industry standard and is not affected by Daylight saving time.</li></ul><h4>Hive cluster of Udemy is configured for PT timezone</h4><p>First problem arises when we use this data in a downstream system that uses a different timezone, like Udemy’s Hive cluster.</p><p>Hive shows the UNIX time fields in its local time, which is PT in our case.</p><p>Consider the following SQL:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9r8abav1cqm-PhlNzW8akg.png" /></figure><p>It returns:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XHKPE371dwpC0wkMzaoR7A.png" /></figure><p>This seems a bit weird since we query the 9th day of May, but the returned data belongs to the 8th of May. The reason for this behavior is that while the partitions are in UTC, Hive converts the UNIX timestamp data inside the time fields to its local timezone, which is PT. Note that if we replace the filtering to <em>receiveTime</em> field, the issue would be solved but the query time would be increased greatly. Issue of inconsistent times in timestamp fields and the queried partition time was asked frequently to the Event Tracking Team, confusing the stakeholders.</p><h4>Many data sets at Udemy are partitioned using PT</h4><p>This discrepancy causes Event Tracking data to be hard to join with the PT partitioned data.</p><p>Consider the following SQL to get data for <em>2020–04–09</em> in PT:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pf55eV_QvQJc3TQOWX6FtA.png" /></figure><p>We needed to manually adjust UTC partitions to match with PT.</p><p>This is far from ideal since it is both counterintuitive and cumbersome to require explicit hourly filtering when one wants to join event tracking data with other tables. Also, the above query is particularly fragile since one would need to account for Daylight Savings Time by changing the hour dynamically depending on the time of year. This kind of behavior makes it necessary to have support for PT partitioned data.</p><p>So we wanted to support PT partitioned tables as well as UTC ones to enable other teams and improve downstream code quality by eliminating the need for custom time handling on each workflow separately. Also, we wanted to keep UTC partitioned tables to be prepared for an eventual migration to UTC over the long run.</p><h3>Possible Solutions to support PT partitions</h3><p>The first and most straightforward solution is to have another <em>connector </em>definition on Kafka Connect.<em> Connector</em>s are logical entities that state the source and destination locations of data and the related configurations for syncing the data between those two data stores. One of the configurations that can be utilized is the `<a href="https://docs.confluent.io/current/connect/kafka-connect-s3/index.html#partitioning-records-into-s3-objects">timezone</a>` parameter. We can use this parameter for creating the data on AWS S3 in PT partitions. In this solution, since we sync the data twice to S3, the storage we use, and the load of Kafka Connect would be doubled.</p><p>This solution has some other issues like losing the clear <em>source of truth </em>definition since there will be two duplicates of the same data on S3 and Hive partitioned differently.</p><p>The second solution is to create a new set of external Hive tables and manually assign the Hive partitions to S3 partitions considering the time difference between PT and UTC for the time data belongs to.<em> </em>This would be handled by a custom workflow since the time difference between PT and UTC changes twice a year.</p><p>Hive allows such a query to manually state which of its partitions are mapped to which S3 folders:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-i-Z3-GwaDY1puj1" /></figure><p>We can use this ability to map S3 folders with an offset, by changing the offset twice a year. The challenging part of this solution is handling time offset changes with the UTC data.</p><p>We decided to go with the second approach because the first solution requires a high amount of data duplication.</p><h3>Implementation of the Second Solution</h3><p>We already had a workflow that works hourly and creates Hive partitions linked with S3 prefixes.</p><p>We modified this workflow to also support PT partition creation:</p><h4>For the times without timezone shifts</h4><ul><li>The Hive table timezone has become a parameter. The workflow is now given Hive’s partition timezone and acts accordingly for that timezone, supporting all possible time zones.</li><li>For partitions that do not involve PST to PDT or PDT to PST timezone shift (all partitions in a year, except for two hours); we can easily calculate the PT timezone offset and adjust the UTC S3 data with that offset to determine hive partition time.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m0zKWLULhFfiHJA7VXsWIA.png" /></figure><h4>Handling the two shifting hours every year</h4><p>PT has two time zones that alternate through the year, PST (Pacific Standard Time) to PDT (Pacific Daylight Time). We need to handle two special hours where the shift occurs: PST to PDT shift and PDT to PST shift. For that, a workflow detects if currently, the change is happening, and acts accordingly.</p><h4>PST to PDT Timezone Shift</h4><p>Handling PST to PDT is easy since the shift does not cause a collision on the mapping. You can see that the corresponding times for UTC are unique on the PST to PDT shift in the below image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jcyeDaELVJ8GGuc5PKbAsA.png" /></figure><p>What happens is that, in Hive, there will be no partition for 2 a.m., which is expected since PT timezone does not have 2 a.m. on the PST to PDT shift day. Since there is no collision on the UTC to PT mapping here, we can easily state the locations of the data to Hive for each hour in PT.</p><h4>PDT to PST Timezone Shift</h4><p>Handling PDT to PST is a bit trickier since the mapping from UTC to PT is not one-to-one during this shift. It can be seen that 1 a.m. happens twice in PT, making it necessary to register two separate external locations to Hive for 1 a.m., which Hive does not support.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KJFb9Fiel5JnFt0AZJ0oog.png" /></figure><p>Hive only supports a single external data location prefix per partition. To overcome this issue, we detect the time when PDT to PST shift is occurring, and at that hour only, we copy the data of two intersecting partitions (8 a.m. and 9 a.m. in the above image) into one folder to have a single data partition. After having a unified copy of those two hours, we register the partition to Hive pointing to the new copied content so that Hive will work on two hours of data when asked to query the time of shift.</p><p>Code for the described operation looks like the following screenshot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tecMW084OvakNgPP" /></figure><p>Note that actual implementation is a bit more complicated since we need to wait for the hour to end before creating a unified S3 folder.</p><blockquote>It is a legacy decision that the many existing datasets in Udemy are partitioned by PT timezone. This fact, as described, causes many inconsistencies mainly because of the time zone changes twice a year. The long term plan is to store and serve all data using UTC partitions which will be an ultimate solution for the described problems and many others.</blockquote><h3>Result</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1liqxIfUL8EPi-mt" /><figcaption>A diagram for the overall journey of data</figcaption></figure><p>This algorithm helped us to prevent duplication of data on storage level and to avoid the increased computational resources that Kafka to S3 sync would have needed in the data duplication scenario. We have been able to successfully support PT partitions without changing UTC partitioning of the source data. In this way, Event Tracking data will be ready for the company-wide migration to UTC partitioning, which is the ultimate solution to related problems.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b884cba46451" width="1" height="1" alt=""><hr><p><a href="https://medium.com/udemy-engineering/supporting-multiple-time-zones-on-hive-with-single-data-source-b884cba46451">Supporting Multiple Time Zones on Hive with Single Data Source</a> was originally published in <a href="https://medium.com/udemy-engineering">Udemy Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>