jt2594838 commented on code in PR #767:
URL: https://github.com/apache/tsfile/pull/767#discussion_r3042869887


##########
python/tsfile/tsfile_py_cpp.pyx:
##########
@@ -922,3 +927,164 @@ cdef object get_all_timeseries_schema(TsFileReader 
reader):
         device_schemas.update([(schema_py.get_device_name(), schema_py)])
     free(schemas)
     return device_schemas
+
+cdef object _c_str_to_py_utf8_or_none(char* p):
+    if p == NULL:
+        return None
+    return p.decode('utf-8')
+
+cdef object timeseries_metadata_c_to_py(TimeseriesMetadata* m):
+    cdef str name_py
+    if m == NULL or m.measurement_name == NULL:
+        name_py = ""
+    else:
+        name_py = m.measurement_name.decode('utf-8')
+    cdef object stat = TimeseriesStatisticPy(
+        bool(m.statistic.has_statistic),
+        int(m.statistic.row_count),
+        int(m.statistic.start_time),
+        int(m.statistic.end_time),
+        bool(m.statistic.sum_valid),
+        float(m.statistic.sum),
+        bool(m.statistic.int_range_valid),
+        int(m.statistic.min_int64),
+        int(m.statistic.max_int64),
+        int(m.statistic.first_int64),
+        int(m.statistic.last_int64),
+        bool(m.statistic.float_range_valid),
+        float(m.statistic.min_float64),
+        float(m.statistic.max_float64),
+        float(m.statistic.first_float64),
+        float(m.statistic.last_float64),
+        bool(m.statistic.bool_ext_valid),
+        bool(m.statistic.first_bool),
+        bool(m.statistic.last_bool),
+        bool(m.statistic.str_ext_valid),
+        _c_str_to_py_utf8_or_none(m.statistic.str_min),
+        _c_str_to_py_utf8_or_none(m.statistic.str_max),
+        _c_str_to_py_utf8_or_none(m.statistic.str_first),
+        _c_str_to_py_utf8_or_none(m.statistic.str_last),
+    )
+    return TimeseriesMetadataPy(
+        name_py,
+        TSDataTypePy(m.data_type),
+        int(m.chunk_meta_count),
+        stat,
+    )
+
+cdef tuple c_device_segments_to_tuple(char** segs, uint32_t n):
+    cdef uint32_t i
+    cdef list out = []
+    for i in range(n):
+        if segs[i] == NULL:
+            out.append("")

Review Comment:
   use none?



##########
cpp/src/cwrapper/tsfile_cwrapper.h:
##########
@@ -104,6 +104,97 @@ typedef struct device_schema {
     int timeseries_num;
 } DeviceSchema;
 
+/**
+ * @brief Aggregated statistic for one timeseries (subset of C++ Statistic).
+ *
+ * String pointers str_* are allocated with malloc; freed by
+ * tsfile_free_device_timeseries_metadata_map (do not free individually).
+ */
+typedef struct TimeseriesStatistic {
+    bool has_statistic;
+    int32_t row_count;
+    int64_t start_time;
+    int64_t end_time;
+    /** True when @p sum is meaningful (numeric / boolean aggregate types). */
+    bool sum_valid;
+    /** Sum when sum_valid; boolean uses sum of true as int-like aggregate. */
+    double sum;
+
+    /** INT32, DATE, INT64, TIMESTAMP: min/max/first/last in int64_t form. */
+    bool int_range_valid;
+    int64_t min_int64;
+    int64_t max_int64;
+    int64_t first_int64;
+    int64_t last_int64;
+
+    /** FLOAT, DOUBLE: min/max/first/last. */
+    bool float_range_valid;
+    double min_float64;
+    double max_float64;
+    double first_float64;
+    double last_float64;
+
+    /** BOOLEAN: first/last sample values. */
+    bool bool_ext_valid;
+    bool first_bool;
+    bool last_bool;
+
+    /** STRING: min/max lexicographic; TEXT: first/last only (min/max unused).
+     */
+    bool str_ext_valid;
+    char* str_min;
+    char* str_max;
+    char* str_first;
+    char* str_last;
+} TimeseriesStatistic;

Review Comment:
   typedef struct BaseStatistics {
      TSDataType type;
       int32_t row_count;
       int64_t start_time;
       int64_t end_time;
   } BaseStatistic 
   
   typedef struct FloatStatistics {
       BaseStatistic _base;
       double min_float64;
       double max_float64;
       double first_float64;
       double last_float64;
   } FloatStatistic 
   
   May consider patterns like this?
   Otherwise, the memory footprint of Statistics will be much higher.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to