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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ python/dist
python/__pycache__
python/tsfile.egg-info
python/tsfile/__pycache__
python/tsfile/dataset/__pycache__
python/tsfile/*so*
python/tsfile/*dll*
python/tsfile/*dylib*
Expand Down
142 changes: 75 additions & 67 deletions python/tests/test_write_and_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,31 +508,35 @@ def test_query_result_detach_from_reader():


def test_lower_case_name():
if os.path.exists("lower_case_name.tsfile"):
os.remove("lower_case_name.tsfile")
table = TableSchema(
"tEst_Table",
[
ColumnSchema("Device", TSDataType.STRING, ColumnCategory.TAG),
ColumnSchema("vAlue", TSDataType.DOUBLE, ColumnCategory.FIELD),
],
)
with TsFileTableWriter("lower_case_name.tsfile", table) as writer:
tablet = Tablet(["device", "VALUE"], [TSDataType.STRING, TSDataType.DOUBLE])
for i in range(100):
tablet.add_timestamp(i, i)
tablet.add_value_by_name("device", i, "device" + str(i))
tablet.add_value_by_name("valuE", i, i * 1.1)
try:
if os.path.exists("lower_case_name.tsfile"):
os.remove("lower_case_name.tsfile")
table = TableSchema(
"tEst_Table",
[
ColumnSchema("Device", TSDataType.STRING, ColumnCategory.TAG),
ColumnSchema("vAlue", TSDataType.DOUBLE, ColumnCategory.FIELD),
],
)
with TsFileTableWriter("lower_case_name.tsfile", table) as writer:
tablet = Tablet(["device", "VALUE"], [TSDataType.STRING, TSDataType.DOUBLE])
for i in range(100):
tablet.add_timestamp(i, i)
tablet.add_value_by_name("device", i, "device" + str(i))
tablet.add_value_by_name("valuE", i, i * 1.1)

writer.write_table(tablet)
writer.write_table(tablet)

with TsFileReader("lower_case_name.tsfile") as reader:
result = reader.query_table("test_Table", ["DEvice", "value"], 0, 100)
while result.next():
print(result.get_value_by_name("DEVICE"))
data_frame = result.read_data_frame(max_row_num=130)
assert data_frame.shape == (100, 3)
assert data_frame["value"].sum() == 5445.0
with TsFileReader("lower_case_name.tsfile") as reader:
result = reader.query_table("test_Table", ["DEvice", "value"], 0, 100)
while result.next():
print(result.get_value_by_name("DEVICE"))
data_frame = result.read_data_frame(max_row_num=130)
assert data_frame.shape == (100, 3)
assert data_frame["value"].sum() == 5445.0
finally:
if os.path.exists("lower_case_name.tsfile"):
os.remove("lower_case_name.tsfile")


def test_tsfile_config():
Expand All @@ -547,49 +551,53 @@ def test_tsfile_config():
ColumnSchema("vAlue", TSDataType.DOUBLE, ColumnCategory.FIELD),
],
)
if os.path.exists("test1.tsfile"):
try:
if os.path.exists("test1.tsfile"):
os.remove("test1.tsfile")
with TsFileTableWriter("test1.tsfile", table) as writer:
tablet = Tablet(["device", "VALUE"], [TSDataType.STRING, TSDataType.DOUBLE])
for i in range(100):
tablet.add_timestamp(i, i)
tablet.add_value_by_name("device", i, "device" + str(i))
tablet.add_value_by_name("valuE", i, i * 1.1)

writer.write_table(tablet)

config_normal = get_tsfile_config()
print(config_normal)
assert config_normal["chunk_group_size_threshold_"] == 128 * 1024 * 1024

os.remove("test1.tsfile")
with TsFileTableWriter("test1.tsfile", table) as writer:
tablet = Tablet(["device", "VALUE"], [TSDataType.STRING, TSDataType.DOUBLE])
for i in range(100):
tablet.add_timestamp(i, i)
tablet.add_value_by_name("device", i, "device" + str(i))
tablet.add_value_by_name("valuE", i, i * 1.1)

writer.write_table(tablet)

config_normal = get_tsfile_config()
print(config_normal)
assert config_normal["chunk_group_size_threshold_"] == 128 * 1024 * 1024

os.remove("test1.tsfile")
with TsFileTableWriter("test1.tsfile", table, 100 * 100) as writer:
tablet = Tablet(["device", "VALUE"], [TSDataType.STRING, TSDataType.DOUBLE])
for i in range(100):
tablet.add_timestamp(i, i)
tablet.add_value_by_name("device", i, "device" + str(i))
tablet.add_value_by_name("valuE", i, i * 1.1)

writer.write_table(tablet)
config_modified = get_tsfile_config()
assert config_normal != config_modified
assert config_modified["chunk_group_size_threshold_"] == 100 * 100
set_tsfile_config({"chunk_group_size_threshold_": 100 * 20})
assert get_tsfile_config()["chunk_group_size_threshold_"] == 100 * 20
with pytest.raises(TypeError):
set_tsfile_config({"time_compress_type_": TSDataType.DOUBLE})
with pytest.raises(TypeError):
set_tsfile_config({"chunk_group_size_threshold_": -1 * 100 * 20})

set_tsfile_config({"float_encoding_type_": TSEncoding.PLAIN})
assert get_tsfile_config()["float_encoding_type_"] == TSEncoding.PLAIN

with pytest.raises(TypeError):
set_tsfile_config({"float_encoding_type_": -1 * 100 * 20})
with pytest.raises(NotSupportedError):
set_tsfile_config({"float_encoding_type_": TSEncoding.BITMAP})
with pytest.raises(NotSupportedError):
set_tsfile_config({"time_compress_type_": Compressor.PAA})
with TsFileTableWriter("test1.tsfile", table, 100 * 100) as writer:
tablet = Tablet(["device", "VALUE"], [TSDataType.STRING, TSDataType.DOUBLE])
for i in range(100):
tablet.add_timestamp(i, i)
tablet.add_value_by_name("device", i, "device" + str(i))
tablet.add_value_by_name("valuE", i, i * 1.1)

writer.write_table(tablet)
config_modified = get_tsfile_config()
assert config_normal != config_modified
assert config_modified["chunk_group_size_threshold_"] == 100 * 100
set_tsfile_config({"chunk_group_size_threshold_": 100 * 20})
assert get_tsfile_config()["chunk_group_size_threshold_"] == 100 * 20
with pytest.raises(TypeError):
set_tsfile_config({"time_compress_type_": TSDataType.DOUBLE})
with pytest.raises(TypeError):
set_tsfile_config({"chunk_group_size_threshold_": -1 * 100 * 20})

set_tsfile_config({"float_encoding_type_": TSEncoding.PLAIN})
assert get_tsfile_config()["float_encoding_type_"] == TSEncoding.PLAIN

with pytest.raises(TypeError):
set_tsfile_config({"float_encoding_type_": -1 * 100 * 20})
with pytest.raises(NotSupportedError):
set_tsfile_config({"float_encoding_type_": TSEncoding.BITMAP})
with pytest.raises(NotSupportedError):
set_tsfile_config({"time_compress_type_": Compressor.PAA})
finally:
if os.path.exists("test1.tsfile"):
os.remove("test1.tsfile")


def test_tsfile_to_df():
Expand Down Expand Up @@ -835,8 +843,8 @@ def test_tree_all_datatype_query_to_dataframe_variants():
pass

finally:
if os.path.exists("tablet_write_and_read.tsfile"):
os.remove("tablet_write_and_read.tsfile")
if os.path.exists("record_write_and_read.tsfile"):
os.remove("record_write_and_read.tsfile")


if __name__ == "__main__":
Expand Down
Loading