<?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 Lakshika Amarasinghe on Medium]]></title>
        <description><![CDATA[Stories by Lakshika Amarasinghe on Medium]]></description>
        <link>https://medium.com/@lakshikaamarasinghe?source=rss-1e22e3d38308------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mTAEolcGZ16k4DS35wRJXg.jpeg</url>
            <title>Stories by Lakshika Amarasinghe on Medium</title>
            <link>https://medium.com/@lakshikaamarasinghe?source=rss-1e22e3d38308------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 13:15:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lakshikaamarasinghe/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[Connect Azure Data Factory and Azure SQL Database using System-Assigned Managed Identity]]></title>
            <link>https://medium.com/@lakshikaamarasinghe/connect-azure-data-factory-and-azure-sql-database-using-system-assigned-managed-identity-3bf8292352b5?source=rss-1e22e3d38308------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bf8292352b5</guid>
            <dc:creator><![CDATA[Lakshika Amarasinghe]]></dc:creator>
            <pubDate>Mon, 20 Feb 2023 15:52:31 GMT</pubDate>
            <atom:updated>2023-02-20T15:52:31.955Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog post, we will discuss how to configure Azure Data Factory to use a system-assigned managed identity to connect to Azure SQL Database securely 😎.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*9UObGraX3H8d3BO1VQOxZw.png" /></figure><p>Let’s start by configuring the Azure SQL Database.</p><h4>➡️Configuring Azure SQL Database</h4><ol><li>Go to the SQL server and check if an Azure Active Directory Administrator is already provisioned to the SQL Server to which the Azure SQL database belongs. If the server doesn’t have an AAD Admin click on set admin and <a href="https://learn.microsoft.com/en-us/azure/azure-sql/database/authentication-aad-configure?view=azuresql&amp;tabs=azure-powershell#provision-azure-ad-admin-sql-database">provision an admin</a>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HVFu1H3ibs_2Ck3NZJCm9A.png" /></figure><p>2. Connect to the <strong>database</strong> using a tool like SQL Server Management Studio, using the above admin-assigned AD identity or any Azure AD identity that has at least ALTER ANY USER permission.</p><p>3. Create a contained database user for the system-assigned managed identity using the below script. If you get an error at this step. <strong>Please refer section at the end of this article.</strong></p><pre><br>IF NOT EXISTS  (SELECT * FROM sys.sysusers WHERE islogin = 1 AND name =&#39;df-test-data-factory&#39;) <br><br>BEGIN<br>  CREATE USER [df-test-data-factory] FROM EXTERNAL PROVIDER;<br>END</pre><p>3. Above 2 steps are sufficient to create and test the connectivity. Grant necessary permission same as you do for SQL users to execute data reads, data writes, and stored procedure executions from the ADF side.</p><pre>EXEC sp_addrolemember &#39;db_datareader&#39;,&#39;df-test-data-factory&#39;</pre><h4>➡️Configuring Azure Data Factory</h4><ol><li>Launch ADF studio &gt; Manage &gt; Linked services. Select a new linked service as Azure SQL Database. After assigning server and database details assign the <strong>Authentication type</strong> as <strong>System Assigned Managed Identity </strong>type. This can be done to an already existing Azure SQL Database linked service as well.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*UUTUkOZVubkoBWK5z4RwQg.png" /><figcaption>AzureSQLDatabaseLinkedService</figcaption></figure><p>2. Hit on the Test connection to test the connectivity.</p><p>If all is well you should get a “Connection successful” message. If you get Connection failed message. Keep reading.</p><h4>⛔️Possible Issues you might face and the resolutions</h4><ol><li><em>When Configuring Azure SQL Database</em></li></ol><p>❗️<strong>Issue:</strong> “Principal ‘{the name you used for the user}’ could not be found or this principal type is not supported.”</p><p>✅<strong>Resolution: </strong>Use the <strong>exact data factory name </strong>as the username of the new user in your script.</p><p><em>2. When Configuring ADF Linked Service</em></p><p>❗️<strong>Issue: </strong>Cannot connect to SQL Database. Please contact SQL server team for further support. Server: ‘servername.database.windows.net’, Database: ‘databasename’, User: ‘’. Check the linked service configuration is correct, and make sure the SQL Database firewall allows the integration runtime to access. Login failed for user ‘&lt;token-identified principal&gt;’., SqlErrorNumber=18456,Class=14,State=1, Activity ID: 9d0ef71c-30c0–465d-84.</p><p>✅<strong>Resolution: </strong>Check if you have selected the correct database (for which you have created the managed instance identity) in the linked service. Or else check if you have done the ASQL configuration against the correct database.</p><p>In this post, I’ve provided a step-by-step guide on how to use a system-assigned managed identity to connect Azure Data Factory and Azure SQL Database. By using this approach, you can avoid the need to store credentials in your ADF Linked services or keep them in a key vault, making your solution more secure and easier to manage. I hope this post will be a helpful resource for anyone looking to implement this solution 😊.</p><p><strong>Reference</strong></p><p><a href="https://learn.microsoft.com/en-us/azure/data-factory/connector-azure-sql-database?tabs=data-factory#managed-identity">Copy and transform data in Azure SQL Database - Azure Data Factory &amp; Azure Synapse</a></p><p>Thanks for reading my article 🤗.</p><p>Feel free to follow me for more content 🧡.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bf8292352b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure SQL Database Maximizing Storage Efficiency: A Guide to Checking Table Space Consumption]]></title>
            <link>https://medium.com/@lakshikaamarasinghe/maximizing-storage-efficiency-a-guide-to-checking-table-space-consumption-in-azure-sql-databases-5c87e3b09de0?source=rss-1e22e3d38308------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c87e3b09de0</guid>
            <category><![CDATA[azure-sql-database]]></category>
            <dc:creator><![CDATA[Lakshika Amarasinghe]]></dc:creator>
            <pubDate>Sat, 04 Feb 2023 03:32:31 GMT</pubDate>
            <atom:updated>2023-02-08T08:42:01.463Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently we encountered an issue with one of our Azure SQL databases saying “{Database Name} has reached its size quota. Partition or delete data, drop indexes or consult the documentation for possible resolutions” and the data storage view from the Azure portal was as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/246/1*sRnZYvDvxTwQDlW-h79e-w.png" /><figcaption>Azure SQL database data storage view</figcaption></figure><p>While we were addressing the issue we wanted to check the storage consumption of each table in the database. Do you know how to do that? 🤔.</p><p>If not keep reading.</p><p>In this post, we will look at a query that provides a simple way to retrieve information about the physical storage of data in a database, including the name of the object, schema name, and size of the object in MB.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bfd3e2c9c3d5e0b291f8ae2f31ffb77b/href">https://medium.com/media/bfd3e2c9c3d5e0b291f8ae2f31ffb77b/href</a></iframe><p>The sys.dm_db_partition_stats DMV is a valuable tool for database administrators, developers, and data engineers to understand the physical storage of data within database partitions. The query starts by joining the sys.dm_db_partition_stats DMV with the sys.objects and sys.schemas system views. The sys.dm_db_partition_stats DMV provides information about the physical storage of data within a table or index partition, while the sys.objects view contains information about all objects in a database, and the sys.schemas view contains information about the schemas in a database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*NQLCtuAThTxhgYmDDz1W0A.png" /><figcaption>Result of the query on AdventureWorksDatabase</figcaption></figure><p>Databases can quickly grow in size, making it important to monitor the physical storage of data in a database. By using this query in Azure SQL / SQL server you can monitor the physical storage of data in your database. This information can be used for various purposes, such as monitoring database growth, capacity planning, and performance optimization. With Azure SQL, you can take advantage of the high performance, scalability, and security offered by the cloud, and ensure that your database is performing optimally with enough disk space for storing your data.</p><p>Save the script and thank me later 😉.</p><p>Thanks for reading my article 🤗.</p><p>Feel free to follow me for more content 🧡.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c87e3b09de0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Snowflake Stream and Task Use Case]]></title>
            <link>https://selectfrom.dev/snowflake-stream-and-task-use-case-8f0fbed95d39?source=rss-1e22e3d38308------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f0fbed95d39</guid>
            <category><![CDATA[snowflake-computing]]></category>
            <category><![CDATA[snowflake-data-cloud]]></category>
            <category><![CDATA[snowflake]]></category>
            <dc:creator><![CDATA[Lakshika Amarasinghe]]></dc:creator>
            <pubDate>Tue, 14 Jun 2022 06:41:55 GMT</pubDate>
            <atom:updated>2022-07-15T13:19:30.927Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JhfFUDBWd2qWK7lV" /><figcaption>Photo by <a href="https://unsplash.com/@dariuscotoi?utm_source=medium&amp;utm_medium=referral">Darius Cotoi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this article, we are going to look at how to automate a Snowflake procedure execution as soon as a Snowflake table is loaded with data. For the implementation, the following Snowflake features are used.</p><ul><li><a href="https://docs.snowflake.com/en/user-guide/streams-intro.html#introduction-to-streams"><strong>Snowflake Streams</strong></a></li><li><a href="https://docs.snowflake.com/en/user-guide/tasks-intro.html#introduction-to-tasks"><strong>Snowflake Task</strong></a></li></ul><p><strong>Use case:</strong> A table is inserted with data multiple times of the day in an ad hoc manner. Before every data insertion, that table is truncated and loaded (let’s call this table as staging table). A procedure has to be executed soon after the staging table is inserted with data. The procedure script should get the data in the staging table and compare the data with another table (let’s called this table as destination table).</p><p>If a record in the staging table already exists in the destination table, that record should be updated else it should be inserted into the destination table.</p><p>First, let’s create the staging and destination tables.</p><pre>//staging table <br>CREATE OR REPLACE TABLE ITEM_STAGE (<br> ID NUMBER(38,0),<br> NAME VARCHAR(20),<br> CATEGORY VARCHAR(20)<br>);</pre><pre>//destination table<br>CREATE OR REPLACE TABLE ITEM (<br> ID NUMBER(38,0),<br> NAME VARCHAR(20),<br> CATEGORY VARCHAR(20),<br> INSERT_DATE_TIME TIMESTAMP_NTZ(9) DEFAULT CURRENT_TIMESTAMP (),<br> UPDATE_DATE_TIME TIMESTAMP_NTZ(9)<br>);</pre><p>Snowflake stream keeps track of DML changes made to tables. So that action can be taken using those changed data. Therefore, by creating a stream on the staging table, we would be able to identify once records are inserted into the table.</p><p>The next step is creating the stream on the staging table. After stream creation, we can check the stream details using the <strong>show streams</strong> command.</p><pre>CREATE OR REPLACE STREAM ITEM_UPLOAD_STREAM<br>ON TABLE ITEM_STAGE;</pre><pre>SHOW STREAMS;</pre><p>To check the stream functionality we can insert data into the staging table and query the stream to check if the data insertion is captured by the stream.</p><pre>INSERT OVERWRITE INTO ITEM_STAGE  <br>VALUES (1, &#39;Product1&#39;,&#39;Category1&#39;)  ;</pre><pre>SELECT * FROM ITEM_UPLOAD_STREAM;</pre><p>Following is the output of the select query on stream.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fXgPFU7qJpZ8AAJ4LZ_Nbg.png" /><figcaption>Record Captured in Stream</figcaption></figure><p>Snowflake task is capable calling a procedure once changed data is captured into the stream.</p><p>The next step is creating the procedure and the task. The procedure includes using a merge script to insert new records into the destination table and update the existing records. Since the staging table is loaded as truncate-insert way, stream is capturing it as deletes and inserts. Therefore by adding the <strong>METADATA$ACTION = ‘INSERT’ </strong>condition in the script, we can filter only the inserts recorded in the stream.</p><pre>CREATE OR REPLACE PROCEDURE &quot;UDF_PRODUCT_UPDATE&quot;()<br>RETURNS VARCHAR(16777216)<br>LANGUAGE SQL<br>EXECUTE AS OWNER<br>AS <br>$$<br>BEGIN</pre><pre>  MERGE INTO ITEM p USING ITEM_UPLOAD_STREAM ps<br>  ON p.ID = ps.ID<br>  WHEN MATCHED AND METADATA$ACTION = &#39;INSERT&#39; <br>    THEN UPDATE SET p.NAME = ps.NAME,<br>              p.CATEGORY = ps.CATEGORY,<br>              p.UPDATE_DATE_TIME = CURRENT_TIMESTAMP()<br>  WHEN NOT MATCHED AND METADATA$ACTION = &#39;INSERT&#39; <br>    THEN INSERT (p.ID, p.NAME, p.CATEGORY ) <br>         VALUES (ps.ID, ps.NAME, ps.CATEGORY);   <br>  <br>END;<br>$$;</pre><p>Snowflake tasks can create tasks to be <a href="https://docs.snowflake.com/en/user-guide/tasks-intro.html#compute-resources">serverless tasks or user-managed tasks</a>. The serverless tasks are still in preview mode. To use it, we should request from Snowflake Support and get it enabled to the relevant account.</p><p>A task triggers on a schedule only. This task is scheduled to be executed at a 1-minute interval. The <strong>SYSTEM$STREAM_HAS_DATA</strong> function indicates if the specified stream contains any change tracking data. The function <strong>SYSTEM$STREAM_HAS_DATA </strong>will be evaluated every 1 minute. If the result is “<strong>FALSE</strong>” then the task will not run. If the result is “<strong>TRUE</strong>” the task will run and execute the procedure.</p><p>The last step is creating the task either way. The following script includes the creation script of both serverless tasks and user-managed tasks.</p><pre>//serverless task<br>CREATE OR REPLACE TASK PUSH_ITEM_UPLOADS_TASK<br> SCHEDULE = &#39;1 MINUTE&#39; <br> USER_TASK_MANAGED_INITIAL_WAREHOUSE_SIZE = &#39;XSMALL&#39; <br>WHEN <br> SYSTEM$STREAM_HAS_DATA(&#39;ITEM_UPLOAD_STREAM&#39;) <br> AS CALL UDF_ITEM_UPDATE();</pre><pre>OR </pre><pre>//user-managed task<br>CREATE OR REPLACE TASK PUSH_ITEM_UPLOADS_TASK<br> WAREHOUSE = {warehouse_name}<br> SCHEDULE = &#39;1 MINUTE&#39;<br>WHEN <br> SYSTEM$STREAM_HAS_DATA(&#39;ITEM_UPLOAD_STREAM&#39;) <br> AS CALL UDF_ITEM_UPDATE();</pre><p>Create task is suspended by default. The following script will resume the task. <strong>SHOW TASKS</strong> will return the metadata of the task.</p><pre>ALTER TASK PUSH_ITEM_UPLOADS_TASK RESUME;</pre><pre>SHOW TASKS;</pre><p>Once the task is resumed, the record captured in the stream will be inserted into the destination table within a one-minute interval.</p><p>And once the destination table is inserted with the record, changed data related to that record will be removed from the stream.</p><p>We can check <a href="https://docs.snowflake.com/en/sql-reference/functions/task_history.html">task history</a> by running the following query.</p><pre>SELECT *<br>FROM TABLE(information_schema.task_history(<br>            scheduled_time_range_start =&gt;   DATEADD(&#39;hour&#39;,-72,CURRENT_TIMESTAMP()),<br>      result_limit =&gt; 10,<br>            task_name=&gt; &#39;PUSH_ITEM_UPLOADS_TASK&#39;))<br>ORDER BY QUERY_START_TIME DESC;</pre><p>As I explained earlier, in the task history below, we can see the task is executed only when the stream is having any records, else it will be skipped in every one-minute execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*75jNDeWR9X_kjgAnR-tJuQ.png" /><figcaption>Task History</figcaption></figure><p>And with that, you’ve crossed another level to becoming a boss coder. GG! 👏</p><p>I hope you found this article instructional and informative. If you have any feedback or queries, please let me know in the comments below. And follow <a href="https://selectfrom.dev/">SelectFrom</a> for more tutorials and guides on topics like <a href="https://selectfrom.dev/tagged/big-data">Big Data</a>, <a href="https://selectfrom.dev/tagged/spark">Spark</a>, and <a href="https://selectfrom.dev/tagged/data-warehouse">data warehousing</a>.</p><p><strong>The world’s fastest cloud data warehouse:</strong></p><p>When designing analytics experiences which are consumed by customers in production, even the smallest delays in query response times become critical. Learn how to achieve <strong>sub-second</strong> performance over TBs of data with <a href="https://www.firebolt.io/?v=m"><strong>Firebolt</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f0fbed95d39" width="1" height="1" alt=""><hr><p><a href="https://selectfrom.dev/snowflake-stream-and-task-use-case-8f0fbed95d39">Snowflake Stream and Task Use Case</a> was originally published in <a href="https://selectfrom.dev/">SelectFrom</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>