Skip to content

Commit 88d0e11

Browse files
committed
update string datapoint constraints to be in line with API changes
1 parent 6e8a485 commit 88d0e11

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ Changes are grouped as follows
1212
- `Fixed` for any bug fixes.
1313
- `Security` in case of vulnerabilities.
1414

15+
## 7.9.0
16+
17+
### Changed
18+
19+
* Updated string time series datapoints maximum size to be constrained by UTF-8 encoded bytes count instead of string length when using upload queue(s), aligning with the API behavior changes.
20+
1521
## 7.8.1
1622

1723
### Fixed

cognite/extractorutils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
Cognite extractor utils is a Python package that simplifies the development of new extractors.
1717
"""
1818

19-
__version__ = "7.8.1"
19+
__version__ = "7.9.0"
2020
from .base import Extractor
2121

2222
__all__ = ["Extractor"]

cognite/extractorutils/uploader/time_series.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
from cognite.extractorutils.util import EitherId, cognite_exceptions, retry
5454

5555
MIN_DATAPOINT_TIMESTAMP = -2208988800000
56-
MAX_DATAPOINT_STRING_LENGTH = 255
56+
MAX_DATAPOINT_STRING_BYTES = 1023
5757
MAX_DATAPOINT_VALUE = 1e100
5858
MIN_DATAPOINT_VALUE = -1e100
5959

@@ -154,7 +154,7 @@ def _verify_datapoint_value(self, value: int | float | datetime | str) -> bool:
154154
math.isnan(value) or math.isinf(value) or value > MAX_DATAPOINT_VALUE or value < MIN_DATAPOINT_VALUE
155155
)
156156
elif isinstance(value, str):
157-
return len(value) <= MAX_DATAPOINT_STRING_LENGTH
157+
return len(value.encode("utf-8")) <= MAX_DATAPOINT_STRING_BYTES
158158
return not isinstance(value, datetime)
159159

160160
def _is_datapoint_valid(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "cognite-extractor-utils"
3-
version = "7.8.1"
3+
version = "7.9.0"
44
description = "Utilities for easier development of extractors for CDF"
55
authors = [
66
{name = "Mathias Lohne", email = "mathias.lohne@cognite.com"}

tests/tests_integration/test_cdm_time_series_integration.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
from cognite.client.data_classes.data_modeling import NodeApply, NodeId
1616
from cognite.client.data_classes.data_modeling.extractor_extensions.v1 import CogniteExtractorTimeSeriesApply
1717
from cognite.client.exceptions import CogniteAPIError, CogniteNotFoundError
18-
from cognite.extractorutils.uploader.time_series import CDMTimeSeriesUploadQueue
19-
20-
MIN_DATAPOINT_TIMESTAMP = -2208988800000
21-
MAX_DATAPOINT_STRING_LENGTH = 255
22-
MAX_DATAPOINT_VALUE = 1e100
23-
MIN_DATAPOINT_VALUE = -1e100
18+
from cognite.extractorutils.uploader.time_series import (
19+
MAX_DATAPOINT_STRING_BYTES,
20+
MAX_DATAPOINT_VALUE,
21+
MIN_DATAPOINT_TIMESTAMP,
22+
MIN_DATAPOINT_VALUE,
23+
CDMTimeSeriesUploadQueue,
24+
)
2425

2526

2627
@pytest.fixture
@@ -197,7 +198,7 @@ def test_cdm_queue_discards_invalid_values(set_upload_test: tuple[CogniteClient,
197198
bad_val_inf = (now + 1_000, float("inf"))
198199
bad_val_max = (now + 1_000, MAX_DATAPOINT_VALUE * 10)
199200
bad_val_min = (now + 1_000, MIN_DATAPOINT_VALUE * 10)
200-
too_long_str = (now + 2_000, "x" * (MAX_DATAPOINT_STRING_LENGTH + 1))
201+
too_long_str = (now + 2_000, "x" * (MAX_DATAPOINT_STRING_BYTES + 1))
201202
valid_temp_str_dp = (now + 3_000, "valid_short_string")
202203

203204
queue.add_to_upload_queue(

0 commit comments

Comments
 (0)