SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
ColumnList.cc
Go to the documentation of this file.
1 /*
2  * SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3  * License details at <https://github.com/kashirin-alex/swc-db/#license>
4  */
5 
6 
7 #include "swcdb/core/Exception.h"
9 
10 
11 namespace SWC { namespace client { namespace SQL {
12 
14  const std::string& a_sql,
15  DB::SchemasVec& a_schemas,
16  std::string& a_message)
17  : Reader(a_sql, a_message),
18  patterns(),
19  clients(a_clients), schemas(a_schemas) {
20 }
21 
22 int ColumnList::parse_list_columns(const char* expect_cmd,
23  uint8_t& output_flags) {
24  _parse_list_columns(expect_cmd);
25  if(err)
26  return err;
27  bool any = true;
28  while(any && remain && !err) {
29  if(found_space())
30  continue;
31  if((any = found_token("OUTPUT_ONLY_CID", 15))) {
32  output_flags |= ColumnOutputFlag::ONLY_CID;
33  continue;
34  }
35  }
36  if(!err)
38  return err;
39 }
40 
41 int ColumnList::parse_list_columns(const char* expect_cmd) {
42  _parse_list_columns(expect_cmd);
43  if(!err)
45  return err;
46 }
47 
48 void ColumnList::_parse_list_columns(const char* expect_cmd) {
49  bool token_cmd = false;
50  bool token_typ = false;
51 
52  while(remain && !err) {
53  if(found_space())
54  continue;
55 
56  if(!token_cmd && (found_token("get", 3) || found_token("list", 4) ||
57  found_token("compact", 7))) {
58  token_cmd = true;
59  continue;
60  }
61  if(!token_cmd) {
62  expect_token(expect_cmd, strlen(expect_cmd), token_cmd);
63  break;
64  }
65  if(!token_typ && (found_token("columns", 7) || found_token("column", 6) ||
66  found_token("schemas", 7) || found_token("schema", 6))) {
67  token_typ = true;
68  continue;
69  }
70  if(token_typ)
71  break;
72  expect_token("columns", 7, token_typ);
73  break;
74  }
75 }
76 
78  bool bracket = false;
79  char stop[3];
80  stop[0] = ',';
81  stop[1] = ' ';
82  stop[2] = 0;
83 
84  while(remain && !err) {
85  if(found_space())
86  continue;
87 
88  if(found_char('[')) {
89  stop[1] = ']';
90  bracket = true;
91  continue;
92  } else if(found_char('(')) {
93  stop[1] = ')';
94  bracket = true;
95  continue;
96  }
97 
98  read_columns(schemas, stop);
99 
100  if(bracket)
101  expect_token(&stop[1], 1, bracket);
102  break;
103  }
104 }
105 
106 void ColumnList::read_columns(DB::SchemasVec& cols, const char* stop) {
107  std::string col_name;
108  while(remain && !err) {
109  if(found_char(',') || found_space())
110  continue;
111 
112  if(found_token("tags", 4)) {
114  continue;
115  }
116 
117  read_column(stop, col_name, patterns.names);
118  if(!col_name.empty()) {
119  cols.push_back(get_schema(clients, col_name));
120  col_name.clear();
121  } else if(remain && !err && stop[1] != ' ' && is_char(&stop[1])) {
122  break;
123  }
124  }
125 }
126 
127 
128 }}} // SWC::client:SQL namespace
SWC::client::SQL::Reader::expect_token
void expect_token(const char *token, uint8_t token_len, bool &found)
Definition: Reader.cc:122
SWC::client::Clients::Ptr
ClientsPtr Ptr
Definition: Clients.h:58
SWC::client::SQL::Reader::remain
uint32_t remain
Definition: Reader.h:124
SWC::client::SQL::ColumnList::ColumnList
ColumnList(const Clients::Ptr &clients, const std::string &sql, DB::SchemasVec &schemas, std::string &message)
Definition: ColumnList.cc:13
SWC::client::SQL::ColumnList::patterns
DB::Schemas::SelectorPatterns patterns
Definition: ColumnList.h:26
SWC::client::SQL::ColumnList::read_columns
void read_columns(DB::SchemasVec &cols, const char *stop)
Definition: ColumnList.cc:106
SWC::client::SQL::Reader::read_column_tags
void read_column_tags(DB::Schemas::TagsPattern &tags)
Definition: Reader.cc:416
SWC::client::SQL::Reader
Definition: Reader.h:28
SWC::DB::Schemas::SelectorPatterns::names
NamePatterns names
Definition: Schemas.h:101
SWC::client::SQL::Reader::found_char
bool found_char(const char c)
Definition: Reader.cc:28
SWC::client::SQL::Reader::found_space
bool found_space()
Definition: Reader.cc:37
SWC::client::SQL::Reader::get_schema
DB::Schema::Ptr get_schema(const Clients::Ptr &clients, const std::string &col)
Definition: Reader.cc:137
Exception.h
SWC::client::SQL::ColumnList::clients
Clients::Ptr clients
Definition: ColumnList.h:45
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::client::SQL::Reader::found_token
bool found_token(const char *token, uint8_t token_len)
Definition: Reader.cc:58
SWC::client::SQL::ONLY_CID
@ ONLY_CID
Definition: ColumnList.h:18
SWC::client::SQL::ColumnList::parse_list_columns
void parse_list_columns()
Definition: ColumnList.cc:77
SWC::client::SQL::ColumnList::schemas
DB::SchemasVec & schemas
Definition: ColumnList.h:46
SWC::Core::Vector< Schema::Ptr >
SWC::DB::Schemas::SelectorPatterns::tags
TagsPattern tags
Definition: Schemas.h:102
SWC::client::SQL::ColumnList::_parse_list_columns
void _parse_list_columns(const char *expect_cmd)
Definition: ColumnList.cc:48
SWC::client::SQL::Reader::is_char
bool SWC_PURE_FUNC is_char(const char *stop) const
Definition: Reader.cc:20
SWC::client::SQL::Reader::err
int err
Definition: Reader.h:125
SWC::client::SQL::Reader::read_column
void read_column(const char *stop, std::string &col_name, DB::Schemas::NamePatterns &names)
Definition: Reader.cc:467
SWC::Core::Vector::push_back
SWC_CAN_INLINE void push_back(ArgsT &&... args)
Definition: Vector.h:331
ColumnList.h