Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions python/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ def test_tablet_add_column():
assert tablet.get_value_by_index(1, 2) == 22


def test_tablet_column_names_are_case_insensitive():
tablet = Tablet(["First"], [TSDataType.INT32], 1)
tablet.add_column("NewField", TSDataType.INT32)
tablet.add_value_by_name("NEWFIELD", 0, 42)

assert tablet.get_column_name_list() == ["first", "newfield"]
assert tablet.get_value_by_name("NewField", 0) == 42
assert tablet.get_value_list_by_name("NEWFIELD") == [42]
tablet.remove_column("FIRST")
assert tablet.get_column_name_list() == ["newfield"]
assert tablet.get_value_by_index(0, 0) == 42


def test_tablet_remove_column_with_repeated_type():
tablet = Tablet(
["a", "b", "c", "d"],
Expand Down
21 changes: 21 additions & 0 deletions python/tests/test_write_and_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,27 @@ def test_tablet_remove_and_add_column_round_trip(tmp_path):
assert not result.next()


def test_tablet_added_mixed_case_column_round_trip(tmp_path):
path = str(tmp_path / "mixed_case_column.tsfile")
dtype = TSDataType.INT32
table = TableSchema(
"readings", [ColumnSchema("base", dtype), ColumnSchema("value", dtype)]
)
tablet = Tablet(["base"], [dtype], 1)
tablet.add_column("VaLuE", dtype)
tablet.add_timestamp(0, 1)
tablet.add_value_by_index(0, 0, 11)
tablet.add_value_by_index(1, 0, 42)

with TsFileTableWriter(path, table) as writer:
writer.write_table(tablet)
with TsFileReader(path) as reader:
with reader.query_table("readings", ["base", "value"], 1, 1) as result:
assert result.next()
assert result.get_value_by_name("base") == 11
assert result.get_value_by_name("value") == 42


def test_table_writer_and_reader():
table = TableSchema(
"test_table",
Expand Down
8 changes: 4 additions & 4 deletions python/tsfile/tablet.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ def get_max_row_num(self):

def add_column(self, column_name: str, data_type: TSDataType):
values = [None] * self.max_row_num
self.column_name_list.append(column_name)
self.column_name_list.append(column_name.lower())
self.type_list.append(data_type)
self.data_list.append(values)

def remove_column(self, column_name: str):
col_index = self.column_name_list.index(column_name)
col_index = self.column_name_list.index(column_name.lower())
del self.column_name_list[col_index]
del self.type_list[col_index]
del self.data_list[col_index]
Expand Down Expand Up @@ -178,7 +178,7 @@ def get_value_by_index(self, col_index: int, row_index: int):

def get_value_by_name(self, column_name: str, row_index: int):
try:
col_index = self.column_name_list.index(column_name)
col_index = self.column_name_list.index(column_name.lower())
except ValueError:
raise ValueError(f"Column '{column_name}' does not exist") from None
if not (0 <= row_index < self.max_row_num):
Expand All @@ -189,7 +189,7 @@ def get_value_by_name(self, column_name: str, row_index: int):

def get_value_list_by_name(self, column_name: str):
try:
col_index = self.column_name_list.index(column_name)
col_index = self.column_name_list.index(column_name.lower())
except ValueError:
raise ValueError(f"Column '{column_name}' does not exist") from None
return self.data_list[col_index]
2 changes: 2 additions & 0 deletions skills/tsfile/references/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ it has a public `name` attribute.
Use `tablet.remove_column(name)` to discard a column and its buffered values.
`tablet.add_column(name, data_type)` appends a column with `None` in every row.
Existing columns retain their types and values across both operations.
`Tablet` stores column names in lowercase. You can use any capitalization
when reading or writing a value by column name or removing a column.

## Table-Model Read

Expand Down
Loading