@@ -104,6 +104,134 @@ typedef struct device_schema {
104104 int timeseries_num ;
105105} DeviceSchema ;
106106
107+ /**
108+ * @brief Common header for all statistic variants (first member of each
109+ * TsFile*Statistic struct; also aliases the start of TimeseriesStatistic::u).
110+ *
111+ * When @p has_statistic is false, @p type is undefined. Otherwise @p type
112+ * selects which @ref TimeseriesStatisticUnion member is active (INT32/DATE/
113+ * INT64/TIMESTAMP share @c int_s). @c sum exists only on @c bool_s, @c int_s,
114+ * and @c float_s. Heap strings in string_s/text_s are
115+ * freed by tsfile_free_device_timeseries_metadata_map only.
116+ */
117+ typedef struct TsFileStatisticBase {
118+ bool has_statistic ;
119+ TSDataType type ;
120+ int32_t row_count ;
121+ int64_t start_time ;
122+ int64_t end_time ;
123+ } TsFileStatisticBase ;
124+
125+ typedef struct TsFileBoolStatistic {
126+ TsFileStatisticBase base ;
127+ double sum ;
128+ bool first_bool ;
129+ bool last_bool ;
130+ } TsFileBoolStatistic ;
131+
132+ typedef struct TsFileIntStatistic {
133+ TsFileStatisticBase base ;
134+ double sum ;
135+ int64_t min_int64 ;
136+ int64_t max_int64 ;
137+ int64_t first_int64 ;
138+ int64_t last_int64 ;
139+ } TsFileIntStatistic ;
140+
141+ typedef struct TsFileFloatStatistic {
142+ TsFileStatisticBase base ;
143+ double sum ;
144+ double min_float64 ;
145+ double max_float64 ;
146+ double first_float64 ;
147+ double last_float64 ;
148+ } TsFileFloatStatistic ;
149+
150+ typedef struct TsFileStringStatistic {
151+ TsFileStatisticBase base ;
152+ char * str_min ;
153+ char * str_max ;
154+ char * str_first ;
155+ char * str_last ;
156+ } TsFileStringStatistic ;
157+
158+ typedef struct TsFileTextStatistic {
159+ TsFileStatisticBase base ;
160+ char * str_first ;
161+ char * str_last ;
162+ } TsFileTextStatistic ;
163+
164+ /**
165+ * @brief One of the typed layouts; active member follows @c base.type.
166+ */
167+ typedef union TimeseriesStatisticUnion {
168+ TsFileBoolStatistic bool_s ;
169+ TsFileIntStatistic int_s ;
170+ TsFileFloatStatistic float_s ;
171+ TsFileStringStatistic string_s ;
172+ TsFileTextStatistic text_s ;
173+ } TimeseriesStatisticUnion ;
174+
175+ /**
176+ * @brief Aggregated statistic for one timeseries (subset of C++ Statistic).
177+ *
178+ * Read common fields via @c tsfile_statistic_base(s). Type-specific fields
179+ * via @c s->u.int_s, @c s->u.float_s, etc., per @c base.type.
180+ */
181+ typedef struct TimeseriesStatistic {
182+ TimeseriesStatisticUnion u ;
183+ } TimeseriesStatistic ;
184+
185+ /** Pointer to the common header at the start of @p s->u (any active arm). */
186+ #define tsfile_statistic_base (s ) ((TsFileStatisticBase*)&(s)->u)
187+
188+ /**
189+ * @brief One measurement's metadata as exposed to C.
190+ */
191+ typedef struct TimeseriesMetadata {
192+ char * measurement_name ;
193+ TSDataType data_type ;
194+ int32_t chunk_meta_count ;
195+ TimeseriesStatistic statistic ;
196+ } TimeseriesMetadata ;
197+
198+ /**
199+ * @brief Device identity from IDeviceID (path, table name, segments).
200+ *
201+ * Heap fields are freed by tsfile_device_id_free_contents or
202+ * tsfile_free_device_id_array, or as part of
203+ * tsfile_free_device_timeseries_metadata_map for entries.
204+ */
205+ typedef struct DeviceID {
206+ char * path ;
207+ char * table_name ;
208+ uint32_t segment_count ;
209+ char * * segments ;
210+ } DeviceID ;
211+
212+ /**
213+ * @brief One device's timeseries metadata list plus DeviceID.
214+ *
215+ * @p device heap fields freed by tsfile_free_device_timeseries_metadata_map.
216+ */
217+ typedef struct DeviceTimeseriesMetadataEntry {
218+ DeviceID device ;
219+ TimeseriesMetadata * timeseries ;
220+ uint32_t timeseries_count ;
221+ } DeviceTimeseriesMetadataEntry ;
222+
223+ /**
224+ * @brief Map device -> list of TimeseriesMetadata (C layout with explicit
225+ * counts).
226+ */
227+ typedef struct DeviceTimeseriesMetadataMap {
228+ DeviceTimeseriesMetadataEntry * entries ;
229+ uint32_t device_count ;
230+ } DeviceTimeseriesMetadataMap ;
231+
232+ /** Frees path, table_name, and segments inside @p d; zeros @p d. */
233+ void tsfile_device_id_free_contents (DeviceID * d );
234+
107235typedef struct result_set_meta_data {
108236 char * * column_names ;
109237 TSDataType * data_types ;
@@ -316,6 +444,37 @@ ERRNO tsfile_writer_close(TsFileWriter writer);
316444 */
317445ERRNO tsfile_reader_close (TsFileReader reader );
318446
447+ /**
448+ * @brief Lists all devices (path, table name, segments from IDeviceID).
449+ *
450+ * @param out_devices [out] Allocated array; caller frees with
451+ * tsfile_free_device_id_array.
452+ */
453+ ERRNO tsfile_reader_get_all_devices (TsFileReader reader , DeviceID * * out_devices ,
454+ uint32_t * out_length );
455+
456+ void tsfile_free_device_id_array (DeviceID * devices , uint32_t length );
457+
458+ /**
459+ * @brief Timeseries metadata for all devices in the file.
460+ */
461+ ERRNO tsfile_reader_get_timeseries_metadata_all (
462+ TsFileReader reader , DeviceTimeseriesMetadataMap * out_map );
463+
464+ /**
465+ * @brief Timeseries metadata for a subset of devices.
466+ *
467+ * @param devices NULL and length>0 is E_INVALID_ARG. length==0: empty result
468+ * (E_OK); @p devices is not read.
469+ * For each entry, @p path must be non-NULL (canonical device path).
470+ */
471+ ERRNO tsfile_reader_get_timeseries_metadata_for_devices (
472+ TsFileReader reader , const DeviceID * devices , uint32_t length ,
473+ DeviceTimeseriesMetadataMap * out_map );
474+
475+ void tsfile_free_device_timeseries_metadata_map (
476+ DeviceTimeseriesMetadataMap * map );
477+
319478/*--------------------------Tablet API------------------------ */
320479
321480/**
0 commit comments