OmniSciDB  c07336695a
omnisql.cpp File Reference

OmniSci SQL Client Tool. More...

#include <rapidjson/document.h>
#include <termios.h>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/filesystem.hpp>
#include <boost/format.hpp>
#include <boost/program_options.hpp>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits>
#include <sstream>
#include <string>
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/protocol/TJSONProtocol.h>
#include <thrift/transport/TBufferTransports.h>
#include <thrift/transport/TSocket.h>
#include "../Fragmenter/InsertOrderFragmenter.h"
#include "MapDRelease.h"
#include "MapDServer.h"
#include "Shared/Logger.h"
#include "Shared/StringTransform.h"
#include "Shared/ThriftClient.h"
#include "Shared/ThriftTypesConvert.h"
#include "Shared/base64.h"
#include "Shared/checked_alloc.h"
#include "Shared/mapd_shared_ptr.h"
#include "gen-cpp/MapD.h"
#include "linenoise.h"
#include "ClientContext.h"
#include "CommandFunctors.h"
#include "CommandHistoryFile.h"
+ Include dependency graph for omnisql.cpp:

Go to the source code of this file.

Namespaces

 anonymous_namespace{omnisql.cpp}
 

Macros

#define LOAD_PATCH_SIZE   10000
 

Enumerations

enum  anonymous_namespace{omnisql.cpp}::Action { anonymous_namespace{omnisql.cpp}::INITIALIZE, anonymous_namespace{omnisql.cpp}::TURN_ON, anonymous_namespace{omnisql.cpp}::TURN_OFF, anonymous_namespace{omnisql.cpp}::INTERRUPT }
 

Functions

const std::string OmniSQLRelease (MAPD_RELEASE)
 
void anonymous_namespace{omnisql.cpp}::completion (const char *buf, linenoiseCompletions *lc)
 
void anonymous_namespace{omnisql.cpp}::copy_table (char const *filepath, char const *table, ClientContext &context)
 
void anonymous_namespace{omnisql.cpp}::detect_table (char *file_name, TCopyParams &copy_params, ClientContext &context)
 
size_t anonymous_namespace{omnisql.cpp}::get_row_count (const TQueryResult &query_result)
 
void anonymous_namespace{omnisql.cpp}::get_table_epoch (ClientContext &context, const std::string &table_specifier)
 
void anonymous_namespace{omnisql.cpp}::set_table_epoch (ClientContext &context, const std::string &table_details)
 
void anonymous_namespace{omnisql.cpp}::process_backslash_commands (char *command, ClientContext &context)
 
std::string anonymous_namespace{omnisql.cpp}::scalar_datum_to_string (const TDatum &datum, const TTypeInfo &type_info)
 
std::string anonymous_namespace{omnisql.cpp}::datum_to_string (const TDatum &datum, const TTypeInfo &type_info)
 
TDatum anonymous_namespace{omnisql.cpp}::columnar_val_to_datum (const TColumn &col, const size_t row_idx, const TTypeInfo &col_type)
 
std::string anonymous_namespace{omnisql.cpp}::mapd_getpass ()
 
bool anonymous_namespace{omnisql.cpp}::backchannel (int action, ClientContext *cc, const std::string &ccn="")
 
void anonymous_namespace{omnisql.cpp}::omnisql_signal_handler (int signal_number)
 
void anonymous_namespace{omnisql.cpp}::register_signal_handler ()
 
void anonymous_namespace{omnisql.cpp}::print_memory_summary (ClientContext &context, std::string memory_level)
 
void anonymous_namespace{omnisql.cpp}::print_memory_info (ClientContext &context, std::string memory_level)
 
std::string anonymous_namespace{omnisql.cpp}::print_gpu_specification (TGpuSpecification gpu_spec)
 
std::string anonymous_namespace{omnisql.cpp}::print_hardware_specification (THardwareInfo hw_spec)
 
void anonymous_namespace{omnisql.cpp}::print_all_hardware_info (ClientContext &context)
 
static void anonymous_namespace{omnisql.cpp}::print_privs (const std::vector< bool > &privs, TDBObjectType::type type)
 
void anonymous_namespace{omnisql.cpp}::get_db_objects_for_grantee (ClientContext &context)
 
void anonymous_namespace{omnisql.cpp}::get_db_object_privs (ClientContext &context)
 
void anonymous_namespace{omnisql.cpp}::set_license_key (ClientContext &context, const std::string &token)
 
void anonymous_namespace{omnisql.cpp}::get_license_claims (ClientContext &context)
 
std::string anonymous_namespace{omnisql.cpp}::hide_sensitive_data_from_connect (const std::string &connect_str)
 
std::string anonymous_namespace{omnisql.cpp}::get_process_role (TRole::type role)
 
void anonymous_namespace{omnisql.cpp}::print_status (ClientContext &context)
 
int main (int argc, char **argv)
 
void oom_trace_dump ()
 

Variables

ClientContextanonymous_namespace{omnisql.cpp}::g_client_context_ptr {nullptr}
 

Detailed Description

OmniSci SQL Client Tool.

Author
Wei Hong wei@m.nosp@m.ap-d.nosp@m..com

Definition in file omnisql.cpp.

Macro Definition Documentation

◆ LOAD_PATCH_SIZE

#define LOAD_PATCH_SIZE   10000

Definition at line 91 of file omnisql.cpp.

Referenced by anonymous_namespace{omnisql.cpp}::copy_table().

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 1063 of file omnisql.cpp.

References run-benchmark-import::args, anonymous_namespace{omnisql.cpp}::backchannel(), anonymous_namespace{ExecuteTest.cpp}::c(), MetaClientContext< CLIENT_TYPE, TRANSPORT_TYPE >::cluster_hardware_info, anonymous_namespace{omnisql.cpp}::columnar_val_to_datum(), anonymous_namespace{omnisql.cpp}::completion(), anonymous_namespace{omnisql.cpp}::copy_table(), CPU, DatabaseDBObjectType, datum_to_string(), MetaClientContext< CLIENT_TYPE, TRANSPORT_TYPE >::db_name, anonymous_namespace{omnisql.cpp}::detect_table(), MetaClientContext< CLIENT_TYPE, TRANSPORT_TYPE >::execution_mode, anonymous_namespace{omnisql.cpp}::g_client_context_ptr, anonymous_namespace{omnisql.cpp}::get_db_object_privs(), anonymous_namespace{omnisql.cpp}::get_db_objects_for_grantee(), anonymous_namespace{omnisql.cpp}::get_license_claims(), anonymous_namespace{omnisql.cpp}::get_row_count(), anonymous_namespace{omnisql.cpp}::get_table_epoch(), GPU, anonymous_namespace{omnisql.cpp}::hide_sensitive_data_from_connect(), hide_sensitive_data_from_query(), MetaClientContext< CLIENT_TYPE, TRANSPORT_TYPE >::http, MetaClientContext< CLIENT_TYPE, TRANSPORT_TYPE >::https, anonymous_namespace{omnisql.cpp}::INITIALIZE, INVALID_SESSION_ID, kCLEAR_MEMORY_CPU, kCLEAR_MEMORY_GPU, kCONNECT, kDISCONNECT, kGET_HARDWARE_INFO, kGET_MEMORY_CPU, kGET_MEMORY_GPU, kGET_MEMORY_SUMMARY, kGET_SERVER_STATUS, kGET_VERSION, kINTERRUPT, kSET_EXECUTION_MODE, kSQL, anonymous_namespace{omnisql.cpp}::mapd_getpass(), MetaClientContext< CLIENT_TYPE, TRANSPORT_TYPE >::object_type, OMNISCI_ROOT_USER, OmniSQLRelease(), MetaClientContext< CLIENT_TYPE, TRANSPORT_TYPE >::passwd, MetaClientContext< CLIENT_TYPE, TRANSPORT_TYPE >::port, anonymous_namespace{omnisql.cpp}::print_all_hardware_info(), anonymous_namespace{omnisql.cpp}::print_memory_info(), anonymous_namespace{omnisql.cpp}::print_memory_summary(), anonymous_namespace{omnisql.cpp}::print_status(), MetaClientContext< CLIENT_TYPE, TRANSPORT_TYPE >::privs_object_name, MetaClientContext< CLIENT_TYPE, TRANSPORT_TYPE >::privs_role_name, anonymous_namespace{omnisql.cpp}::process_backslash_commands(), anonymous_namespace{UpdateMetadataTest.cpp}::query, MetaClientContext< CLIENT_TYPE, TRANSPORT_TYPE >::query_return, register_signal_handler(), run, MetaClientContext< CLIENT_TYPE, TRANSPORT_TYPE >::server_host, MetaClientContext< CLIENT_TYPE, TRANSPORT_TYPE >::session, anonymous_namespace{omnisql.cpp}::set_license_key(), anonymous_namespace{omnisql.cpp}::set_table_epoch(), MetaClientContext< CLIENT_TYPE, TRANSPORT_TYPE >::skip_host_verify, split(), TableDBObjectType, thrift_with_retry(), anonymous_namespace{omnisql.cpp}::TURN_OFF, anonymous_namespace{omnisql.cpp}::TURN_ON, run-benchmark-import::type, MetaClientContext< CLIENT_TYPE, TRANSPORT_TYPE >::user_name, and MetaClientContext< CLIENT_TYPE, TRANSPORT_TYPE >::version.

1063  {
1064  std::string server_host{"localhost"};
1065  int port = 6274;
1066  std::string delimiter("|");
1067  bool print_header = true;
1068  bool print_connection = true;
1069  bool print_timing = false;
1070  bool http = false;
1071  bool https = false;
1072  bool skip_host_verify = false;
1073  TQueryResult _return;
1074  std::string db_name;
1075  std::string user_name{"admin"};
1076  std::string ca_cert_name{""};
1077  std::string passwd;
1078  CommandHistoryFile cmd_file;
1079 
1080  namespace po = boost::program_options;
1081 
1082  po::options_description desc("Options");
1083  desc.add_options()("help,h", "Print help messages ");
1084  desc.add_options()("version,v", "Print omnisql version number");
1085  desc.add_options()("no-header,n", "Do not print query result header");
1086  desc.add_options()(
1087  "timing,t",
1088  po::bool_switch(&print_timing)->default_value(print_timing)->implicit_value(true),
1089  "Print timing information");
1090  desc.add_options()("delimiter,d",
1091  po::value<std::string>(&delimiter)->default_value(delimiter),
1092  "Field delimiter in row output");
1093  desc.add_options()("db",
1094  po::value<std::string>(&db_name),
1095  "Database name (server default is omnisci)");
1096  desc.add_options()("user,u",
1097  po::value<std::string>(&user_name)->default_value(user_name),
1098  "User name");
1099  desc.add_options()(
1100  "ca-cert",
1101  po::value<std::string>(&ca_cert_name)->default_value(ca_cert_name),
1102  "Path to trusted server certificate. Initiates an encrypted connection");
1103  desc.add_options()("passwd,p", po::value<std::string>(&passwd), "Password");
1104  desc.add_options()(
1105  "history", po::value<CommandHistoryFile>(&cmd_file), "History filename");
1106  desc.add_options()("server,s",
1107  po::value<std::string>(&server_host)->default_value(server_host),
1108  "Server hostname");
1109  desc.add_options()("port", po::value<int>(&port)->default_value(port), "Port number");
1110  desc.add_options()("http",
1111  po::bool_switch(&http)->default_value(http)->implicit_value(true),
1112  "Use HTTP transport");
1113  desc.add_options()("https",
1114  po::bool_switch(&https)->default_value(https)->implicit_value(true),
1115  "Use HTTPS transport");
1116  desc.add_options()("skip-verify",
1117  po::bool_switch(&skip_host_verify)
1118  ->default_value(skip_host_verify)
1119  ->implicit_value(true),
1120  "Don't verify SSL certificate validity");
1121  desc.add_options()("quiet,q", "Do not print result headers or connection strings ");
1122 
1123  po::variables_map vm;
1124  po::positional_options_description positionalOptions;
1125  positionalOptions.add("db", 1);
1126 
1127  try {
1128  po::store(po::command_line_parser(argc, argv)
1129  .options(desc)
1130  .positional(positionalOptions)
1131  .run(),
1132  vm);
1133  if (vm.count("help")) {
1134  std::cout << "Usage: omnisql [<database>] [{--user|-u} <user>] [{--passwd|-p} "
1135  "<password>] [--port <port number>] "
1136  "[{-s|--server} <server host>] [--http] [{--no-header|-n}] "
1137  "[{--quiet|-q}] [{--delimiter|-d}]\n\n";
1138  std::cout << desc << std::endl;
1139  return 0;
1140  }
1141  if (vm.count("version")) {
1142  std::cout << "OmniSQL Version: " << OmniSQLRelease << std::endl;
1143  return 0;
1144  }
1145  if (vm.count("quiet")) {
1146  print_header = false;
1147  print_connection = false;
1148  }
1149  if (vm.count("no-header")) {
1150  print_header = false;
1151  }
1152  if (vm.count("db") && !vm.count("user")) {
1153  std::cerr << "Must specify a user name to access database " << db_name << std::endl;
1154  return 1;
1155  }
1156 
1157  po::notify(vm);
1158  } catch (boost::program_options::error& e) {
1159  std::cerr << "Usage Error: " << e.what() << std::endl;
1160  return 1;
1161  }
1162 
1163  if (!vm.count("passwd")) {
1164  passwd = mapd_getpass();
1165  }
1166  mapd::shared_ptr<ThriftClientConnection> connMgr;
1167  connMgr = std::make_shared<ThriftClientConnection>();
1168  mapd::shared_ptr<TTransport> transport;
1169  mapd::shared_ptr<TProtocol> protocol;
1170  mapd::shared_ptr<TTransport> socket;
1171  if (https || http) {
1172  transport = connMgr->open_http_client_transport(
1173  server_host, port, ca_cert_name, https, skip_host_verify);
1174  protocol = mapd::shared_ptr<TProtocol>(new TJSONProtocol(transport));
1175  } else {
1176  transport = connMgr->open_buffered_client_transport(server_host, port, ca_cert_name);
1177  protocol = mapd::shared_ptr<TProtocol>(new TBinaryProtocol(transport));
1178  }
1179  MapDClient c(protocol);
1180  ClientContext context(*transport, c);
1181  g_client_context_ptr = &context;
1182 
1183  context.db_name = db_name;
1184  context.user_name = user_name;
1185  context.passwd = passwd;
1186  context.server_host = server_host;
1187  context.port = port;
1188  context.http = http;
1189  context.https = https;
1190  context.skip_host_verify = skip_host_verify;
1191  context.session = INVALID_SESSION_ID;
1192 
1193  try {
1194  transport->open();
1195  } catch (...) {
1196  std::cout << "Failed to open transport. Is omnisci_server running?" << std::endl;
1197  return 1;
1198  }
1199 
1200  if (thrift_with_retry(kCONNECT, context, nullptr)) {
1201  if (print_connection) {
1202  std::cout << "User " << context.user_name << " connected to database "
1203  << context.db_name << std::endl;
1204  }
1205  }
1206  if (context.db_name.empty()) {
1207  std::cout << "Not connected to any database. See \\h for help." << std::endl;
1208  }
1209 
1211  (void)backchannel(INITIALIZE, &context, ca_cert_name);
1212 
1213  /* Set the completion callback. This will be called every time the
1214  * user uses the <tab> key. */
1215  linenoiseSetCompletionCallback(completion);
1216 
1217  /* Load history from file. The history file is just a plain text file
1218  * where entries are separated by newlines. */
1219  linenoiseHistoryLoad(cmd_file); /* Load the history at startup */
1220  /* default to multi-line mode */
1221  linenoiseSetMultiLine(1);
1222 
1223  std::string current_line;
1224  std::string prompt("omnisql> ");
1225 
1226  /* Now this is the main loop of the typical linenoise-based application.
1227  * The call to linenoise() will block as long as the user types something
1228  * and presses enter.
1229  *
1230  * The typed string that is malloc() allocated by linenoise() is managed by a smart
1231  * pointer with a custom free() deleter; no need to free this memory explicitly. */
1232 
1233  while (true) {
1234  using LineType = std::remove_pointer<__decltype(linenoise(prompt.c_str()))>::type;
1235  using LineTypePtr = LineType*;
1236 
1237  std::unique_ptr<LineType, std::function<void(LineTypePtr)>> smart_line(
1238  linenoise(prompt.c_str()), [](LineTypePtr l) { free((l)); });
1239  if (smart_line == nullptr) {
1240  break;
1241  }
1242  LineType* line = smart_line.get(); // Alias to make the C stuff work
1243 
1244  {
1245  TQueryResult empty;
1246  swap(_return, empty);
1247  }
1248 
1249  /* Do something with the string. */
1250  if (line[0] != '\0' && line[0] != '\\') {
1251  // printf("echo: '%s'\n", line);
1252  if (context.session == INVALID_SESSION_ID) {
1253  std::cerr << "Not connected to any OmniSci databases." << std::endl;
1254  continue;
1255  }
1256  std::string trimmed_line = std::string(line);
1257  boost::algorithm::trim(trimmed_line);
1258  current_line.append(" ").append(trimmed_line);
1259  boost::algorithm::trim(current_line);
1260  if (current_line.back() == ';') {
1261  std::string query(current_line);
1262  linenoiseHistoryAdd(hide_sensitive_data_from_query(current_line).c_str());
1263  linenoiseHistorySave(cmd_file);
1264  current_line.clear();
1265  prompt.assign("omnisql> ");
1266  (void)backchannel(TURN_ON, nullptr);
1267  if (thrift_with_retry(kSQL, context, query.c_str())) {
1268  (void)backchannel(TURN_OFF, nullptr);
1269  if (context.query_return.row_set.row_desc.empty()) {
1270  continue;
1271  }
1272  const size_t row_count{get_row_count(context.query_return)};
1273  if (!row_count) {
1274  static const std::string insert{"INSERT"};
1275  std::string verb(query, 0, insert.size());
1276  if (!boost::iequals(verb, insert)) {
1277  std::cout << "No rows returned." << std::endl;
1278  }
1279  if (print_timing) {
1280  std::cout << "Execution time: " << context.query_return.execution_time_ms
1281  << " ms,"
1282  << " Total time: " << context.query_return.total_time_ms << " ms"
1283  << std::endl;
1284  }
1285  continue;
1286  }
1287  bool not_first = false;
1288  if (print_header) {
1289  for (auto p : context.query_return.row_set.row_desc) {
1290  if (p.is_physical) {
1291  // TODO(d): skip if we decide to suppress displaying physical columns
1292  }
1293  if (not_first) {
1294  std::cout << delimiter;
1295  } else {
1296  not_first = true;
1297  }
1298  std::cout << p.col_name;
1299  }
1300  std::cout << std::endl;
1301  }
1302  for (size_t row_idx = 0; row_idx < row_count; ++row_idx) {
1303  const auto& col_desc = context.query_return.row_set.row_desc;
1304  for (size_t col_idx = 0; col_idx < col_desc.size(); ++col_idx) {
1305  if (col_idx) {
1306  std::cout << delimiter;
1307  }
1308  const auto& col_type = col_desc[col_idx].col_type;
1309  std::cout << datum_to_string(
1311  context.query_return.row_set.columns[col_idx], row_idx, col_type),
1312  col_type);
1313  }
1314  std::cout << std::endl;
1315  }
1316  if (print_timing) {
1317  std::cout << row_count << " rows returned." << std::endl;
1318  std::cout << "Execution time: " << context.query_return.execution_time_ms
1319  << " ms,"
1320  << " Total time: " << context.query_return.total_time_ms << " ms"
1321  << std::endl;
1322  }
1323  } else {
1324  (void)backchannel(TURN_OFF, nullptr);
1325  }
1326  } else {
1327  // change the prommpt
1328  prompt.assign("..> ");
1329  }
1330  continue;
1331  } else if (!strncmp(line, "\\interrupt", 10)) {
1332  (void)thrift_with_retry(kINTERRUPT, context, nullptr);
1333  } else if (!strncmp(line, "\\cpu", 4)) {
1334  context.execution_mode = TExecuteMode::CPU;
1335  (void)thrift_with_retry(kSET_EXECUTION_MODE, context, nullptr);
1336  } else if (!strncmp(line, "\\gpu", 4)) {
1337  context.execution_mode = TExecuteMode::GPU;
1338  (void)thrift_with_retry(kSET_EXECUTION_MODE, context, nullptr);
1339  } else if (!strncmp(line, "\\hybrid", 5)) {
1340  std::cout << "Hybrid execution mode has been deprecated." << std::endl;
1341  } else if (!strncmp(line, "\\version", 8)) {
1342  if (thrift_with_retry(kGET_VERSION, context, nullptr)) {
1343  std::cout << "OmniSci Server Version: " << context.version << std::endl;
1344  } else {
1345  std::cout << "Cannot connect to OmniSci Server." << std::endl;
1346  }
1347  } else if (!strncmp(line, "\\memory_gpu", 11)) {
1348  if (thrift_with_retry(kGET_MEMORY_GPU, context, nullptr)) {
1349  print_memory_info(context, "gpu");
1350  } else {
1351  std::cout << "Cannot connect to OmniSci Server." << std::endl;
1352  }
1353  } else if (!strncmp(line, "\\memory_cpu", 11)) {
1354  if (thrift_with_retry(kGET_MEMORY_CPU, context, nullptr)) {
1355  print_memory_info(context, "cpu");
1356  }
1357  } else if (!strncmp(line, "\\clear_gpu", 11)) {
1358  if (thrift_with_retry(kCLEAR_MEMORY_GPU, context, nullptr)) {
1359  std::cout << "OmniSci Server GPU memory Cleared " << std::endl;
1360  }
1361  } else if (!strncmp(line, "\\clear_cpu", 11)) {
1362  if (thrift_with_retry(kCLEAR_MEMORY_CPU, context, nullptr)) {
1363  std::cout << "OmniSci Server CPU memory Cleared " << std::endl;
1364  }
1365  } else if (!strncmp(line, "\\memory_summary", 11)) {
1366  if (thrift_with_retry(kGET_MEMORY_SUMMARY, context, nullptr)) {
1367  print_memory_summary(context, "cpu");
1368  print_memory_summary(context, "gpu");
1369  }
1370  } else if (!strncmp(line, "\\hardware_info", 13)) {
1371  if (context.cluster_hardware_info.hardware_info.size() > 0 ||
1372  thrift_with_retry(kGET_HARDWARE_INFO, context, nullptr)) {
1373  // TODO(vraj): try not to abuse using short circuit here
1374  print_all_hardware_info(context);
1375  }
1376  } else if (!strncmp(line, "\\status", 8)) {
1377  if (thrift_with_retry(kGET_SERVER_STATUS, context, nullptr)) {
1378  print_status(context);
1379  }
1380  } else if (!strncmp(line, "\\detect", 7)) {
1381  char* filepath = strtok(line + 8, " ");
1382  TCopyParams copy_params;
1383 #ifdef ENABLE_IMPORT_PARQUET
1384  // users may give only a directory name which has no obvious connection to parquet.
1385  // need users to explicitly specify that they want to detect cols in parquet files
1386  if (boost::iequals(filepath, "parquet")) {
1387  copy_params.file_type = TFileType::PARQUET;
1388  filepath = strtok(0, " ");
1389  }
1390 #endif
1391  copy_params.delimiter = ",";
1392  char* env;
1393  if (nullptr != (env = getenv("AWS_REGION"))) {
1394  copy_params.s3_region = env;
1395  }
1396  if (nullptr != (env = getenv("AWS_ACCESS_KEY_ID"))) {
1397  copy_params.s3_access_key = env;
1398  }
1399  if (nullptr != (env = getenv("AWS_SECRET_ACCESS_KEY"))) {
1400  copy_params.s3_secret_key = env;
1401  }
1402  detect_table(filepath, copy_params, context);
1403  } else if (!strncmp(line, "\\historylen", 11)) {
1404  /* The "/historylen" command will change the history len. */
1405  int len = atoi(line + 11);
1406  linenoiseHistorySetMaxLen(len);
1407  } else if (!strncmp(line, "\\privileges", 11)) {
1408  std::string temp_line(line);
1409  boost::algorithm::trim(temp_line);
1410  if (temp_line.size() > 11) {
1411  context.privs_role_name.clear();
1412  context.privs_role_name = strtok(line + 12, " ");
1413  if (!context.privs_role_name.compare(OMNISCI_ROOT_USER)) {
1414  std::cerr << "Command privileges failed because " << OMNISCI_ROOT_USER
1415  << " root user has all privileges by default." << std::endl;
1416  } else {
1417  get_db_objects_for_grantee(context);
1418  }
1419  } else {
1420  std::cerr << "Command privileges failed because parameter role name or user name "
1421  "is missing."
1422  << std::endl;
1423  }
1424  } else if (!strncmp(line, "\\object_privileges", 18)) {
1425  std::string cmd(line);
1426  boost::trim(cmd);
1427  std::vector<std::string> args;
1428  boost::split(args, cmd, boost::is_any_of("\t "), boost::token_compress_on);
1429  if (args.size() == 3) {
1430  context.privs_object_name = args[2];
1431  if (args[1] == "database") {
1432  context.object_type = TDBObjectType::DatabaseDBObjectType;
1433  get_db_object_privs(context);
1434  } else if (args[1] == "table") {
1435  context.object_type = TDBObjectType::TableDBObjectType;
1436  get_db_object_privs(context);
1437  } else {
1438  std::cerr << "Object type should be on in { database, table }" << std::endl;
1439  }
1440  } else {
1441  std::cerr << "Command object_privileges failed. It requires two parameters: "
1442  "object type and object name."
1443  << std::endl;
1444  }
1445  } else if (line[0] == '\\' && line[1] == 'q') {
1446  break;
1447  } else { // Experimental Cleanup
1449 
1450  // clang-format off
1451  auto resolution_status = CommandResolutionChain<>( line, "\\copygeo", 1, 4, CopyGeoCmd<>(context), "") // deprecated
1452  ( "\\copy", 3, 3, [&](Params const& p) { copy_table(p[1].c_str() /* filepath */, p[2].c_str() /* table */, context); } )
1453  ( "\\ste", 2, 2, [&](Params const& p) { set_table_epoch(context, p[1] /* table_details */); } )
1454  ( "\\gte", 2, 2, [&](Params const& p) { get_table_epoch(context, p[1] /* table_details */); } )
1455  ( "\\export_dashboard", 3, 4, ExportDashboardCmd<>( context ), "Usage \\export_dashboard <dash name> <file name> <optional:dash_owner>" )
1456  ( "\\import_dashboard", 3, 3, ImportDashboardCmd<>( context ), "Usage \\import_dashboard <dash name> <file name>" )
1457  ( "\\role_list", 2, 2, RoleListCmd<>(context), "Usage: \\role_list <userName>")
1458  ( "\\roles", 1, 1, RolesCmd<>(context))("\\set_license", 2, 2, [&](Params const& p ) { set_license_key(context, p[1]); })
1459  ( "\\get_license", 1, 1, [&](Params const&) { get_license_claims(context); })
1460  ( "\\status", 1, 1, StatusCmd<>( context ), "Usage \\status" )
1461  ( "\\dash", 1, 1, ListDashboardsCmd<>( context ) )
1462  ( "\\multiline", 1, 1, [&](Params const&) { linenoiseSetMultiLine(1); } )
1463  ( "\\singleline", 1, 1, [&](Params const&) { linenoiseSetMultiLine(0); } )
1464  ( "\\keycodes", 1, 1, [&](Params const&) { linenoisePrintKeyCodes(); } )
1465  ( "\\timing", 1, 1, [&](Params const&) { print_timing = true; } )
1466  ( "\\notiming", 1, 1, [&](Params const&) { print_timing = false; } )
1467  ( "\\db", 1, 2, SwitchDatabaseCmd<>( context ), "Usage: \\db [database|...]" )
1468  .is_resolved();
1469 
1470  if (resolution_status == false) {
1471  if (line[0] == '\\' && line[1] == 'q') {
1472  break;
1473  } else if (line[0] == '\\') {
1474  process_backslash_commands(line, context);
1475  }
1476  }
1477  // clang-format on
1478  }
1479 
1480  /* Add to the history. */
1481  if (line[0] == '\\' && line[1] == 'c') {
1482  linenoiseHistoryAdd(hide_sensitive_data_from_connect(line).c_str());
1483  } else {
1484  linenoiseHistoryAdd(hide_sensitive_data_from_query(line).c_str());
1485  }
1486  linenoiseHistorySave(cmd_file);
1487  }
1488 
1489  if (context.session != INVALID_SESSION_ID) {
1490  if (thrift_with_retry(kDISCONNECT, context, nullptr)) {
1491  if (print_connection) {
1492  std::cout << "User " << context.user_name << " disconnected from database "
1493  << context.db_name << std::endl;
1494  }
1495  }
1496  }
1497  transport->close();
1498 
1499  return 0;
1500 }
std::string hide_sensitive_data_from_query(std::string const &query_str)
ClientContext * g_client_context_ptr
Definition: omnisql.cpp:76
void print_status(ClientContext &context)
Definition: omnisql.cpp:1000
void get_license_claims(ClientContext &context)
Definition: omnisql.cpp:961
void completion(const char *buf, linenoiseCompletions *lc)
Definition: omnisql.cpp:78
std::string datum_to_string(const TargetValue &tv, const SQLTypeInfo &ti, const std::string &delim)
void c(const std::string &query_string, const ExecutorDeviceType device_type)
void get_table_epoch(ClientContext &context, const std::string &table_specifier)
Definition: omnisql.cpp:220
void get_db_objects_for_grantee(ClientContext &context)
Definition: omnisql.cpp:881
void print_memory_info(ClientContext &context, std::string memory_level)
Definition: omnisql.cpp:740
void get_db_object_privs(ClientContext &context)
Definition: omnisql.cpp:923
const std::string OmniSQLRelease(MAPD_RELEASE)
#define INVALID_SESSION_ID
size_t get_row_count(const TQueryResult &query_result)
Definition: omnisql.cpp:211
void print_memory_summary(ClientContext &context, std::string memory_level)
Definition: omnisql.cpp:652
void set_license_key(ClientContext &context, const std::string &token)
Definition: omnisql.cpp:948
void process_backslash_commands(char *command, ClientContext &context)
Definition: omnisql.cpp:373
TDatum columnar_val_to_datum(const TColumn &col, const size_t row_idx, const TTypeInfo &col_type)
Definition: omnisql.cpp:491
bool backchannel(int action, ClientContext *cc, const std::string &ccn="")
Definition: omnisql.cpp:565
const std::string OMNISCI_ROOT_USER
Definition: SysCatalog.h:59
void detect_table(char *file_name, TCopyParams &copy_params, ClientContext &context)
Definition: omnisql.cpp:158
std::vector< std::string > split(const std::string &str, const std::string &delim)
void register_signal_handler(int signum, void(*handler)(int))
Definition: MapDServer.cpp:100
void set_table_epoch(ClientContext &context, const std::string &table_details)
Definition: omnisql.cpp:282
void print_all_hardware_info(ClientContext &context)
Definition: omnisql.cpp:838
void copy_table(char const *filepath, char const *table, ClientContext &context)
Definition: omnisql.cpp:93
bool thrift_with_retry(SERVICE_ENUM which_service, CLIENT_CONTEXT &context, char const *arg, const int try_count=1)
static bool run
std::string hide_sensitive_data_from_connect(const std::string &connect_str)
Definition: omnisql.cpp:973
std::vector< std::string > CommandTokenList
+ Here is the call graph for this function:

◆ OmniSQLRelease()

const std::string OmniSQLRelease ( MAPD_RELEASE  )

Referenced by main().

+ Here is the caller graph for this function:

◆ oom_trace_dump()

void oom_trace_dump ( )

Definition at line 1502 of file omnisql.cpp.

1502 {}