@@ -141,19 +141,18 @@ std::string join_stringlist(const std::vector<std::string>& list)
141
141
return ret;
142
142
}
143
143
144
- void join_stringlist ( std::string& in, const std::vector<std::string >& list)
144
+ std::string join_stringlist ( const std::vector<StringConverter >& list)
145
145
{
146
- for (const auto & s : list) {
147
- if (!in.empty ())
148
- in.append (" ," );
149
- in.append (s);
146
+ std::string ret;
147
+ int c = 0 ;
148
+
149
+ for (const StringConverter& sc : list) {
150
+ if (c++ > 0 )
151
+ ret.append (" ," );
152
+ ret.append (sc.to_string ());
150
153
}
151
- }
152
154
153
- std::string find_or (const std::map<std::string, std::string>& m, const std::string& k, const std::string v = " " )
154
- {
155
- auto it = m.find (k);
156
- return it != m.end () ? it->second : v;
155
+ return ret;
157
156
}
158
157
159
158
std::string expand_variables (const std::string& in, const std::string& val)
@@ -340,15 +339,6 @@ void add_metadata(const std::string& args, info_map_t& info)
340
339
341
340
class ConfigManager ::OptionSpec
342
341
{
343
- struct query_arg_t {
344
- std::vector<std::string> select;
345
- std::vector<std::string> groupby;
346
- std::vector<std::string> let;
347
- std::vector<std::string> where;
348
- std::vector<std::string> aggregate;
349
- std::vector<std::string> orderby;
350
- };
351
-
352
342
struct option_spec_t {
353
343
std::string type;
354
344
std::string description;
@@ -357,7 +347,7 @@ class ConfigManager::OptionSpec
357
347
std::vector<std::string> services;
358
348
std::vector<std::string> inherited_specs;
359
349
360
- std::map<std::string, query_arg_t > query_args ;
350
+ std::map<std::string, std::string> query ;
361
351
std::map<std::string, std::string> config;
362
352
};
363
353
@@ -372,8 +362,10 @@ class ConfigManager::OptionSpec
372
362
m_error_msg = msg;
373
363
}
374
364
375
- void parse_select (const std::vector<StringConverter>& list, query_arg_t & qarg )
365
+ std::string parse_select (const std::vector<StringConverter>& list)
376
366
{
367
+ std::string ret;
368
+
377
369
for (const StringConverter& sc : list) {
378
370
bool is_a_dict = false ;
379
371
std::map<std::string, StringConverter> dict = sc.rec_dict (&is_a_dict);
@@ -397,50 +389,58 @@ class ConfigManager::OptionSpec
397
389
str.append (it->second .to_string ());
398
390
str.append (" \" " );
399
391
}
400
- qarg.select .push_back (str);
392
+ if (!ret.empty ())
393
+ ret.append (" ," );
394
+ ret.append (str);
401
395
} else {
402
- qarg.select .push_back (sc.to_string ());
403
- }
396
+ if (!ret.empty ())
397
+ ret.append (" ," );
398
+ ret.append (sc.to_string ());
399
+ }
404
400
}
401
+
402
+ return ret.empty () ? ret : std::string (" select " ) + ret;
405
403
}
406
404
407
405
void parse_query_args (const std::vector<StringConverter>& list, option_spec_t & opt)
408
406
{
407
+ // parses the deprecated list-of-dicts form of the query args
408
+
409
409
for (const StringConverter& sc : list) {
410
410
std::map<std::string, StringConverter> dict = sc.rec_dict ();
411
- query_arg_t qarg ;
411
+ std::string query ;
412
412
413
413
auto it = dict.find (" group by" );
414
414
if (it != dict.end ())
415
- qarg. groupby = :: to_stringlist (it->second .rec_list ());
415
+ query. append ( " group by " ). append (:: join_stringlist (it->second .rec_list () ));
416
416
417
417
it = dict.find (" let" );
418
418
if (it != dict.end ())
419
- qarg. let = :: to_stringlist (it->second .rec_list ());
419
+ query. append ( " let " ). append (:: join_stringlist (it->second .rec_list () ));
420
420
421
421
it = dict.find (" where" );
422
422
if (it != dict.end ())
423
- qarg. where = :: to_stringlist (it->second .rec_list ());
423
+ query. append ( " where " ). append (:: join_stringlist (it->second .rec_list () ));
424
424
425
425
it = dict.find (" aggregate" );
426
426
if (it != dict.end ())
427
- qarg. aggregate = :: to_stringlist (it->second .rec_list ());
427
+ query. append ( " aggregate " ). append (:: join_stringlist (it->second .rec_list () ));
428
428
429
429
it = dict.find (" order by" );
430
430
if (it != dict.end ())
431
- qarg. orderby = :: to_stringlist (it->second .rec_list ());
431
+ query. append ( " order by " ). append (:: join_stringlist (it->second .rec_list () ));
432
432
433
433
it = dict.find (" select" );
434
434
if (it != dict.end ())
435
- parse_select (it->second .rec_list (), qarg );
435
+ query. append ( parse_select (it->second .rec_list ()) );
436
436
437
437
it = dict.find (" level" );
438
438
if (it == dict.end ()) {
439
439
set_error (" : query arg: missing \" level\" " );
440
440
continue ;
441
441
}
442
442
443
- opt.query_args [it->second .to_string ()] = qarg ;
443
+ opt.query [it->second .to_string ()] = std::move (query) ;
444
444
}
445
445
}
446
446
@@ -468,8 +468,17 @@ class ConfigManager::OptionSpec
468
468
if (ok && !m_error && it != dict.end ())
469
469
parse_config (it->second .rec_dict (&ok), opt);
470
470
it = dict.find (" query" );
471
- if (ok && !m_error && it != dict.end ())
472
- parse_query_args (it->second .rec_list (&ok), opt);
471
+ if (ok && !m_error && it != dict.end ()) {
472
+ bool is_dict = false ;
473
+ auto query_dict = it->second .rec_dict (&is_dict);
474
+ if (is_dict) {
475
+ for (const auto &query_entry : query_dict)
476
+ opt.query [query_entry.first ] = query_entry.second .to_string ();
477
+ } else {
478
+ // try parsing deprecated form of query args
479
+ parse_query_args (it->second .rec_list (&ok), opt);
480
+ }
481
+ }
473
482
it = dict.find (" type" );
474
483
if (ok && !m_error && it != dict.end ())
475
484
opt.type = it->second .to_string ();
@@ -691,50 +700,22 @@ struct ConfigManager::Options::OptionsImpl {
691
700
}
692
701
}
693
702
694
- std::string build_query (const char * level, const std::map<std:: string, std::string> & in) const
703
+ std::string build_query (const char * level, const std::string& in) const
695
704
{
696
- std::string q_let = ::find_or (in, " let" );
697
- std::string q_select = ::find_or (in, " select" );
698
- std::string q_groupby = ::find_or (in, " group by" );
699
- std::string q_where = ::find_or (in, " where" );
700
- std::string q_aggregate = ::find_or (in, " aggregate" );
701
- std::string q_orderby = ::find_or (in, " order by" );
702
- std::string q_format = ::find_or (in, " format" );
705
+ std::string ret = in;
703
706
704
707
for (const std::string& opt : enabled_options) {
705
708
auto s_it = spec.data .find (opt);
706
709
if (s_it == spec.data .end ())
707
710
continue ;
708
711
709
- auto l_it = s_it->second .query_args .find (level);
710
- if (l_it != s_it->second .query_args .end ()) {
711
- const auto & q = l_it->second ;
712
- ::join_stringlist (q_let, q.let);
713
- ::join_stringlist (q_select, q.select);
714
- ::join_stringlist (q_groupby, q.groupby);
715
- ::join_stringlist (q_where, q.where);
716
- ::join_stringlist (q_aggregate, q.aggregate);
717
- ::join_stringlist (q_orderby, q.orderby);
712
+ auto l_it = s_it->second .query .find (level);
713
+ if (l_it != s_it->second .query .end ()) {
714
+ ret.append (" " );
715
+ ret.append (l_it->second );
718
716
}
719
717
}
720
718
721
- std::string ret;
722
-
723
- if (!q_let.empty ())
724
- ret.append (" let " ).append (q_let);
725
- if (!q_select.empty ())
726
- ret.append (" select " ).append (q_select);
727
- if (!q_groupby.empty ())
728
- ret.append (" group by " ).append (q_groupby);
729
- if (!q_where.empty ())
730
- ret.append (" where " ).append (q_where);
731
- if (!q_aggregate.empty ())
732
- ret.append (" aggregate " ).append (q_aggregate);
733
- if (!q_orderby.empty ())
734
- ret.append (" order by " ).append (q_orderby);
735
- if (!q_format.empty ())
736
- ret.append (" format " ).append (q_format);
737
-
738
719
return ret;
739
720
}
740
721
@@ -858,7 +839,7 @@ void ConfigManager::Options::update_channel_metadata(info_map_t& metadata) const
858
839
mP ->update_channel_metadata (metadata);
859
840
}
860
841
861
- std::string ConfigManager::Options::build_query (const char * level, const std::map<std:: string, std::string> & in) const
842
+ std::string ConfigManager::Options::build_query (const char * level, const std::string& in) const
862
843
{
863
844
return mP ->build_query (level, in);
864
845
}
0 commit comments