cancel
Showing results for 
Search instead for 
Did you mean: 
Databricks Free Edition Help
Engage in discussions about the Databricks Free Edition within the Databricks Community. Share insights, tips, and best practices for getting started, troubleshooting issues, and maximizing the value of your trial experience to explore Databricks' capabilities effectively.
cancel
Showing results for 
Search instead for 
Did you mean: 

Possible bug in Lakeflow Connect SQL Server ingestion with GUID primary keys – Missing records

volodymyr_b
New Contributor

Hi everyone,

We've encountered a strange issue with Databricks Lakeflow Connect query-based ingestion from SQL Server, and I'm wondering if anyone else has experienced something similar.

We have a SQL Server table with 1,448 records and a uniqueidentifier primary key. When performing a full refresh, Databricks ingests only 364 records, but the pipeline completes successfully without any errors.

After digging into the cluster logs, I suspect the problem is related to how Databricks handles GUID ordering during snapshot partitioning.

The connector correctly identifies 1,448 distinct IDs:

-- logs
getSnapshotSplitsByNonNumericKey: splitCount=1, totalDistinct=1448

However, the generated query applies the following filter:

-- logs
Pushed Filters: Id IS NOT NULL, (RPAD(Id, 36, ' ')) <= '38C5A9C6-D111-4182-8A7F-FFE14F608876'

The snapshot then completes with:

-- logs
numInputRows: 364 dropped: 0

What I think is happening

SQL Server compares uniqueidentifier values differently from their string representations.

My theory is that Databricks:

  1. Retrieves the GUIDs using SQL Server's native GUID ordering.

  2. Determines the upper boundary for the snapshot partition.

  3. Applies that boundary using a string comparison (RPAD(Id, 36, ' ') <= ...).

  4. Accidentally excludes records because string ordering and native GUID ordering are different.

For example, consider these two GUIDs:

38DE50FE-2AC8-46E8-91AB-EAB0A9E944B0
38C5A9C6-D111-4182-8A7F-FFE14F608876

You can reproduce the difference directly in SQL Server. Try this query:

DECLARE @guid_a uniqueidentifier = '38DE50FE-2AC8-46E8-91AB-EAB0A9E944B0';
DECLARE @guid_b uniqueidentifier = '38C5A9C6-D111-4182-8A7F-FFE14F608876';

SELECT CASE WHEN @guid_a < @guid_b THEN 'TRUE' ELSE 'FALSE' END, 'GUID'
UNION
SELECT CASE WHEN CONVERT(char(36), @guid_a) < CONVERT(char(36), @guid_b) THEN 'TRUE' ELSE 'FALSE' END, 'STR';

The result is:

TRUE     GUID
FALSE    STR

So the same two GUIDs produce opposite comparison results depending on whether they are compared as native uniqueidentifier values or strings.

My questions

  • Has anyone encountered this issue with Lakeflow Connect query-based ingestion?

  • Is there a way to override the automatically selected snapshot partitioning column in the pipeline configuration?

  • Are there any known workarounds that don't require modifying the source SQL Server tables?

 

What concerns me most is that the pipeline reports a successful full refresh despite missing a significant number of records. This could easily go unnoticed and lead to silently incomplete datasets.

Any insights would be appreciated. Thanks!

2 REPLIES 2

data_pulse
Contributor

@volodymyr_b 

The SQL Server connector reference confirms that UNIQUEIDENTIFIER is automatically converted to STRING, which makes the ordering behaviour you've identified worth investigating.

I ran a few independent test using SQL Server and Databricks serverless.

Using the boundary 38C5A9C6-D111-4182-8A7F-FFE14F608876, I observed that GUID 38DE50FE-2AC8-46E8-91AB-EAB0A9E944B0 satisfies SQL Server's native UNIQUEIDENTIFIER comparison but is excluded when the same comparison is performed using its string representation.

To cross-check this, I ran the equivalent RPAD(Id, 36, ' ') <= boundary filter in Databricks serverless and observed the same GUID being excluded.

Then further tested with a synthetic dataset of 1,000 deterministic, distinct GUIDs in SQL Server and ran the equivalent filter in Databricks. 

Using the boundary 38C5A9C6-D111-4182-8A7F-FFE14F608876, I observed:

  • SQL Server native UNIQUEIDENTIFIER comparison: 1,000 rows matched
  • SQL Server string comparison: 222 rows matched
  • Databricks Spark RPAD(Id, 36, ' ') <= boundary: 222 rows matched

So, for this dataset and boundary, 778 rows satisfy the native GUID comparison but are excluded by the string comparison.

These confirms the ordering difference across both environments and lends further support to your hypothesis about a potential mismatch in the connector's snapshot partitioning logic. Although this doesn't establish how Lakeflow internally calculates partition boundaries, it demonstrates the impact that inconsistent comparison could have.

Regarding question about overriding the snapshot partitioning column, the query-based connector limitations mention that you can contact your Databricks account team to request a partitioning column override when the automatically selected column is unsuitable.

ethan_parmer
New Contributor III

Hi @volodymyr_b — I think your theory is right, and your own log line backs it up.

SQL Server doesn’t sort uniqueidentifier the way the string sorts. It compares the last 6-byte group first (the FFE14F608876 part), then works backward through the other groups. Look at the upper bound in your snapshot filter: 38C5A9C6-…-8A7F-FFE14F608876. That last group is close to the top of the range, which is exactly what you’d expect if the connector computed MAX(Id) using GUID ordering. But the predicate it applies is a string comparison (RPAD(Id, 36, ' ') <= '38C5…'), so only IDs that start with roughly 0–38… make it through. With splitCount=1 and no “dropped” rows, the pipeline thinks it read everything.

You can confirm it on the source without changing anything:

 
sql
SELECT
  MAX(Id)                         AS max_as_guid,
  MAX(CONVERT(char(36), Id))      AS max_as_string,
  SUM(CASE WHEN CONVERT(char(36), Id) <= '38C5A9C6-D111-4182-8A7F-FFE14F608876'
           THEN 1 ELSE 0 END)     AS rows_kept_by_string_filter
FROM dbo.YourTable;

If max_as_guid matches the boundary in your log and rows_kept_by_string_filter comes back as 364, that proves it.

On workarounds: I’m not aware of a documented setting to change the split column for the SQL Server connector. Until it’s fixed:

  • Treat it as a connector bug. If you have a paid workspace, open a support ticket with the query above and the log lines. That’s the fastest route to a fix.
  • Don’t trust the snapshot for GUID-keyed tables. A quick COUNT(*) check between source and target after each full refresh would catch it.
  • As a stopgap, pull the table through Lakehouse Federation or JDBC into a separate table and reconcile against that.

A couple of questions that would help others reproduce it: are you using CDC or Change Tracking, and does a table with an INT/BIGINT key in the same pipeline come through complete?

Ethan