Skip to content

Commit

Permalink
support py.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinLeeo committed Feb 10, 2025
1 parent 2bc0e62 commit a26064c
Show file tree
Hide file tree
Showing 21 changed files with 358 additions and 477 deletions.
File renamed without changes.
14 changes: 7 additions & 7 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ def copy_header(source, target):
]

# source_include_dir = os.path.join(
# project_dir, "..", "cpp", "src", "cwrapper", "TsFile-cwrapper.h"
# project_dir, "..", "cpp", "c_include", "cwrapper", "TsFile-cwrapper.h"
# )
# target_include_dir = os.path.join(project_dir, "tsfile", "TsFile-cwrapper.h")
# copy_header(source_include_dir, target_include_dir)

if system == "Darwin":
copy_lib_files(libtsfile_shard_dir, libtsfile_dir, version + ".dylib")
elif system == "Linux":
copy_lib_files(libtsfile_shard_dir, libtsfile_dir, "so." + version)
else:
copy_lib_files(libtsfile_shard_dir, libtsfile_dir, "dll")
# if system == "Darwin":
# copy_lib_files(libtsfile_shard_dir, libtsfile_dir, version + ".dylib")
# elif system == "Linux":
# copy_lib_files(libtsfile_shard_dir, libtsfile_dir, "so." + version)
# else:
# copy_lib_files(libtsfile_shard_dir, libtsfile_dir, "dll")

ext_modules_tsfile = [
Extension(
Expand Down
2 changes: 1 addition & 1 deletion python/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


import tsfile as ts
from tsfile.tsfile import EmptyFileError
from tsfile.tsfile_dataframe import EmptyFileError

TABLE_NAME = "test_table"
DATA_PATH = os.path.join(os.path.dirname(__file__), "target")
Expand Down
8 changes: 7 additions & 1 deletion python/tsfile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@
# specific language governing permissions and limitations
# under the License.
#
from .tsfile import read_tsfile, write_tsfile
from .tsfile_dataframe import read_tsfile, write_tsfile
from .tsfile_reader import TsFileReaderPy as TsFileReader
from .tsfile_writer import TsFileWriterPy as TsFileWriter
from .constants import *
from .schema import *
from .row_record import *
from .tablet import *
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ typedef struct table_schema {
} TableSchema;

typedef struct timeseries_schema {
char* name;
char* timeseries_name;
TSDataType data_type;
TSEncoding encoding;
CompressionType compression;
Expand All @@ -87,7 +87,7 @@ typedef struct device_schema {
int timeseries_num;
} DeviceSchema;

typedef struct {
typedef struct result_set_meta_data {
char** column_names;
TSDataType* data_types;
int column_num;
Expand Down Expand Up @@ -173,7 +173,7 @@ ERRNO tsfile_writer_close(TsFileWriter writer);
ERRNO tsfile_reader_close(TsFileReader reader);

/*--------------------------TsFile Writer Register------------------------ */
void tsfile_writer_register_table(TsFileWriter writer, TableSchema* schema);
ERRNO tsfile_writer_register_table(TsFileWriter writer, TableSchema* schema);
ERRNO tsfile_writer_register_timeseries(TsFileWriter writer,
const char* device_name,
TimeseriesSchema* schema);
Expand Down
19 changes: 1 addition & 18 deletions python/tsfile/Constants.py → python/tsfile/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
# specific language governing permissions and limitations
# under the License.
#
from datetime import date
from enum import unique, IntEnum
import numpy as np

from enum import unique, IntEnum

@unique
class TSDataType(IntEnum):
Expand All @@ -33,21 +31,6 @@ class TSDataType(IntEnum):
BLOB = 10
STRING = 11

def np_dtype(self):
return {
TSDataType.BOOLEAN: np.dtype(">?"),
TSDataType.FLOAT: np.dtype(">f4"),
TSDataType.DOUBLE: np.dtype(">f8"),
TSDataType.INT32: np.dtype(">i4"),
TSDataType.INT64: np.dtype(">i8"),
TSDataType.TEXT: str,
TSDataType.TIMESTAMP: np.dtype(">i8"),
TSDataType.DATE: date,
TSDataType.BLOB: bytes,
TSDataType.STRING: str,
}[self]


@unique
class TSEncoding(IntEnum):
PLAIN = 0
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions python/tsfile/Field.py → python/tsfile/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#

# for package
from Constants import TSDataType
from utils.DateUtils import parse_int_to_date
from constants import TSDataType
from tsfile.date_utils import parse_int_to_date
import numpy as np
import pandas as pd

Expand Down
3 changes: 1 addition & 2 deletions python/tsfile/RowRecord.py → python/tsfile/row_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
#

# for package
from iotdb.utils.Field import Field

from tsfile.field import Field

class RowRecord(object):
def __init__(self, timestamp, field_list: list = None):
Expand Down
20 changes: 10 additions & 10 deletions python/tsfile/Schema.py → python/tsfile/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,52 @@
#
from typing import List

from .Constants import TSDataTypePy, Category, TSEncodingPy, CompressorPy
from .constants import TSDataType, Category, TSEncoding, Compressor

def class TimeseriesSchemapy:
class TimeseriesSchema:
timeseries_name = None
data_type = None
encoding_type = None
compression_type = None

def __init__(self, timeseries_name : str, data_type : TSDataTypePy, encoding_type : TSEncodingPy = None, compression_type : CompressorPy = None):
def __init__(self, timeseries_name : str, data_type : TSDataType, encoding_type : TSEncoding = None, compression_type : Compressor = None):
self.timeseries_name = timeseries_name
self.data_type = data_type
self.encoding_type = encoding_type
self.compression_type = compression_type

def class DeviceSchemapy:
class DeviceSchema:
device_name = None
timeseries_list = None
def __init__(self, device_name : str, timeseries_list : List[TimeseriesSchema]):
self.device_name = device_name
self.timeseries_list = timeseries_list

def class ColumnSchemapy:
class ColumnSchema:
column_name = None
data_type = None
category = None
def __init__(self, column_name : str, data_type : TSDataTypePy, category : Category):
def __init__(self, column_name : str, data_type : TSDataType, category : Category):
self.column_name = column_name
self.data_type = data_type
self.category = category


def class TableSchemapy:
class TableSchema:
table_name = None
columns = None
def __init__(self, table_name : str, columns : List[ColumnSchema]):
self.table_name = table_name
self.columns = columns

def class ResultSetMetaDatapy:
class ResultSetMetaData:
column_list = None
data_types = None
def __init__(self, column_list : List[str], data_types : List[TSDataTypePy]):
def __init__(self, column_list : List[str], data_types : List[TSDataType]):
self.column_list = column_list
self.data_types = data_types

def get_data_type(self, column_index : int) -> TSDataTypePy:
def get_data_type(self, column_index : int) -> TSDataType:
return self.data_types[column_index]
def get_column_name(self, column_index : int) -> str:
return self.column_list[column_index]
Expand Down
6 changes: 3 additions & 3 deletions python/tsfile/Tablet.py → python/tsfile/tablet.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
from enum import unique, IntEnum
from typing import List, Union

from tsfile.utils.DateUtils import parse_date_to_int
from tsfile.BitMap import BitMap
from Constants import TSDataType
from tsfile.date_utils import parse_date_to_int
from tsfile.bitmap import BitMap
from constants import TSDataType


@unique
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
#cython: language_level=3
from libc.stdint cimport uint32_t, int32_t, int64_t

ctypedef int32_t ErrorCode

# import symbols from tsfile_cwrapper.h
cdef extern from "./tsfile_cwrapper.h":
cdef extern from "./c_include/tsfile_cwrapper.h":
# common
ctypedef int ErrorCode
ctypedef int64_t timestamp

# reader and writer etc
Expand All @@ -32,7 +33,7 @@ cdef extern from "./tsfile_cwrapper.h":
ctypedef void* ResultSet

# enum types
cdef enum TSDataType:
ctypedef enum TSDataType:
TS_DATATYPE_BOOLEAN = 0
TS_DATATYPE_INT32 = 1
TS_DATATYPE_INT64 = 2
Expand All @@ -43,7 +44,7 @@ cdef extern from "./tsfile_cwrapper.h":
TS_DATATYPE_NULL_TYPE = 254
TS_DATATYPE_INVALID = 255

cdef enum TSEncoding:
ctypedef enum TSEncoding:
TS_ENCODING_PLAIN = 0,
TS_ENCODING_DICTIONARY = 1,
TS_ENCODING_RLE = 2,
Expand All @@ -57,7 +58,7 @@ cdef extern from "./tsfile_cwrapper.h":
TS_ENCODING_FREQ = 10,
TS_ENCODING_INVALID = 255

cdef enum CompressionType:
ctypedef enum CompressionType:
TS_COMPRESSION_UNCOMPRESSED = 0,
TS_COMPRESSION_SNAPPY = 1,
TS_COMPRESSION_GZIP = 2,
Expand All @@ -68,33 +69,33 @@ cdef extern from "./tsfile_cwrapper.h":
TS_COMPRESSION_LZ4 = 7,
TS_COMPRESSION_INVALID = 255

cdef enum ColumnCategory:
ctypedef enum ColumnCategory:
TAG = 0,
FIELD = 1

# struct types
cdef struct ColumnSchema:
ctypedef struct ColumnSchema:
char* column_name
TSDataType data_type
ColumnCategory column_category

cdef struct TableSchema:
ctypedef struct TableSchema:
char* table_name
ColumnSchema* column_schemas
int column_num

cdef struct TimeseriesSchema:
ctypedef struct TimeseriesSchema:
char* timeseries_name
TSDataType data_type
TSEncoding encoding
CompressionType compression

cdef struct DeviceSchema:
ctypedef struct DeviceSchema:
char* device_name
TimeseriesSchema * timeseries_schema
TimeseriesSchema* timeseries_schema
int timeseries_num

cdef struct ResultSetMetaData:
ctypedef struct ResultSetMetaData:
char** column_names
TSDataType* data_types
int column_num
Expand Down Expand Up @@ -152,3 +153,12 @@ cdef extern from "./tsfile_cwrapper.h":
float tsfile_result_set_get_value_by_index_float(ResultSet result_set, uint32_t column_index);
double tsfile_result_set_get_value_by_index_double(ResultSet result_set, uint32_t column_index);
ResultSetMetaData tsfile_result_set_get_metadata(ResultSet result_set);

ctypedef struct TsFileReaderStruct:
TsFileReader reader
ctypedef struct ResultSetStruct:
ResultSet result
ctypedef struct TsFileWriterStruct:
TsFileWriter writer
ctypedef struct TabletStruct:
Tablet tablet
Empty file.
File renamed without changes.
55 changes: 55 additions & 0 deletions python/tsfile/tsfile_py_cpp.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

#cython: language_level=3

from .tsfile_cpp cimport *

ctypedef struct TsFileReaderStruct:
TsFileReader reader
ctypedef struct ResultSetStruct:
ResultSet result
ctypedef struct TsFileWriterStruct:
TsFileWriter writer
ctypedef struct TabletStruct:
Tablet tablet

cdef object from_c_result_set_meta_data(ResultSetMetaData schema)
cdef TSDataType to_c_data_type(object data_type)
cdef TSEncoding to_c_encoding_type(object encoding_type)
cdef CompressionType to_c_compression_type(object compression_type)
cdef ColumnCategory to_c_category(object category)
cdef TimeseriesSchema* to_c_timeseries_schema(object py_schema)
cdef DeviceSchema* to_c_device_schema(object py_schema)
cdef ColumnSchema* to_c_column_schema(object py_schema)
cdef TableSchema* to_c_table_schema(object py_schema)
cdef TabletStruct* to_c_tablet(object tablet)
cdef void free_c_table_schema(TableSchema* c_schema)
cdef void free_c_column_schema(ColumnSchema* c_schema)
cdef void free_c_timeseries_schema(TimeseriesSchema* c_schema)
cdef void free_c_device_schema(DeviceSchema* c_schema)
cdef void free_c_tablet(Tablet tablet)
cdef TsFileWriterStruct* tsfile_writer_new_c(object pathname)
cdef TsFileReaderStruct* tsfile_reader_new_c(object pathname)
cdef ErrorCode tsfile_writer_register_device_py_cpp(TsFileWriterStruct *writer, DeviceSchema *schema)
cdef ErrorCode tsfile_writer_register_timeseries_py_cpp(TsFileWriterStruct *writer, object device_name,
TimeseriesSchema *schema)
cdef ErrorCode tsfile_writer_register_table_py_cpp(TsFileWriterStruct *writer, TableSchema *schema)
cdef bint tsfile_result_set_is_null_by_name_c(ResultSet result_set, object name)
cdef ResultSetStruct* tsfile_reader_query_table_c(TsFileReader reader, object table_name, object column_list,
int64_t start_time, int64_t end_time)
Loading

0 comments on commit a26064c

Please sign in to comment.