Skip to content

Commit 7f2d801

Browse files
authored
Add 'properties' to DataSources (#1268)
* MNT: Update readme * ENH: add properties column to the DataSources table * MNT: Update changelog * DOC: update documentation * TST: test DataSource.properties
1 parent 6f56cf5 commit 7f2d801

File tree

12 files changed

+55
-3
lines changed

12 files changed

+55
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ Write the date in place of the "Unreleased" in the case a new version is release
2121
### Fixed
2222

2323
- Error handling in `tiled.client.download._download_url`.
24-
25-
### Fixed
26-
2724
- Slow performance when deleting nodes in large catalogs with many nodes.
25+
- Add `properties` field to the DataSource object and table, to store additional
26+
metadata about the data source (e.g. array chunking information).
2827

2928
## v0.2.3 (2025-12-17)
3029

docs/source/explanations/catalog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ and `assets`, describes the format, structure, and location of the data.
5353
(This is used by Tiled to identify a suitable Adapter to read this data.)
5454
- `parameters` --- JSON object with additional parameters that will be passed
5555
to the Adapter
56+
- `properties` --- JSON object with additional properties of the native data format,
57+
such as compression type, chunking, column names, etc. These are not passed to the Adapter,
58+
but are stored for informational purposes.
5659
- `management` --- enum indicating whether the data is registered `"external"` data
5760
or `"writable"` data managed by Tiled
5861
- `structure_family` --- enum of structure types (`"container"`, `"array"`, `"table"`, ...)

tests/test_catalog.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ async def test_write_array_external(a, tmpdir):
226226
mimetype="image/tiff",
227227
structure=structure,
228228
parameters={},
229+
properties={"chunks": structure["chunks"]}, # Optional property
229230
management="external",
230231
assets=[
231232
Asset(
@@ -240,6 +241,7 @@ async def test_write_array_external(a, tmpdir):
240241
)
241242
x = await a.lookup_adapter(["x"])
242243
assert numpy.array_equal(await x.read(), arr)
244+
assert x.data_sources[0].properties == {"chunks": [[5], [3]]}
243245

244246

245247
@pytest.mark.asyncio
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
Generic single-database configuration.
2+
3+
To generate a new revision file, run:
4+
5+
```
6+
python -m tiled.authn_database revision -m "description..."
7+
```

tiled/catalog/adapter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@ async def create_node(
751751
mimetype=data_source.mimetype,
752752
management=data_source.management,
753753
parameters=data_source.parameters,
754+
properties=data_source.properties,
754755
structure_id=structure_id,
755756
)
756757
db.add(data_source_orm)

tiled/catalog/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
# This is list of all valid revisions (from current to oldest).
88
ALL_REVISIONS = [
9+
"4cf6011a8db5",
910
"a86a48befff6",
1011
"dfbb7478c6bd",
1112
"a963a6c32a0c",

tiled/catalog/migrations/README

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
Generic single-database configuration.
2+
3+
To generate a new revision file, run:
4+
5+
```
6+
python -m tiled.catalog revision -m "description..."
7+
```
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Add 'properties' column to the DataSources table
2+
3+
Revision ID: 4cf6011a8db5
4+
Revises: a86a48befff6
5+
Create Date: 2026-01-09 13:59:48.448079
6+
7+
"""
8+
import sqlalchemy as sa
9+
from alembic import op
10+
11+
from tiled.catalog.orm import JSONVariant
12+
13+
# revision identifiers, used by Alembic.
14+
revision = "4cf6011a8db5"
15+
down_revision = "a86a48befff6"
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade():
21+
op.add_column(
22+
"data_sources",
23+
sa.Column("properties", JSONVariant, nullable=False, server_default="{}"),
24+
)
25+
26+
27+
def downgrade():
28+
op.drop_column("data_sources", "properties")

tiled/catalog/orm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ class DataSource(Timestamped, Base):
467467
# These are additional parameters passed to the Adapter to guide
468468
# it to access and arrange the data in the file correctly.
469469
parameters = Column(JSONVariant, nullable=True)
470+
# These are additional properties describing the data source (e.g. array chunks).
471+
properties = Column(JSONVariant, nullable=True)
470472
# This relates to the mutability of the data.
471473
management = Column(Enum(Management), nullable=False)
472474
structure_family = Column(Enum(StructureFamily), nullable=False)

tiled/server/schemas.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class DataSource(pydantic.BaseModel, Generic[StructureT]):
149149
structure: Optional[StructureT]
150150
mimetype: Optional[str] = None
151151
parameters: dict = {}
152+
properties: dict = {}
152153
assets: List[Asset] = []
153154
management: Management = Management.writable
154155

@@ -167,6 +168,7 @@ def from_orm(cls, orm: tiled.catalog.orm.DataSource) -> DataSource:
167168
structure=structure,
168169
mimetype=orm.mimetype,
169170
parameters=orm.parameters,
171+
properties=orm.properties,
170172
assets=[Asset.from_assoc_orm(assoc) for assoc in orm.asset_associations],
171173
management=orm.management,
172174
)

0 commit comments

Comments
 (0)