Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(mssql): map tinyint to unsigned arrow type (#125289)

Tom Owers4995119a30b9
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/mssql.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/mssql.py
index 833dc785e1e7..d11b9d96198a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/mssql.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/mssql.py
@@ -605,7 +605,8 @@ class MSSQLColumn(Column):
case "smallint":
arrow_type = pa.int16()
case "tinyint":
- arrow_type = pa.int8()
+ # MSSQL's tinyint is unsigned (0 to 255), unlike every other integer type here.
+ arrow_type = pa.uint8()
case "decimal" | "numeric" | "money":
if not self.numeric_precision or not self.numeric_scale:
raise TypeError("expected `numeric_precision` and `numeric_scale` to be `int`, got `NoneType`")
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/tests/test_mssql.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/tests/test_mssql.py
index 44879a570177..2d7bd692dfe6 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/tests/test_mssql.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mssql/tests/test_mssql.py
@@ -3,7 +3,9 @@ import threading
import pytest
from unittest.mock import MagicMock
+import pyarrow as pa
import pymssql
+from parameterized import parameterized
from products.warehouse_sources.backend.temporal.data_imports.discover_schemas_workflow import (
DISCOVER_SCHEMAS_ACTIVITY_TIMEOUT,
@@ -104,6 +106,20 @@ class TestMSSQLColumnToArrowField:
with pytest.raises(TypeError, match="numeric_precision"):
col.to_arrow_field()
+ @parameterized.expand(
+ [
+ ("tinyint", pa.uint8()),
+ ("smallint", pa.int16()),
+ ("int", pa.int32()),
+ ("bigint", pa.int64()),
+ ]
+ )
+ def test_integer_types_match_mssql_value_range(self, data_type, expected_arrow_type):
+ # tinyint is 0-255 in MSSQL, unlike every signed integer type here; a signed arrow
+ # type raises ArrowInvalid as soon as a row carries a value above 127.
+ col = MSSQLColumn(name="x", data_type=data_type, nullable=True)
+ assert col.to_arrow_field().type == expected_arrow_type
+
class TestBuildQuery:
def test_in_filter_expands_to_named_placeholders(self):