<?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 Dinushi Ariyasena on Medium]]></title>
        <description><![CDATA[Stories by Dinushi Ariyasena on Medium]]></description>
        <link>https://medium.com/@dinunirmani9d?source=rss-18ac3d0fd723------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bCrpPh9c52NOTnhfwtdIpA.jpeg</url>
            <title>Stories by Dinushi Ariyasena on Medium</title>
            <link>https://medium.com/@dinunirmani9d?source=rss-18ac3d0fd723------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 23:18:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dinunirmani9d/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[Automating File Transfers from EC2 to S3: A Step-by-Step Guide Using Shell Script and Cron Jobs]]></title>
            <link>https://medium.com/@dinunirmani9d/automating-file-transfers-from-ec2-to-s3-a-step-by-step-guide-using-shell-script-and-cron-jobs-d6f136a06709?source=rss-18ac3d0fd723------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6f136a06709</guid>
            <dc:creator><![CDATA[Dinushi Ariyasena]]></dc:creator>
            <pubDate>Sun, 30 Mar 2025 17:30:28 GMT</pubDate>
            <atom:updated>2025-03-30T17:34:39.324Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will provide a step-by-step guide on how to automate file transfers from a Linux EC2 instance to an AWS S3 bucket using a Shell Script and a Cron Job. This automation ensures that files are regularly and efficiently transferred without manual intervention.</p><p><strong>Table of Content</strong></p><p><strong>· </strong><a href="#64ac"><strong>Prerequisite</strong></a><strong><br> ∘ </strong><a href="#6a56"><strong>1. Create a Linux EC2 machine.</strong></a><strong><br> ∘ </strong><a href="#a883"><strong>2. Create new S3 bucket</strong></a><strong><br> ∘ </strong><a href="#1e61"><strong>3. Create EC2 IAM Role</strong></a><strong><br>· </strong><a href="#1f2e"><strong>Create Folders</strong></a><strong><br>· </strong><a href="#6846"><strong>Write Shell Script to Transfer Files to S3</strong></a><strong><br> ∘ </strong><a href="#0289"><strong>Develop Shell Script</strong></a><strong><br> ∘ </strong><a href="#4f2c"><strong>Hosting shell script in ec2 shellScriptLoc folder</strong></a><strong><br>· </strong><a href="#816e"><strong>Run the Shell Script</strong></a><strong><br>· </strong><a href="#278e"><strong>Scheduling Cron Job</strong></a><strong><br> ∘ </strong><a href="#797d"><strong>First install cron in EC2:</strong></a><strong><br> ∘ </strong><a href="#04f9"><strong>Schedule a new cron job:</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SJUdUssiJcr9M1IBl_e67w.png" /></figure><h3>Prerequisite</h3><h4>1. Create a Linux EC2 machine.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s_-qqq_djVeJvubg0eATYw.png" /><figcaption>EC2 Creation</figcaption></figure><h4>2. Create new S3 bucket</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*snFtEu8QwyG_SPXqgwT1Zg.png" /><figcaption>S3 Bucket</figcaption></figure><h4>3. Create EC2 <strong>IAM Role</strong> with S3 Full Access — &gt; Attach IAM Role to EC2</h4><ul><li>Go to the <strong>AWS IAM Console</strong> → <strong>Roles</strong> → <strong>Create Role</strong>.</li><li>Select <strong>AWS Service</strong> → <strong>EC2</strong> → <strong>Next</strong>.</li><li>Attach the <strong>AmazonS3FullAccess</strong> policy (or create a custom policy with limited permissions).</li><li>Give it a name.</li><li>Create the role.</li><li>Go to <strong>EC2 Console</strong> → Select your EC2 instance.</li><li>Click <strong>Actions</strong> → <strong>Security</strong> → <strong>Modify IAM Role</strong>.</li><li>Attach the newly created role.</li><li>Save changes.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6w8byAUMYobqQDo9EkHlmQ.png" /><figcaption>IAM Role Creation</figcaption></figure><p><strong>You can check the connectivity between your EC2 instance and S3 using the following command:</strong></p><p>Log into the EC2 using this command.</p><pre>ssh -i shell-s3.pem ec2-user054.158.47.222</pre><p>List S3 buckets using this command.</p><pre>aws s3 ls</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y00OavaEGrhzZJRdfWp_AQ.png" /><figcaption>Listing S3 Buckets</figcaption></figure><p>If the S3 buckets are successfully listed, it means the connectivity is established.</p><h3>Create Folders</h3><p>Log in to the EC2 machine and create three folders:</p><ul><li><strong>fileLandingLoc</strong> — To store new data files</li><li><strong>shellScriptLoc</strong> — To store the shell script</li><li><strong>processedFolder</strong> — To store compressed files</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m46jVn98heqBH6U5P73EXA.png" /><figcaption>Folder Creation</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gL_y2gdE3mDRXaJ56_ZUSg.png" /><figcaption>Processed Foler Creation</figcaption></figure><h3>Write Shell Script to Transfer Files to S3</h3><h4>Develop Shell Script</h4><p>The following is the shell script you can use:</p><pre>LOG_DATE=$(date)<br>echo &quot;________________________________________________&quot;<br>echo &quot;Start Time: $LOG_DATE                           &quot;<br>echo &quot;________________________________________________&quot;<br><br>cd ../fileLandingLoc<br>cp * ../processedFolder<br>pigz -1 ../processedFolder/*<br><br>echo &quot;Transfer files to s3&quot;<br>         <br>now=$(date --date &quot;now -0 days&quot; +&quot;%Y%m%d&quot;)<br>aws s3 mv ../processedFolder s3://landing-s3-dinushi/$now/ --recursive --exclude &quot;*&quot; --include &quot;*.gz&quot;</pre><p>Here’s what the shell script does:</p><ul><li><strong>Sets the current date</strong> as LOG_DATE:</li></ul><pre>LOG_DATE=$(date)</pre><ul><li><strong>Navigates to the file location</strong>:</li></ul><pre>cd ../fileLandingLoc</pre><ul><li><strong>Copies all files</strong> from fileLandingLoc to processedFolder:</li></ul><pre>cp * ../processedFolder</pre><ul><li><strong>Compresses all files</strong> in the processedFolder using pigz, which improves transfer efficiency:</li></ul><pre>pigz -1 ../processedFolder/*</pre><ul><li><strong>Moves the compressed files</strong> to the S3 bucket:</li></ul><pre>aws s3 mv ../processedFolder s3://landing-s3-dinushi/$LOG_DATE/ --recursive --exclude &quot;*&quot; --include &quot;*.gz&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*332EV6PVEyVPvUSWyOyeWA.png" /><figcaption>Shell Script</figcaption></figure><h4>Hosting shell script in ec2 shellScriptLoc folder</h4><p>Use the following command to transfer the shell script from your local computer(MacOS) to the EC2 instance:</p><pre>scp -i shell-s3.pem file-transfer.sh ec2-user@54.158.47.222:shellScriptLoc</pre><p>Then, make the script executable by running the following command:</p><pre>chmod +x file-transfer.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*1-l3fxlgr72G7SjZY4sTsQ.png" /><figcaption>Make file executable</figcaption></figure><h3>Run the Shell Script</h3><p>Now it’s time to run the shell script manually and test it.</p><p>Before running the shell script, move the new .csv files from your local computer to the EC2 landing location (fileLandingLoc).</p><pre>scp -i shell-s3.pem file1.csv ec2-user@54.158.47.222:fileLandingLoc</pre><pre>scp -i shell-s3.pem file2.csv ec2-user@54.158.47.222:fileLandingLoc</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8SFD4wulIlXup_spqE9yHg.png" /></figure><p>Then, install pigz on the Linux EC2 instance using the following command:</p><pre>sudo yum install pigz -y</pre><p>Then, navigate to the folder where the script is hosted.</p><pre>cd shellScriptLoc</pre><p>Then, run the shell script manually using the following command:</p><pre>sh file-transfer.sh</pre><p>Once the script has run successfully, the files will be moved to the S3 bucket. You can verify this by using the following command:</p><pre>aws s3 ls s3://&lt;s3-bucket-name&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XvgfygqBAmSleWigEfYcZg.png" /><figcaption>s3 files listing</figcaption></figure><h3>Scheduling Cron Job</h3><p>To run the above shell script automatically at a scheduled time, we can use a cron job.</p><h4>First install cron in EC2:</h4><pre>sudo yum install cronie -y</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cMIgLBmKsHDvuZfgr7n_NA.png" /><figcaption>cron installation</figcaption></figure><h4>To schedule a new cron job, follow these steps:</h4><ul><li>Open the cron table for editing by running:</li></ul><pre>crontab -e</pre><ul><li>Add a new cron job to run the script at your desired schedule. For example, to run the script every day at 8 AM, add the following line:</li></ul><pre>0 8 * * * /shellScriptLoc/file-transfer.sh</pre><ul><li>Save and exit the cron editor.</li></ul><p>This will execute your shell script automatically at the specified time.</p><p>The schedule time and frequency are set as 0 8 * * *, which means the script will run every day at 8:00 AM.</p><p>The shell script to be executed automatically is located at /shellScripting/file-transfer.sh.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*rQumcY5zXmGiOqt9-V6n1g.png" /><figcaption>cron table</figcaption></figure><p>You can list all the scheduled cron jobs using the following command:</p><pre>crontab -l</pre><p>To start and enable the cron service on your Linux EC2 instance, run the following commands:</p><ul><li>Start the cron service:</li></ul><pre>sudo systemctl start crond</pre><ul><li>Enable the cron service to start automatically on boot:</li></ul><pre>sudo systemctl enable cron</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*9c39yIlEnnVaYrmIiYYvhg.png" /><figcaption>cron enabling</figcaption></figure><p>Now, the automation steps are complete.</p><p>To conclude, automating file transfers from an EC2 instance to an S3 bucket using a shell script and cron job significantly improves efficiency and reduces manual intervention. By following the steps outlined in this article, you can ensure that your data is transferred securely and on schedule, making it a great solution for regular backups, data pipelines, or log management.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6f136a06709" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Transformation and Cleansing Techniques]]></title>
            <link>https://medium.com/@dinunirmani9d/data-transformation-and-cleansing-techniques-b4218cfe457a?source=rss-18ac3d0fd723------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4218cfe457a</guid>
            <dc:creator><![CDATA[Dinushi Ariyasena]]></dc:creator>
            <pubDate>Fri, 28 Mar 2025 05:12:04 GMT</pubDate>
            <atom:updated>2025-03-28T05:12:04.989Z</atom:updated>
            <content:encoded><![CDATA[<p>· <a href="#4299">Check For Nulls or Duplicates in Primary Key</a><br> ∘ <a href="#f21e">How to select only the latest record from duplicates</a><br>· <a href="#d3cd">Check for unwanted spaces in string values</a><br> ∘ <a href="#e901">Remove unwanted spaces from column values (TRIM)</a><br>· <a href="#6277">Check the consistency of values in low cardinality columns</a><br> ∘ <a href="#bfed">Data Standardization</a><br>· <a href="#b6dd">Extract a specific part of a string value</a><br>· <a href="#447a">Replace values in string</a><br>· <a href="#8c67">Check Nulls or Negative numbers</a><br> ∘ <a href="#2485">Handle Nulls → Assign 0</a><br>· <a href="#ed53">Convert String Date values to Date format (CAST)</a><br> ∘ <a href="#dc50">Clean date values and CAST</a><br>· <a href="#84b3">Return NULL based on conditions</a><br>· <a href="#4c24">Applying Business Rules</a></p><h3>Check For Nulls or Duplicates in Primary Key</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*5R-kyPu74VvNeqBY1aXiRg.png" /><figcaption>cust_info table</figcaption></figure><pre>SELECT cst_id, count(*)<br>FROM db.schema.cust_info<br>group by cst_id<br>having count(*) &gt; 1 or cst_id is null</pre><h4>How to select only the latest record from duplicates</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*al-TbpSumUltqN-PwT8lxg.png" /></figure><pre>SELECT *,<br>ROW_NUMBER() OVER(PARTITION BY cst_id ORDER BY cst_create_date DESC) AS flag_last<br>FROM db.schema.cust_info</pre><p>Above query returns all records with rank. Latest records will get rank 1. In order to get only latest records, we need to filter only rank no 1 records.</p><pre>SELECT *<br>FROM (<br><br>SELECT *,<br>ROW_NUMBER() OVER(PARTITION BY cst_id ORDER BY cst_create_date DESC) AS flag_last<br>FROM db.schema.cust_info<br><br>)t<br>WHERE flag_last = 1</pre><h3>Check for unwanted spaces in string values</h3><pre>SELECT cst_firstname<br>FROM db.schema.cust_info<br>WHERE cst_firstname != TRIM(cst_firstname)</pre><h4>Remove unwanted spaces from column values (TRIM)</h4><pre>SELECT <br>cst_id,<br>cst_key,<br>TRIM(cst_firstname) AS cst_firstname,<br>TRIM(cst_lastname) AS cst_lastname,<br>cst_marital_status,<br>cst_gndr,<br>cst_create_date<br>FROM db.schema.cust_info</pre><h3>Check the consistency of values in low cardinality columns</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W72QrgIcisBwZFGW5F3Ecg.png" /></figure><pre>SELECT DISTINCT cst_gndr<br>FROM db.schema.cust_info</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*--pqclKdtAElQYR8hjYMpg.png" /></figure><h4>Data Standardization</h4><pre>SELECT<br>cst_id,<br>CASE WHEN UPPER(TRIM(cst_gndr)) = &#39;F&#39; THEN &#39;Female&#39;<br>     WHEN UPPER(TRIM(cst_gndr)) = &#39;M&#39; THEN &#39;Male&#39;<br>     ELSE &#39;n/a&#39;<br>END cst_gndr,<br>cst_gndr<br>FROM db.schema.cust_info</pre><h3>Extract a specific part of a string value</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-_G4SU-xfbct8zShJ-e6BQ.png" /><figcaption>prd_info table</figcaption></figure><p>If we want to create new column named cat_id as a deriving column from prd_key, we can do following.</p><pre>SELECT<br>prd_key,<br>SUBSTRING(prd_key, 1, 5) as cat_id<br>from dbo.schema.prd_info</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*50NH_asDzC-TpsVgqlrluQ.png" /></figure><h3>Replace values in string</h3><pre>SELECT<br>prd_key,<br>REPLACE(SUBSTRING(prd_key, 1, 5),&#39;-&#39;,&#39;_&#39;) as cat_id<br>from dbo.schema.prd_info</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*MvIbmTrpGZpkKk75P_acwg.png" /></figure><h3>Check Nulls or Negative numbers</h3><pre>SELECT<br>prd_cost<br>FROM dbo.schema.prd_info<br>WHERE prd_cost &lt; 0 or prd_cost is NULL</pre><h4>Handle Nulls → Assign 0</h4><pre>SELECT<br>ISNULL(prd_cost, 0) AS prd_cost<br>FROM dbo.schema.prd_info</pre><h3>Convert String Date values to Date format (CAST)</h3><pre>SELECT<br>prd_id,<br>CAST(prd_start_dt AS DATE) as prd_start_dt<br>FROM dbo.schema.prd_info</pre><h4>Clean date values and CAST</h4><pre>SELECT<br>sls_cust_id,<br>CASE WHEN sls_order_dt = 0 OR LEN(sls_order_dt) != 8 THEN NULL<br>     ELSE CAST(CAST(sls_order_dt AS VARCHAR) AS DATE)<br>END AS sls_order_dt<br>FROM dbo.schema.sales_details</pre><h3>Return NULL based on conditions</h3><p>If value equals to 0, then assign NULL</p><pre>SELECT<br>NULLIF(sls_order_dt, 0) AS sls_order_dt<br>FROM dbo.schema.prd_info</pre><h3>Applying Business Rules</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KHYkQcke2ahHA247tfOGBQ.png" /></figure><p>Next task is applying business rules to the above columns</p><ul><li>Sales = Quantity * Price</li><li>Negative, Zeros, NULLs are not allowed</li></ul><p>Check</p><pre>SELECT<br>sls_sales,<br>sls_quantity,<br>sls_price<br>FROM dbo.schema.sales_details<br>WHERE sls_sales != sls_quantity*sls_price<br>OR sls_sales IS NULL OR sls_quantity IS NULL OR sls_price IS NULL<br>OR sls_sales &lt;= 0 OR sls_quantity &lt;= 0 OR sls_price &lt;= 0</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*5QLSTsCA-O8w1P3s5VqPqQ.png" /></figure><p>Apply Rules</p><ul><li>If sales in negative, zero or null, derive it using quantity and price</li><li>If price is zero or null, calculate it using Sales and Quantity</li><li>If price is negative convert it into positive value</li></ul><pre>SELECT<br><br>CASE WHEN sls_sales IS NULL OR sls_sales &lt;= 0 OR sls_sales!=sls_quantity*ABS(sls_price)<br>     THEN sls_quantity * ABS(sls_price)<br>ELSE sls_sales<br>END AS sls_sales<br><br>CASE WHEN sls_price IS NULL OR sls_price &lt;= 0<br>     THEN sls_price = sls_sales/NULLIF(sls_quantity,0)<br>ELSE sls_price<br>END AS sls_price<br><br>FROM dbo.schema.sales_details</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4218cfe457a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Star Schema Data Modeling]]></title>
            <link>https://medium.com/@dinunirmani9d/star-schema-data-modeling-1267a9700412?source=rss-18ac3d0fd723------2</link>
            <guid isPermaLink="false">https://medium.com/p/1267a9700412</guid>
            <dc:creator><![CDATA[Dinushi Ariyasena]]></dc:creator>
            <pubDate>Fri, 28 Mar 2025 05:07:16 GMT</pubDate>
            <atom:updated>2025-03-28T05:07:16.458Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will show you how to build a Star Schema data model for a data warehouse using sample source tables.</p><p><strong><em>Table of Contents</em></strong></p><p>· <a href="#3244">Source Tables’ Structure</a><br> ∘ <a href="#0d7b">Physical tables structures.</a><br>· <a href="#62c2">Star Schema Data Modeling</a><br> ∘ <a href="#944a">Dim Table Creation</a><br> ∘ <a href="#0b20">Fact Table Creation</a><br>· <a href="#f121">Star Schema Model</a></p><h3>Source Tables’ Structure</h3><p>I have 6 tables. Below is an image showing how these tables are interconnected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*b8GVRPFGwvMRfCA-R_K-lQ.png" /><figcaption>Logical Structure</figcaption></figure><h4>The following picture shows the physical tables structures.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BJiyhAKDkdq6pKGU5W8rNw.png" /><figcaption>crm_sales_details table</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rsEL7wQW_vTZjWo6Y9-XLw.png" /><figcaption>crm_prd_info table</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*776vn9sYwyNtDmms6Ups-g.png" /><figcaption>erp_df_px_cat_g1v2 table</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O-A5q8rJXlhsU8NQNkeEDA.png" /><figcaption>crm_cust_info table</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TTuPIpLEDOKtmHXJB-neow.png" /><figcaption>erp_cust_az12 table</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aB4Tq-5tmX-CU0H68qwfEQ.png" /><figcaption>erp_loc_a101 table</figcaption></figure><h3>Star Schema Data Modeling</h3><h4>Dim Table Creation</h4><ul><li><strong><em>Dim_Customers</em></strong></li></ul><pre>create view gold.dim_customers as<br>select<br>row_number() over (order by cst_id) as customer_key, --surrogate key<br>cu.cst_id as customer_id,<br>cu.cst_key as customer_number,<br>cu.cst_firstname as first_name,<br>cu.cst_lastname as last_name,<br>lc.cntry as country,<br>cu.cst_marital_status as marital_status,<br>case when cu.cst_gndr != &#39;n/a&#39; then cu.cst_gndr<br>     else coalesce(bd.gen, &#39;n/a&#39;)<br>end as gender,<br>bd.bdate as birth_date,<br>cu.cst_create_date as create_date<br>from Silver.dbo.crm_cust_info cu<br>left join Silver.dbo.erp_cust_az12 bd<br>on cu.cst_key = bd.cid<br>left join Silver.dbo.erp_loc_a101 lc<br>on cu.cst_key = lc.cid</pre><p>When creating the <strong>Dim_Customers</strong> table, I joined the <strong>crm_cust_info</strong> table (which contains customer information) with the <strong>erp_cust_az12</strong> table (which contains customer birthday information) and the <strong>erp_loc_a101</strong> table (which contains customer location information).</p><p>I added a surrogate key to the <strong>Dim_Customers</strong> table using the ROW_NUMBER() window function, designating it as the <strong>customer_key</strong> attribute. This surrogate key was created to uniquely identify each record in the dimension table.</p><ul><li><strong><em>Dim_Products</em></strong></li></ul><pre>create view gold.dim_products as<br>select<br>row_number() over (order by prd_start_dt, prd_key) as product_key, --surrogate key<br>pr.prd_id as product_id,<br>pr.prd_key as product_number,<br>pr.prd_nm as product_name,<br>pr.cat_id as category_id,<br>ct.cat as category,<br>ct.subcat as subcategory,<br>ct.maintenance,<br>pr.prd_cost as cost,<br>pr.prd_line as product_line,<br>pr.prd_start_dt as start_date<br>from Silver.dbo.crm_prd_info pr<br>left join Silver.dbo.erp_df_px_cat_g1v2 ct<br>on pr.cat_id = ct.id<br>where pr.prd_end_dt is null</pre><p>When creating the <strong>Dim_Products</strong> table, I joined the crm_prd_info table (which contains product information) with the <strong>erp_df_px_cat_g1v2</strong> table (which contains product category information) table.</p><p>I added a surrogate key to the <strong>Dim_Products </strong>table using the ROW_NUMBER() window function, designating it as the <strong>product_key </strong>attribute. This surrogate key was created to uniquely identify each record in the dimension table.</p><h4>Fact Table Creation</h4><ul><li><strong><em>Fact_Sales</em></strong></li></ul><pre>CREATE VIEW gold.fact_sales as <br>select <br>sl.sls_ord_num as order_number,<br>pr.product_key,<br>cs.customer_key,<br>sl.sls_order_dt as order_date,<br>sl.sls_ship_dt as shipping_date,<br>sl.sls_due_dt as due_date,<br>CAST(sl.sls_sales AS float) as sales_amount,<br>CAST(sl.sls_quantity AS float) as quantity,<br>CAST(sl.sls_price AS float) as price<br>from Silver.dbo.crm_sales_details sl<br>left join gold.dim_products pr<br>on sl.sls_prd_key = pr.product_number<br>left join gold.dim_customers cs<br>on sl.sls_cust_id = cs.customer_id</pre><p>Finally, I created the <strong>Fact_Sales</strong> table by joining the <strong>crm_sales_details</strong> table with the <strong>Dim_Products</strong> and <strong>Dim_Customers</strong> tables.</p><h3>Star Schema Model</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3osMIxFOWsEbQGVLpcuJWg.png" /><figcaption>Final Star Schema Model</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1267a9700412" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microsoft Fabric Project: Building a Data Warehouse]]></title>
            <link>https://medium.com/@dinunirmani9d/microsoft-fabric-project-building-a-data-warehouse-1c723a6d100a?source=rss-18ac3d0fd723------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c723a6d100a</guid>
            <dc:creator><![CDATA[Dinushi Ariyasena]]></dc:creator>
            <pubDate>Mon, 24 Mar 2025 06:26:31 GMT</pubDate>
            <atom:updated>2025-03-24T09:48:13.401Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fCBKTTMfjeqsrf82ceq5fg.png" /></figure><p>📌 In this project, I built a complete end-to-end data warehouse solution using Microsoft Fabric, following the Medallion Architecture. The pipeline starts by ingesting raw CSV files stored in GitHub. These datasets go through structured layers — Bronze for raw data, Silver for cleaned and transformed data, and Gold for dimensional modeling in a star schema using Fabric’s Data Warehouse. Finally, I connected the warehouse to Power BI to build a dashboard for data visualization. This project showcases my hands-on experience with <strong>Microsoft Fabric ecosystem.</strong></p><p><strong>Table of Content</strong></p><p><strong>· </strong><a href="#b492"><strong>Data Source Overview</strong></a><br> ∘ <a href="#4bfa">📁 CRM System Files</a><br> ∘ <a href="#cebf">🧾 ERP System Files</a><br><strong>· </strong><a href="#f33d"><strong>Step 1: Setting Up the Fabric Workspace</strong></a><br><strong>· </strong><a href="#ef7d"><strong>Step 2: Bronze Layer — Data Ingestion</strong></a><br> ∘ <a href="#151e">Creating the Bronze Lakehouse</a><br> ∘ <a href="#e2fb">Building the Data Pipeline to Load Data from GitHub</a><br> ∘ <a href="#4d89">Raw Data Storage in Bronze Layer</a><br><strong>· </strong><a href="#6cc4"><strong>Step 3: Silver Layer — Data Cleaning &amp; Transformation</strong></a><br> ∘ <a href="#ebf4">Creating the Silver Lakehouse</a><br> ∘ <a href="#a6a8">Data Cleaning &amp; Transformation using Notebooks (PySpark &amp; SQL)</a><br> ∘ <a href="#5b3d">Storing Processed Data in Silver Layer</a><br><strong>· </strong><a href="#f6e7"><strong>Step 4: Gold Layer — Data Warehouse Modeling</strong></a><br> ∘ <a href="#a34e">Creating the Fabric Data Warehouse</a><br> ∘ <a href="#1794">Building the Star Schema (Dimensional Modeling)</a><br><strong>· </strong><a href="#c7ca"><strong>Step 5: Data Visualization with Power BI</strong></a><br> ∘ <a href="#8f1b">Connecting Power BI to the Data Warehouse</a><br> ∘ <a href="#505a">Building Dashboards and Visuals</a><br><strong>· </strong><a href="#986d"><strong>Step 6: Workspace Lineage and Deploying Workspace</strong></a><br> ∘ <a href="#0561">Check Workspace Lineage</a><br> ∘ <a href="#2e5a">Deploying Workspace</a></p><h3>Data Source Overview</h3><p>For this project, I worked with <strong>six CSV files</strong> sourced from simulated <strong>CRM</strong> and <strong>ERP systems</strong>. These files were uploaded to my <strong>GitHub repository</strong> and served as the raw input for the data pipeline.</p><p>Source Files :<br><a href="https://github.com/DinuAR/FabricDataWarehouseSourceFiles.git">https://github.com/DinuAR/FabricDataWarehouseSourceFiles.git</a></p><h4>📁 CRM System Files</h4><ol><li>cust_info.csv – Contains basic customer information</li><li>prd_info.csv – Includes product-level details</li><li>sales_details.csv – Holds transaction-level sales data</li></ol><h4>🧾 ERP System Files</h4><ol><li>CUST_AZ12.csv – Adds customer attributes like birthdate and gender</li><li>LOC_A101.csv – Maps customers to their countries</li><li>PX_CAT_G1V2.csv – Provides product category and subcategory information</li></ol><p>These datasets represent a <strong>realistic business scenario</strong> with scattered data across different systems. The goal was to <strong>integrate, clean, and model</strong> this data into a unified structure for analytics using the <strong>Medallion Architecture</strong> in Microsoft Fabric.</p><h3>Step 1: Setting Up the Fabric Workspace</h3><p>To kick off the project, I created a <strong>new Microsoft Fabric workspace</strong> dedicated to this project. This workspace served as a centralized environment to organize and manage all the components I would use throughout the development lifecycle — such as Lakehouses, Data Pipelines, Notebooks, the Data Warehouse, and the Power BI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7nOGw-pQJogf8gkR3kX0XA.png" /><figcaption>Workspace</figcaption></figure><h3>Step 2: Bronze Layer — Data Ingestion</h3><h4>Creating the Bronze Lakehouse</h4><p>Following the <strong>Medallion Architecture</strong> pattern, the next step was to create a <strong>Bronze Lakehouse</strong> in my workspace. This Lakehouse acts as the raw data storage layer, where I ingest and store the unprocessed source files exactly as they are.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zmQ6N-z54grwyQdHVBQkmQ.png" /><figcaption>Bronze Lakehouse</figcaption></figure><h4>Building the Data Pipeline to Load Data from GitHub</h4><p>To ingest the raw source data into the Bronze Lakehouse, I created a <strong>Fabric Data Pipeline</strong>. This pipeline was configured to <strong>extract the CSV files directly from my GitHub repository</strong> and load them into the Bronze layer.</p><p>This is the home page of Fabric Data Pipeline Item</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wtWK_B3gDbDFUpPZ-m4HxQ.png" /><figcaption>DataPipeline Home</figcaption></figure><p>Configured copy data activity to extract CRM data files from Github</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mEUX7tySRfTh7UlU77DNtA.png" /><figcaption>Copy Data Activity Configurations</figcaption></figure><p>Created a new connection to connect with Github</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gU92nxz0Xd-cRi14m94jdw.png" /><figcaption>Setup New connection to Github</figcaption></figure><p>Used a ForEach activity to dynamically extract all data files in Github CRM folder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vRhWb_YWi4P7ugOy4U0VIw.png" /><figcaption>ForEach Activity to extract all files in a folder</figcaption></figure><p>Set up the Copy Data activity inside the For Each activity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JQ69hYy_pXhK68GyE1VVrQ.png" /><figcaption>CRM Data Extraction Activity</figcaption></figure><p>Configured the same setup to extract ERP data from GitHub and connected the components to complete the source data extraction pipeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P1zFYdaWCNRyXaJiXqe4EQ.png" /><figcaption>Complete Data Pipeline</figcaption></figure><p>Running Data Pipeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ekc3XiHbrVJFWOupjibPUA.png" /><figcaption>Pipeline Status</figcaption></figure><h4>Raw Data Storage in Bronze Layer</h4><p>Once the data pipeline successfully runs, the source files are uploaded to the bronze data lake.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KhIwOLGpfctG0JbOAGcUKA.png" /><figcaption>Bronze Data Lake with Source Files</figcaption></figure><h3>Step 3: Silver Layer — Data Cleaning &amp; Transformation</h3><h4>Creating the Silver Lakehouse</h4><p>After setting up the Bronze layer, I created a second Fabric Lakehouse to serve as the <strong>Silver Layer</strong> in the Medallion Architecture. This Silver Lakehouse is used to store <strong>cleaned, transformed, and enriched data</strong> derived from the raw source files in the Bronze layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ycxaKdUkelb4vcR-Q-MA6Q.png" /><figcaption>Silver Lakehouse</figcaption></figure><h4>Data Cleaning &amp; Transformation using Notebooks (PySpark &amp; SQL)</h4><p>To process the raw data stored in the Bronze Lakehouse, I created a <strong>Fabric Notebook</strong>. Using a combination of <strong>PySpark and SQL</strong>, I performed various data cleaning and transformation tasks — such as handling missing values, standardizing column formats, joining related datasets, and preparing the data for dimensional modeling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gi4ZaeuL7UIW_gldpRjSCQ.png" /><figcaption>Fabric Notebook</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aea378369f67bad097256b76a6a1722c/href">https://medium.com/media/aea378369f67bad097256b76a6a1722c/href</a></iframe><h4>Storing Processed Data in Silver Layer</h4><p>Once the data cleaning and transformation were complete, I <strong>saved the processed datasets into the Silver Lakehouse</strong>. These cleaned files now represented a more structured and analytics-ready version of the original data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FIBiriMyHT5fGipnMkOiBA.png" /><figcaption>Silver Lakehouse</figcaption></figure><h3>Step 4: Gold Layer — Data Warehouse Modeling</h3><h4>Creating the Fabric Data Warehouse</h4><p>Next, I created a <strong>Data Warehouse item in Microsoft Fabric</strong> to serve as the <strong>Gold Layer</strong> of the pipeline. This layer is designed to support advanced analytics and reporting by storing structured, query-optimized data. Using the cleaned and transformed datasets from the <strong>Silver Lakehouse</strong>, I began building the dimensional model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LkyY2F61Cctt9qn4cHdrig.png" /><figcaption>Data Warehouse in Fabric</figcaption></figure><p>Inside the Fabric Data Warehouse, I created a new schema named <strong>gold</strong> to logically organize the <strong>dimension tables and fact table</strong>.</p><pre>CREATE SCHEMA gold<br>GO</pre><h4>Building the Star Schema (Dimensional Modeling)</h4><p>To implement the <strong>star schema</strong> model, I created the <strong>dimension and fact tables as SQL views</strong> within the gold schema of the Data Warehouse.</p><p>Dimension Tables: dim_customers, dim_products</p><pre>create view gold.dim_customers as<br>select<br>row_number() over (order by cst_id) as customer_key,<br>cu.cst_id as customer_id,<br>cu.cst_key as customer_number,<br>cu.cst_firstname as first_name,<br>cu.cst_lastname as last_name,<br>lc.cntry as country,<br>cu.cst_marital_status as marital_status,<br>case when cu.cst_gndr != &#39;n/a&#39; then cu.cst_gndr<br>     else coalesce(bd.gen, &#39;n/a&#39;)<br>end as gender,<br>bd.bdate as birth_date,<br>cu.cst_create_date as create_date<br>from Silver.dbo.crm_cust_info cu<br>left join Silver.dbo.erp_cust_az12 bd<br>on cu.cst_key = bd.cid<br>left join Silver.dbo.erp_loc_a101 lc<br>on cu.cst_key = lc.cid</pre><pre>create view gold.dim_products as<br>select<br>row_number() over (order by prd_start_dt, prd_key) as product_key,<br>pr.prd_id as product_id,<br>pr.prd_key as product_number,<br>pr.prd_nm as product_name,<br>pr.cat_id as category_id,<br>ct.cat as category,<br>ct.subcat as subcategory,<br>ct.maintenance,<br>pr.prd_cost as cost,<br>pr.prd_line as product_line,<br>pr.prd_start_dt as start_date<br>from Silver.dbo.crm_prd_info pr<br>left join Silver.dbo.erp_df_px_cat_g1v2 ct<br>on pr.cat_id = ct.id<br>where pr.prd_end_dt is null</pre><p>Fact Table: fact_sales</p><pre>CREATE VIEW gold.fact_sales as <br>select <br>sl.sls_ord_num as order_number,<br>pr.product_key,<br>cs.customer_key,<br>sl.sls_order_dt as order_date,<br>sl.sls_ship_dt as shipping_date,<br>sl.sls_due_dt as due_date,<br>CAST(sl.sls_sales AS float) as sales_amount,<br>CAST(sl.sls_quantity AS float) as quantity,<br>CAST(sl.sls_price AS float) as price<br>from Silver.dbo.crm_sales_details sl<br>left join gold.dim_products pr<br>on sl.sls_prd_key = pr.product_number<br>left join gold.dim_customers cs<br>on sl.sls_cust_id = cs.customer_id</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Z2bFOuqVIlIzB3oTHiiFg.png" /><figcaption>Gold Layer</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1QQxVLxbqNpwjV0xiBFj8g.png" /><figcaption>Star Schema Model</figcaption></figure><h3>Step 5: Data Visualization with Power BI</h3><h4>Connecting Power BI to the Data Warehouse</h4><p>To bring the data to life, I connected the <strong>Fabric Data Warehouse</strong> to <strong>Power BI</strong>. This allowed me to seamlessly access the gold schema views (dim_customer, dim_product, and fact_sales) and use them as the foundation for building an <strong>interactive report</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oxGU-rMRX7ssLKsCrllDBQ.png" /><figcaption>Data Warehouse tables in Power BI</figcaption></figure><h4>Building Dashboards and Visuals</h4><p>Here is the <strong>Power BI report</strong> I built using the data from the Fabric Data Warehouse.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lF95YgifEDrxjFHJICuDKA.png" /><figcaption>PowerBI Report</figcaption></figure><h3>Step 6: Workspace Lineage and Deploying Workspace</h3><h4>Check Workspace Lineage</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ica4ChKzXZJlpkBVSvgZfQ.png" /><figcaption>Checking Workspace Lineage</figcaption></figure><p>Here is the <strong>lineage view</strong> of all the items in my Microsoft Fabric workspace.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O-0yITpEOcwoe0kXbUs3Dw.png" /><figcaption>My Workspace Lineage</figcaption></figure><h4>Deploying Workspace</h4><p>Once the development phase was complete, I <strong>deployed all my workspace items — Lakehouses, Pipelines, Notebooks, Data Warehouse, and Power BI report — into a new Microsoft Fabric workspace</strong>. This represented a clean, production-like environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AarGmLMIloZEVlCXFbOAZA.png" /><figcaption>Newly created production environment</figcaption></figure><p><strong>New Deployment Pipeline</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zyNmSKcNjyYJ4gthgEhp0Q.png" /><figcaption>Deployment Pipeline Home</figcaption></figure><p>✅ <strong>Pipeline Successfully Deployed!</strong> 🚀</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d7_WN0UQPrETCGhvHq_FtQ.png" /><figcaption>Deployed Pipeline</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c723a6d100a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating File Transfer from OneDrive to Snowflake via Azure Blob Storage using Power Automate]]></title>
            <link>https://medium.com/@dinunirmani9d/automating-file-transfer-from-onedrive-to-snowflake-via-azure-blob-storage-using-power-automate-0baf7ae94551?source=rss-18ac3d0fd723------2</link>
            <guid isPermaLink="false">https://medium.com/p/0baf7ae94551</guid>
            <dc:creator><![CDATA[Dinushi Ariyasena]]></dc:creator>
            <pubDate>Sun, 23 Feb 2025 17:56:57 GMT</pubDate>
            <atom:updated>2025-02-23T17:56:57.110Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3VXOacgcVK9U3JJzsP9yAA.png" /></figure><p>In this project, I implemented an automated file ingestion flow from OneDrive to Snowflake.</p><p>The process is triggered when a file is uploaded to a specific OneDrive location. Upon upload, the file is automatically transferred to Azure Blob Storage, utilizing Power Automate for orchestration. Once the file resides in Azure Blob Storage, I established a connection between Azure Blob Storage and Snowflake.</p><h3>Prerequisites</h3><ol><li>OneDrive Account</li><li>Snowflake Account</li><li>Azure Account</li></ol><h3>Automation Process:</h3><h4>OneDrive to Azure Automation</h4><p>Select Power Automate App</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tpz1mzYSbRvkr9EKZ6n_MA.png" /></figure><p>Create a new Automated Cloud Flow</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v0TXenpQg6UpzYnUz_B-kQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6a8g-wCsuPSgZw2m5VMFqw.png" /></figure><p>Provide a name for the Flow and Select a Trigger</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rikw_211lTE-NPf70XGl-g.png" /></figure><p>In the design canvas, set parameter values for the trigger as follows</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NayWoGcevblBjnrdM2OLRQ.png" /></figure><p>Add another task to send file to azure as blob</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JD_oyWnaMnpvBYuEYBOeug.png" /></figure><p>Copy the Access key of storage location</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2bPJhOeHyuohgT7eVozF6A.png" /><figcaption>Storage Account</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BWKNZQ2X9tJJuyYg-AQ7Sg.png" /><figcaption>Container Location</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j3LZksdqWTjBumEDsIuMPg.png" /><figcaption>Storage Account Access Key</figcaption></figure><p>Create new connection for Azure</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DqnaIzKLweVHG-MepFGP7w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R1dGdDrdpcYnUu8nUp2wJg.png" /></figure><p>Save and Test the flow</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JBUkO_K0ChRyd8qX7xXGog.png" /></figure><p>Once testing begins, upload a new file to the OneDrive location. If the flow is correctly set up, the test will pass.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oWl17qBS1yKDmrbG9VU6iQ.png" /></figure><p>The automated workflow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k7uBqnrZyjTQtsw_8d5iNQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f0Cfw1QlzkR5DYy-aHF9QA.png" /><figcaption>OneDrive File</figcaption></figure><p>Hereafter, when the file is uploaded to OneDrive, it will automatically be synced with the Azure container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ap1GAPNWhtetrehhMHfRqQ.png" /></figure><h4>Azure to Snowflake</h4><p>To facilitate the transfer of data from the Blob Storage file to a Snowflake table, I configured a storage integration and created a Snowflake stage, which acts as a pointer to the location of the data in Azure Blob Storage. I then utilised the COPY INTO command in Snowflake to load the data from the stage into the target Snowflake table.</p><p>Create the target table in Snowflake</p><pre>CREATE TABLE DB_NAME.SCHEMA_NAME.TABLE_NAME(<br> ID NUMBER(38,0),<br> NAME VARCHAR(20),<br> AGE NUMBER(38,0)<br>);</pre><p>Create the Storage Integration for Azure in Snowflake</p><pre>CREATE STORAGE integration AZURE_INTEGRATION_TEST<br>type = external_stage<br>storage_provider=&#39;azure&#39;<br>enabled = true<br>AZURE_TENANT_ID = &#39;#################################&#39;<br>storage_allowed_locations = (&#39;azure://&lt;azure_storage_account_name&gt;.blob.core.windows.net/&lt;container_name&gt;&#39;);</pre><p>Create Stage in the Snowflake</p><pre>CREATE STAGE new_stage_name<br>STORAGE_INTEGRATION = AZURE_INTEGRATION_TEST<br>URL = &#39;azure://&lt;azure_storage_account_name&gt;.blob.core.windows.net/&lt;container_name&gt;&#39;<br>file_format = (type=csv);</pre><p>COPY INTO the target table from staging area.</p><pre>COPY INTO DB_NAME.SCHEMA_NAME.TABLE_NAME<br>FROM @new_stage_name<br>file_format = (type=csv, skip_header = 1)<br>on_error = &#39;skip_file&#39;<br>purge = false;</pre><p>Once the COPY INTO command is successful, the table will be populated with the data.</p><p>The issue was that every time a file was uploaded to OneDrive, the COPY INTO command had to be executed manually. To address this, I automated the execution of the COPY INTO command.</p><p>For full automation of this COPY INTO, I developed a stored procedure in Snowflake to execute the COPY INTO command. To ensure the procedure runs on a regular basis, I scheduled the stored procedure using Snowflake Tasks, which triggers the data loading process automatically whenever a new file is available in Blob Storage.</p><p>This end-to-end automation ensures a seamless and consistent flow of data from OneDrive to Snowflake, leveraging Power Automate, Azure Blob Storage, Snowflake stages, and Snowflake tasks for efficient and timely data loading.</p><blockquote>Thank you very much for reading this article! Feel free to share your <strong>feedback</strong> or suggestions related to this project. 😊</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0baf7ae94551" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure Data Engineering Project]]></title>
            <link>https://medium.com/@dinunirmani9d/azure-etl-data-warehouse-project-a8a44eb4b0ae?source=rss-18ac3d0fd723------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8a44eb4b0ae</guid>
            <dc:creator><![CDATA[Dinushi Ariyasena]]></dc:creator>
            <pubDate>Sun, 16 Feb 2025 18:22:21 GMT</pubDate>
            <atom:updated>2025-02-23T18:03:56.345Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4ooFvGNAYQak4kCrdv_8Rw.png" /></figure><p>In this project, I successfully implemented an end-to-end Azure data engineering solution that covers ETL, data warehousing, and data visualisation. The source dataset consists of three files related to the sales data of a fast-food franchise. These files were extracted from different sources: GitHub, an API, and an AWS S3 bucket.</p><p>After extracting the files, I stored them in an <strong>Azure Data Lake Storage Gen2 (ADLS Gen2) raw container</strong>. To ingest data from these sources into ADLS, I used <strong>Azure Data Factory (ADF)</strong>. Once the source data was ingested into the raw container, I used <strong>Azure Databricks</strong> to clean and transform it. The transformed data was then stored in a separate ADLS Gen2 container designated for processed data.</p><p>Next, I set up a <strong>dedicated SQL pool in Azure Synapse Analytics</strong> to create a data warehouse model. I first created a <strong>staging table</strong> in the SQL pool to load the transformed data from ADLS. Using the COPY INTO command, I populated this table. Then, I designed the <strong>fact and dimension tables</strong> based on a <strong>star schema</strong> and populated them using data from the staging table.</p><p>Finally, I connected the dedicated SQL pool database to <strong>Power BI</strong> to create visualisations based on the data warehouse. I built interactive dashboards to analyse the sales data effectively.</p><h3>Prerequisites</h3><ol><li>Azure Account</li><li>A container in <strong>Azure Data Lake Storage Gen2 (ADLS Gen2)</strong> with two directories: one for storing <strong>raw data</strong> and another for <strong>transformed data</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MBEtseBuekKYkOXvZvjuSg.png" /><figcaption>ADLS Container</figcaption></figure><p><strong>3. Azure Synapse Analytics workspace</strong> with a <strong>dedicated sql pool.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iL3S7YalXl3mdKHoBuJD4A.png" /><figcaption>Synapse Analytics Workspace</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UCNhcy6a1k_fWQzRUnAFwQ.png" /><figcaption>Dedicated SQL Pool</figcaption></figure><p><strong>4. Azure Data Factory.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oK4rWnJhexzQc8YmfbmFNg.png" /><figcaption>Azure Data Factory</figcaption></figure><p><strong>5. Azure Databricks workspace.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r-_Ur_fjNmJnAsgSub9Nvw.png" /><figcaption>Azure Databricks Workspace</figcaption></figure><h3>Source Dataset</h3><p>For this project, I created the source files by myself, which contain sales data for the franchise. My source data consists of three CSV files, all sharing the same schema with 28 columns.</p><p>To simulate <strong>multiple data sources</strong>, I hosted these files in three different locations:</p><ol><li><strong>GitHub</strong></li><li><strong>An AWS S3 bucket</strong></li><li><strong>An API</strong></li></ol><p>You can download one of my source files from the following link if needed.</p><p><a href="https://etabetapiapi.onrender.com/export_csv">https://etabetapiapi.onrender.com/export_csv</a></p><h3><strong>Data Ingestion</strong></h3><p>For data ingestion from the source locations to <strong>Azure Data Lake</strong>, I utilized <strong>Azure Data Factory (ADF)</strong>. I created a <strong>data pipeline</strong> with <strong>three Copy Data activities</strong>, each responsible for extracting one of the three files from its respective source location and copying it to the <strong>raw data container</strong> in the data lake.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ch30bL9ymy34laVX1bMwTQ.png" /><figcaption>Data Ingestion Pipeline</figcaption></figure><p>The following are the connection details for each <strong>Copy Data</strong> <strong>activity</strong> in my pipeline.</p><p><strong>GitHub File Extraction</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2AoTqp5R5T2ZIxstydgu4A.png" /><figcaption>Github File — Source Properties</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hNvP9CG5gOp0hDu36QD45w.png" /><figcaption>Sink Properties (Target)</figcaption></figure><p><strong>AWS S3 File</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KD0ZI1w99kGqOdGT_sQyWg.png" /><figcaption>S3 File — Source Properties</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SJLVaRX4VDUiSw1tropr6Q.png" /><figcaption>Sink Properties (Target)</figcaption></figure><p><strong>API File</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GXl61hxHrQSuXqtgCdZ6ig.png" /><figcaption>API — Source Properties</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QL9uGHL-tg7dWVN9gZO3hA.png" /><figcaption>Sink Properties (Target)</figcaption></figure><p>Once the <strong>Data Factory pipeline</strong> is triggered, the source files are copied to the target <strong>ADLS container</strong>. The following image shows the target<strong> ADLS container directory</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rmb-NvCkvfWbXbkPDrJ8dw.png" /><figcaption>ADLS Container Directory for Raw Data</figcaption></figure><h3>Data Transformation</h3><p>As the next step, I performed data cleaning and transformations on the source data using <strong>Azure Databricks</strong> with <strong>PySpark</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NZ0buBxZqKVwMeHjb5msMw.png" /><figcaption>Azure Databricks Workspace</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a13b344369dbbb37fafb46764ee4807a/href">https://medium.com/media/a13b344369dbbb37fafb46764ee4807a/href</a></iframe><p>After performing cleaning and transformation jobs on all three source files, I merged them into a single CSV file within the Databricks notebook and stored it in the <strong>transformed container directory</strong> in ADLS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B-KR6j9V0GWOY-qHbMy86g.png" /><figcaption>ADLS Container Directory for Transformed Data</figcaption></figure><h3>Data Loading to Synapse</h3><p>My next goal was to <strong>build a data warehouse model in a star schema</strong> using the transformed data stored in ADLS. As the first step, I created a <strong>staging table</strong> in the <strong>Azure Synapse Analytics dedicated SQL pool</strong>. Then, using the <strong>COPY INTO</strong> command, I loaded the transformed data from ADLS into the staging table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jXRiF27Dj4tqtcMEmCoKzQ.png" /><figcaption>Creating and Loading Staging table</figcaption></figure><p>Create Table Code:</p><pre>CREATE TABLE [dbo].[EtaBetaPiMasterTable]<br>( <br>    [InvoiceNumber] [varchar](100)  NULL,<br> [SaleDateTime] [varchar](100)  NULL,<br> [OrderType] [varchar](100)  NULL,<br> [AppliedOfferName] [varchar](100)  NULL,<br> [CouponName] [varchar](100)  NULL,<br> [CustomerName] [varchar](100)  NULL,<br> [CustomerLoyaltyNumber] [varchar](100)  NULL,<br> [CustomerMobileNumber] [varchar](100)  NULL,<br> [CustomerEmail] [varchar](100)  NULL,<br> [TotalBillValue] [varchar](100)  NULL,<br> [DiscountAmount] [varchar](100)  NULL,<br> [TaxAmount] [varchar](100)  NULL,<br> [PaymentType] [varchar](100)  NULL,<br> [CreditCardDetails] [varchar](100)  NULL,<br> [BillingTimeStamp] [varchar](100)  NULL,<br> [BillingStaffName] [varchar](100)  NULL,<br> [FoodItemsPurchased] [varchar](100)  NULL,<br> [ServeTimeStamp] [varchar](100)  NULL,<br> [ServeStaffName] [varchar](100)  NULL,<br> [ChefStaffName] [varchar](100)  NULL,<br> [ChefTimeStamp] [varchar](100)  NULL,<br> [DeliveryRequired] [varchar](100)  NULL,<br> [DeliveryTimeStamp] [varchar](100)  NULL,<br> [DeliveryStaffName] [varchar](100)  NULL,<br> [FranchiseLocation] [varchar](100)  NULL,<br> [FranchiseName] [varchar](100)  NULL,<br> [CarPlateNumber] [varchar](100)  NULL,<br> [DeliveryFees] [varchar](100)  NULL<br>)<br>WITH<br>(<br> DISTRIBUTION = ROUND_ROBIN,<br> CLUSTERED COLUMNSTORE INDEX<br>)<br>GO</pre><p>COPY INTO Code:</p><pre>CREATE DATABASE SCOPED CREDENTIAL ManagedIdentityCredential<br>WITH IDENTITY = &#39;Managed Identity&#39;;<br><br>COPY INTO [dbo].[EtaBetaPiMasterTable]<br>FROM &#39;https://etabetapian.dfs.core.windows.net/etabetapifsn/TransPosData/part-00000-tid-5782541842881519311-f10126f1-45f8-44d7-aae4-9e2a84f8e775-15-1-c000.csv&#39;<br>WITH (<br>    FILE_TYPE = &#39;CSV&#39;,<br>    CREDENTIAL=(IDENTITY= &#39;Managed Identity&#39;)<br>)</pre><h3>Data Warehouse building</h3><h4>Create Dimension tables and Fact table</h4><p>As the next step, I created the <strong>fact table</strong> and <strong>dimension tables</strong> based on my <strong>star schema model</strong> in the <strong>dedicated SQL pool</strong> in Azure Synapse Analytics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FyujJv0JDMxzg34h4D_JJQ.png" /><figcaption>Data Warehouse table creation</figcaption></figure><p>Create table code:</p><pre>CREATE TABLE DimCustomer (<br>    CustomerKey INT IDENTITY(1,1) NOT NULL,<br>    CustomerName VARCHAR(100),<br>    CustomerLoyaltyNumber VARCHAR(100),<br>    CustomerMobileNumber VARCHAR(100),<br>    CustomerEmail VARCHAR(100)<br>)<br><br>CREATE TABLE DimOrderType (<br>    OrderTypeKey INT IDENTITY(1,1) NOT NULL,<br>    OrderType VARCHAR (100)<br>)<br><br>CREATE TABLE DimPaymentType (<br>    PaymentTypeKey INT IDENTITY(1,1) NOT NULL,<br>    PaymentType VARCHAR (100)<br>)<br><br>---more dim tables--<br>--------------------<br><br>CREATE TABLE FactSales (<br>    InvoiceNumber INT PRIMARY KEY NONCLUSTERED NOT ENFORCED,<br>    DeliveryRequired VARCHAR (10),<br>    TaxAmount DECIMAL (10,2),<br>    DiscountAmount DECIMAL (10,2),<br>    TotalBillValue DECIMAL (10,2),<br>    DeliveryFees DECIMAL (10,2),<br>    SaleDateTime VARCHAR (100),<br>    DeliveryTimeStamp VARCHAR (100),<br>    ServeTimeStamp VARCHAR (100),<br>    BillingTimeStamp VARCHAR (100),<br>    ChefTimeStamp VARCHAR (100),<br>    CustomerKey INT,<br>    StaffKey INT,<br>    FranchiseKey INT,<br>    OrderTypeKey INT,<br>    PaymentTypeKey INT,<br>    PromoKey INT,<br>    CouponKey INT,<br>    CreditCardKey INT,<br>    DriveThroughKey INT<br>)</pre><h4>Dimenstion Tables Loading</h4><p>Then, I loaded data into the Dimension tables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y-_PBkFe37kppA2GzT1x9A.png" /><figcaption>Dim tables loading</figcaption></figure><p>Dim table loading code:</p><pre>INSERT INTO DimCustomer (CustomerName, CustomerLoyaltyNumber, CustomerMobileNumber, CustomerEmail)<br>SELECT DISTINCT CustomerName, CustomerLoyaltyNumber, CustomerMobileNumber, CustomerEmail <br>FROM dbo.EtaBetaPiMasterTable<br><br>INSERT INTO DimFranchise (FranchiseName, FranchiseLocation)<br>SELECT DISTINCT FranchiseName, FranchiseLocation <br>FROM dbo.EtaBetaPiMasterTable;<br><br>INSERT INTO DimOrderType (OrderType)<br>SELECT DISTINCT OrderType <br>FROM dbo.EtaBetaPiMasterTable;<br><br>---more dim tables--<br>--------------------</pre><h4>Fact Table Loading</h4><p>Then, I loaded data into the Fact table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l3IxC2mJ4csyvMHYGxBHbw.png" /><figcaption>Fact table loading</figcaption></figure><p>Fact table loading code:</p><pre>INSERT INTO FactSales (<br>    InvoiceNumber,<br>    DeliveryRequired,<br>    TaxAmount,<br>    DiscountAmount,<br>    TotalBillValue,<br>    DeliveryFees,<br>    SaleDateTime,<br>    DeliveryTimeStamp,<br>    ServeTimeStamp,<br>    BillingTimeStamp,<br>    ChefTimeStamp,<br>    CustomerKey,<br>    StaffKey,<br>    FranchiseKey,<br>    OrderTypeKey,<br>    PaymentTypeKey,<br>    PromoKey,<br>    CouponKey,<br>    CreditCardKey,<br>    DriveThroughKey<br>)<br>SELECT <br>    CAST(EBP.InvoiceNumber AS INT) AS InvoiceNumber,<br>    EBP.DeliveryRequired,<br>    CAST(EBP.TaxAmount AS DECIMAL(10,2)) AS TaxAmount,<br>    CAST(EBP.DiscountAmount AS DECIMAL(10,2)) AS DiscountAmount,<br>    CAST(EBP.TotalBillValue AS DECIMAL(10,2)) AS TotalBillValue,<br>    CAST(EBP.DeliveryFees AS DECIMAL(10,2)) AS DeliveryFees,<br>    EBP.SaleDateTime AS SaleDateTime,<br>    EBP.DeliveryTimeStamp AS DeliveryTimeStamp,<br>    EBP.ServeTimeStamp AS ServeTimeStamp,<br>    EBP.BillingTimeStamp AS BillingTimeStamp,<br>    EBP.ChefTimeStamp AS ChefTimeStamp,<br>    DC.CustomerKey,<br>    DS.StaffKey AS StaffKey,<br>    DF.FranchiseKey,<br>    --DFM.ItemKey,<br>    DOT.OrderTypeKey,<br>    DPT.PaymentTypeKey,<br>    DP.PromoKey,<br>    DCN.CouponKey,<br>    DCC.CreditCardKey,<br>    DDT.DriveThroughKey<br>FROM [dbo].[EtaBetaPiMasterTable] EBP<br>LEFT JOIN DimCustomer DC <br>    ON EBP.CustomerName = DC.CustomerName <br>    AND EBP.CustomerLoyaltyNumber = DC.CustomerLoyaltyNumber <br>    AND EBP.CustomerMobileNumber = DC.CustomerMobileNumber <br>    AND EBP.CustomerEmail = DC.CustomerEmail<br>LEFT JOIN DimEmployee DS<br>    ON (EBP.BillingStaffName = DS.StaffName and DS.StaffRole = &#39;Billing Staff&#39;) OR (EBP.ChefStaffName = DS.StaffName and DS.StaffRole = &#39;Chef&#39;) OR (EBP.DeliveryStaffName = DS.StaffName and DS.StaffRole = &#39;Delivery Staff&#39;) OR (EBP.ServeStaffName = DS.StaffName and DS.StaffRole = &#39;Serve Staff&#39;)<br>LEFT JOIN DimFranchise DF <br>    ON EBP.FranchiseName = DF.FranchiseName <br>    AND EBP.FranchiseLocation = DF.FranchiseLocation<br>LEFT JOIN DimOrderType DOT <br>    ON EBP.OrderType = DOT.OrderType<br>LEFT JOIN DimPaymentType DPT <br>    ON EBP.PaymentType = DPT.PaymentType<br>LEFT JOIN DimPromo DP <br>    ON EBP.AppliedOfferName = DP.AppliedOfferName<br>LEFT JOIN DimCoupon DCN <br>    ON EBP.CouponName = DCN.CouponName<br>LEFT JOIN DimCreditCardData DCC <br>    ON EBP.CreditCardDetails = DCC.CreditCardDetails<br>LEFT JOIN DimDriveThroughData DDT <br>    ON EBP.CarPlateNumber = DDT.CarPlateNumber;</pre><h3>Dashboard Development</h3><p>As the final step of the project, I wanted to create visualisations to gain analytical insights from the data warehouse. To achieve this, I downloaded <strong>Power BI</strong> Desktop.</p><p>Once the Power BI was installed, I connected it to the Azure Synapse Analytics dedicated SQL pool to the Power BI as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RwDZhkpZsL7f5SoaiMHCSg.png" /><figcaption>Connecting synapse analytics to power bi</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tg21ix0E2si8g6pHYWegNg.png" /><figcaption>Dedicated SQL Pool server name</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BPVEIjclp_03DEkXAT0ZRg.png" /><figcaption>Specify server name</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iDUpuQwIWiyvwUdPn0ibCg.png" /><figcaption>Select tables to import</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m7Gk3OdRANCyESecDy5Rqw.png" /><figcaption>Data Warehouse diagram</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s1SpIRklOsd6q6loYmPLDw.png" /><figcaption>Dashboard Creation</figcaption></figure><p>As shown in the images above, I created various <strong>charts and graphs</strong> to visualize <strong>business-related insights</strong> from the data warehouse.</p><p>Thank you very much for reading this project article! Feel free to share your <strong>feedback</strong> or suggestions related to this project. 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8a44eb4b0ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Oracle Integration to Import/Load AP Invoice using FBDI (Bulk Upload)]]></title>
            <link>https://medium.com/@dinunirmani9d/oracle-integration-to-import-load-ap-invoice-using-fbdi-bulk-upload-dde8dada923f?source=rss-18ac3d0fd723------2</link>
            <guid isPermaLink="false">https://medium.com/p/dde8dada923f</guid>
            <dc:creator><![CDATA[Dinushi Ariyasena]]></dc:creator>
            <pubDate>Tue, 30 Apr 2024 09:29:25 GMT</pubDate>
            <atom:updated>2024-04-30T09:29:25.315Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*64jHrU2kQGCPJP8Fh-cAow.png" /></figure><h3>Read AP Invoice Header &amp; AP Invoice Lines CSV files from SFTP server.</h3><p>In this integration we will read the AP invoice Header and AP invoice line file from SFTP server. Also we will add notification to send email in case of no data file found over SFTP server.</p><ol><li>First connect to the sftp server and upload source Header file &amp; Lines files.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4v83KMbETGKmuRzWRe8F5A.png" /></figure><p>2. In Integration cloud, create a REST connection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4sYiLe3BfETfvuJknCfeoA.png" /></figure><p>3. Then create a FTP connection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2edttcMd_VNpoAlG8Fa2ug.png" /></figure><p>4. Now create a new Integration with App Driven Orchestration style.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/0*0DI47y-PdrD-6VVw.png" /></figure><p>5. Add the REST end-point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lk3wMHO_w2fMmfjRfd-ehA.png" /></figure><p>6. Create Assign Action and assign directory paths for both files in SFTP server for 2 variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kdWf7x8oJq9_jEiuW8k-vQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YkZ5EuStmW-h4os1XOa-bg.png" /></figure><p>7. Add FTP adapter (with List operation) to read <strong>Header file</strong> from SFTP server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FIVX0EGLyNjvZymFrFNcOA.png" /></figure><p>8. Then map the header directory as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QQZ4ojMl9t85O_ntruNcwA.png" /></figure><p>9. Add switch action to check whether the header folder has only one file. If not, send notifications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*eLDGsGh4msT1QQkeYHlCbQ.png" /></figure><p>10. Now add FTP adapter to read Header file.<br>* Ready a Dummy Header file with all the columns available in the server and upload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UD2gHxVPLilLKQ2Pzdd-mw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rAPDkfN0GJiEigDEtY2f4g.png" /></figure><ul><li>In the mapping action, map the file name and the directory.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CIJEUSSttyUef3-u70vAMQ.png" /></figure><p>11. Add FTP adapter (with List operation) to read <strong>Line file</strong> from SFTP server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BKCbj38iaFmQkIxuJICg_g.png" /></figure><p>12. Then map the line directory as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2qFwO6yofYZDfMzv5Bizqg.png" /></figure><p>13. Add switch action to check whether the line folder has only one file. If not, send notifications.<br>* Create 2 more variables to from and to email addresses, to send notifications</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ouoMq6wh-W5bR01MTN38FA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*eIAzpzjXsVOYnj5Qd4ZISw.png" /></figure><p>14. Now add FTP adapter to read Line file.<br>* Ready a Dummy line file with all the columns available in the server and upload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-WoA-YZ8bpyDVw_hdN7CwA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*unrmgTK7BdSHXU-TKFljzw.png" /></figure><ul><li>In the mapping action, map the file name and the directory.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1-eJZDqwl3ibPFLug75Q2g.png" /></figure><h3>Create Properties file to add in ZIP for upload.</h3><p>In this part we will create the AP invoice header and Line CSV file based on FBDI template. Also we will create properties file and zip file to upload using ERP cloud adapter.</p><p><strong>Prerequisites<br></strong><em>* Ready a Header Interface file according to the FBDI format.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k1chPPYaiFzMF7V82_fZcg.png" /></figure><p><em>* Ready a Line file according to the FBDI format.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0VOqKwCaG8fXS199wanQPA.png" /></figure><p><em>* Ready the Property file for the bulk upload.(Properties file defines what kind of import program we have to execute.)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Iq1T_XjfRXu7PqzzGvf_7w.png" /></figure><ul><li>Create a new variable for temperory directory and zip directory.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GkCNxD3DgV-bmA-lah2oUQ.png" /><figcaption>temp directory path</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ykqqii5R1M9je9mT6Bup8A.png" /><figcaption>zip directory path</figcaption></figure><ul><li>Create another new variable for Import Set name.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jPW33KIiX7PjKRGCE4C5Cw.png" /><figcaption>Import set name</figcaption></figure><ol><li>Add stage operation to write header csv file</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*95SKGUk7msYWwlS8Sjpf-w.png" /></figure><ul><li>Select Header interface structure file.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1j1uh8k7TN5SSusbUptuqw.png" /></figure><p>2. Now map the columns with header structure file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XUV-GCXxFUAGsLvhdRzY0g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X768SHkDpNEPVrn0uzgVOw.png" /></figure><p>3. Add stage operation to write line csv file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pn63rpn8-rcYWacXXpGruQ.png" /></figure><ul><li>Select Line structure file.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sL-FvLy8SwsX7C98SHkt3Q.png" /></figure><p>4. Now map the columns with line structure file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tQBQuS2Gg442EHES9n60bw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XJa4oYwE8fCYXHcTmZO8dQ.png" /></figure><p>5. Create flags to identify both Interface file and Lines file created successfully.<br><em>* Create 2 variables and assign default values as ‘N’</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gaEJu1G-DGLR7mEXZPdXpQ.png" /></figure><ul><li>Update these variable values to ’N’ if both created successfully.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f-WeY8lun5JBpmNJelojjg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VcwGZGoNW-vLQ7Ax3xSWkQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*INlrdUy1_goLmg5Vi2gTWg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S56qecDsE6s0WlkiEyEPAQ.png" /></figure><p>6. Now create switch action to check whether the both flags update as ‘Y’.<br>(Check if both files created)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*gTyl2bOlGF01MtmfOY49GA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JzHFDtY6P9ot5EWTK8ZL6A.png" /></figure><p>7. Then use stage operation to create properties file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*dqE3atu9if488jLd7LiKow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kyvf9XZ9zHZcjNGkbVdq-g.png" /></figure><ul><li>Now create necessary variables for default values.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cbu8pRQdCqWqkeHKxmR1Jg.png" /></figure><ul><li>Now do the mapping of properties file.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w36hG-E1ptgezV2IcN2YMg.png" /></figure><p>Now our properties file is ready.</p><p>8. Now create the ZIP file by merging Header, Line and properties csv files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5epK3AL8Yya4R4QABnYNfQ.png" /></figure><ul><li>Use stage operation</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D7HRKiPylEZK3MkhERTmMA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PsJMJev3ZZ45lv1p3_wgWA.png" /></figure><ul><li>Add notification to send the zip file over email.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_E9-9uU-3OikbW9nWopKJw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*003VnErzwD8_wMRMI4bMgg.png" /></figure><h3>Upload ZIP file using ERP cloud adapter</h3><p>In this integration we will add Oracle ERP Cloud adapter connection to add the zip file for upload in oracle.</p><ol><li>Create ERP Cloud connetion.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S9qW4PiPNeHQQzzuu3Zx8w.png" /></figure><p>2. Create Oracle ERP Cloud adapter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ikpc97yrCiRFP15XZPRtdQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lw2WmoDK1W9mkxIfFP12ww.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1LSwKYuc-1azhJ55PZ2TvQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rj5oOWlUsC86EBYKjmvIfw.png" /></figure><p>3. Map the zip file properties.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cxIege013lGGeqnd9eXVTQ.png" /></figure><p>4. Now map the import process ID with integration response.</p><ul><li>Create assign value action to update import id.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SCjK7h7b-xaySBniXhWr1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ladTBecagK-jK2GC14rOjA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*nloG43RXvVivZ9SQrI8dKg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OiyO7asSmOMh_S5m7RhjQQ.png" /></figure><h3>Now Test the Integration</h3><p>If the Integration runs successfully, You will get zip file from email and ERP base tables will populate with the data you added to the file server.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dde8dada923f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ingesting Streaming Data from s3 to Snowflake using: Snowpipe]]></title>
            <link>https://medium.com/@dinunirmani9d/ingesting-streaming-data-from-s3-to-snowflake-using-snowpipe-b22462aeacb5?source=rss-18ac3d0fd723------2</link>
            <guid isPermaLink="false">https://medium.com/p/b22462aeacb5</guid>
            <dc:creator><![CDATA[Dinushi Ariyasena]]></dc:creator>
            <pubDate>Wed, 14 Feb 2024 12:35:01 GMT</pubDate>
            <atom:updated>2025-04-21T06:33:16.161Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9KhM4mKwtGvk7uAZu2uQYw.png" /></figure><p>In this article, I will guide you on how to use Snowpipe to automatically and continuously load data into snowflake.</p><h4>Table of Content</h4><p>· <a href="#779a">Create a stage in Snowflake for s3</a><br>· <a href="#6f77">Define a target table for the data</a><br>· <a href="#e72d">Create the Snowpipe</a><br>· <a href="#cccd">Get the AWS ARN (Amazon Resource Name)</a><br>· <a href="#7c74">Configure notifications for s3 bucket</a><br>· <a href="#05d0">Setup a data stream to the s3 bucket</a><br>· <a href="#1e3b">Get the data to snowflake in real time</a></p><h3>Create a stage in Snowflake DW</h3><ul><li>Database name -<em>‘Product’</em></li><li>Schema name -‘<em>public</em>’</li><li>Stage name - ‘<em>snowstage</em>’</li><li>s3 bucket name - ‘<em>data-streaming-real-time-using-snowpipe-bucket’.</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EVHn4G9wALv3_xTmNrU-5g.png" /></figure><pre>create or replace stage Product.public.snowstage<br>url=&#39;s3://data-streaming-real-time-using-snowpipe-bucket/&#39;<br>credentials = (AWS_KEY_ID=&#39;***********&#39;, AWS_SECRET_KEY=&#39;***********&#39;);</pre><h3>Define a target table for the data</h3><p>Target table name — ‘<em>snowtable</em>’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kHdC2bcM5UPjiTcX6Aw8CQ.png" /></figure><pre>--create target table for JSON data<br>create or replace table Product.public.snowtable<br>(<br>    jsontext variant<br>);</pre><h3>Create the Snowpipe</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2amQH3ImlcyJiwn-C4P_5w.png" /></figure><pre>--create a pipe to ingest JSON data<br>create or replace pipe Product.public.snowpipe auto_ingest=true as<br>    copy into Product.public.snowtable<br>    from @Product.public.snowstage<br>    file_format = (type = &#39;JSON&#39;);</pre><p><em>‘auto_ingest=true’ </em>means that we are using notifications from the s3 bucket into SQS (SQS is a message queuing service) to notify Snowflake about newly arrived data that is ready to load.</p><p>Now if we look the target table, we can see no data in the target table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2th2PO1ICIA_LFIAroJ-cg.png" /></figure><p>Use ‘show pipes’ statement to see all the pipes created.</p><pre>show pipes;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GCvD54L8m9hqcY9Yai7iaw.png" /></figure><h3>Get the AWS ARN (Amazon Resource Name)</h3><p>Copy the arn that is there under the ‘<em>notification channel’ </em>column</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RDnNksODv2bwmEezniToyg.png" /></figure><p>This is the ARN for the SQS queue where we need to send our s3 notifications to.</p><h3>Configure notifications for s3 bucket</h3><p>Create event notification</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bSPn98I5DWFrHJo4FyQygg.png" /></figure><p>Enter a name for the event</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*59QYTZxd5u7x2g-5ZwhuXg.png" /></figure><p>Tick on the <em>‘All object create event’</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y5o6bDP2M4DGcK0S20DZiA.png" /></figure><p>Select SQS queue as destination and paste the above copied ARN.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lE3LlcZdHzmgxO7YSe9lzw.png" /></figure><p>Then save the event notification.</p><h3>Setup a data stream to the s3 bucket</h3><p>For this project, let’s manually upload JSON files to the S3 bucket and verify whether the Snowflake target table is populating with that data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sW6gyBMN0G8XH_Y4jtTdxw.png" /><figcaption>Uploading a new data file to s3</figcaption></figure><h3>Get the data to snowflake in real time</h3><p>Now check the target table by executing the following query</p><pre>select *<br>from Product.public.snowtable;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X5IwASJTcAJEWJ3BKIrwYw.png" /></figure><p>Now you can see that the uploaded JSON data to the S3 bucket has automatically populated the Snowflake target table.</p><blockquote>As demonstrated above, if we set up a data stream to the S3 bucket, the streaming data will automatically be ingested into the Snowflake table.</blockquote><p><strong><em>Check out my article on streaming real-time data to an S3 bucket: </em></strong><a href="https://medium.com/@dinunirmani9d/changed-data-capture-pipeline-using-debezium-kafka-aws-s3-athena-1a53d91801c7">https://medium.com/@dinunirmani9d/changed-data-capture-pipeline-using-debezium-kafka-aws-s3-athena-1a53d91801c7</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b22462aeacb5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Oracle Business Intelligence Publisher Report Key Areas (BIP).]]></title>
            <link>https://medium.com/@dinunirmani9d/oracle-business-intelligence-publisher-report-key-areas-bip-75898f9d447d?source=rss-18ac3d0fd723------2</link>
            <guid isPermaLink="false">https://medium.com/p/75898f9d447d</guid>
            <dc:creator><![CDATA[Dinushi Ariyasena]]></dc:creator>
            <pubDate>Tue, 13 Feb 2024 05:16:04 GMT</pubDate>
            <atom:updated>2024-03-07T07:22:13.817Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*hG9GFNrNwlvHGszT7SDigg.jpeg" /></figure><p>In this article, I have described step-by-step the following areas related to Oracle Business Intelligence Publisher reports:</p><p>· <a href="#c289">Creating a Data Model</a><br>· <a href="#5bc0">Add a text Parameter to the Data Model</a><br>· <a href="#f944">Add a menu Parameter to the Data Model</a><br>· <a href="#8a0b">Create a Report using this Data Model</a><br>· <a href="#2d3b">Bursting a Report — By Email</a><br> ∘ <a href="#87fc">Alternative: Create an ESS job to send emails using bursting</a><br>· <a href="#d034">Create an ESS Job</a><br>· <a href="#e184">Event Triggers</a></p><h3>Creating a Data Model</h3><ol><li>Log in to Oracle Fusion Applications using your credentials.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NMDprVHbMPrSKpU5bNeuvw.png" /></figure><p>2. Then go to Tools in left-pane and select ‘Reports &amp; Analytics’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EPaAnF3hoTtZoWIXOGiXLw.png" /></figure><p>3. Click on ‘Browse Catalog’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ossFuny_pUOT2DQalF2TNw.png" /></figure><p>4. Then click on ‘Data Model’ under the create list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*I7d1rtRnK5c6fJ53bEOBNQ.png" /></figure><p>5. Click on ‘SQL Query’ to create a data set using SQL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rdriP8yX1xbpbU1JelZxXw.png" /></figure><p>6. Enter a name for the data set, select FSCM as data source and write the SQL query.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5j8R1XDkAckUC1sqKzRbRA.png" /><figcaption>This is the sql query that I used</figcaption></figure><pre>select po.SEGMENT1 PO_NUMBER, pr.PARTY_NAME SUPPLIER_NAME, v.SEGMENT1 SUPPLIER_NUMBER, li.PO_LINE_ID, li.UNIT_PRICE * NVL(li.QUANTITY, 1) AMOUNT<br>from PO_HEADERS_ALL po<br>join POZ_SUPPLIERS v<br>ON po.VENDOR_ID = v.VENDOR_ID<br>join HZ_PARTIES pr<br>ON v.PARTY_ID = pr.PARTY_ID<br>join PO_LINES_ALL li<br>ON po.PO_HEADER_ID = li.PO_HEADER_ID</pre><p>7. Check the Diagram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tpin5LCOzkS1OATUYB63Pw.png" /></figure><p>8. View the Data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qW2UPYPtq_5t2SbgtMuFrA.png" /></figure><p>9. Save this Data as Sample data for our data model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QCyrtEFqSNoPFpDdZsohkQ.png" /></figure><p>10. Save the data model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T2xJtuPhMRRDW35CogVh-w.png" /></figure><p>11. Provide a name for the data model and Save!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*EKra5i_dgVzy-pXHYIVdVQ.png" /></figure><h3>Add a text Parameter to the Data Model</h3><ol><li>Go to the ‘Edit data set’ option</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hAHzG0ed1zdgB2KK_kNm1w.png" /></figure><p>2. Edit SQL query as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VrbtmErAn5XAMBHsWos77Q.png" /></figure><p>Add a were clause to filter data according to a column in data set. ‘your_column’ is the selected column from data set and ‘:YourParameter’ is the name you are giving to the parameter.</p><pre>WHERE (your_column = :YourParameter OR :YourParameter IS NULL)</pre><p>In here, <strong><em>‘OR :YourParameter IS NULL’</em></strong> part is added because I wanted to retrieve all the data when I am not entering a value to the filter. If you do not want to retrieve data when a filter is not added, then use only the <strong><em>‘WHERE your_column = :YourParameter’</em></strong> part.</p><p>3. Now go to the ‘parameters’ section</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zfwjNtrOjg-vl4-x1O6HQw.png" /></figure><p>4. Enter the parameter name (should be same as ‘YourParameter’ name) and add any name as Display Label.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*_pDwzId8XLgRajUGZGcsQg.png" /></figure><p>5. Now view the data. You may see a filter is added to the data set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gSX291K16vQnV5HlYeElUw.png" /></figure><h3>Add a menu Parameter to the Data Model</h3><ol><li>First of all we need to create a List of Values before creating a menu parameter</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8b60tCEX-9tarDTOdwiyYg.png" /></figure><p>2. Create List of Values using a SQL Query</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*xB_XbUeHsrt7sxg3AowNgg.png" /></figure><p>3. Edit the Data Set to capture the menu parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*piFW_nMDyij2R-wNXC3Sag.png" /></figure><p>4. Create the Menu Parameter as follows. Select Parameter type as ‘Menu’ and select above created list of values for the menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*JsQSn-JnfeWIxxKML-rsYw.png" /></figure><p>5. Now you may see the new menu parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VCn1m32x4Et0wioweoAwrQ.png" /></figure><p>6. Filtered Results!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cMag2B0v06_-DxBDPFJyaA.png" /></figure><h3>Create a Report using this Data Model</h3><ol><li>Click on ‘Create Report’</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nnSXHrJiw7495xvv9SAB-w.png" /></figure><p>2. Check the data model is selected</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*2q0s1HqCN25wpwpylvPxfg.png" /></figure><p>3. Select Layout for the report</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*yYIEvlPubTFBmIrlDAKJJg.png" /></figure><p>4. Drag fields from the Data Source to create the table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*jiaBfBV6c6ZqETjhyC3GZw.png" /></figure><p>5. Save Report!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*lcxljkszvGrwBVhEraTELg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*4MC2xVsGtcd8sVYl8xdyoA.png" /></figure><p>6. Now you may see the report we created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UmkP8E0nzUzEZIwvTFGCCQ.png" /></figure><h3>Bursting a Report — By Email</h3><ol><li>Edit Data Model</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tC1ZbY0Mt1iMcE_ZDDls4Q.png" /></figure><p>2. Go to the ‘Bursting’ section and click on + sign to add new bursting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1tEV4Rm8PuODmHCN2b0h6w.png" /></figure><p>3. Provide a name, select <em>‘SQL Query’</em> as type, select <em>‘FSCM’</em> as data source, select parameters for <em>‘split by’</em> and <em>‘deliver by’.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LrJ_OjpRhmpGNXe5Zd6FLg.png" /></figure><p>4. Provide the SQL Query.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IdVUHP1AxnsKjycYcCV3Wg.png" /></figure><pre>select PARTY_NAME KEY, --KEY is the Delivery key and must match the Deliver By element<br>&#39;ReportByDinu&#39; TEMPLATE, --name of the Layout to apply<br>&#39;en-US&#39; LOCALE,   --language<br>&#39;PDF&#39; OUTPUT_FORMAT,    --output format (html, pdf, ppt, xml, etc)<br>&#39;EMAIL&#39; DEL_CHANNEL,<br>&#39;Bursting Practice&#39; OUTPUT_NAME, --output file name<br>&#39;dariyasena.ext@deloitte.com&#39; PARAMETER1, --To email address<br>&#39;dinunirmani9d@gmail.com&#39; PARAMETER2,   --cc<br>&#39;no-reply@oracle.com&#39; PARAMETER3,      --from<br>&#39;SUPPLIER INFO&#39; PARAMETER4,    --Email Subject<br>&#39;Please Ignore!! BURSTING PRACTICE. PLEASE FIND THE DETAIL IN THE ATTACHMENT.&#39; PARAMETER5, --Email Body<br>&#39;true&#39; PARAMETER6 --Attachment value (&#39;true&#39; or &#39;false&#39;)<br>from HZ_PARTIES<br>WHERE PARTY_NAME in (&#39;Ace Steel Inc&#39;, &#39;MI SUPP&#39;, &#39;Vendor ABC&#39;)</pre><p>Check how to write bursting query : <a href="https://docs.oracle.com/cd/E21764_01/bi.1111/e18862/T527073T555155.htm">https://docs.oracle.com/cd/E21764_01/bi.1111/e18862/T527073T555155.htm</a></p><p>5. Enable bursting on the report.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*xmETNOsYonZNOqF-JMSLuw.png" /></figure><p>Go to the edit mode and Enable Bursting</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cxfMFSnWY7kc7XqLjwPLTQ.png" /></figure><p>After enabling bursting, schedule the report as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/249/1*4ROHmsK00cRcpFfnEvCQjQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UjhrwIdSwrR1QEuLf33-RA.png" /></figure><p>Now check the email inbox!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*hItOwm8JflWhbLzTvsTChA.png" /></figure><h4>Alternatively we can Create an ESS job to send emails using bursting</h4><h3>Create an ESS Job</h3><p>1. Go to ‘My Enterprice’ and then select ‘Setup and Maintanance’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NOZSG8fomUoWklQmlwBbtA.png" /></figure><p>2. Select ‘Search’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*OIODEycgrM7Aqo4NSb5QrA.png" /></figure><p>3. Search as <em>‘Manage%Scheduler’</em> and select FSCM option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wJv9z-owLLaRHYHbuR9CTA.png" /></figure><p>4. Click on + sign</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d3BoKhkN2M8Pf1vmB4Q3Eg.png" /></figure><p>5. Enter details as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iG3T3qkNsibB1uW_TNNHWQ.png" /></figure><p>6. Go to the report’s schedule option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NLM2xp22x6bsO3uaIWswag.png" /></figure><p>7. Copy the ‘Report Name’ from there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*olSKNT_-q8KzLjRcvM3aEw.png" /></figure><p>8. Paste it as a Report ID</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eShtmyrLScTNG5rpGFW53Q.png" /></figure><p>9. Save and Close</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*up5ue0FKz6o4pyzNQzznNw.png" /></figure><p>10. Go to the tools and select Scheduled Process</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*8L6JAU9NUpkVYmZ8Re1m8g.png" /></figure><p>11. Select Schedule New Process</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oQFWQUJzoMUwy6ISZ6i1-Q.png" /></figure><p>12. Click on Search option</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*-TbNnchoQ-WILfCxpbhK_A.png" /></figure><p>13. Search the scheduler we created above</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*hxtv-PFD4ce_FTmzNMUWJw.png" /></figure><p>14. Select and click on ‘OK’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*HVL3XChId3-qHUou2AKuIQ.png" /></figure><p>15. Submit the process</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*feM3hViCUbP0ldC--cr2AA.png" /></figure><p>16. After submitting the process, we can see the bursting reports are coming to the email address we provided.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dJtlLrGllt7XAMzLVeu7Dg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*LXW3p-gV-cjGF7YsXyYTPQ.png" /></figure><h3>Event Triggers</h3><ol><li>Click the ‘Schedule’ on report.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WCTDysus1_znaAZpHQBaRw.png" /></figure><p>2. Go to the ‘Output’ pane.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kdbDwSEuUOl4ppB4F7QCKA.png" /></figure><p>3. Add a destination email address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*_X3GRck2PnmooFSxMgrbxg.png" /></figure><p>4. Select frequency</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*M5nJ2sFjXvuPJS2k6LkXIg.png" /></figure><p>5. Submit the report job</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8VywCCh3nPVl2Jd0v4H4wQ.png" /></figure><p>6. Enter a name for report job</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*JieVJ775On7n0F175Jzahg.png" /></figure><p>7. Now go to the ‘history’ and check the job status.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*iGmBXZb-RH31rRn58aDYPg.png" /></figure><p>8. You may see the job status as ‘Success’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o5SlqnTAGgKdNVNF8ft62A.png" /></figure><p>9. Check the destination inbox.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/1*MR4qPOBgHmSu6wh12J8wtQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*95AC4mEyNcYQ_qnL3_rZyw.png" /></figure><h4>If our report does not contains any data, then our report job will run with the message saying ‘Failed’. But if our requirement is to see the job status as ‘Skipped’ instead of ‘failed’ when report contains no data, how can we do that?? Lets do that now!</h4><ol><li>Edit the data model to return no data.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*ucUSfVfc7Cbk83OFEjkQfQ.png" /></figure><p>2. You can see, no data returning for the new data set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tz6rg1XAtUYeeIKORKeaTg.png" /></figure><p>3. Now create an event trigger.<br>* Use same SQL query used for the data model without select columns. Instead use 1 in select. (If query returns some data, then it will execute the schedule. If this query does not returns any data, it will not execute the schedule)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*aSK1Ku3gm69D36oBXUrVLQ.png" /></figure><p>4. Now you may see the new event trigger.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*FjUUyhKOjBC5ptZdUrNOjg.png" /></figure><p>5. Check the report. No data is showing in the report.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fcdXJRygjokvtEVEeTKEcg.png" /></figure><p>6. Go to the report schedule section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VOKipWfLP_0WoSepTSCaBw.png" /></figure><p>7. Add a destination email address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_8tk_NohW2bx_zajrPVABw.png" /></figure><p>8. Use trigger we created in the data model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*2sqbN6oY5Xn9LDuBGW7-VQ.png" /></figure><p>9. Provide a name and submit the report job.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*smbW5icyB8iVt6N5XTNC2A.png" /></figure><p>10. Now check the report job history. You can see the job status is ‘Skipped’ because data model does not returns any data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mYRNyA7HmL-4imFUPQl_MA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75898f9d447d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Changed Data Capture Pipeline using Debezium, Kafka, AWS S3 & Athena]]></title>
            <link>https://medium.com/@dinunirmani9d/changed-data-capture-pipeline-using-debezium-kafka-aws-s3-athena-1a53d91801c7?source=rss-18ac3d0fd723------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a53d91801c7</guid>
            <dc:creator><![CDATA[Dinushi Ariyasena]]></dc:creator>
            <pubDate>Tue, 30 Jan 2024 17:35:13 GMT</pubDate>
            <atom:updated>2024-02-19T13:45:34.172Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S9GQURZSbTa_YOxfDevRGA.png" /></figure><p>In this project, I’ve successfully implemented an end-to-end real-time Change Data Capture (CDC) pipeline from SQL Server to AWS Athena. When a data change occurs in the SQL Server database, the changes are captured in real-time through Debezium, and that data is streamed to a Kafka topic. <br>A Python script processes the data from the Kafka topic and seamlessly directs these real-time changes to an S3 bucket. Subsequently, a Glue crawler is used to automatically populate a Glue database with the data stored in the S3 bucket. <br>Using Athena, users can perform queries to analyze and retrieve insights from the continuously updating dataset, providing an efficient and dynamic solution for real-time data exploration.</p><h4>Table of Content</h4><p>· <a href="#e6b4">Create 2 EC2 machines</a><br>· <a href="#7f89">Setup SQL - Server on Linux-EC2</a><br>· <a href="#8d0f">Setup Kafka on Linux-EC2</a><br>· <a href="#1ec7">Setup Debezium-SQL Server Connector on EC2</a><br>· <a href="#2f18">Consume Real-Time Changes under Kafka Topic</a><br>· <a href="#0ed3">Streaming this real-time changes to S3 Bucket</a><br>· <a href="#bc3c">Extend the data pipeline from s3 to Glue Database</a><br>· <a href="#99fa">Query Data using Athena</a></p><p><strong><em>Step-by-step guide on how I built this pipeline</em></strong></p><h3><strong>Create 2 EC2 machines</strong></h3><ol><li>1st EC2 —To Setup SQL Server</li><li>2nd EC2 — To setup Kafka</li></ol><h3><strong>Setup SQL - Server on Linux-EC2</strong></h3><ol><li><strong>Download SQL-Server</strong></li></ol><pre>sudo yum update -y<br><br>sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc<br><br>sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2019.repo<br><br>sudo yum install -y mssql-server<br><br>sudo /opt/mssql/bin/mssql-conf setup<br><br>systemctl status mssql-server</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FYNpnUi0TXhiLlweOyElYw.png" /></figure><p><strong>2. Setup SQL command-line tools</strong></p><pre>sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/8/prod.repo<br><br>sudo yum remove unixODBC-utf16 unixODBC-utf16-devel<br><br>sudo yum install -y mssql-tools unixODBC-devel<br><br>echo &#39;export PATH=&quot;$PATH:/opt/mssql-tools/bin&quot;&#39; &gt;&gt; ~/.bash_profile</pre><p><strong>3. Enable SQL Server Agent</strong></p><ul><li>SQL server agent is required to capture CDC changes.</li></ul><pre>sudo /opt/mssql/bin/mssql-conf set sqlagent.enabled true <br><br>sudo systemctl restart mssql-server</pre><p><strong>4. Connect to SQL server and create a database and a table</strong></p><pre>sqlcmd -S localhost -U sa -P password</pre><pre>CREATE DATABASE Products;<br><br>USE Products;<br>GO<br><br>CREATE TABLE dbo.product (id INT, name NVARCHAR(50), quantity INT, PRIMARY KEY (id));<br><br>INSERT INTO dbo.product VALUES (1, &#39;p1&#39;, 154);<br>INSERT INTO dbo.product VALUES (2, &#39;p4&#39;, 160);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VYqfsmjjOwCxL4j4dkj8Tg.png" /></figure><p><strong>5. Enable CDC on Database and Tables</strong></p><ul><li>To capture CDC (Change Data Capture) on a SQL Server database table, we need to enable CDC on the database and the necessary tables</li></ul><pre>USE Products;<br>EXEC sys.sp_cdc_enable_db;<br>GO<br><br>EXEC sys.sp_cdc_enable_table @source_schema = &#39;dbo&#39;, @source_name = &#39;product&#39;, @role_name = NULL;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3G9VDMM8fnqKg8B78NHjBQ.png" /></figure><h3>Setup Kafka on Linux-EC2</h3><ol><li><strong>Download java-11</strong></li></ol><ul><li>Debezium, being a Java-based platform, typically requires Java 11 or a higher version to run successfully</li></ul><pre>sudo amazon-linux-extras install java-openjdk11<br>java -version</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yGCgYXsqwc0aUISf-R5GWw.png" /></figure><p><strong>2. Download Apache Kafka and Unzip</strong></p><pre>wget https://dlcdn.apache.org/kafka/3.5.0/kafka_2.13-3.5.0.tgz<br><br>tar -xzf kafka_2.13-3.5.0.tgz</pre><p><strong>3. Edit<em> the ‘server.properties’ </em>file in config folder as follows</strong></p><pre>cd kafka_2.13-3.5.0<br><br>vi config/server.properties<br><br>Uncomment &quot;advertised.listeners=PLAINTEXT://&lt;host-ip&gt;:9092&quot; line<br>Add host ip address inside &lt;&gt;</pre><p><strong>4. Edit the <em>‘connect-distributed.properties’</em> file in config folder as follows</strong></p><ul><li>Uncomment “plugin.path” line at the bottom of the file.</li><li>Edit that line as follows:<br><em>plugin.path=/home/ec2-user/kafka_2.12–3.2.3/libs</em></li><li><em>bootstrap.servers=&lt;host-ip&gt;:9092</em></li><li><em>group.id=debezium</em></li><li><em>listeners=HTTP://localhost</em></li><li><em>rest.advertised.host.name=localhost</em></li><li><em>rest. advertised.port=8083</em></li></ul><h3>Setup Debezium-SQL Server Connector on EC2</h3><p><em>Edit the inbound rules for both EC2 instances to allow all traffic.</em></p><ol><li><a href="https://repo1.maven.org/maven2/io/debezium/debezium-connector-sqlserver/2.5.1.Final/debezium-connector-sqlserver-2.5.1.Final-plugin.tar.gz"><strong>Download the Debezium connector for the SQL Server</strong></a></li></ol><p><strong>2. Transfer all the Debezium <em>jar</em> files to Kafka <em>libs</em> folder</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GSUvCmLPYtH5nqwXrN1Lug.png" /></figure><p><strong>3. Create the configuration file as <em>‘sqlserver.json’</em> inside <em>config</em> folder</strong></p><pre>vi sqlserver.json</pre><p><strong>4. Add the following JSON content to it and save it. (edit database.hostname)</strong></p><pre>{                                                                                                                                                                              <br>        &quot;name&quot;: &quot;sqlserver-connector&quot;,                                                                                                                                         <br>        &quot;config&quot;: {                                                                                                                                                            <br>                &quot;connector.class&quot;: &quot;io.debezium.connector.sqlserver.SqlServerConnector&quot;,                                                                                       <br>                &quot;tasks.max&quot;: &quot;1&quot;,                                                                                                                                              <br>                &quot;database.hostname&quot;: &quot;&lt;sql-server-host-ip&gt;&quot;,                                                                                                                              <br>                &quot;database.port&quot;: &quot;1433&quot;,                                                                                                                                       <br>                &quot;database.user&quot;: &quot;sa&quot;,                                                                                                                                         <br>                &quot;database.password&quot;: &quot;password&quot;,                                                                                                                            <br>                &quot;database.server.name&quot;: &quot;myserver&quot;,                                                                                                                            <br>                &quot;database.names&quot;: &quot;products&quot;,                                                                                                                                     <br>                &quot;topic.prefix&quot;: &quot;history&quot;,                                                                                                                                     <br>                &quot;table.include.list&quot;: &quot;dbo.product&quot;,                                                                                                                            <br>                &quot;schema.history.internal.kafka.topic&quot;: &quot;myserver_history&quot;,                                                                                                     <br>                &quot;schema.history.internal.kafka.bootstrap.servers&quot;: &quot;localhost:9092&quot;,                                                                                           <br>                &quot;database.encrypt&quot;: false                                                                                                                                      <br>        }                                                                                                                                                                      <br>}</pre><p><strong>5. Now start Zookeeper using the following command</strong></p><pre>bin/zookeeper-server-start.sh config/zookeeper.properties</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*__9BO7PeWDZF-IA1gFT7fw.png" /></figure><p><strong>6. Start Kafka Server</strong></p><pre>bin/kafka-server-start.sh config/server.properties</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KsGVCUChF4_zPxeqdy-QJQ.png" /></figure><p><strong>7. Start Kafka Connect</strong></p><pre>bin/connect-distributed.sh config/connect-distributed.properties</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vFVMC-YfysHWuJNxMVfCOQ.png" /></figure><p><strong>8. Deploy the connector</strong></p><pre>curl -X POST -H &quot;Content-Type: application/json&quot; --data @config/sqlserver.json http://localhost:8083/connectors</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hWRo5lyTOvJvnKPiQGh3Ug.png" /></figure><p><strong>9. Check connector status</strong></p><pre>curl http://localhost:8083/connectors/sqlserver-connector/status</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dVUrS6Yz8tUABMkDT_iqYQ.png" /></figure><h3>Consume Real-Time Changes under Kafka Topic</h3><ol><li><strong>Check the existing topic list</strong></li></ol><pre>bin/kafka-topics.sh --list --bootstrap-server &lt;host-ip&gt;:9092</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zcalnFM0bCAJCSO4VBa90g.png" /></figure><p>You can see <em>history.Products.dbo.product</em> topic is automatically created. Consume that topic.</p><p><strong>2. Start consuming under the relevant topic</strong></p><p>All the data changes to SQL-server will appear under this topic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BwT17QZHByJD8Q_WJAhWVw.png" /></figure><h3>Streaming this real-time changes to S3 Bucket</h3><ol><li><strong>Create a new S3 bucket</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jQcSE4XJi13MschCORHtug.png" /></figure><p><a href="https://aws.amazon.com/cli/"><strong>2. Download AWS CLI tools on the local machine</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7MIUxgYR7z8Of0JpI0lNsg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wwej9yz_s23_awohWrbkyw.png" /></figure><p><strong>3. Write a Python script to upload changes from Kafka to S3</strong></p><pre>pip install kafka-python<br>pip install s3fs<br>pip install boto3</pre><pre>import pandas as pd<br>from kafka import KafkaConsumer<br>from time import sleep<br>from json import dumps,loads<br>import json<br>from s3fs import S3FileSystem<br>import boto3</pre><pre>consumer = KafkaConsumer(<br>    &#39;history.Products.dbo.product&#39;,<br>    bootstrap_servers=[&#39;&lt;kafka-host-ip&gt;:9092&#39;],<br>)</pre><pre>s3 = S3FileSystem()</pre><pre>for count, c in enumerate (consumer):<br>  if c.value is not None:<br>    output = c.value<br>    output = output.decode(&#39;utf-8&#39;) <br>    data = json.loads(output)<br>    payload_data = data.get(&#39;payload&#39;, {})<br><br>    before_data = payload_data.get(&#39;before&#39;, {})<br>    after_data = payload_data.get(&#39;after&#39;, {})<br>    before_id = before_data[&#39;id&#39;] if before_data is not None else 0<br>    after_id = after_data[&#39;id&#39;] if after_data is not None else 0<br>    <br>    # INSERT<br>    if before_data is None:<br>      with s3.open(&quot;s3://data-streaming-real-time-using-debezium-bucket/cdc_change_{}.json&quot;.format(after_id), &#39;w&#39;) as file:<br>        json.dump(after_data, file)<br>    <br>    # DELETE<br>    if after_data is None:<br>      #code to remove before_data file from s3<br>      s3 = boto3.client(&#39;s3&#39;)<br>      bucket_name = &quot;data-streaming-real-time-using-debezium-bucket&quot;<br>      file_key = &quot;cdc_change_{}.json&quot;.format(before_id)<br>      s3.delete_object(Bucket=bucket_name, Key=file_key)<br><br>    # UPDATE<br>    if before_data is not None and after_data is not None:<br>      #code to remove before_data file from s3<br>      s3 = boto3.client(&#39;s3&#39;)<br>      bucket_name = &quot;data-streaming-real-time-using-debezium-bucket&quot;<br>      file_key = &quot;cdc_change_{}.json&quot;.format(before_id)<br>      s3.delete_object(Bucket=bucket_name, Key=file_key)<br>      #code to add after_data file to s3<br>      s3 = S3FileSystem()<br>      with s3.open(&quot;s3://data-streaming-real-time-using-debezium-bucket/cdc_change_{}.json&quot;.format(after_id), &#39;w&#39;) as file:<br>        json.dump(after_data, file)</pre><ul><li>When a new record is INSERTED into a SQL Server database table, this Python script adds that record as a new file to the S3 bucket.</li><li>In the case of an UPDATE to a record in the SQL Server database table, the Python script deletes the file related to the record before the update from the S3 bucket. Additionally, it adds the UPDATED new record as a new file to the S3 bucket.</li><li>If a record is DELETED from the SQL Server database table, the Python script deletes the file related to that record from the S3 bucket.</li></ul><p><strong>4. Check whether the pipeline is working from SQL-Server to S3 bucket</strong></p><ul><li>Run the Python Script</li><li>Insert/Delete/Update some records to SQL Server table</li><li>Check the S3 bucket (refresh the bucket). If the pipeline is correctly configured so far, we should observe that each table change will be automatically uploaded to S3 as separate JSON files.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1u12vWQMeda-K3_pSIgqyw.png" /></figure><h3>Extend the data pipeline from s3 to Glue Database</h3><ol><li><strong>Create a new database in the AWS Glue Data Catalog</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uYnbd4XWE0Kac4WOTtfhZg.png" /></figure><p><strong>2. Setup a Glue Crawler to crawl data from s3 to Glue Database</strong></p><ul><li>Give a name to the Crawler</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vbWXCCI8gwt2kVFm5WZDgw.png" /></figure><ul><li>Choose the s3 bucket above created for the data source s3 path</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1b6ovBoWRUO-sGcG6QLuvw.png" /></figure><ul><li>We need to have an IAM role with Glue-access</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*97CwMqDnUdwOmpw5wN-85g.png" /></figure><ul><li>Choose the above created Glue database as target database</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k98I9lnHH8iUHz1oajUAqQ.png" /></figure><p><strong>3. Run the crawler and check whether the Glue database is populated with the data.</strong></p><h3>Query Data using Athena</h3><ol><li><strong>Create a separate s3 bucket to store query results</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HvKRkvtany2-32bjJugYMQ.png" /></figure><p><strong>2. Start querying data in Athena</strong></p><pre>SELECT * FROM &quot;products_database&quot;.&quot;data_streaming_real_time_using_debezium_bucket&quot; limit 10;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MD2N48l6QS29epHSKJmwdA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FS7vit1UgwdN26ZWGf90-w.png" /></figure><blockquote><strong>Finally!!! Check whether the whole pipeline is working from SQL-Server to AWS Athena in Real-Time Successfully!</strong></blockquote><ul><li><strong>Make sure the Python script is running</strong></li><li><strong>Insert/Delete/Update some records to the SQL Server table</strong></li><li><strong>Run the ‘SELECT *’ command in Athena repeatedly to verify whether the data changes from the SQL Server database are reflected in the Athena query results.</strong></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a53d91801c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>