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
8 changes: 8 additions & 0 deletions cpp/examples/c_examples/demo_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
// This example shows you how to write tsfile.
ERRNO write_tsfile() {
ERRNO code = 0;
code = set_global_compression(TS_COMPRESSION_LZ4);
if (code != RET_OK) {
return code;
}
code = set_datatype_encoding(TS_DATATYPE_INT32, TS_ENCODING_TS_2DIFF);
if (code != RET_OK) {
return code;
}
char* table_name = "table1";

// Create table schema to describe a table in a tsfile.
Expand Down
102 changes: 73 additions & 29 deletions cpp/src/common/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ FORCE_INLINE int set_global_time_data_type(uint8_t data_type) {

FORCE_INLINE int set_global_time_encoding(uint8_t encoding) {
ASSERT(encoding >= PLAIN && encoding <= FREQ);
if (encoding != TS_2DIFF && encoding != PLAIN) {
if (encoding != TS_2DIFF && encoding != PLAIN && encoding != GORILLA &&
encoding != ZIGZAG && encoding != RLE && encoding != SPRINTZ) {
return E_NOT_SUPPORT;
}
g_config_value_.time_encoding_type_ = static_cast<TSEncoding>(encoding);
Expand All @@ -49,7 +50,8 @@ FORCE_INLINE int set_global_time_encoding(uint8_t encoding) {

FORCE_INLINE int set_global_time_compression(uint8_t compression) {
ASSERT(compression >= UNCOMPRESSED && compression <= LZ4);
if (compression != UNCOMPRESSED && compression != LZ4) {
if (compression != UNCOMPRESSED && compression != SNAPPY &&
compression != GZIP && compression != LZO && compression != LZ4) {
return E_NOT_SUPPORT;
}
g_config_value_.time_compress_type_ =
Expand All @@ -58,51 +60,52 @@ FORCE_INLINE int set_global_time_compression(uint8_t compression) {
}

FORCE_INLINE int set_datatype_encoding(uint8_t data_type, uint8_t encoding) {
TSDataType dtype = static_cast<TSDataType>(data_type);
const TSDataType dtype = static_cast<TSDataType>(data_type);
const TSEncoding encoding_type = static_cast<TSEncoding>(encoding);

// Validate input parameters
ASSERT(dtype >= BOOLEAN && dtype <= STRING);
TSEncoding encoding_type = static_cast<TSEncoding>(encoding);
ASSERT(encoding >= PLAIN && encoding <= FREQ);
ASSERT(encoding >= PLAIN && encoding <= SPRINTZ);

// Check encoding support for each data type
switch (dtype) {
case BOOLEAN:
if (encoding_type != PLAIN) {
return E_NOT_SUPPORT;
}
if (encoding_type != PLAIN) return E_NOT_SUPPORT;
g_config_value_.boolean_encoding_type_ = encoding_type;
break;

case INT32:
if (encoding_type != PLAIN && encoding_type != TS_2DIFF &&
encoding_type != GORILLA) {
return E_NOT_SUPPORT;
}
g_config_value_.int32_encoding_type_ = encoding_type;
break;
case DATE:
case INT64:
if (encoding_type != PLAIN && encoding_type != TS_2DIFF &&
encoding_type != GORILLA) {
return E_NOT_SUPPORT;
}
g_config_value_.int64_encoding_type_ = encoding_type;
break;
case STRING:
if (encoding_type != PLAIN) {
encoding_type != GORILLA && encoding_type != ZIGZAG &&
encoding_type != RLE && encoding_type != SPRINTZ) {
return E_NOT_SUPPORT;
}
g_config_value_.string_encoding_type_ = encoding_type;
dtype == INT32
? g_config_value_.int32_encoding_type_ = encoding_type
: g_config_value_.int64_encoding_type_ = encoding_type;
break;

case FLOAT:
case DOUBLE:
if (encoding_type != PLAIN && encoding_type != TS_2DIFF &&
encoding_type != GORILLA) {
encoding_type != GORILLA && encoding_type != SPRINTZ) {
return E_NOT_SUPPORT;
}
g_config_value_.float_encoding_type_ = encoding_type;
dtype == FLOAT
? g_config_value_.float_encoding_type_ = encoding_type
: g_config_value_.double_encoding_type_ = encoding_type;
break;
case DOUBLE:
if (encoding_type != PLAIN && encoding_type != TS_2DIFF &&
encoding_type != GORILLA) {

case STRING:
case TEXT:
if (encoding_type != PLAIN && encoding_type != DICTIONARY) {
return E_NOT_SUPPORT;
}
g_config_value_.double_encoding_type_ = encoding_type;
g_config_value_.string_encoding_type_ = encoding_type;
break;

default:
break;
}
Expand All @@ -111,14 +114,55 @@ FORCE_INLINE int set_datatype_encoding(uint8_t data_type, uint8_t encoding) {

FORCE_INLINE int set_global_compression(uint8_t compression) {
ASSERT(compression >= UNCOMPRESSED && compression <= LZ4);
if (compression != UNCOMPRESSED && compression != LZ4) {
if (compression != UNCOMPRESSED && compression != SNAPPY &&
compression != GZIP && compression != LZO && compression != LZ4) {
return E_NOT_SUPPORT;
}
g_config_value_.default_compression_type_ =
static_cast<CompressionType>(compression);
return E_OK;
}

FORCE_INLINE uint8_t get_global_time_encoding() {
return static_cast<uint8_t>(g_config_value_.time_encoding_type_);
}

FORCE_INLINE uint8_t get_global_time_compression() {
return static_cast<uint8_t>(g_config_value_.time_compress_type_);
}

FORCE_INLINE uint8_t get_datatype_encoding(uint8_t data_type) {
const TSDataType dtype = static_cast<TSDataType>(data_type);

// Validate input parameter
ASSERT(dtype >= BOOLEAN && dtype <= STRING);

switch (dtype) {
case BOOLEAN:
return static_cast<uint8_t>(g_config_value_.boolean_encoding_type_);
case INT32:
return static_cast<uint8_t>(g_config_value_.int32_encoding_type_);
case INT64:
return static_cast<uint8_t>(g_config_value_.int64_encoding_type_);
case FLOAT:
return static_cast<uint8_t>(g_config_value_.float_encoding_type_);
case DOUBLE:
return static_cast<uint8_t>(g_config_value_.double_encoding_type_);
case STRING:
case TEXT:
return static_cast<uint8_t>(g_config_value_.string_encoding_type_);
case DATE:
return static_cast<uint8_t>(g_config_value_.int64_encoding_type_);
default:
return static_cast<uint8_t>(
PLAIN); // Return default encoding for unknown types
}
}

FORCE_INLINE uint8_t get_global_compression() {
return static_cast<uint8_t>(g_config_value_.default_compression_type_);
}

extern int init_common();
extern bool is_timestamp_column_name(const char *time_col_name);
extern void cols_to_json(ByteStream *byte_stream,
Expand Down
30 changes: 30 additions & 0 deletions cpp/src/cwrapper/tsfile_cwrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,36 @@ void init_tsfile_config() {
}
}

uint8_t get_global_time_encoding() {
return common::get_global_time_encoding();
}

uint8_t get_global_time_compression() {
return common::get_global_time_compression();
}

uint8_t get_datatype_encoding(uint8_t data_type) {
return common::get_datatype_encoding(data_type);
}

uint8_t get_global_compression() { return common::get_global_compression(); }

int set_global_time_encoding(uint8_t encoding) {
return common::set_global_time_encoding(encoding);
}

int set_global_time_compression(uint8_t compression) {
return common::set_global_time_compression(compression);
}

int set_datatype_encoding(uint8_t data_type, uint8_t encoding) {
return common::set_datatype_encoding(data_type, encoding);
}

int set_global_compression(uint8_t compression) {
return common::set_global_compression(compression);
}

WriteFile write_file_new(const char *pathname, ERRNO *err_code) {
int ret;
init_tsfile_config();
Expand Down
73 changes: 73 additions & 0 deletions cpp/src/cwrapper/tsfile_cwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,79 @@ typedef void* ResultSet;
typedef int32_t ERRNO;
typedef int64_t Timestamp;

/**
* @brief Get the encoding type for global time column
*
* @return uint8_t Time encoding type enum value (cast to uint8_t)
*/
uint8_t get_global_time_encoding();

/**
* @brief Get the compression type for global time column
*
* @return uint8_t Time compression type enum value (cast to uint8_t)
*/
uint8_t get_global_time_compression();

/**
* @brief Get the encoding type for specified data type
*
* @param data_type The data type to query encoding for
* @return uint8_t Encoding type enum value (cast to uint8_t)
*/
uint8_t get_datatype_encoding(uint8_t data_type);

/**
* @brief Get the global default compression type
*
* @return uint8_t Compression type enum value (cast to uint8_t)
*/
uint8_t get_global_compression();

/**
* @brief Sets the global time column encoding method
*
* Validates and sets the encoding type for time series timestamps.
* Supported encodings: TS_2DIFF, PLAIN, GORILLA, ZIGZAG, RLE, SPRINTZ
*
* @param encoding The encoding type to set (as uint8_t)
* @return int E_OK on success, E_NOT_SUPPORT for invalid encoding
*/
int set_global_time_encoding(uint8_t encoding);

/**
* @brief Sets the global time column compression method
*
* Validates and sets the compression type for time series timestamps.
* Supported compressions: UNCOMPRESSED, SNAPPY, GZIP, LZO, LZ4
*
* @param compression The compression type to set (as uint8_t)
* @return int E_OK on success, E_NOT_SUPPORT for invalid compression
*/
int set_global_time_compression(uint8_t compression);

/**
* @brief Set encoding type for specific data type
* @param data_type The data type to configure
* @param encoding The encoding type to set
* @return E_OK if success, E_NOT_SUPPORT if encoding is not supported for the
* data type
* @note Supported encodings per data type:
* - BOOLEAN: PLAIN only
* - INT32/INT64: PLAIN, TS_2DIFF, GORILLA, ZIGZAG, RLE, SPRINTZ
* - FLOAT/DOUBLE: PLAIN, TS_2DIFF, GORILLA, SPRINTZ
* - STRING: PLAIN, DICTIONARY
*/
int set_datatype_encoding(uint8_t data_type, uint8_t encoding);

/**
* @brief Set the global default compression type
* @param compression Compression type to set
* @return E_OK if success, E_NOT_SUPPORT if compression is not supported
* @note Supported compressions: UNCOMPRESSED, SNAPPY, GZIP, LZO, LZ4
*/
int set_global_compression(uint8_t compression);

/*--------------------------TsFile Reader and Writer------------------------ */

/**
Expand Down
Loading
Loading