This is an automated email from the ASF dual-hosted git repository.

XiaoHongbo-Hope pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new 7924961ed4 [python] Preserve LeRobot Episode extensions during import 
(#11081)
7924961ed4 is described below

commit 7924961ed48235e0356564178f5fb6d36420bd70
Author: XiaoHongbo <[email protected]>
AuthorDate: Wed Nov 11 06:09:52 2026 +0800

    [python] Preserve LeRobot Episode extensions during import (#11081)
---
 docs/docs/pypaimon/lerobot.md                      |  19 ++-
 .../pypaimon/multimodal/lerobot/aggregate.py       |  93 +++++++++---
 .../pypaimon/multimodal/lerobot/dataset.py         |  13 +-
 .../pypaimon/tests/lerobot_aggregate_test.py       | 159 +++++++++++++++++++--
 4 files changed, 235 insertions(+), 49 deletions(-)

diff --git a/docs/docs/pypaimon/lerobot.md b/docs/docs/pypaimon/lerobot.md
index df33b2b306..876f61e3a7 100644
--- a/docs/docs/pypaimon/lerobot.md
+++ b/docs/docs/pypaimon/lerobot.md
@@ -90,12 +90,16 @@ identifies a frame. The training reader derives continuous 
positions at read
 time. Source task/subtask ID-to-text mappings use `_datasets.tasks` and
 `_datasets.subtasks`; stats remain JSON.
 
-Merged `_episodes` keeps source-local Episode keys and frame ranges. Its
-`meta/`, `data/`, `videos/`, and `stats/` fields are grouped into JSON columns.
+Merged `_episodes` keeps source-local Episode keys and frame ranges. Fields 
with
+`/` are grouped by prefix into JSON columns, including `meta/`,
+`data/`, `videos/`, and `stats/`.
 Grouped fields must use JSON-native Arrow types: null, boolean, integer,
 floating point, string, list, or struct, including nested combinations.
-Binary, temporal, decimal, map, and extension types are rejected before any
-target table is created. Other Episode extension fields are not imported.
+Binary, temporal, decimal, map, and extension types in these JSON groups are
+rejected before any target table is created. Episode fields without `/` retain
+their original names and Paimon-supported Arrow types as columns in 
`_episodes`;
+unsupported types are rejected before table creation.
+Training metadata reads only Episode controls; query `_episodes` for 
extensions.
 Control-field statistics reflect merged IDs; their original quantiles are
 omitted. Training reads skip `stats`. Repeated task/subtask text within one
 source is rejected before creating tables to avoid losing original frame IDs.
@@ -109,14 +113,15 @@ require an import option.
 ### Schema evolution
 
 `schema_evolution=True` is the default. The importer plans the union of source
-columns before creating `_frames` and any declared extra `_datasets` columns.
+columns before creating `_frames`, `_episodes`, and any declared extra
+`_datasets` columns. Episode fields with `/` are grouped by prefix into JSON:
+`camera_intrinsics/head_left` becomes the `head_left` key in
+`_episodes.camera_intrinsics`. Other Episode fields retain their Arrow types.
 For appends, it compares the incoming columns with the existing table group and
 adds new nullable columns. Existing rows read as null in those columns; 
incoming
 rows receive nulls for omitted optional columns. Existing optional columns are
 made nullable when necessary. All three component schemas are checked before
 catalog changes, and existing field IDs are preserved.
-Merged `_episodes` keeps its fixed typed controls and JSON group columns;
-source-specific keys remain inside those JSON values.
 Missing columns receive typed nulls. Optional columns become nullable; source
 indices, timestamps, task indices, and required Episode controls remain 
required.
 Common columns must have identical types, and common frame features must retain
diff --git a/paimon-python/pypaimon/multimodal/lerobot/aggregate.py 
b/paimon-python/pypaimon/multimodal/lerobot/aggregate.py
index 81bc3ca74b..ce4e0d8bf6 100644
--- a/paimon-python/pypaimon/multimodal/lerobot/aggregate.py
+++ b/paimon-python/pypaimon/multimodal/lerobot/aggregate.py
@@ -24,6 +24,7 @@ import numpy as np
 import pyarrow as pa
 import pyarrow.compute as pc
 
+from pypaimon import Schema as PaimonSchema
 from pypaimon.multimodal.arrow_utils import strict_arrow_table
 from pypaimon.multimodal.lerobot.loader import (
     _commit_messages, _prepare_dataset, _video_fps,
@@ -65,6 +66,7 @@ _REBUILT_INFO = {
 }
 _DATASET_INDEX_COLUMN = "dataset_index"
 _EPISODE_JSON_GROUPS = ("meta", "data", "videos", "stats")
+_EPISODE_EXTRA_JSON_GROUP_DESCRIPTION = "pypaimon.lerobot.episode-json-group"
 _SOURCE_TASKS_TYPE = pa.list_(pa.struct([
     pa.field("task_index", pa.int64(), nullable=False),
     pa.field("task", pa.string(), nullable=False),
@@ -164,11 +166,20 @@ def _episode_json_group(original, group):
         ensure_ascii=False, separators=(",", ":"))
 
 
+def _episode_json_groups(schema):
+    groups = dict.fromkeys(_EPISODE_JSON_GROUPS)
+    for name in schema.names:
+        if "/" in name:
+            group, key = name.split("/", 1)
+            if not group or not key:
+                raise ValueError("Invalid LeRobot Episode field name %r." % 
name)
+            groups[group] = None
+    return tuple(groups)
+
+
 def _validate_episode_json(table, source_index):
-    fields = [
-        field for field in table.schema
-        if field.name.startswith(tuple(group + "/" for group in 
_EPISODE_JSON_GROUPS))
-    ]
+    fields = [field for field in table.schema if "/" in field.name]
+    groups = _episode_json_groups(table.schema)
     for field in fields:
         if not _json_native_arrow_type(field.type):
             raise ValueError(
@@ -177,7 +188,7 @@ def _validate_episode_json(table, source_index):
                 % (source_index, field.name, field.type))
     names = [field.name for field in fields]
     for row_index, original in enumerate(table.select(names).to_pylist()):
-        for group in _EPISODE_JSON_GROUPS:
+        for group in groups:
             try:
                 _episode_json_group(original, group)
             except (TypeError, ValueError, OverflowError) as error:
@@ -332,11 +343,29 @@ def _plan_merge(plans, extra_dataset_fields=None, 
schema_evolution=True,
     info["features"] = features
     metadata = dict(first["metadata"])
     metadata["frame_schema"] = frame_schema
-    # Merged Episode extensions are stored in JSON, not added as typed columns.
-    schemas = [pa.schema([
-        plan["metadata"]["episodes_schema"].field(name)
-        for name in _EPISODE_CONTROL_COLUMNS
-    ]) for plan in plans]
+    # Keep ungrouped fields typed and turn each slash prefix into one JSON 
column.
+    groups = tuple(dict.fromkeys(group for plan in plans
+                                 for group in _episode_json_groups(
+                                     plan["metadata"]["episodes_schema"])))
+    if _DATASET_INDEX_COLUMN in groups:
+        raise ValueError("LeRobot Episode JSON group uses reserved column 
dataset_index.")
+    reserved_episode_fields = {_DATASET_INDEX_COLUMN, *groups}
+    for ordinal, plan in enumerate(plans):
+        conflicts = reserved_episode_fields.intersection(
+            plan["metadata"]["episodes_schema"].names)
+        if conflicts:
+            raise ValueError("LeRobot source %d Episode uses reserved columns: 
%s."
+                             % (ordinal, sorted(conflicts)))
+    schemas = []
+    for plan in plans:
+        source_schema = plan["metadata"]["episodes_schema"]
+        source_groups = _episode_json_groups(source_schema)
+        schemas.append(pa.schema(
+            [field for field in source_schema if "/" not in field.name]
+            + [pa.field(group, pa.string(), nullable=False,
+                        metadata={b"description":
+                                  
_EPISODE_EXTRA_JSON_GROUP_DESCRIPTION.encode("utf-8")})
+               for group in source_groups if group not in 
_EPISODE_JSON_GROUPS]))
     metadata["episodes_schema"] = _merge_schemas(schemas, schema_evolution, 
_EPISODE_CONTROL_COLUMNS)
     frame_offset = episode_offset = 0
     for ordinal, plan in enumerate(plans):
@@ -365,18 +394,6 @@ def _plan_merge(plans, extra_dataset_fields=None, 
schema_evolution=True,
             del info[key]
     metadata["tasks_table"] = _vocabulary(plans, "tasks", existing_sources)
     metadata["subtasks_table"] = _vocabulary(plans, "subtasks", 
existing_sources)
-    metadata["episodes_schema"] = pa.schema([
-        metadata["episodes_schema"].field(name)
-        for name in _EPISODE_CONTROL_COLUMNS
-    ], metadata=metadata["episodes_schema"].metadata)
-    reserved_episode_fields = {
-        _DATASET_INDEX_COLUMN,
-        "meta", "data", "videos", "stats",
-    }
-    if any(reserved_episode_fields.intersection(
-            plan["metadata"]["episodes_schema"].names)
-           for plan in plans):
-        raise ValueError("Source Episode metadata uses reserved source index 
columns.")
     for field in (
             pa.field(_DATASET_INDEX_COLUMN, pa.int64(), nullable=False),
             pa.field("meta", pa.string(), nullable=False),
@@ -384,6 +401,13 @@ def _plan_merge(plans, extra_dataset_fields=None, 
schema_evolution=True,
             pa.field("videos", pa.string(), nullable=False),
             pa.field("stats", pa.string(), nullable=False)):
         metadata["episodes_schema"] = metadata["episodes_schema"].append(field)
+    episode_names = metadata["episodes_schema"].names
+    if len(episode_names) != len(set(episode_names)):
+        raise ValueError("Merged LeRobot Episode schema has duplicate columns: 
%s."
+                         % sorted(name for name in set(episode_names)
+                                  if episode_names.count(name) > 1))
+    # Use the same Arrow-to-Paimon conversion as table creation before 
creating frames.
+    PaimonSchema.from_pyarrow_schema(metadata["episodes_schema"])
     metadata["datasets_table"] = pa.Table.from_pylist([
         {
             "index": ordinal,
@@ -478,14 +502,23 @@ def _transform_frames(plan, batch, episode):
 
 
 def _merged_episodes(plans, schema):
+    extra_groups = tuple(dict.fromkeys(
+        group for plan in plans
+        for group in _episode_json_groups(plan["metadata"]["episodes_schema"])
+        if group not in _EPISODE_JSON_GROUPS))
     for plan in plans:
         for table in _source_episode_tables(plan["metadata"]):
+            source_groups = set(_episode_json_groups(table.schema))
             records = []
             for original in table.to_pylist():
                 row = {name: original[name] for name in schema.names
                        if name in original}
                 for group in ("meta", "data", "videos"):
                     row[group] = _episode_json_group(original, group)
+                for group in extra_groups:
+                    row[group] = (_episode_json_group(original, group)
+                                  if group in source_groups
+                                  else None)
                 stats = {}
                 for key, value in original.items():
                     if key.startswith("stats/"):
@@ -598,6 +631,22 @@ def _import_sources(connection, table_name, sources, 
batch_size, options,
             tables = _prepare_metadata_tables(connection, table.raw_table, 
metadata)
         else:
             table, tables, source_rows, ranges = existing
+            existing_episode_schema = _target_schema(tables["episodes"])
+            existing_groups = set(_EPISODE_JSON_GROUPS)
+            existing_groups.update(
+                field.name for field in existing_episode_schema
+                if (field.metadata or {}).get(b"description") ==
+                _EPISODE_EXTRA_JSON_GROUP_DESCRIPTION.encode("utf-8"))
+            incoming_groups = set(group for plan in plans
+                                  for group in _episode_json_groups(
+                                      plan["metadata"]["episodes_schema"]))
+            conflicts = sorted(
+                name for name in set(existing_episode_schema.names)
+                & set(metadata["episodes_schema"].names)
+                if (name in existing_groups) != (name in incoming_groups))
+            if conflicts:
+                raise ValueError("LeRobot append Episode JSON groups conflict 
with "
+                                 "plain columns: %s." % conflicts)
             first_info = ranges[0][0]
             old_features = {}
             for source in source_rows:
diff --git a/paimon-python/pypaimon/multimodal/lerobot/dataset.py 
b/paimon-python/pypaimon/multimodal/lerobot/dataset.py
index 94fe2fb4f6..d66d330f61 100644
--- a/paimon-python/pypaimon/multimodal/lerobot/dataset.py
+++ b/paimon-python/pypaimon/multimodal/lerobot/dataset.py
@@ -42,6 +42,7 @@ from pypaimon.multimodal.lerobot.aggregate import (
 )
 from pypaimon.common.options.core_options import CoreOptions
 from pypaimon.multimodal.lerobot.metadata import (
+    _EPISODE_CONTROL_COLUMNS,
     _dataset_fps,
     _positive_integer,
     _companion_table_identifiers,
@@ -1282,12 +1283,12 @@ def _episode_dataset(table, datasets=None):
             "PaimonLeRobotDataset requires datasets from "
             "'pypaimon[lerobot]'.") from error
 
-    projection = [
-        name for name in _target_schema(table).names
-        if not name.startswith("stats/") and name != "stats"
-        and (datasets is None or name not in (
-            "source_episode_patch_json", "source_episode_json", 
"source_episode_ipc"))
-    ]
+    if datasets is not None:
+        # Merged Episodes may contain Arrow extensions unsupported by HF 
Dataset.
+        projection = _EPISODE_CONTROL_COLUMNS + ["dataset_index"]
+    else:
+        projection = [name for name in _target_schema(table).names
+                      if not name.startswith("stats/") and name != "stats"]
     data = _read_arrow(table, projection)
     if datasets is not None:
         data = data.sort_by([
diff --git a/paimon-python/pypaimon/tests/lerobot_aggregate_test.py 
b/paimon-python/pypaimon/tests/lerobot_aggregate_test.py
index fa6f91494d..5992b93662 100644
--- a/paimon-python/pypaimon/tests/lerobot_aggregate_test.py
+++ b/paimon-python/pypaimon/tests/lerobot_aggregate_test.py
@@ -220,6 +220,42 @@ def 
test_append_rejects_incompatible_source_without_writing(setup):
     assert rows(conn, "robot_datasets").num_rows == 1
 
 
[email protected]("group_first", [False, True])
+def test_append_rejects_episode_group_plain_column_collision(setup, 
group_first):
+    conn, sources = setup
+    for index, uri in enumerate(sources):
+        path = Path(uri[7:]) / "meta/episodes/chunk-000/file-000.parquet"
+        grouped = (index == 0) == group_first
+        name = "camera_intrinsics/head_left" if grouped else 
"camera_intrinsics"
+        values = pa.array([[1.], [2.]] if grouped else ["plain one", "plain 
two"])
+        pq.write_table(pq.read_table(path).append_column(name, values), path)
+    conn.load_from_lerobot("robot", [sources[0]])
+    before = episode_rows(conn, 
"robot_episodes")["camera_intrinsics"].to_pylist()
+
+    with pytest.raises(ValueError, match="JSON groups conflict with plain 
columns"):
+        conn.append_to_lerobot("robot", sources[1])
+
+    assert episode_rows(conn, 
"robot_episodes")["camera_intrinsics"].to_pylist() == before
+    assert rows(conn, "robot_frames").num_rows == 5
+    assert rows(conn, "robot_datasets").num_rows == 1
+
+
+def test_append_preserves_episode_group_kind(setup):
+    conn, sources = setup
+    for index, uri in enumerate(sources):
+        path = Path(uri[7:]) / "meta/episodes/chunk-000/file-000.parquet"
+        values = pa.array([[float(index)], [float(index + 1)]])
+        pq.write_table(pq.read_table(path).append_column(
+            "camera_intrinsics/head_left", values), path)
+    conn.load_from_lerobot("robot", [sources[0]])
+    conn.append_to_lerobot("robot", sources[1])
+    actual = episode_rows(conn, 
"robot_episodes")["camera_intrinsics"].to_pylist()
+    assert [json.loads(value) for value in actual] == [
+        {"head_left": [0.]}, {"head_left": [1.]},
+        {"head_left": [1.]}, {"head_left": [2.]},
+    ]
+
+
 def test_append_episode_task_stats_use_group_vocabulary(setup):
     conn, sources = setup
     conn.load_from_lerobot("robot", [sources[0]])
@@ -500,6 +536,7 @@ def 
test_merge_keeps_source_specific_episode_statistics_in_json(setup):
         [1700000000123456789, None], type=pa.timestamp("ns", tz="UTC"))),
     ("stats/measurement/mean", pa.array(
         [Decimal("123456789.123"), None], type=pa.decimal128(12, 3))),
+    ("camera_intrinsics/head_left", pa.array([b"invalid", None])),
 ])
 def test_merge_rejects_non_json_episode_fields_before_create(setup, name, 
values):
     conn, sources = setup
@@ -1110,7 +1147,8 @@ def test_existing_source_episode_fps(setup, tmp_path, 
import_parallelism, multip
     conn.load_from_lerobot("merged", sources if multiple else [sources[0]],
                            parallelism=import_parallelism)
     episodes = episode_rows(conn, "merged_episodes")
-    assert "fps" not in episodes.column_names
+    assert episodes["fps"].to_pylist() == (
+        [10, 10, None, None] if multiple else [10, 10])
     assert episodes["dataset_index"].to_pylist() == (
         [0, 0, 1, 1] if multiple else [0, 0])
     assert [json.loads(value)["fps"] for value in
@@ -1311,10 +1349,7 @@ def 
test_default_fps_preserves_importer_contract(tmp_path, multiple, video_rate)
     pq.write_table(pq.read_table(path).append_column("fps", pa.array([10.0, 
10.0])), path)
     conn.load_from_lerobot("merged", [uri] if multiple else uri)
     episodes = rows(conn, "merged_episodes")
-    if multiple:
-        assert "fps" not in episodes.column_names
-    else:
-        assert episodes["fps"].to_pylist() == [10.0, 10.0]
+    assert episodes["fps"].to_pylist() == [10.0, 10.0]
     assert "fps_mode" not in metadata(conn, "info")
     reader = pm.PaimonLeRobotDataset(conn.get_table("merged_frames"), 
video_backend="pyav")
     try:
@@ -1426,7 +1461,7 @@ def 
test_merge_archives_standard_vocabulary_columns(setup, import_parallelism):
 
 
 @pytest.mark.parametrize("import_parallelism", [1, 2], indirect=True)
-def test_merge_omits_unmapped_arrow_native_episode_fields(setup, 
import_parallelism):
+def test_merge_preserves_arrow_native_episode_extensions(setup, 
import_parallelism):
     conn, sources = setup
     for index, uri in enumerate(sources):
         path = Path(uri[7:]) / "meta/episodes/chunk-000/file-000.parquet"
@@ -1440,11 +1475,37 @@ def 
test_merge_omits_unmapped_arrow_native_episode_fields(setup, import_parallel
         pq.write_table(table, path)
     conn.load_from_lerobot("merged", sources, parallelism=import_parallelism, 
tag_name="train")
     episodes = episode_rows(conn, "merged_episodes")
-    assert not {"native_bytes", "captured_at", "measurement"}.intersection(
-        episodes.column_names)
+    names = ["native_bytes", "captured_at", "measurement"]
+    for index, uri in enumerate(sources):
+        expected = pq.read_table(Path(uri[7:]) / 
"meta/episodes/chunk-000/file-000.parquet")
+        assert episodes.slice(index * 2, 2).select(names).to_pylist() == (
+            expected.select(names).to_pylist())
     assert rows(conn, "merged_frames").num_rows == 10
 
 
+def test_training_metadata_ignores_episode_map_extension(setup):
+    pytest.importorskip("datasets")
+    pytest.importorskip("torch")
+    conn, sources = setup
+    path = Path(sources[0][7:]) / "meta/episodes/chunk-000/file-000.parquet"
+    values = pa.array([[("vendor", 1)], [("vendor", 2)]],
+                      type=pa.map_(pa.string(), pa.int64()))
+    pq.write_table(pq.read_table(path).append_column("vendor_map", values), 
path)
+
+    conn.load_from_lerobot("merged", sources, tag_name="train")
+    episodes = episode_rows(conn, "merged_episodes")
+    assert episodes.schema.field("vendor_map").type == values.type
+    assert episodes["vendor_map"].to_pylist() == values.to_pylist() + [None, 
None]
+
+    reader = pm.PaimonLeRobotDataset(conn.get_table("merged_frames"), 
tag_name="train")
+    try:
+        assert reader.num_episodes == 4
+        assert "vendor_map" not in reader.meta.episodes.column_names
+        assert int(reader[0]["episode_index"]) == 0
+    finally:
+        reader.close()
+
+
 @pytest.mark.parametrize("dataset_index", [None, 1])
 def test_training_projects_out_source_archives(setup, dataset_index):
     from pypaimon.multimodal.lerobot import dataset as dataset_module
@@ -1492,7 +1553,7 @@ def test_training_projects_out_source_archives(setup, 
dataset_index):
 
 
 @pytest.mark.parametrize("import_parallelism", [1, 2], indirect=True)
-def test_merge_omits_unmapped_episode_timestamp(setup, import_parallelism):
+def test_merge_preserves_episode_timestamp(setup, import_parallelism):
     conn, sources = setup
     for uri in sources:
         path = Path(uri[7:]) / "meta/episodes/chunk-000/file-000.parquet"
@@ -1501,7 +1562,8 @@ def test_merge_omits_unmapped_episode_timestamp(setup, 
import_parallelism):
         pq.write_table(data, path)
     conn.load_from_lerobot("merged", sources, parallelism=import_parallelism, 
tag_name="train")
     data = episode_rows(conn, "merged_episodes")
-    assert "capture_time" not in data.column_names
+    expected = pq.read_table(Path(sources[0][7:]) / 
"meta/episodes/chunk-000/file-000.parquet")
+    assert data["capture_time"].to_pylist() == 
expected["capture_time"].to_pylist() * 2
     assert conn.catalog.get_tag(conn._identifier("merged_frames"), "train") is 
not None
 
 
@@ -1604,13 +1666,16 @@ def 
test_merge_source_specific_episode_extensions(setup, import_parallelism, rev
     pytest.importorskip("datasets")
     pytest.importorskip("torch")
     conn, sources = setup
+    original = sources[:]
     for index, uri in enumerate(sources):
         path = Path(uri[7:]) / "meta/episodes/chunk-000/file-000.parquet"
         data = pq.read_table(path)
         if index == 1:
             data = data.append_column("vendor_note", pa.array(["note", None]))
+            data = data.append_column("camera_intrinsics/head_left", pa.array(
+                [[1.] * 8, [2.] * 8], type=pa.list_(pa.float32(), 8)))
         data = data.append_column("vendor_value", pa.array(
-            [1, 2] if index == 0 else [b"a", b"b"]))
+            [1, 2] if index == 0 else [3, 4]))
         field = pa.field("shared_note", pa.string(), nullable=index == 1)
         data = data.append_column(field, pa.array(["shared", "note"] if index 
== 0 else [None, "note"]))
         pq.write_table(data, path)
@@ -1618,9 +1683,22 @@ def test_merge_source_specific_episode_extensions(setup, 
import_parallelism, rev
         sources.reverse()
     conn.load_from_lerobot("merged", sources, parallelism=import_parallelism, 
tag_name="train")
     data = episode_rows(conn, "merged_episodes")
-    assert "vendor_note" not in data.column_names
-    assert "vendor_value" not in data.column_names
-    assert "shared_note" not in data.column_names
+    assert data.schema.field("vendor_note").nullable
+    assert data.schema.field("camera_intrinsics").type == pa.string()
+    assert data.schema.field("camera_intrinsics").nullable
+    for ordinal, uri in enumerate(sources):
+        source_index = original.index(uri)
+        values = data.slice(ordinal * 2, 2)
+        assert values["vendor_note"].to_pylist() == (
+            [None, None] if source_index == 0 else ["note", None])
+        assert values["vendor_value"].to_pylist() == (
+            [1, 2] if source_index == 0 else [3, 4])
+        assert values["shared_note"].to_pylist() == (
+            ["shared", "note"] if source_index == 0 else [None, "note"])
+        assert [None if value is None else json.loads(value)
+                for value in values["camera_intrinsics"].to_pylist()] == (
+                    [None, None] if source_index == 0 else [
+                        {"head_left": [1.] * 8}, {"head_left": [2.] * 8}])
     reader = pm.PaimonLeRobotDataset(conn.get_table("merged_frames"), 
tag_name="train")
     try:
         assert [int(sample["episode_index"]) for sample in 
reader.get_items([0, 2, 5, 7])] == [0, 1, 2, 3]
@@ -1628,6 +1706,48 @@ def test_merge_source_specific_episode_extensions(setup, 
import_parallelism, rev
         reader.close()
 
 
+def test_merge_rejects_conflicting_episode_extension_types(setup):
+    conn, sources = setup
+    for index, uri in enumerate(sources):
+        path = Path(uri[7:]) / "meta/episodes/chunk-000/file-000.parquet"
+        data = pq.read_table(path).append_column(
+            "vendor_value", pa.array([1, 2] if index == 0 else [b"a", b"b"]))
+        pq.write_table(data, path)
+    with pytest.raises(ValueError, match="incompatible type.*vendor_value"):
+        conn.load_from_lerobot("merged", sources)
+    with pytest.raises(TableNotExistException):
+        conn.get_table("merged_frames")
+
+
+def test_merge_rejects_episode_json_group_column_collision(setup):
+    conn, sources = setup
+    for index, uri in enumerate(sources):
+        path = Path(uri[7:]) / "meta/episodes/chunk-000/file-000.parquet"
+        data = pq.read_table(path).append_column(
+            "camera_intrinsics" if index == 0 else 
"camera_intrinsics/head_left",
+            pa.array(["already a column"] * 2 if index == 0 else [[1.] * 8] * 
2))
+        pq.write_table(data, path)
+    with pytest.raises(ValueError, match="reserved 
columns:.*camera_intrinsics"):
+        conn.load_from_lerobot("merged", sources)
+    with pytest.raises(TableNotExistException):
+        conn.get_table("merged_frames")
+
+
[email protected]("name,values,error", [
+    ("dataset_index/vendor", pa.array([1, 2]), "reserved column 
dataset_index"),
+    ("vendor_flag", pa.array([1, 2], type=pa.uint8()), "Unsupported pyarrow 
type: uint8"),
+])
+def test_merge_rejects_unwritable_episode_extensions_before_create(setup, 
name, values, error):
+    conn, sources = setup
+    path = Path(sources[0][7:]) / "meta/episodes/chunk-000/file-000.parquet"
+    pq.write_table(pq.read_table(path).append_column(name, values), path)
+    with pytest.raises(ValueError, match=error):
+        conn.load_from_lerobot("merged", sources)
+    for component in ("frames", "episodes", "datasets"):
+        with pytest.raises(TableNotExistException):
+            conn.get_table("merged_" + component)
+
+
 def test_merge_rejects_incompatible_episode_controls(setup):
     conn, sources = setup
     path = Path(sources[1][7:]) / "meta/episodes/chunk-000/file-000.parquet"
@@ -2022,6 +2142,17 @@ def 
test_schema_evolution_disabled_keeps_first_source_schema(setup, add_new):
         assert rows(conn, "merged_frames")["temperature"].null_count == 5
 
 
+def test_schema_evolution_disabled_rejects_new_episode_json_group(setup):
+    conn, sources = setup
+    path = Path(sources[1][7:]) / "meta/episodes/chunk-000/file-000.parquet"
+    pq.write_table(pq.read_table(path).append_column(
+        "camera_intrinsics/head_left", pa.array([[1.] * 8] * 2)), path)
+    with pytest.raises(ValueError, match="schema_evolution disabled"):
+        conn.load_from_lerobot("merged", sources, schema_evolution=False)
+    with pytest.raises(TableNotExistException):
+        conn.get_table("merged_frames")
+
+
 @pytest.mark.parametrize("kind", ["frame", "shape"])
 def test_schema_evolution_rejects_type_changes(setup, kind):
     conn, sources = setup

Reply via email to