diff --git a/python/tests/test_write_and_read.py b/python/tests/test_write_and_read.py index 787318995..9e7cdc18d 100644 --- a/python/tests/test_write_and_read.py +++ b/python/tests/test_write_and_read.py @@ -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 diff --git a/python/tsfile/__init__.py b/python/tsfile/__init__.py index 0c5081fa8..f5a927e61 100644 --- a/python/tsfile/__init__.py +++ b/python/tsfile/__init__.py @@ -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 \ No newline at end of file diff --git a/python/tsfile/tsfile_cpp.pxd b/python/tsfile/tsfile_cpp.pxd index 1b04051c9..2aa378354 100644 --- a/python/tsfile/tsfile_cpp.pxd +++ b/python/tsfile/tsfile_cpp.pxd @@ -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) diff --git a/python/tsfile/tsfile_py_cpp.pyx b/python/tsfile/tsfile_py_cpp.pyx index e17430399..be4fdd36a 100644 --- a/python/tsfile/tsfile_py_cpp.pyx +++ b/python/tsfile/tsfile_py_cpp.pyx @@ -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((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((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_']}") @@ -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