OmniSciDB  c0231cc57d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
foreign_storage::anonymous_namespace{LogFileBufferParser.cpp} Namespace Reference

Functions

std::string remove_quotes (const std::string &value)
 
std::map< std::string,
std::string > 
create_map_from_arrays (const std::string &keys_array, const std::string &values_array)
 
std::string get_node_name ()
 
void add_column_value (std::vector< std::string > &parsed_columns_str, std::vector< std::string_view > &parsed_columns_sv, const std::string &value, size_t count=1)
 
void add_nonce_values (std::vector< std::string > &parsed_columns_str, std::vector< std::string_view > &parsed_columns_sv, const std::string &nonce, int32_t table_id, int32_t db_id)
 

Function Documentation

void foreign_storage::anonymous_namespace{LogFileBufferParser.cpp}::add_column_value ( std::vector< std::string > &  parsed_columns_str,
std::vector< std::string_view > &  parsed_columns_sv,
const std::string &  value,
size_t  count = 1 
)

Definition at line 59 of file LogFileBufferParser.cpp.

Referenced by add_nonce_values(), and foreign_storage::LogFileBufferParser::regexMatchColumns().

62  {
63  for (size_t i = 0; i < count; i++) {
64  parsed_columns_str.emplace_back(value);
65  parsed_columns_sv.emplace_back(parsed_columns_str.back());
66  }
67 }

+ Here is the caller graph for this function:

void foreign_storage::anonymous_namespace{LogFileBufferParser.cpp}::add_nonce_values ( std::vector< std::string > &  parsed_columns_str,
std::vector< std::string_view > &  parsed_columns_sv,
const std::string &  nonce,
int32_t  table_id,
int32_t  db_id 
)

Definition at line 69 of file LogFileBufferParser.cpp.

References add_column_value(), CHECK, CHECK_GT, CHECK_LE, Catalog_Namespace::SysCatalog::getCatalog(), Catalog_Namespace::SysCatalog::instance(), and split().

Referenced by foreign_storage::LogFileBufferParser::regexMatchColumns().

73  {
74  // Nonce has the following format: "{dashboard id}/{chart id}-{layer id}"
75  auto dashboard_and_chart_id = split(nonce, "/");
76  if (dashboard_and_chart_id.size() == 2) {
77  auto dashboard_id_str = dashboard_and_chart_id[0];
78  int32_t dashboard_id{0};
79  if (dashboard_id_str == "null" ||
80  !(dashboard_id = std::atoi(dashboard_id_str.c_str()))) {
81  dashboard_id_str = "";
82  }
83  add_column_value(parsed_columns_str, parsed_columns_sv, dashboard_id_str);
84 
85  // Get dashboard name from dashboard id.
86  std::string dashboard_name;
87  if (dashboard_id > 0) {
88  // Get dashboard database name.
89  auto info_schema_catalog =
91  CHECK(info_schema_catalog);
92  auto db_name_column =
93  info_schema_catalog->getMetadataForColumn(table_id, "database_name");
94  CHECK(db_name_column);
95  CHECK_GT(db_name_column->columnId, 0);
96  CHECK_LE(size_t(db_name_column->columnId), parsed_columns_str.size());
97  const auto& db_name = parsed_columns_str[db_name_column->columnId - 1];
98 
99  // Get dashboard metadata.
100  Catalog_Namespace::DBMetadata db_metadata;
101  auto& sys_catalog = Catalog_Namespace::SysCatalog::instance();
102  if (sys_catalog.getMetadataForDB(db_name, db_metadata)) {
103  auto catalog = sys_catalog.getCatalog(db_metadata, false);
104  auto dashboard = catalog->getMetadataForDashboard(dashboard_id);
105  if (dashboard) {
106  dashboard_name = dashboard->dashboardName;
107  } else {
108  dashboard_name = "<DELETED>";
109  }
110  }
111  add_column_value(parsed_columns_str, parsed_columns_sv, dashboard_name);
112 
113  auto chart_and_layer_id = split(dashboard_and_chart_id[1], "-");
114  add_column_value(parsed_columns_str, parsed_columns_sv, chart_and_layer_id[0]);
115  } else {
116  // Null dashboard name and chart id.
117  add_column_value(parsed_columns_str, parsed_columns_sv, "", 2);
118  }
119  } else {
120  // Null dashboard id, dashboard name, and chart id.
121  add_column_value(parsed_columns_str, parsed_columns_sv, "", 3);
122  }
123 }
#define CHECK_GT(x, y)
Definition: Logger.h:234
std::vector< std::string > split(std::string_view str, std::string_view delim, std::optional< size_t > maxsplit)
split apart a string into a vector of substrings
static SysCatalog & instance()
Definition: SysCatalog.h:341
std::shared_ptr< Catalog > getCatalog(const std::string &dbName)
#define CHECK_LE(x, y)
Definition: Logger.h:233
#define CHECK(condition)
Definition: Logger.h:222
void add_column_value(std::vector< std::string > &parsed_columns_str, std::vector< std::string_view > &parsed_columns_sv, const std::string &value, size_t count=1)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::map<std::string, std::string> foreign_storage::anonymous_namespace{LogFileBufferParser.cpp}::create_map_from_arrays ( const std::string &  keys_array,
const std::string &  values_array 
)

Definition at line 31 of file LogFileBufferParser.cpp.

References import_export::delimited_parser::parse_string_array(), and remove_quotes().

Referenced by foreign_storage::LogFileBufferParser::regexMatchColumns().

33  {
34  std::vector<std::string> keys;
35  import_export::delimited_parser::parse_string_array(keys_array, {}, keys, true);
36  std::vector<std::string> values;
37  import_export::delimited_parser::parse_string_array(values_array, {}, values, true);
38  if (keys.size() == values.size()) {
39  std::map<std::string, std::string> values_map;
40  for (size_t i = 0; i < keys.size(); i++) {
41  values_map[remove_quotes(keys[i])] = remove_quotes(values[i]);
42  }
43  return values_map;
44  } else {
45  return {};
46  }
47 }
void parse_string_array(const std::string &s, const import_export::CopyParams &copy_params, std::vector< std::string > &string_vec, bool truncate_values)
Parses given string array and inserts into given vector of strings.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string foreign_storage::anonymous_namespace{LogFileBufferParser.cpp}::get_node_name ( )

Definition at line 49 of file LogFileBufferParser.cpp.

References g_distributed_leaf_idx, dist::is_leaf_node(), and to_string().

Referenced by foreign_storage::LogFileBufferParser::regexMatchColumns().

49  {
50  std::string node_name;
51  if (dist::is_leaf_node()) {
52  node_name = "Leaf " + to_string(g_distributed_leaf_idx);
53  } else {
54  node_name = "Server";
55  }
56  return node_name;
57 }
std::string to_string(char const *&&v)
bool is_leaf_node()
Definition: distributed.cpp:29
int32_t g_distributed_leaf_idx
Definition: Catalog.cpp:98

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string foreign_storage::anonymous_namespace{LogFileBufferParser.cpp}::remove_quotes ( const std::string &  value)

Definition at line 24 of file LogFileBufferParser.cpp.

Referenced by create_map_from_arrays(), and main().

24  {
25  if (value.length() > 1 && value[0] == '"' && value[value.length() - 1] == '"') {
26  return value.substr(1, value.length() - 2);
27  }
28  return value;
29 }

+ Here is the caller graph for this function: