ClockWork DB CoreAPI 1.0.48
Abstract Time Series and Storage/Management Library
Loading...
Searching...
No Matches
datastore.hpp
1#ifndef HAVE_TOM_TSDB_DATASTORE_HPP
2#define HAVE_TOM_TSDB_DATASTORE_HPP
3
4#include <map>
5#include <vector>
6#include <tom-tsdb/time_series.hpp>
7#include <tom-tsdb/sparse_series.hpp>
8#include <tom-tsdb/types.hpp>
9#include <tom-tsdb/logger.hpp>
10#include <tom-tsdb/smart_pointers.hpp>
11#include <tom-tsdb/runtime_metrics.hpp>
12
13namespace tom {
21 class TOM_UTIL_API observation;
22 namespace calendars {
23 class TOM_UTIL_API calendar;
24 }
25 namespace tsdb {
26 namespace calendars {
27 enum nct
28 {
29 UNDEFINED = 0,
30 DATE_INTERVAL_DAILY,
31 DATE_INTERVAL_BUSINESS,
32 DATE_INTERVAL_WEEKLY_MONDAY,
33 DATE_INTERVAL_WEEKLY_TUESDAY,
34 DATE_INTERVAL_WEEKLY_WEDNESDAY,
35 DATE_INTERVAL_WEEKLY_THURSDAY,
36 DATE_INTERVAL_WEEKLY_FRIDAY,
37 DATE_INTERVAL_WEEKLY_SATURDAY,
38 DATE_INTERVAL_WEEKLY_SUNDAY,
39 DATE_INTERVAL_MONTHLY,
40 DATE_INTERVAL_QUARTERLY_OCTOBER,
41 DATE_INTERVAL_QUARTERLY_NOVEMBER,
42 DATE_INTERVAL_QUARTERLY_DECEMBER,
43 DATE_INTERVAL_SEMIANNUAL_JULY,
44 DATE_INTERVAL_SEMIANNUAL_AUGUST,
45 DATE_INTERVAL_SEMIANNUAL_SEPTEMBER,
46 DATE_INTERVAL_SEMIANNUAL_OCTOBER,
47 DATE_INTERVAL_SEMIANNUAL_NOVEMBER,
48 DATE_INTERVAL_SEMIANNUAL_DECEMBER,
49 DATE_INTERVAL_ANNUAL_JANUARY,
50 DATE_INTERVAL_ANNUAL_FEBRUARY,
51 DATE_INTERVAL_ANNUAL_MARCH,
52 DATE_INTERVAL_ANNUAL_APRIL,
53 DATE_INTERVAL_ANNUAL_MAY,
54 DATE_INTERVAL_ANNUAL_JUNE,
55 DATE_INTERVAL_ANNUAL_JULY,
56 DATE_INTERVAL_ANNUAL_AUGUST,
57 DATE_INTERVAL_ANNUAL_SEPTEMBER,
58 DATE_INTERVAL_ANNUAL_OCTOBER,
59 DATE_INTERVAL_ANNUAL_NOVEMBER,
60 DATE_INTERVAL_ANNUAL_DECEMBER,
61 ORDINAL
62 };
63 } // end calendars namespace
64
65 // import date_int_type into our namespace
66 using tom::calendars::date_int_type;
67
79 class TOM_UTIL_API native_calendar_type
80 {
81 public:
85 bool
86 operator==( const native_calendar_type &rhs );
87
91 bool
92 operator!=( const native_calendar_type &rhs );
93
100 static
102 factory( unsigned short int t);
103
107 static
109 daily();
110
114 static
116 business();
117
121 static
123 weekly_monday();
124
128 static
130 weekly_tuesday();
131
135 static
137 weekly_wednesday();
138
142 static
144 weekly_thursday();
145
149 static
151 weekly_friday();
152
156 static
158 weekly_saturday();
159
163 static
165 weekly_sunday();
166
170 static
172 monthly();
173
177 static
179 quarterly_october();
180
184 static
186 quarterly_november();
187
191 static
193 quarterly_december();
194
198 static
200 semiannual_july();
201
205 static
207 semiannual_august();
208
212 static
214 semiannual_september();
215
219 static
221 semiannual_october();
222
226 static
228 semiannual_november();
229
233 static
235 semiannual_december();
236
240 static
242 annual_january();
243
247 static
249 annual_february();
250
254 static
256 annual_march();
257
261 static
263 annual_april();
264
268 static
270 annual_may();
271
275 static
277 annual_june();
278
282 static
284 annual_july();
285
289 static
291 annual_august();
292
296 static
298 annual_september();
299
303 static
305 annual_october();
306
310 static
312 annual_november();
313
317 static
319 annual_december();
320
324 static
326 ordinal();
327
331 unsigned short int
332 value() const;
333
334 private:
335 native_calendar_type( unsigned short int t ) : m_type(t) { }
337 unsigned short int m_type;
338
339 };
346 class TOM_UTIL_API access_mode
347 {
348 public:
352 static
354 read_only();
355
359 static
361 read_write();
362
367 static
369 create();
370
374 static
376 exclusive();
377
382 static
384 exclusive_create();
385
386 unsigned int
387 bit_map() const;
388
392 bool
393 is_read_only() const;
394
398 bool
399 is_writeable() const;
400
404 bool
405 is_createable() const;
406
410 bool
411 is_exclusive() const;
412
413 static
414 unsigned int READ;
415
416 static
417 unsigned int WRITE;
418
419 static
420 unsigned int CREATE;
421
422 static
423 unsigned int EXCLUSIVE;
424
425 private:
426 access_mode();
427 access_mode( unsigned int flag );
428 unsigned int m_mode;
429
430 };
431
432 class TOM_UTIL_API time_series;
433 class TOM_UTIL_API alias_set;
434 class TOM_UTIL_API datastore_match;
435 class TOM_UTIL_API connection;
436
444 class TOM_UTIL_API datastore : public tom::tsdb::logger
445 {
446 public:
447 friend class time_series;
448
449 datastore( const access_mode &mode ) : m_mode(mode) { }
450
451 virtual
452 ~datastore() { }
453
457 virtual
458 const tom::string &
459 get_name() const = 0;
460
464 virtual
465 const tom::string &
466 get_description() const = 0;
467
471 virtual
472 void
474
478 virtual
479 const tom::string &
480 get_documentation() const = 0;
481
485 virtual
486 void
488
492 virtual
493 const tom::calendars::date_time &
495
499 virtual
500 const tom::calendars::date_time &
502
506 virtual
509
513 const access_mode &
514 get_mode() const { return m_mode; }
515
526 //time_series &
527 tom::tsdb::time_series_sptr
528 get_time_series( const char *name, bool lazy_eval = false );
529
536 virtual
537 void
538 close() = 0;
539
543 virtual
544 bool
545 is_open() const = 0;
546
555 bool
556 has_time_series( const char *name )
557 {
558 return has_time_series( tom::String(name) );
559 }
568 virtual
569 bool
571
582 virtual
583 tom::tsdb::time_series_sptr
584 get_time_series( const tom::observation &name, bool lazy_eval = false ) = 0;
585
597 virtual
598 void
599 save_time_series( const tom::tsdb::time_series &ts, bool overwrite = false ) = 0;
600
606 virtual
607 bool
609
615 bool
616 delete_time_series( const char *name );
617
627 tom::tsdb::time_series_sptr
628 create_time_series( const char *name,
629 native_data_type data_t,
630 native_calendar_type calendar_t,
641 virtual
642 tom::tsdb::time_series_sptr
643 create_time_series( const tom::observation &name,
644 native_data_type data_t,
645 native_calendar_type calendar_t,
647
657 tom::tsdb::sparse_series_sptr
658 create_sparse_series( const char *name,
659 native_data_type data_t,
660 native_calendar_type calendar_t,
662
672 virtual
673 tom::tsdb::sparse_series_sptr
674 create_sparse_series( const tom::observation &name,
675 native_data_type data_t,
676 native_calendar_type calendar_t,
678
688 virtual
689 tom::tsdb::datastore_match_sptr
691
701 tom::tsdb::datastore_match_sptr
702 regex_name_search( const char *regex );
703
704 // retrieve an unique id for any given calendar
705 // mainly useful, for persisting meta-data
706 static
707 unsigned int
708 get_calendar_id( tom::calendars::calendar &cal );
709
710 static
712 get_calendar( unsigned int cal_t );
713
714 const datastore_metrics &
715 get_datastore_metrics() {
716 populate_datastore_metrics(m_ds_metrics);
717 return m_ds_metrics;
718 }
719
720
721 protected:
722 // time series are designed to lazy init aliases.
723 // the first time someone calls ts.get_alias_set()
724 // the ts asks the db to populate it
725 virtual
726 bool
727 populate_alias_set( const tom::String &name, alias_set &aliases ) = 0;
728
729 virtual
730 const tom::String &
731 get_attribute( const tom::string &obj_name,
732 const tom::String &att_name ) = 0;
733
734 virtual
735 void
736 set_attribute( const tom::string &obj_name,
737 const tom::String &att_name,
738 const tom::String &att_value ) = 0;
739
740 virtual
741 tom::tsdb::time_series_sptr
742 create_time_series( const tom::observation &name,
743 native_data_type data_t,
744 native_calendar_type calendar_t,
746 const tom::calendars::date_time &,
747 const tom::calendars::date_time &);
748 virtual
749 tom::tsdb::time_series_sptr
750 create_time_series( const tom::observation &name,
751 native_data_type data_t,
752 native_calendar_type calendar_t,
754 const tom::calendars::date_time &,
755 const tom::calendars::date_time &,
756 tom::calendars::date_int_type start,
757 void *iter_begin, void *iter_end );
758 // new lazy results creator!
759 // register a callback to fetch data should
760 // the data be requested by time_series client
761 virtual
762 tom::tsdb::time_series_sptr
763 create_time_series( const tom::observation &name,
764 native_data_type data_t,
765 native_calendar_type calendar_t,
767 const tom::calendars::date_time &,
768 const tom::calendars::date_time &,
769 tom::calendars::date_int_type first_date,
770 tom::calendars::date_int_type last_date,
771 tom::tsdb::time_series::populate_data_func );
772
773 virtual
774 tom::tsdb::sparse_series_sptr
775 create_sparse_series( const tom::observation &name,
776 native_data_type data_t,
777 native_calendar_type calendar_t,
779 const tom::calendars::date_time &,
780 const tom::calendars::date_time & );
781
782 virtual
783 tom::tsdb::sparse_series_sptr
784 create_sparse_series( const tom::observation &name,
785 native_data_type data_t,
786 native_calendar_type calendar_t,
788 const tom::calendars::date_time &,
789 const tom::calendars::date_time &,
790 bool ignore_same_value, bool ignore_missing_value,
791 void *iter_begin, void *iter_end );
792
793 static
794 tom::tsdb::time_series_sptr
795 build_time_series( datastore &ds,
796 const tom::observation &name,
797 native_data_type data_t,
798 native_calendar_type calendar_t,
800
801 static
802 tom::tsdb::time_series_sptr
803 build_time_series( datastore &ds,
804 const tom::observation &name,
805 native_data_type data_t,
806 native_calendar_type calendar_t,
808 const tom::calendars::date_time &,
809 const tom::calendars::date_time & );
810
811 static
812 tom::tsdb::time_series_sptr
813 build_time_series( datastore &ds,
814 const tom::observation &name,
815 native_data_type data_t,
816 native_calendar_type calendar_t,
818 const tom::calendars::date_time &,
819 const tom::calendars::date_time &,
820 tom::calendars::date_int_type start,
821 void *iter_begin, void *iter_end );
822
823 static
824 tom::tsdb::time_series_sptr
825 build_time_series( datastore &ds,
826 const tom::observation &name,
827 native_data_type data_t,
828 native_calendar_type calendar_t,
830 const tom::calendars::date_time &,
831 const tom::calendars::date_time &,
832 tom::calendars::date_int_type start,
833 tom::calendars::date_int_type end,
834 tom::tsdb::time_series::populate_data_func );
835
836 static
837 tom::tsdb::sparse_series_sptr
838 build_sparse_series( datastore &ds,
839 const tom::observation &name,
840 native_data_type data_t,
841 native_calendar_type calendar_t,
843
844 static
845 tom::tsdb::sparse_series_sptr
846 build_sparse_series( datastore &ds,
847 const tom::observation &name,
848 native_data_type data_t,
849 native_calendar_type calendar_t,
851 const tom::calendars::date_time &,
852 const tom::calendars::date_time & );
853
854 static
855 tom::tsdb::sparse_series_sptr
856 build_sparse_series( datastore &ds,
857 const tom::observation &name,
858 native_data_type data_t,
859 native_calendar_type calendar_t,
861 const tom::calendars::date_time &,
862 const tom::calendars::date_time &,
863 bool ignore_same_value, bool ignore_missing_value,
864 void *iter_begin, void *iter_end );
865
866 // when users call the public const get_datastore_metrics()
867 // the implementation class will be called so it can update m_ds_metrics
868 virtual
869 void
870 populate_datastore_metrics( datastore_metrics & metrics ) = 0;
871
872 /*datastore_metrics &
873 get_datastore_metrics() { return m_ds_metrics; }
874 */
875 access_mode m_mode;
876 datastore_metrics m_ds_metrics;
877
878 private:
879 struct time_series_builder
880 {
881 virtual ~time_series_builder() { }
882
883 virtual
884 tom::tsdb::time_series_sptr
885 operator()( datastore &ds, const tom::observation &name,
886 native_calendar_type cal_t,
887 aggregation_type ) = 0;
888
889 virtual
890 tom::tsdb::time_series_sptr
891 operator()( datastore &ds, const tom::observation &name,
892 native_calendar_type cal_t,
893 aggregation_type,
894 const tom::calendars::date_time &,
895 const tom::calendars::date_time & ) = 0;
896
897 virtual
898 tom::tsdb::time_series_sptr
899 operator()( datastore &ds, const tom::observation &name,
900 native_calendar_type cal_t,
901 aggregation_type,
902 const tom::calendars::date_time &,
903 const tom::calendars::date_time &,
904 tom::calendars::date_int_type start,
905 void *iter_begin, void *iter_end ) = 0;
906
907 virtual
908 tom::tsdb::time_series_sptr
909 operator()( datastore &ds, const tom::observation &name,
910 native_calendar_type calendar_t,
911 aggregation_type,
912 const tom::calendars::date_time &,
913 const tom::calendars::date_time &,
914 tom::calendars::date_int_type first_date,
915 tom::calendars::date_int_type last_date,
916 tom::tsdb::time_series::populate_data_func ) = 0;
917
918 virtual
919 tom::tsdb::sparse_series_sptr
920 sparse_series_factory( datastore &ds, const tom::observation &name,
921 native_calendar_type cal_t,
922 aggregation_type ) = 0;
923
924 virtual
925 tom::tsdb::sparse_series_sptr
926 sparse_series_factory( datastore &ds, const tom::observation &name,
927 native_calendar_type cal_t,
928 aggregation_type,
929 const tom::calendars::date_time &,
930 const tom::calendars::date_time & ) = 0;
931
932 virtual
933 tom::tsdb::sparse_series_sptr
934 sparse_series_factory( datastore &ds, const tom::observation &name,
935 native_calendar_type cal_t,
936 aggregation_type, const tom::calendars::date_time &,
937 const tom::calendars::date_time &,
938 bool ignore_same_value, bool ignore_missing_value,
939 void *iter_begin, void *iter_end ) = 0;
940 };
941
942 template <typename T, typename NATIVE_TYPE>
943 tom::tsdb::time_series_sptr
944 build_time_series( const tom::observation &name,
945 native_calendar_type cal_t,
946 aggregation_type agg_t )
947 {
948 return tom::tsdb::time_series_sptr(new ::tom::tsdb::collections::time_series<T,NATIVE_TYPE>
949 ( datastore::get_calendar( cal_t.value() ) , *this, name, agg_t ) );
950 }
951 template <typename T, typename NATIVE_TYPE>
952 tom::tsdb::time_series_sptr
953 build_time_series( const tom::observation &name,
954 native_calendar_type cal_t,
955 aggregation_type agg_t,
956 const tom::calendars::date_time &created,
957 const tom::calendars::date_time &modified )
958 {
959 return tom::tsdb::time_series_sptr( new ::tom::tsdb::collections::time_series<T,NATIVE_TYPE>
960 ( datastore::get_calendar( cal_t.value() ) , *this,
961 name, agg_t, created, modified ) );
962 }
963 template <typename T, typename NATIVE_TYPE>
964 inline
965 tom::tsdb::time_series_sptr
966 build_time_series( const tom::observation &name,
967 native_calendar_type cal_t,
968 aggregation_type agg_t,
969 const tom::calendars::date_time &created,
970 const tom::calendars::date_time &modified,
971 tom::calendars::date_int_type start,
972 void *iter_begin, void *iter_end )
973 {
974 using namespace tom::calendars;
975 typename T::value_type *begin =
976 static_cast<typename T::value_type *>( iter_begin );
977 typename T::value_type *end =
978 static_cast<typename T::value_type *>( iter_end );
979 calendar &cal = datastore::get_calendar( cal_t.value() );
980 return tom::tsdb::time_series_sptr( new ::tom::tsdb::collections::time_series<T,NATIVE_TYPE>
981 ( cal, *this, name, agg_t, created, modified, start, begin, end ) );
982 }
983 template <typename T, typename NATIVE_TYPE>
984 inline
985 tom::tsdb::time_series_sptr
986 build_time_series( const tom::observation &name,
987 native_calendar_type cal_t,
988 aggregation_type agg_t,
989 const tom::calendars::date_time &created,
990 const tom::calendars::date_time &modified,
991 tom::calendars::date_int_type start,
992 tom::calendars::date_int_type end,
993 tom::tsdb::time_series::populate_data_func callback)
994 {
995 using namespace tom::calendars;
996 calendar &cal = datastore::get_calendar( cal_t.value() );
997 return tom::tsdb::time_series_sptr( new ::tom::tsdb::collections::time_series<T,NATIVE_TYPE>
998 ( cal, *this, name, agg_t, created, modified, start, end, callback ) );
999 }
1000 template <typename T, typename NATIVE_TYPE>
1001 inline
1002 tom::tsdb::sparse_series_sptr
1003 build_sparse_series( const tom::observation &name,
1004 native_calendar_type cal_t,
1005 aggregation_type agg_t )
1006 {
1007 using namespace tom::calendars;
1008 calendar &cal = datastore::get_calendar( cal_t.value() );
1009 return tom::tsdb::sparse_series_sptr(new tom::tsdb::collections::sparse_series<T,NATIVE_TYPE>
1010 ( cal, *this, name, agg_t ));
1011 }
1012 template <typename T, typename NATIVE_TYPE>
1013 inline
1014 tom::tsdb::sparse_series_sptr
1015 build_sparse_series( const tom::observation &name,
1016 native_calendar_type cal_t,
1017 aggregation_type agg_t,
1018 const tom::calendars::date_time &created,
1019 const tom::calendars::date_time &modified )
1020 {
1021 using namespace tom::calendars;
1022 calendar &cal = datastore::get_calendar( cal_t.value() );
1023 return tom::tsdb::sparse_series_sptr(new tom::tsdb::collections::sparse_series<T,NATIVE_TYPE>
1024 ( cal, *this, name, agg_t, created, modified ));
1025 }
1026 template <typename T, typename NATIVE_TYPE>
1027 inline
1028 tom::tsdb::sparse_series_sptr
1029 build_sparse_series( const tom::observation &name,
1030 native_calendar_type cal_t,
1031 aggregation_type agg_t,
1032 const tom::calendars::date_time &created,
1033 const tom::calendars::date_time &modified,
1034 bool ignore_same_value, bool ignore_missing_value,
1035 void *iter_begin, void *iter_end )
1036 {
1037 using namespace tom::calendars;
1038 struct pair_type
1039 {
1040 date_int_type date;
1041 typename T::value_type value;
1042 };
1043 pair_type *begin =
1044 static_cast<pair_type *>( iter_begin );
1045 pair_type *end =
1046 static_cast<pair_type *>( iter_end );
1047 calendar &cal = datastore::get_calendar( cal_t.value() );
1050 ( cal, *this, name, agg_t, created, modified );
1051 tmp->set_ignore_same_values( ignore_same_value );
1052 tmp->set_ignore_missing_values( ignore_missing_value );
1053 for( ; begin != end; begin++ )
1054 tmp->set_observation( begin->date, T( begin->value ) );
1055 return tom::tsdb::sparse_series_sptr(tmp);
1056 }
1057 template <typename T, unsigned int NATIVE_TYPE_ID>
1058 struct time_series_builder_impl : public time_series_builder
1059 {
1060 static
1061 time_series_builder_impl &
1062 Instance() { static time_series_builder_impl instance; return instance; }
1063
1064 virtual
1065 tom::tsdb::time_series_sptr
1066 operator()( datastore &ds, const tom::observation &name,
1067 native_calendar_type cal_t,
1068 aggregation_type agg_t)
1069 {
1070 return ds.build_time_series<T,values::data_type_impl<
1071 T,NATIVE_TYPE_ID> >( name, cal_t, agg_t );
1072 }
1073
1074 virtual
1075 tom::tsdb::time_series_sptr
1076 operator()( datastore &ds, const tom::observation &name,
1077 native_calendar_type cal_t,
1078 aggregation_type agg_t,
1079 const tom::calendars::date_time &created,
1080 const tom::calendars::date_time &modified )
1081 {
1082 return ds.build_time_series<T,values::data_type_impl<
1083 T,NATIVE_TYPE_ID> >( name, cal_t, agg_t, created, modified );
1084 }
1085 virtual
1086 tom::tsdb::time_series_sptr
1087 operator()( datastore &ds, const tom::observation &name,
1088 native_calendar_type cal_t,
1089 aggregation_type agg_t,
1090 const tom::calendars::date_time &created,
1091 const tom::calendars::date_time &modified,
1092 tom::calendars::date_int_type start,
1093 void *iter_begin, void *iter_end )
1094 {
1095 return ds.build_time_series<T,values::data_type_impl<T,NATIVE_TYPE_ID> >
1096 ( name, cal_t, agg_t, created, modified, start, iter_begin, iter_end );
1097 }
1098 virtual
1099 tom::tsdb::time_series_sptr
1100 operator()( datastore &ds, const tom::observation &name,
1101 native_calendar_type cal_t,
1102 aggregation_type agg_t,
1103 const tom::calendars::date_time & created,
1104 const tom::calendars::date_time & modified,
1105 tom::calendars::date_int_type first_date,
1106 tom::calendars::date_int_type last_date,
1107 tom::tsdb::time_series::populate_data_func callback)
1108 {
1109 return ds.build_time_series<T,values::data_type_impl<T,NATIVE_TYPE_ID> >
1110 ( name, cal_t, agg_t, created, modified, first_date, last_date, callback );
1111 }
1112 virtual
1113 tom::tsdb::sparse_series_sptr
1114 sparse_series_factory( datastore &ds, const tom::observation &name,
1115 native_calendar_type cal_t,
1116 aggregation_type agg_t )
1117 {
1118 return ds.build_sparse_series<T,values::data_type_impl<T,NATIVE_TYPE_ID> >
1119 ( name, cal_t, agg_t );
1120 }
1121 virtual
1122 tom::tsdb::sparse_series_sptr
1123 sparse_series_factory( datastore &ds, const tom::observation &name,
1124 native_calendar_type cal_t,
1125 aggregation_type agg_t,
1126 const tom::calendars::date_time &created,
1127 const tom::calendars::date_time &modified )
1128 {
1129 return ds.build_sparse_series<T,values::data_type_impl<T,NATIVE_TYPE_ID> >
1130 ( name, cal_t, agg_t, created, modified );
1131 }
1132 virtual
1133 tom::tsdb::sparse_series_sptr
1134 sparse_series_factory( datastore &ds, const tom::observation &name,
1135 native_calendar_type cal_t,
1136 aggregation_type agg_t, const tom::calendars::date_time &created,
1137 const tom::calendars::date_time &modified,
1138 bool ignore_same_value, bool ignore_missing_value,
1139 void *iter_begin, void *iter_end )
1140 {
1141 return ds.build_sparse_series<T,values::data_type_impl<T,NATIVE_TYPE_ID> >
1142 ( name, cal_t, agg_t, created, modified,
1143 ignore_same_value, ignore_missing_value,
1144 iter_begin, iter_end );
1145 }
1146
1147 private:
1148 time_series_builder_impl(){ }
1149 };
1150
1151 typedef std::pair<const tom::calendars::calendar *, unsigned int > calendar_pair_t;
1152 typedef std::map< tom::calendars::calendar *,unsigned int, std::less<const tom::calendars::calendar *> > calendar_map_t;
1153 typedef std::vector< tom::calendars::calendar * > reverse_calendar_map_t;
1154 typedef std::pair<const char *, unsigned int > value_pair_t;
1155 typedef std::map< const char *, unsigned int, std::less<const char *> > value_map_t;
1156 typedef std::vector< time_series_builder * > time_series_factory_map_t;
1157
1158 static calendar_map_t *
1159 populate_calendar_map( );
1160
1161 static value_map_t *
1162 populate_value_map( );
1163
1164 static reverse_calendar_map_t *
1165 populate_reverse_calendar_map( );
1166
1167 static time_series_factory_map_t *
1168 populate_time_series_factory_map( );
1169
1170 };
1171 template <>
1172 inline
1173 tom::tsdb::time_series_sptr
1174 datastore::build_time_series<
1176 values::data_type_impl<tom::String,tom::tsdb::values::STRING>
1177 >
1178 ( const tom::observation &name,
1179 native_calendar_type cal_t,
1180 aggregation_type agg_t,
1181 const tom::calendars::date_time &created,
1182 const tom::calendars::date_time &modified,
1183 tom::calendars::date_int_type start,
1184 void *iter_begin, void *iter_end )
1185 {
1186 using namespace tom::calendars;
1187 typedef values::data_type_impl<tom::String,tom::tsdb::values::STRING> NATIVE_TYPE;
1188 char **begin = static_cast<char **>( iter_begin );
1189 char **end = static_cast<char **>( iter_end );
1190 calendar &cal = datastore::get_calendar( cal_t.value() );
1191 return tom::tsdb::time_series_sptr( new ::tom::tsdb::collections::time_series<tom::String,NATIVE_TYPE>
1192 ( cal, *this, name, agg_t, created, modified,
1193 start, begin, end ) );
1194 }
1195 template <>
1196 inline
1197 tom::tsdb::sparse_series_sptr
1198 datastore::build_sparse_series<
1200 values::data_type_impl<tom::String,tom::tsdb::values::STRING>
1201 >
1202 ( const tom::observation &name,
1203 native_calendar_type cal_t,
1204 aggregation_type agg_t,
1205 const tom::calendars::date_time &created,
1206 const tom::calendars::date_time &modified,
1207 bool ignore_same_value, bool ignore_missing_value,
1208 void *iter_begin, void *iter_end )
1209 {
1210 using namespace tom::calendars;
1211 struct pair_type
1212 {
1213 date_int_type date;
1214 const char * value;
1215 };
1216 pair_type *begin =
1217 static_cast<pair_type *>( iter_begin );
1218 pair_type *end =
1219 static_cast<pair_type *>( iter_end );
1220 calendar &cal = datastore::get_calendar( cal_t.value() );
1221
1223 values::data_type_impl<tom::String,tom::tsdb::values::STRING> > * tmp =
1224 new ::tom::tsdb::collections::sparse_series<tom::String,
1225 values::data_type_impl<tom::String,tom::tsdb::values::STRING> >
1226 ( cal, *this, name, agg_t, created, modified );
1227 tmp->set_ignore_same_values( ignore_same_value );
1228 tmp->set_ignore_missing_values( ignore_missing_value );
1229
1230 for( ; begin != end; begin++ )
1231 tmp->set_observation( begin->date, String(begin->value) );
1232 return tom::tsdb::sparse_series_sptr(tmp);
1233 }
1239 public:
1240 virtual ~datastore_match(){ }
1244 virtual bool next() = 0;
1248 virtual const tom::String &name() = 0;
1249 };
1250 } // end tsdb namespace
1251
1252} // end tom namespace
1253#endif
Definition string.hpp:15
Definition calendar.hpp:120
Definition calendar.hpp:47
Definition observation.hpp:13
Definition datastore.hpp:347
Definition time_series.hpp:22
Definition time_series.hpp:142
Definition sparse_series.hpp:51
Definition connection.hpp:46
Definition datastore.hpp:1238
virtual const tom::String & name()=0
Definition runtime_metrics.pb.h:510
Definition datastore.hpp:445
virtual const tom::string & get_name() const =0
virtual const tom::calendars::date_time & get_create_date_time() const =0
virtual const tom::string & get_description() const =0
const access_mode & get_mode() const
Definition datastore.hpp:514
virtual tom::tsdb::time_series_sptr get_time_series(const tom::observation &name, bool lazy_eval=false)=0
virtual const tom::calendars::date_time & get_modify_date_time() const =0
virtual tom::tsdb::datastore_match_sptr regex_name_search(const tom::observation &regex)=0
virtual tom::tsdb::connection & get_connection()=0
virtual void save_time_series(const tom::tsdb::time_series &ts, bool overwrite=false)=0
bool has_time_series(const char *name)
Definition datastore.hpp:556
virtual void set_documentation(const tom::observation &)=0
virtual bool has_time_series(const tom::observation &name)=0
virtual bool delete_time_series(const tom::observation &name)=0
virtual const tom::string & get_documentation() const =0
virtual bool is_open() const =0
virtual void set_description(const tom::observation &)=0
virtual void close()=0
Definition logger.hpp:10
Definition datastore.hpp:80
Definition types.hpp:31
Definition time_series.hpp:313
Definition value_types.hpp:96