ycycse commented on code in PR #765:
URL: https://github.com/apache/tsfile/pull/765#discussion_r3043090295


##########
python/tsfile/dataset/metadata.py:
##########
@@ -0,0 +1,224 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+"""Shared metadata models for dataset readers and views."""
+
+from dataclasses import dataclass, field
+from typing import Any, Dict, Iterable, Iterator, List, Tuple
+
+import numpy as np
+
+from ..constants import TSDataType
+
+
+_PATH_SEPARATOR = "."
+_PATH_ESCAPE = "\\"
+
+
+@dataclass(slots=True)
+class TableEntry:
+    """Schema-level metadata shared by every device in one table."""
+
+    table_name: str
+    tag_columns: Tuple[str, ...]
+    tag_types: Tuple[TSDataType, ...]
+    field_columns: Tuple[str, ...]
+    _field_index_by_name: Dict[str, int] = field(init=False, repr=False)
+
+    def __post_init__(self):
+        self._field_index_by_name = {column: idx for idx, column in 
enumerate(self.field_columns)}
+
+    def get_field_index(self, field_name: str) -> int:
+        if field_name not in self._field_index_by_name:
+            raise ValueError(f"Field not found in table '{self.table_name}': 
{field_name}")
+        return self._field_index_by_name[field_name]
+
+
+@dataclass(slots=True)
+class DeviceEntry:
+    """One logical device identified by table name + ordered tag values."""
+
+    table_id: int
+    tag_values: Tuple[Any, ...]
+    timestamps: np.ndarray
+    length: int
+    min_time: int
+    max_time: int
+
+
+@dataclass(slots=True)
+class MetadataCatalog:
+    """Canonical metadata store shared by dataset readers and dataframes."""
+
+    table_entries: List[TableEntry] = field(default_factory=list)
+    device_entries: List[DeviceEntry] = field(default_factory=list)
+    table_id_by_name: Dict[str, int] = field(default_factory=dict)
+    device_id_by_key: Dict[Tuple[int, tuple], int] = 
field(default_factory=dict)
+
+    def add_table(
+        self,
+        table_name: str,
+        tag_columns: Iterable[str],
+        tag_types: Iterable[TSDataType],
+        field_columns: Iterable[str],
+    ) -> int:
+        table_id = len(self.table_entries)
+        self.table_entries.append(
+            TableEntry(
+                table_name=table_name,
+                tag_columns=tuple(tag_columns),
+                tag_types=tuple(tag_types),
+                field_columns=tuple(field_columns),
+            )
+        )
+        self.table_id_by_name[table_name] = table_id
+        return table_id

Review Comment:
   That's right, I missed that. In current impentation, same table across 
TsFiles are assumed to have the same schema which need some time to support 
field-union merge. Since we have valiation to reject the situaion, I think we 
can note it down and follow up it with a separate PR?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to