<?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 Vangalapudi Dhanya on Medium]]></title>
        <description><![CDATA[Stories by Vangalapudi Dhanya on Medium]]></description>
        <link>https://medium.com/@vangalapudi.dhanya?source=rss-ff755a39db9b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cbltTWff2fKTOrAtrKbZ4Q.jpeg</url>
            <title>Stories by Vangalapudi Dhanya on Medium</title>
            <link>https://medium.com/@vangalapudi.dhanya?source=rss-ff755a39db9b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 02:55:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vangalapudi.dhanya/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[FastMig: Snowflake to BigQuery Accerlerator]]></title>
            <link>https://blog.searce.com/fastmig-snowflake-to-bigquery-accerlerator-d90981187635?source=rss-ff755a39db9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d90981187635</guid>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[bigquery]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[searce]]></category>
            <category><![CDATA[snowflake]]></category>
            <dc:creator><![CDATA[Vangalapudi Dhanya]]></dc:creator>
            <pubDate>Wed, 26 Apr 2023 08:47:58 GMT</pubDate>
            <atom:updated>2023-04-26T08:47:58.345Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>1. Overview:</strong></h3><p>Migrating data from Snowflake to BigQuery involves moving data from one cloud data warehouse platform to another. The process typically involves extracting data from Snowflake, transforming it to match the BigQuery data model, and then loading it into BigQuery.</p><p>This accelerator is designed to perform historical and incremental loads, as well as handle schema evolution, making it a powerful tool for organizations looking to migrate their data quickly and efficiently. In this blog,It will cover an overview of how the accelerator works, what features it offers, and the benefits it can provide. Let’s dive in!</p><p>The Snowflake to BQ accelerator is an automated tool for migrating historical, incremental and schema evolution of the data present in Snowflake.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hWcbgWQbUVqyojQI" /><figcaption>Fig1: Snowflake to BigQuery Migration</figcaption></figure><p><strong>2. Objectives:</strong></p><p>The Objective of Snowflake to BigQuery Accelerator is to automate the process of migrating data from source (Snowflake) to destination (BigQuery) which reduces the cost and manual effort.</p><p>This accelerator capable of handling 5 use cases:</p><ol><li>Batch load</li><li>Incremental load (CDC)</li><li>Schema Evolution (Add , Drop, Rename a Column)</li><li>Create and Drop Table</li><li>Create and Drop View</li></ol><p><strong>3. Benefits:</strong></p><p>Our accelerator provides the following benefits:</p><ul><li>High performance scalability</li><li>Reduces migration complexity</li><li>Reduction in cost</li><li>Improved performance</li><li>Reduce manual effort</li><li>Automates the schema &amp; data migration process</li></ul><p><strong>4. Technical Architecture:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*vhpVWzJnJyInbJN2tRGoMw.png" /><figcaption>Fig 2: Technical Architecture</figcaption></figure><p>This is the architecture diagram. Data gets migrated from Snowflake via the compute engine. The batch load and the incremental load migrations are performed with the help of the cloud storage bucket. The Schema Evolution will take place directly through the compute engine VM.</p><p><strong>4.1 Features :</strong></p><ul><li>Currently working for all three cases,</li></ul><p>i.e Historical, incremental load and schema evolution.</p><ul><li>Able to perform all queries in BQ which is executed in Snowflake</li><li>An Automation script is created which handles creation of source data and the entire migration process.</li><li>A choice is given to the user to choose the type of migration.</li></ul><ol><li>type = Historical &amp;&amp; drop_existing_tables = no</li><li>type = Historical &amp;&amp; drop_existing_tables = yes</li><li>type = Incremental</li></ol><p><strong>5. Prerequisites:</strong></p><ul><li>Snowflake Account with running warehouse</li><li>GCP account with editor/owner access to BigQuery, GCS</li><li>Google Cloud Storage bucket</li><li>BigQuery dataset and table</li><li>Virtual Machine with RHEL 8 OS Boot Disk setup</li><li>Any Python IDE like PyCharm or Visual Studio installed on the local system</li></ul><p><strong>6. Historical Load Migration</strong></p><p>On running the Historical Data Load code on VM, the following happens</p><ol><li>Creating integration between Snowflake and Cloud Storage.</li><li>Given the required permissions for the service account created by Snowflake to access Bigquery and Cloud Storage.</li><li>Copying the data from Snowflake to GCS using Snowflake’s “COPY INTO &lt;location&gt;” command.</li><li>We can copy the data in any file format. (Here parquet file format is used). This will unload the data to GCS.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/0*rqtO_NyFE47Ne5W0" /><figcaption>Fig 3: Tables in GCS Bucket</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/0*ZB-Xv7fecNUScTfl" /><figcaption>Fig 4: Data Stored in Parquet Format</figcaption></figure><p>5. Once we get all the data in GCS, connect to Bigquery, create a dataset, and load all the data to BigQuery.</p><p>6. Create the metadata table in BigQuery for storing the maximum Timestamp for all the tables, which can be used for Incremental Load.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/0*3t5pL46hIfom9g4L" /><figcaption>Fig 5: Table schema in BigQuery</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/0*_oeOX3LBjFxG9Q2p" /><figcaption>Fig 6: preview of the data in BigQuery</figcaption></figure><p><strong>7. Performing Schema Evolution :</strong></p><ol><li>First the code will check for schema evolution. Once all the changes are synced, then it will load the new incremental rows.</li><li>The Metadata table in Bigquery also stores the maximum LAST ALTERED value for all the tables.</li></ol><pre>select max(LAST_ALTERED) from &lt;db-name&gt;.INFORMATION_SCHEMA.TABLES where table_schema = &lt;schema-name&gt;</pre><p>3. Using that maxvalue, fetch the queries executed after that maxvalue from Snowflake Query History.</p><pre>select query_text from table(information_schema.query_history(RESULT_LIMIT =&gt;<br>10000)) where SCHEMA_NAME = &lt;schema-name&gt; and query_type like any (&#39;ALTER%%&#39;,&#39;UPDATE%%&#39;,&#39;DELETE%%&#39;,&#39;DROP%%&#39;,&#39;CREATE%%&#39;) and end_time &gt; &#39;&lt;maxvalue&gt;&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/0*w1QI_itDoHJWf6Ru" /><figcaption>Fig 7: Metadata Table in BigQuery</figcaption></figure><p><strong>a. Update Statement</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*yyCs7yoEye85mfM7" /><figcaption>Fig 8: Before Update Query</figcaption></figure><pre>UPDATE PUBLIC.SHIPPING set SHIP_MODE=&#39;REGULAR AIR&#39; WHERE SHIP_ID=&#39;SHP_1602&#39;;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*VaMY-TCymP4SPkvV" /><figcaption>Fig 9: After Update Query</figcaption></figure><p><strong>b. Alter Statement</strong></p><pre>ALTER TABLE PUBLIC.SHIPPING RENAME COLUMN ORDER_ID TO ORD_ID;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yVGX1P3jY_AFts3j9mp0xQ.png" /><figcaption>Fig 10: Alter Query</figcaption></figure><p><strong>c. Delete Statement</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*vE_UWiMiN9OnKPLE" /><figcaption>Fig 11: Before Delete Statement</figcaption></figure><pre>DELETE FROM PUBLIC.PRODUCTS where PROD_ID = &#39;Prod_23&#39;;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*bBGfJwVdrjTaax_S" /><figcaption>Fig 12 : After Delete Statement</figcaption></figure><p><strong>d. Create View</strong></p><pre>CREATE VIEW PUBLIC.MARKET_VIEW AS SELECT * FROM PUBLIC.MARKETS LIMIT 15;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*7C4W1gqPfWiAjdcoWGIIpg.png" /><figcaption>Fig 13: Create View</figcaption></figure><p><strong>8. For Incremental Load:</strong></p><ol><li>Get the auditing column and maximum value of that column for each table from the BigQuery metadata table.</li><li>Fetch the records inserted after that maximum value from Snowflake and store it in GCS under the &lt;current-date&gt;folder.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/0*iQ6pgu6ynbBHIhOG" /><figcaption>Fig 14: Storing the new records</figcaption></figure><p>3. Then load the data to corresponding tables in Bigquery.</p><p>4. Update the metadata table with the latest maximum value for each table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*Kfrtkj5hV0_Cdf-V" /><figcaption>Fig 15: Latest Timestamp</figcaption></figure><p><strong>9. Steps to Run the Program with Bash Script:</strong></p><ol><li>In the config file, change the Snowflake and GCP credentials.</li><li>Run the shell script using source start.sh .</li><li>It will ask you for some options. Enter the number according to your choice, the code itself will handle everything.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*jzRpYNYwgE4oXuOQYYYlSw.png" /><figcaption>Fig 16: Type of Migration</figcaption></figure><p><strong>10.Benchmarks</strong></p><p>So we had tested our accelerator with about fourteen tables — eight of the tables are in the range of 20–50 GB size, and the other six tables about 300–500 GB. And this total amount of data, it is taking only 17 mins and 30 seconds to execute.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*P1L_L9Ch3EuOKtDB" /><figcaption>Fig 17: Benchmarking</figcaption></figure><p><strong>11. Why Our Accelerator is Best:</strong></p><p><strong>a. Customizable:</strong> our code is customizable and can be tailored to meet the specific needs of the organization, which is not possible with many off-the-shelf migration tools.</p><p><strong>b. Schema Management: </strong>Our Accelerator takes away the tedious task of schema management &amp; automatically detects the schema of incoming data and maps it to the destination schema.</p><p><strong>c. Automated:</strong> We had an automation script which automates the whole migration process reducing the manual effort and errors associated with manual migration.It also reduces the overall time required for migration.This means that the migration process will be completed more quickly, reducing the downtime for the organization</p><p><strong>12. Conclusion</strong></p><p>Using our accelerator,Migration from Snowflake to BigQuery is made easy.It is capable of historical load migration,Incremental migration(CDC) and Schema Evolution. The Multithreading concept is implemented, so it makes it very fast in the migration process. All the processes are automated from end-to-end, as we have seen now. The views are also getting handled successfully. Also there is a backup metadata table also of each of the tables that are getting created. So they are stored in the GCS bucket side, in case there is any loss of data.</p><p><strong>Contributors :</strong></p><ol><li>Pradnya Koli</li><li>Vangalapudi Dhanya</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d90981187635" width="1" height="1" alt=""><hr><p><a href="https://blog.searce.com/fastmig-snowflake-to-bigquery-accerlerator-d90981187635">FastMig: Snowflake to BigQuery Accerlerator</a> was originally published in <a href="https://blog.searce.com/">Searce</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Schema Evolution From Primary Postgres Instance to the Logical Replica of the Postgres Instance.]]></title>
            <link>https://blog.searce.com/schema-evolution-from-primary-postgres-instance-to-the-logical-replica-of-the-postgres-instance-253319d3b3d0?source=rss-ff755a39db9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/253319d3b3d0</guid>
            <category><![CDATA[cloud-sql]]></category>
            <category><![CDATA[schema-evolution]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[cloud-functions]]></category>
            <dc:creator><![CDATA[Vangalapudi Dhanya]]></dc:creator>
            <pubDate>Mon, 30 Jan 2023 05:20:42 GMT</pubDate>
            <atom:updated>2023-02-02T06:33:28.183Z</atom:updated>
            <content:encoded><![CDATA[<p>Schema evolution, or the process of making changes to the schema of a database, can be performed on a primary instance and then replicated to a logical replica using logical replication. A logical replica of a database instance is a copy of the instance that contains the same data and schema as the original instance. Logical replication can be used for a variety of purposes, such as creating backups, replicating data to other locations, or creating read-only copies of the data for reporting or analysis.</p><p>On the GCP VMs, one of our customers has their PostgreSQL database hosted. The three (3) instances they have are the Primary, Read Replica, and Logical Replica. The database migration from PostgreSQL VM to Cloud SQL has already been attempted, however it was unable to reproduce the evolution of the schema from the source to the destination during migration. In order to replicate the Schema changes from Primary to Logical database instances during and after the migration, they asked us to create an automated solution.And also they wanted zero downtime for the schema evolution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*NRqKjMvHgvVl8dP_.jpeg" /><figcaption>Fig1 : Migration from compute engine postgreSQL to Cloud SQL</figcaption></figure><p>There are several ways to perform schema evolution between two instances in Google Cloud Platform (GCP), some of them are:</p><ol><li><strong>Using Cloud SQL Replication</strong>: This method involves configuring logical replication between the primary instance and the logical replica using the Cloud SQL service. Changes made to the schema of the primary instance will be replicated to the logical replica.</li><li><strong>Using Cloud Functions</strong>: This method involves writing a Cloud Function using a programming language such as Node.js, Python or Go that will handle the schema evolution process. The function can use the Cloud SQL API to connect to both instances and make the necessary schema changes.</li><li><strong>Using Cloud Dataflow: </strong>This method involves creating a pipeline using Cloud Dataflow that reads data from the primary instance and writes it to the logical replica. Schema changes can be made to the primary instance and then propagated to the replica by updating the pipeline.</li><li><strong>Using Cloud Composer:</strong> This method involves creating a workflow using Cloud Composer that automates the schema evolution process. This can include using Airflow to create a DAG that exports data from the primary instance, modifies the schema and imports it to the replica instance.</li><li><strong>Using Cloud Dataproc:</strong> This method involves creating a cluster of virtual machines using Cloud Dataproc and then running Apache Hive or Apache Pig jobs to perform the schema evolution.</li></ol><p>Note: The best method to use will depend on the specific requirements of the schema evolution and the specific use case, i.e. the complexity of the schema changes, the amount of data to be replicated, the desired replication frequency, and the cost and performance trade-offs.</p><p>In detail,we will discuss the schema evolution using cloud functions.</p><p><strong>Using Cloud Functions:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*5fiBzOmuqeZUjKyZ" /><figcaption>Fig 2:Architecture</figcaption></figure><p>Create two cloud sql for postgres instance i.e.,one for primary instance and another for logical replica.Create a database in both the instances.</p><pre>gcloud sql databases create details;</pre><p>Create the table in both the instances</p><pre>CREATE TABLE customerv2 ( customerID varchar (255),<br>customerName varchar (255),<br>customerEmail varchar(255),<br>address varchar(255),<br>country varchar(255), <br>orderCount int,<br>updateTS TIMESTAMP default CURRENT_TIMESTAMP,<br>PRIMARY KEY (customerID)<br>);</pre><p>Created a database and table in one Cloud SQL for Postgres instance.Treating this instance as a primary database instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*XV3fb0-udaawU766.jpeg" /><figcaption>Fig 3: Primary database table</figcaption></figure><p>Created a another Cloud SQL for postgres instance and created the same table as primary database table.I will be treating this as a Logical replica database schema.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*3Eikd9QU_T1zhdJ5.jpeg" /><figcaption>Fig 4:Logical replica of a database</figcaption></figure><p>Cloud functions can be used to execute a Python program by uploading the code to a Google Cloud Functions, and configuring the function to run the code when triggered by an event or an HTTP request. The Google Cloud will handle the underlying infrastructure and scaling, allowing the Python code to be run without the need for provisioning or managing servers.Code in cloud functions to perform operations and mention requirements in requirements.txt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*R9_NzZq4CRPoMkXq.jpeg" /><figcaption>Fig 5: Schema Evolution Code</figcaption></figure><p>A python program is written to do the following schema changes in the logical database.Using cloud scheduler,Cloud function is scheduled for every hour.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/0*THCXeB0iBshJfiPB.png" /><figcaption>Fig 6: Scheduling using cloud scheduler</figcaption></figure><p><strong>Scenario 1: Append a Column</strong></p><p>In this Scenario, anytime a new column is added to a table in a primary database, it will also be reflected in the database’s logical replica.<br>In this case, the pincode1 column was added to the table in the primary database.Then, we used cloud scheduler to schedule a cloud function with a 5-minute interval.The cloud function will run every five minutes and make the appropriate adjustments to the logical replica of database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*Lzq-5qaDRlibOMtY.jpeg" /><figcaption>Fig 7:Append a column in table</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*JgK5F_2kfgzAYttk.jpeg" /><figcaption>Fig 8:Column appended in the logical replica</figcaption></figure><p><strong>Scenario 2: Rename a Column</strong></p><p>In this scenario,we will rename the column in primary database table and it will reflect in the logical replica.Here column emailid is renamed to customeremailid. After the cloud function runs,this change will reflect in the logical replica.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*egEGWPI6eWt_egN_.jpeg" /><figcaption>Fig 9:Rename a column</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*lXFZR4Ftsh5bpath.jpeg" /><figcaption>Fig 10:Logical replica table after renaming</figcaption></figure><p><strong>Scenario 3: Drop a Column</strong></p><p>In this scenario,we will drop a column from a primary database table.Here,we are dropping the column country.After the cloud function runs,the column country should be dropped will be dropped from the logical replica</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*oFvOeaV3CYcdb71I.jpeg" /><figcaption>Fig 11:Dropping a column</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*HtO15pifIGTj0cYb.jpeg" /><figcaption>Fig 12:Country column dropped from the table</figcaption></figure><p><strong>Conclusion:</strong></p><p>Schema evolution is important because it allows a database or other system to adapt to changing needs and requirements without losing data or requiring a complete overhaul.When making changes to a primary database, <strong>such as appending, renaming, or dropping a column.</strong>It is important to ensure that these changes are also reflected in any logical replicas of the database. By carefully managing schema evolution, it is possible to maintain <strong>data integrity</strong>, while also allowing the system to evolve and adapt over time. This can help to <strong>improve the overall performance and scalability</strong> of the system, while also reducing the risk of data loss.</p><p>Here are the general steps to perform schema evolution on a primary instance and replicate the changes to a logical replica:</p><ol><li>Make the desired changes to the schema of the primary instance, such as adding or modifying tables, columns, or indexes.</li><li>Verify that the changes have been made correctly and that the primary instance is still functioning as expected.</li><li>Configure logical replication between the primary instance and the logical replica. This can typically be done using a replication tool or feature provided by the database management system.</li><li>Verify that the logical replica is receiving the changes made to the primary instances schema.</li></ol><p>Note: The exact steps for performing schema evolution and configuring logical replication will depend on the specific database management system you are using.</p><p><strong>Future scope:</strong></p><p>We scheduled a cloud function for every hour using cloud scheduler.But this can be done by implementing a event trigger(i.e., whenever a schema changes happens in primary,then based on the schema changes will happen in logical replica instantly) for better performance.</p><p><strong>Schema Evolution Code :</strong></p><p><a href="https://github.com/dhanya777/schema-evolution/blob/main/schemaevolution-postgres-to-postgres.py">schema-evolution/schemaevolution-postgres-to-postgres.py at main · dhanya777/schema-evolution</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=253319d3b3d0" width="1" height="1" alt=""><hr><p><a href="https://blog.searce.com/schema-evolution-from-primary-postgres-instance-to-the-logical-replica-of-the-postgres-instance-253319d3b3d0">Schema Evolution From Primary Postgres Instance to the Logical Replica of the Postgres Instance.</a> was originally published in <a href="https://blog.searce.com/">Searce</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>