<?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"><channel><title><![CDATA[Areeb on Fabric]]></title><description><![CDATA[Areeb on Fabric]]></description><link>https://areebonfabric.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Dec 2026 00:05:49 GMT</lastBuildDate><atom:link href="https://areebonfabric.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Your Delta MERGE is quietly duplicating rows: the NULL-key trap (and the <=> fix)]]></title><description><![CDATA[This one cost me a lot of sleep, because nothing was ever "broken". No errors. No failed runs. Every night the MERGE finished with a happy green tick. And…]]></description><link>https://areebonfabric.hashnode.dev/your-delta-merge-is-quietly-duplicating-rows-the-null-key-trap-and-the-fix</link><guid isPermaLink="true">https://areebonfabric.hashnode.dev/your-delta-merge-is-quietly-duplicating-rows-the-null-key-trap-and-the-fix</guid><category><![CDATA[microsoft fabric]]></category><category><![CDATA[Delta Lake]]></category><category><![CDATA[data-engineering]]></category><category><![CDATA[SQL]]></category><dc:creator><![CDATA[Mohammad Areeb]]></dc:creator><pubDate>Wed, 02 Dec 2026 15:31:12 GMT</pubDate><content:encoded><![CDATA[<p>This one cost me a lot of sleep, because nothing was ever "broken". No errors. No failed runs. Every night the MERGE finished with a happy green tick.</p>
<p>And yet, slowly, one of our big tables was growing faster than it should.</p>
<h2>The symptom: a table that just kept getting bigger</h2>
<p>The row count crept up. Not by a lot on any single day, which is exactly why it was so easy to ignore. But when I finally compared the number of rows with the number of <em>distinct keys</em>, the gap was huge. Some keys existed <strong>dozens of times</strong>.</p>
<p>The table was supposed to hold one row per key. It was holding roughly thirty copies of some of them, and it had been quietly piling them up for weeks.</p>
<h2>The cause: NULL is never equal to NULL</h2>
<p>Here's the pattern. A typical Delta MERGE looks like this:</p>
<pre><code class="language-sql">MERGE INTO target AS t
USING source AS s
  ON t.order_id = s.order_id AND t.serial = s.serial
WHEN MATCHED THEN UPDATE SET *
WHEN NOT MATCHED THEN INSERT *;
</code></pre>
<p>Looks perfectly reasonable. The catch is in SQL's rule for NULLs:</p>
<blockquote>
<p><code>NULL = NULL</code> doesn't give you <code>TRUE</code>. It gives you <code>NULL</code> (unknown), and a MERGE treats "unknown" as <strong>no match</strong>.</p>
</blockquote>
<p>So if one of your key columns is NULL on a row, that row can <strong>never</strong> match itself. Every run, the MERGE says "I've never seen this row before" and takes the <code>WHEN NOT MATCHED</code> branch, inserting it again.</p>
<p>In my case, one of the key columns came from a <code>LEFT JOIN</code> (a serial number that doesn't always exist yet). Rows without a serial had a NULL key, so each one was inserted again on every single run. Nothing errored, because inserting a row is a perfectly legal thing to do.</p>
<h2>See it for yourself in 30 seconds</h2>
<p>Paste this into a Fabric notebook (Spark SQL):</p>
<pre><code class="language-sql">-- A tiny target table, one row has a NULL serial
CREATE TABLE demo_target (order_id INT, serial STRING, qty INT) USING DELTA;
INSERT INTO demo_target VALUES (1, 'A100', 10), (2, NULL, 5);

-- Incoming data: the same two rows, with updated quantities
CREATE OR REPLACE TEMP VIEW demo_source AS
SELECT * FROM VALUES (1, 'A100', 11), (2, NULL, 6) AS s(order_id, serial, qty);
</code></pre>
<p>Now run the "normal" MERGE:</p>
<pre><code class="language-sql">MERGE INTO demo_target AS t
USING demo_source AS s
  ON t.order_id = s.order_id AND t.serial = s.serial
WHEN MATCHED THEN UPDATE SET *
WHEN NOT MATCHED THEN INSERT *;

SELECT * FROM demo_target ORDER BY order_id;
</code></pre>
<p>You started with <strong>2 rows</strong> and you now have <strong>3</strong>. Row 1 updated nicely. Row 2 (the one with the NULL) was inserted again instead of updated. Run the MERGE a second time and you'll have 4. That's the leak.</p>
<h2>The fix: null-safe equality</h2>
<p>Spark has an operator made for exactly this: <code>&lt;=&gt;</code>. It's "equals, but NULL-safe": two NULLs count as equal.</p>
<pre><code class="language-sql">MERGE INTO demo_target AS t
USING demo_source AS s
  ON t.order_id = s.order_id AND t.serial &lt;=&gt; s.serial
WHEN MATCHED THEN UPDATE SET *
WHEN NOT MATCHED THEN INSERT *;
</code></pre>
<p>(In PySpark the same idea is <code>col("t.serial").eqNullSafe(col("s.serial"))</code>.)</p>
<p>With that one operator changed, the NULL row matches itself and gets updated, and the row count stays put, run after run.</p>
<h2>Don't just use <code>&lt;=&gt;</code> everywhere</h2>
<p>It's tempting to swap every <code>=</code> in your MERGE for <code>&lt;=&gt;</code>. I'd think twice. A null-safe comparison can make it harder for Delta to skip files when it looks for matching rows, which can slow a big MERGE down.</p>
<p>What I did instead: use <code>&lt;=&gt;</code> <strong>only on the column that can actually be NULL</strong>, and keep a plain <code>=</code> on the key columns that never are. Same result, and the MERGE stays fast. (Worth testing on your own table, since it depends on how it's laid out.)</p>
<h2>How to know if this is happening to you</h2>
<p>Don't trust the row count alone, and don't trust "distinct keys" either, because <code>COUNT(DISTINCT a, b)</code> quietly skips any row where a column is NULL. Group the keys instead (GROUP BY treats NULLs as equal):</p>
<pre><code class="language-sql">SELECT order_id, serial, COUNT(*) AS copies
FROM my_table
GROUP BY order_id, serial
HAVING COUNT(*) &gt; 1
ORDER BY copies DESC;
</code></pre>
<p>If that returns rows, and especially if the problem keys have a NULL in them, you've found it.</p>
<h2>If you've already got duplicates</h2>
<p>Fixing the MERGE stops the bleeding, but it won't remove the copies already there. A few things I'd do:</p>
<ol>
<li><strong>Note the table version first</strong> (<code>DESCRIBE HISTORY</code>), so you can <code>RESTORE</code> if anything goes wrong.</li>
<li><strong>Clean up once</strong>, keeping one row per key.</li>
<li><strong>Prove you didn't change the good rows.</strong> I compared a checksum of the rows I was keeping before and after. If it matches, you know the cleanup only removed duplicates.</li>
<li><strong>Keep checking afterwards.</strong> Re-run the "copies per key" query after the next few loads. Mine came back at exactly 1.00 copies per key, and stayed there.</li>
</ol>
<h2>One more habit I'd steal</h2>
<p>Add a tiny check at the end of your pipeline: <em>rows per key should be exactly 1.</em> If it ever isn't, alert. A MERGE that "succeeds" tells you nothing about whether it did the right thing.</p>
<h2>Wrapping up</h2>
<p>The lesson I took away: <strong>a green pipeline isn't a correct pipeline.</strong> And whenever a MERGE key can be NULL, use <code>&lt;=&gt;</code> on that column.</p>
<p>Have you been bitten by this one too? Or by a different quiet data bug? I'd love to hear about it in the comments.</p>
<hr />
<p><em>I write about real-world Microsoft Fabric engineering: the problems you only find in production. Follow along if that's your kind of thing.</em></p>
]]></content:encoded></item><item><title><![CDATA[Why your Fabric REST calls hang on Windows (and the one-line fix)]]></title><description><![CDATA[I lost more time to this one than I'd like to admit, so I'm writing it down in the hope it saves you an afternoon. I was automating some routine work in…]]></description><link>https://areebonfabric.hashnode.dev/why-your-fabric-rest-calls-hang-on-windows-and-the-one-line-fix</link><guid isPermaLink="true">https://areebonfabric.hashnode.dev/why-your-fabric-rest-calls-hang-on-windows-and-the-one-line-fix</guid><category><![CDATA[microsoft fabric]]></category><category><![CDATA[data-engineering]]></category><category><![CDATA[Powershell]]></category><dc:creator><![CDATA[Mohammad Areeb]]></dc:creator><pubDate>Sat, 14 Nov 2026 16:32:37 GMT</pubDate><content:encoded><![CDATA[<p>I lost more time to this one than I'd like to admit, so I'm writing it down in the hope it saves you an afternoon.</p>
<h2>The problem</h2>
<p>I was automating some routine work in Microsoft Fabric through the REST API: pulling notebook definitions, updating them, and polling long-running operations until they finished. Normal stuff.</p>
<p>Some calls worked instantly. Others just... sat there. A minute. Two minutes. Sometimes they finished, sometimes PowerShell gave up with an error that told me nothing useful. And it wasn't consistent: the same call would work one minute and hang the next.</p>
<p>My first thought was the usual suspect: <strong>capacity throttling</strong>. Fabric does throttle when you push a capacity too hard, so it's an easy thing to blame. I spent a while looking at capacity metrics. Nothing there.</p>
<h2>What was actually going on</h2>
<p>The clue came when I tried the same call with <code>curl</code> on Windows and got a real error message instead of silence:</p>
<pre><code class="language-plaintext">schannel: next InitializeSecurityContext failed:
CRYPT_E_NO_REVOCATION_CHECK (0x80092012) - The revocation function was
unable to check revocation for the certificate.
</code></pre>
<p>So the problem had nothing to do with Fabric. It was happening <strong>before the request even reached Fabric</strong>, during the TLS handshake.</p>
<p>Here's the short version of what's going on:</p>
<ol>
<li>When Windows makes an HTTPS connection, it uses its built-in TLS stack (<strong>Schannel</strong>).</li>
<li>Schannel doesn't just check that the server's certificate is valid. It also tries to check whether the certificate has been <strong>revoked</strong>, by reaching out to the certificate authority's revocation servers (CRL or OCSP).</li>
<li>On a lot of corporate networks (VPNs, TLS-inspecting proxies, strict firewalls), those revocation servers are <strong>slow, blocked or unreachable</strong>.</li>
<li>So Windows waits... and waits... and eventually either times out or fails the handshake.</li>
</ol>
<p>That explains everything I was seeing: it was intermittent because it depended on whether the revocation lookup got through, and it hit some endpoints more than others. Long-running operation polling redirects you to a different host, which needs its own certificate check.</p>
<p>Fun fact: the same calls worked perfectly from Python. Python's <code>requests</code> uses OpenSSL, which <strong>doesn't do revocation checks by default</strong>. That's why "it works in Python but not in PowerShell" is such a strong hint that you're looking at this problem.</p>
<h2>The fix</h2>
<p>Use <code>curl</code> (it ships with Windows 10 and 11) and tell it how to handle revocation.</p>
<p><strong>The safer option, try this first:</strong></p>
<pre><code class="language-bash">curl --ssl-revoke-best-effort -s "https://api.fabric.microsoft.com/v1/workspaces" \
  -H "Authorization: Bearer $TOKEN"
</code></pre>
<p><code>--ssl-revoke-best-effort</code> still checks revocation, but if the revocation server can't be reached, it carries on instead of failing. For most people on a corporate network, this alone fixes it.</p>
<p><strong>The blunt option, if best-effort still struggles:</strong></p>
<pre><code class="language-bash">curl --ssl-no-revoke -s "https://api.fabric.microsoft.com/v1/workspaces" \
  -H "Authorization: Bearer $TOKEN"
</code></pre>
<p><code>--ssl-no-revoke</code> skips the revocation check completely. In my case the hang disappeared instantly and never came back.</p>
<p>Getting a token is the usual routine. For example, with the Azure CLI:</p>
<pre><code class="language-bash">TOKEN=$(az account get-access-token --resource https://api.fabric.microsoft.com --query accessToken -o tsv)
</code></pre>
<h2>A word of caution</h2>
<p>Revocation checking exists for a reason: it's how your machine finds out that a certificate has been compromised. Turning it off is a <strong>trade-off</strong>, not a free win.</p>
<p>My take:</p>
<ul>
<li>For <strong>calls to well-known Microsoft endpoints, from a managed corporate machine</strong>, the risk is low and the fix is reasonable.</li>
<li>Prefer <code>--ssl-revoke-best-effort</code> over <code>--ssl-no-revoke</code> when it works.</li>
<li>The <strong>real fix</strong> is for your network team to allow the certificate authorities' CRL/OCSP endpoints through the VPN or proxy. Worth raising with them, so you're not working around it forever.</li>
</ul>
<h2>Quick checklist if your Fabric API calls hang</h2>
<ul>
<li><input disabled type="checkbox" /> Does the same call work from Python but not PowerShell or curl? → strong sign it's this.</li>
<li><input disabled type="checkbox" /> Run it with <code>curl -v</code> and look for <code>CRYPT_E_NO_REVOCATION_CHECK</code> or <code>CRYPT_E_REVOCATION_OFFLINE</code>.</li>
<li><input disabled type="checkbox" /> Try <code>--ssl-revoke-best-effort</code>, then <code>--ssl-no-revoke</code>.</li>
<li><input disabled type="checkbox" /> Only <em>then</em> go looking at capacity throttling.</li>
</ul>
<h2>Wrapping up</h2>
<p>The lesson I took from this: <strong>when an API "hangs", check the network layer before blaming the service.</strong> I almost wrote this off as a capacity problem and could have spent days chasing the wrong thing.</p>
<p>If you've hit something similar with Fabric or Power BI APIs, I'd love to hear how you solved it. Drop it in the comments.</p>
<hr />
<p><em>I write about real-world Microsoft Fabric engineering: the problems you only find in production. Follow along if that's your kind of thing.</em></p>
]]></content:encoded></item></channel></rss>