Skip to content
Open
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
42 changes: 42 additions & 0 deletions python/tests/test_write_and_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,45 @@ def test_tsfile_config():
set_tsfile_config({"float_encoding_type_": TSEncoding.BITMAP})
with pytest.raises(NotSupportedError):
set_tsfile_config({"time_compress_type_": Compressor.PAA})

def test_configuration_manager():
"""Test TSFile configuration getter and setter functions"""
from tsfile.tsfile_py_cpp import (
tsconf_get_global_time_encoding,
tsconf_set_global_time_encoding,
tsconf_get_global_time_compression,
tsconf_set_global_time_compression,
tsconf_get_datatype_encoding,
tsconf_set_datatype_encoding,
tsconf_get_global_compression,
tsconf_set_global_compression,
)
from tsfile.constants import TSDataType, TSEncoding, Compressor

def test_config(getter, setter, test_value, original_value):
assert setter(test_value) == 0
assert getter() == test_value
assert setter(original_value) == 0
assert getter() == original_value

# Test global configurations
test_config(tsconf_get_global_time_encoding, tsconf_set_global_time_encoding,
TSEncoding.PLAIN, tsconf_get_global_time_encoding())
test_config(tsconf_get_global_time_compression, tsconf_set_global_time_compression,
Compressor.UNCOMPRESSED, tsconf_get_global_time_compression())
test_config(tsconf_get_global_compression, tsconf_set_global_compression,
Compressor.SNAPPY, tsconf_get_global_compression())

# Test datatype encodings
test_cases = [
(TSDataType.BOOLEAN, TSEncoding.PLAIN),
(TSDataType.INT32, TSEncoding.TS_2DIFF),
(TSDataType.FLOAT, TSEncoding.GORILLA),
(TSDataType.TEXT, TSEncoding.DICTIONARY),
]

for dtype, enc in test_cases:
orig = tsconf_get_datatype_encoding(dtype)
assert tsconf_set_datatype_encoding(dtype, enc) == 0
assert tsconf_get_datatype_encoding(dtype) == enc
assert tsconf_set_datatype_encoding(dtype, orig) == 0
10 changes: 10 additions & 0 deletions python/tsfile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@
from .tsfile_reader import TsFileReaderPy as TsFileReader, ResultSetPy as ResultSet
from .tsfile_writer import TsFileWriterPy as TsFileWriter
from .tsfile_py_cpp import get_tsfile_config, set_tsfile_config
from .tsfile_py_cpp import (
tsconf_set_datatype_encoding,
tsconf_get_datatype_encoding,
tsconf_get_global_time_encoding,
tsconf_get_global_time_compression,
tsconf_get_global_compression,
tsconf_set_global_compression,
tsconf_set_global_time_encoding,
tsconf_set_global_time_compression
)
from .tsfile_table_writer import TsFileTableWriter
12 changes: 9 additions & 3 deletions python/tsfile/tsfile_cpp.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,14 @@ cdef extern from "./common/config/config.h" namespace "common":

cdef extern from "./common/global.h" namespace "common":
ConfigValue g_config_value_
# Getter functions
uint8_t get_global_time_encoding()
uint8_t get_global_time_compression()
uint8_t get_datatype_encoding(uint8_t data_type)
uint8_t get_global_compression()

# Setter functions
int set_datatype_encoding(uint8_t data_type, uint8_t encoding)
int set_global_compression(uint8_t compression)
int set_global_time_data_type(uint8_t data_type);
int set_global_time_encoding(uint8_t encoding);
int set_global_time_compression(uint8_t compression);
int set_global_time_encoding(uint8_t encoding)
int set_global_time_compression(uint8_t compression)
77 changes: 72 additions & 5 deletions python/tsfile/tsfile_py_cpp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,6 @@ cpdef void set_tsfile_config(dict new_config):
raise TypeError(f"Unsupported TSEncoding: {new_config['time_encoding_type_']}")
code = set_global_time_encoding(<uint8_t>(new_config["time_encoding_type_"].value))
check_error(code)
if "time_data_type_" in new_config:
if not isinstance(new_config["time_data_type_"], TSDataTypePy):
raise TypeError(f"Unsupported TSDataType: {new_config['time_data_type_']}")
code = set_global_time_data_type(<uint8_t>(new_config["time_data_type_"].value))
check_error(code)
if "time_compress_type_" in new_config:
if not isinstance(new_config["time_compress_type_"], CompressorPy):
raise TypeError(f"Unsupported Compressor: {new_config['time_compress_type_']}")
Expand Down Expand Up @@ -562,3 +557,75 @@ cdef object get_all_table_schema(TsFileReader reader):
free(schemas)
return table_schemas

# Getter functions to retrieve configuration values
cpdef int tsconf_get_global_time_encoding():
"""Get the global time encoding type"""
return get_global_time_encoding()

cpdef int tsconf_get_global_time_compression():
"""Get the global time compression type"""
return get_global_time_compression()

cpdef int tsconf_get_datatype_encoding(uint8_t data_type):
"""Get the encoding type for a specific data type

Args:
data_type: The TSDataType to query encoding for
Returns:
The encoding type for the specified data type
"""
return get_datatype_encoding(data_type)

cpdef int tsconf_get_global_compression():
"""Get the global compression type"""
return get_global_compression()

# Setter functions to modify configuration values
cpdef ErrorCode tsconf_set_datatype_encoding(uint8_t data_type, uint8_t encoding) except -1:
"""Set the encoding type for a specific data type

Args:
data_type: The TSDataType to configure
encoding: The encoding type to set
Returns:
ErrorCode indicating success or failure
"""
cdef ErrorCode errno = set_datatype_encoding(data_type, encoding)
check_error(errno)
return errno

cpdef ErrorCode tsconf_set_global_compression(uint8_t compression) except -1:
"""Set the global compression type

Args:
compression: The compression type to set
Returns:
ErrorCode indicating success or failure
"""
cdef ErrorCode errno = set_global_compression(compression)
check_error(errno)
return errno

cpdef ErrorCode tsconf_set_global_time_encoding(uint8_t encoding) except -1:
"""Set the global time encoding type

Args:
encoding: The encoding type to set
Returns:
ErrorCode indicating success or failure
"""
cdef ErrorCode errno = set_global_time_encoding(encoding)
check_error(errno)
return errno

cpdef ErrorCode tsconf_set_global_time_compression(uint8_t compression) except -1:
"""Set the global time compression type

Args:
compression: The compression type to set
Returns:
ErrorCode indicating success or failure
"""
cdef ErrorCode errno = set_global_time_compression(compression)
check_error(errno)
return errno
Loading