OmniSciDB  340b00dbf6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Parser Namespace Reference

Namespaces

 anonymous_namespace{ParserNode.cpp}
 

Classes

class  Node
 
class  SQLType
 
class  Expr
 
class  Literal
 
class  NullLiteral
 
class  StringLiteral
 
class  IntLiteral
 
class  FixedPtLiteral
 
class  FloatLiteral
 
class  DoubleLiteral
 
class  TimestampLiteral
 
class  UserLiteral
 
class  ArrayLiteral
 
class  OperExpr
 
class  SubqueryExpr
 
class  IsNullExpr
 
class  InExpr
 
class  InSubquery
 
class  InValues
 
class  BetweenExpr
 
class  CharLengthExpr
 
class  CardinalityExpr
 
class  LikeExpr
 
class  RegexpExpr
 
class  LikelihoodExpr
 
class  ExistsExpr
 
class  ColumnRef
 
class  FunctionRef
 
class  CastExpr
 
class  ExprPair
 
class  CaseExpr
 
class  TableRef
 
class  Stmt
 
class  DMLStmt
 
class  DDLStmt
 
class  TableElement
 
class  ColumnConstraintDef
 
class  CompressDef
 
class  ColumnDef
 
class  TableConstraintDef
 
class  UniqueDef
 
class  ForeignKeyDef
 
class  CheckDef
 
class  SharedDictionaryDef
 
class  ShardKeyDef
 
class  NameValueAssign
 
class  CreateTableBaseStmt
 
class  CreateTableStmt
 
struct  DistributedConnector
 
struct  LocalConnector
 
class  CreateDataframeStmt
 
class  InsertIntoTableAsSelectStmt
 
class  CreateTableAsSelectStmt
 
class  DropTableStmt
 
class  TruncateTableStmt
 
class  OptimizeTableStmt
 
class  ValidateStmt
 
class  RenameDatabaseStmt
 
class  RenameUserStmt
 
class  RenameTableStmt
 
class  RenameColumnStmt
 
class  AddColumnStmt
 
class  DropColumnStmt
 
class  DumpRestoreTableStmtBase
 
class  DumpTableStmt
 
class  RestoreTableStmt
 
class  CopyTableStmt
 
class  CreateRoleStmt
 
class  DropRoleStmt
 
class  GrantPrivilegesStmt
 
class  RevokePrivilegesStmt
 
class  ShowPrivilegesStmt
 
class  GrantRoleStmt
 
class  RevokeRoleStmt
 
class  QueryExpr
 
class  UnionQuery
 
class  SelectEntry
 
class  QuerySpec
 
class  OrderSpec
 
class  SelectStmt
 
class  ShowCreateTableStmt
 
class  ExportQueryStmt
 
class  CreateViewStmt
 
class  DropViewStmt
 
class  CreateDBStmt
 
class  DropDBStmt
 
class  CreateUserStmt
 
class  AlterUserStmt
 
class  DropUserStmt
 
class  InsertStmt
 
class  InsertValuesStmt
 
class  Assignment
 
class  UpdateStmt
 
class  DeleteStmt
 
struct  DefaultValidate
 
struct  DefaultValidate< IntLiteral >
 
struct  DefaultValidate< StringLiteral >
 
struct  CaseSensitiveValidate
 
struct  ShouldInvalidateSessionsByDB
 
struct  ShouldInvalidateSessionsByUser
 
struct  ShouldInvalidateSessionsByDB< DropDBStmt >
 
struct  ShouldInvalidateSessionsByUser< DropUserStmt >
 
struct  ShouldInvalidateSessionsByDB< RenameDatabaseStmt >
 
struct  ShouldInvalidateSessionsByUser< RenameUserStmt >
 
class  TrackedPtr
 
class  TrackedListPtr
 

Functions

template<typename DDLSTMT >
auto parseDDL (const std::string &stmt_type, const std::string &stmt_str)
 
std::shared_ptr< ResultSetgetResultSet (QueryStateProxy query_state_proxy, const std::string select_stmt, std::vector< TargetMetaInfo > &targets, bool validate_only=false, std::vector< size_t > outer_fragment_indices={})
 
void check_alter_table_privilege (const Catalog_Namespace::SessionInfo &session, const TableDescriptor *td)
 
std::vector< std::string > splitObjectHierName (const std::string &hierName)
 
std::string extractObjectNameFromHierName (const std::string &objectHierName, const std::string &objectType, const Catalog_Namespace::Catalog &cat)
 
static std::pair
< AccessPrivileges,
DBObjectType
parseStringPrivs (const std::string &privs, const DBObjectType &objectType, const std::string &object_name)
 
static DBObject createObject (const std::string &objectName, DBObjectType objectType)
 
static void checkStringLiteral (const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
 
static bool readBooleanLiteral (const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
 
void execute_calcite_ddl (const std::string &ddl_statement, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 
void parser_slistval_to_vector (std::list< std::string * > *l, std::vector< std::string > &v)
 

Function Documentation

void Parser::check_alter_table_privilege ( const Catalog_Namespace::SessionInfo session,
const TableDescriptor td 
)

Definition at line 3349 of file ParserNode.cpp.

References AccessPrivileges::ALTER_TABLE, Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::SessionInfo::getCatalog(), Catalog_Namespace::UserMetadata::isSuper, DBObject::loadKey(), DBObject::setPrivileges(), TableDBObjectType, TableDescriptor::tableName, TableDescriptor::userId, and Catalog_Namespace::UserMetadata::userId.

Referenced by Parser::AddColumnStmt::check_executable(), Parser::RenameTableStmt::execute(), Parser::RenameColumnStmt::execute(), and Parser::DropColumnStmt::execute().

3350  {
3351  if (session.get_currentUser().isSuper ||
3352  session.get_currentUser().userId == td->userId) {
3353  return;
3354  }
3355  std::vector<DBObject> privObjects;
3356  DBObject dbObject(td->tableName, TableDBObjectType);
3357  dbObject.loadKey(session.getCatalog());
3358  dbObject.setPrivileges(AccessPrivileges::ALTER_TABLE);
3359  privObjects.push_back(dbObject);
3360  if (!SysCatalog::instance().checkPrivileges(session.get_currentUser(), privObjects)) {
3361  throw std::runtime_error("Current user does not have the privilege to alter table: " +
3362  td->tableName);
3363  }
3364 }
std::string tableName
static const AccessPrivileges ALTER_TABLE
Definition: DBObject.h:166
Catalog & getCatalog() const
Definition: SessionInfo.h:65
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:68
std::atomic< bool > isSuper
Definition: SysCatalog.h:94

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void Parser::checkStringLiteral ( const std::string &  option_name,
const std::unique_ptr< NameValueAssign > &  p 
)
static

Definition at line 4856 of file ParserNode.cpp.

References CHECK.

Referenced by Parser::CreateDBStmt::execute(), Parser::CreateUserStmt::execute(), and Parser::AlterUserStmt::execute().

4857  {
4858  CHECK(p);
4859  if (!dynamic_cast<const StringLiteral*>(p->get_value())) {
4860  throw std::runtime_error(option_name + " option must be a string literal.");
4861  }
4862 }
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the caller graph for this function:

static DBObject Parser::createObject ( const std::string &  objectName,
DBObjectType  objectType 
)
static

Definition at line 4268 of file ParserNode.cpp.

References DashboardDBObjectType.

Referenced by Parser::GrantPrivilegesStmt::execute(), Parser::RevokePrivilegesStmt::execute(), and Parser::ShowPrivilegesStmt::execute().

4268  {
4269  if (objectType == DashboardDBObjectType) {
4270  int32_t dashboard_id = -1;
4271  if (!objectName.empty()) {
4272  try {
4273  dashboard_id = stoi(objectName);
4274  } catch (const std::exception&) {
4275  throw std::runtime_error(
4276  "Privileges on dashboards should be changed via integer dashboard ID");
4277  }
4278  }
4279  return DBObject(dashboard_id, objectType);
4280  } else {
4281  return DBObject(objectName, objectType);
4282  }
4283 }

+ Here is the caller graph for this function:

void Parser::execute_calcite_ddl ( const std::string &  plan_result,
std::shared_ptr< Catalog_Namespace::SessionInfo const >  session_ptr 
)

A helper function for parsing the DDL returned from calcite as part of the plan result to a parser node in this class. Currently only used in QueryRunner/DistributedQueryRunner, where we do not want to link in the thrift dependencies wich DdlCommandExecutor currently brings along.

Definition at line 5070 of file ParserNode.cpp.

References CHECK, and VLOG.

5072  {
5073  CHECK(!ddl_statement.empty());
5074  VLOG(2) << "Parsing JSON DDL from Calcite: " << ddl_statement;
5075  rapidjson::Document ddl_query;
5076  ddl_query.Parse(ddl_statement);
5077  CHECK(ddl_query.IsObject());
5078  CHECK(ddl_query.HasMember("payload"));
5079  CHECK(ddl_query["payload"].IsObject());
5080  const auto& payload = ddl_query["payload"].GetObject();
5081  CHECK(payload.HasMember("command"));
5082  CHECK(payload["command"].IsString());
5083 
5084  const auto& ddl_command = std::string_view(payload["command"].GetString());
5085  if (ddl_command == "CREATE_TABLE") {
5086  auto create_table_stmt = Parser::CreateTableStmt(payload);
5087  create_table_stmt.execute(*session_ptr);
5088  } else if (ddl_command == "CREATE_VIEW") {
5089  auto create_view_stmt = Parser::CreateViewStmt(payload);
5090  create_view_stmt.execute(*session_ptr);
5091  } else {
5092  throw std::runtime_error("Unsupported DDL command");
5093  }
5094 }
#define CHECK(condition)
Definition: Logger.h:197
#define VLOG(n)
Definition: Logger.h:291
std::string Parser::extractObjectNameFromHierName ( const std::string &  objectHierName,
const std::string &  objectType,
const Catalog_Namespace::Catalog cat 
)

Definition at line 4135 of file ParserNode.cpp.

References splitObjectHierName().

Referenced by Parser::GrantPrivilegesStmt::execute(), Parser::RevokePrivilegesStmt::execute(), and Parser::ShowPrivilegesStmt::execute().

4137  {
4138  std::string objectName;
4139  std::vector<std::string> componentNames = splitObjectHierName(objectHierName);
4140  if (objectType.compare("DATABASE") == 0) {
4141  if (componentNames.size() == 1) {
4142  objectName = componentNames[0];
4143  } else {
4144  throw std::runtime_error("DB object name is not correct " + objectHierName);
4145  }
4146  } else {
4147  if (objectType.compare("TABLE") == 0 || objectType.compare("DASHBOARD") == 0 ||
4148  objectType.compare("VIEW") == 0 || objectType.compare("SERVER") == 0) {
4149  switch (componentNames.size()) {
4150  case (1): {
4151  objectName = componentNames[0];
4152  break;
4153  }
4154  case (2): {
4155  objectName = componentNames[1];
4156  break;
4157  }
4158  default: {
4159  throw std::runtime_error("DB object name is not correct " + objectHierName);
4160  }
4161  }
4162  } else {
4163  throw std::runtime_error("DB object type " + objectType + " is not supported.");
4164  }
4165  }
4166  return objectName;
4167 }
std::vector< std::string > splitObjectHierName(const std::string &hierName)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr<ResultSet> Parser::getResultSet ( QueryStateProxy  query_state_proxy,
const std::string  select_stmt,
std::vector< TargetMetaInfo > &  targets,
bool  validate_only = false,
std::vector< size_t >  outer_fragment_indices = {} 
)

Definition at line 2512 of file ParserNode.cpp.

Referenced by Parser::LocalConnector::query().

2516  {}) {
2517  auto const session = query_state_proxy.getQueryState().getConstSessionInfo();
2518  auto& catalog = session->getCatalog();
2519 
2521 #ifdef HAVE_CUDA
2522  const auto device_type = session->get_executor_device_type();
2523 #else
2524  const auto device_type = ExecutorDeviceType::CPU;
2525 #endif // HAVE_CUDA
2526  auto calcite_mgr = catalog.getCalciteMgr();
2527 
2528  // TODO MAT this should actually get the global or the session parameter for
2529  // view optimization
2530  const auto query_ra =
2531  calcite_mgr
2532  ->process(query_state_proxy, pg_shim(select_stmt), {}, true, false, false, true)
2533  .plan_result;
2534  RelAlgExecutor ra_executor(executor.get(), catalog, query_ra);
2536  const auto& query_hints = ra_executor.getParsedQueryHints();
2537  if (query_hints.cpu_mode) {
2538  co.device_type = ExecutorDeviceType::CPU;
2539  }
2541  // TODO(adb): Need a better method of dropping constants into this ExecutionOptions
2542  // struct
2543  ExecutionOptions eo = {false,
2544  true,
2545  false,
2546  true,
2547  false,
2548  false,
2549  validate_only,
2550  false,
2551  10000,
2552  false,
2553  false,
2554  0.9,
2555  false,
2556  1000,
2558  outer_fragment_indices};
2559  ExecutionResult result{std::make_shared<ResultSet>(std::vector<TargetInfo>{},
2562  nullptr,
2563  nullptr),
2564  {}};
2565  result = ra_executor.executeRelAlgQuery(co, eo, false, nullptr);
2566  targets = result.getTargetsMeta();
2567 
2568  return result.getRows();
2569 }
static std::shared_ptr< Executor > getExecutor(const ExecutorId id, const std::string &debug_dir="", const std::string &debug_file="", const SystemParameters system_parameters=SystemParameters())
Definition: Execute.cpp:150
QueryState & getQueryState()
Definition: QueryState.h:172
static CompilationOptions defaults(const ExecutorDeviceType device_type=ExecutorDeviceType::GPU)
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:77
std::string pg_shim(const std::string &query)
static const ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:337

+ Here is the caller graph for this function:

template<typename DDLSTMT >
auto Parser::parseDDL ( const std::string &  stmt_type,
const std::string &  stmt_str 
)

Definition at line 29 of file ParseDDL.h.

References run_benchmark_import::parser.

29  {
30  std::list<std::unique_ptr<Parser::Stmt>> parse_trees;
31  std::string last_parsed;
32  SQLParser parser;
33  if (parser.parse(stmt_str, parse_trees, last_parsed) > 0) {
34  throw std::runtime_error("Syntax error in " + stmt_type + " \"" + stmt_str +
35  "\" at " + last_parsed);
36  }
37  if (auto ddl_stmt = dynamic_cast<DDLSTMT*>(parse_trees.front().get())) {
38  parse_trees.front().release();
39  return std::unique_ptr<DDLSTMT>(ddl_stmt);
40  }
41  throw std::runtime_error("Expected " + stmt_type + " is not found in \"" + stmt_str +
42  "\"");
43 }
void Parser::parser_slistval_to_vector ( std::list< std::string * > *  l,
std::vector< std::string > &  v 
)
inline

Definition at line 1515 of file ParserNode.h.

References CHECK.

Referenced by Parser::GrantPrivilegesStmt::GrantPrivilegesStmt(), Parser::GrantRoleStmt::GrantRoleStmt(), Parser::RevokePrivilegesStmt::RevokePrivilegesStmt(), and Parser::RevokeRoleStmt::RevokeRoleStmt().

1516  {
1517  CHECK(l);
1518  for (auto str : *l) {
1519  v.push_back(*str);
1520  delete str;
1521  }
1522  delete l;
1523 }
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the caller graph for this function:

static std::pair<AccessPrivileges, DBObjectType> Parser::parseStringPrivs ( const std::string &  privs,
const DBObjectType objectType,
const std::string &  object_name 
)
static

Definition at line 4169 of file ParserNode.cpp.

References AccessPrivileges::ACCESS, AccessPrivileges::ALL_DASHBOARD, AccessPrivileges::ALL_DATABASE, AccessPrivileges::ALL_SERVER, AccessPrivileges::ALL_TABLE, AccessPrivileges::ALL_VIEW, AccessPrivileges::ALTER_SERVER, AccessPrivileges::ALTER_TABLE, AccessPrivileges::CREATE_DASHBOARD, AccessPrivileges::CREATE_SERVER, AccessPrivileges::CREATE_TABLE, AccessPrivileges::CREATE_VIEW, DashboardDBObjectType, DatabaseDBObjectType, AccessPrivileges::DELETE_DASHBOARD, AccessPrivileges::DELETE_FROM_TABLE, AccessPrivileges::DROP_SERVER, AccessPrivileges::DROP_TABLE, AccessPrivileges::DROP_VIEW, AccessPrivileges::EDIT_DASHBOARD, AccessPrivileges::INSERT_INTO_TABLE, run_benchmark_import::result, AccessPrivileges::SELECT_FROM_TABLE, AccessPrivileges::SELECT_FROM_VIEW, ServerDBObjectType, TableDBObjectType, AccessPrivileges::TRUNCATE_TABLE, AccessPrivileges::UPDATE_IN_TABLE, AccessPrivileges::VIEW_DASHBOARD, AccessPrivileges::VIEW_SQL_EDITOR, and ViewDBObjectType.

Referenced by Parser::GrantPrivilegesStmt::execute(), and Parser::RevokePrivilegesStmt::execute().

4172  {
4173  static const std::map<std::pair<const std::string, const DBObjectType>,
4174  std::pair<const AccessPrivileges, const DBObjectType>>
4175  privileges_lookup{
4176  {{"ALL"s, DatabaseDBObjectType},
4179  {{"ALL"s, DashboardDBObjectType},
4182  {{"ALL"s, ServerDBObjectType},
4184 
4185  {{"CREATE TABLE"s, DatabaseDBObjectType},
4187  {{"CREATE"s, DatabaseDBObjectType},
4189  {{"SELECT"s, DatabaseDBObjectType},
4191  {{"INSERT"s, DatabaseDBObjectType},
4193  {{"TRUNCATE"s, DatabaseDBObjectType},
4195  {{"UPDATE"s, DatabaseDBObjectType},
4197  {{"DELETE"s, DatabaseDBObjectType},
4199  {{"DROP"s, DatabaseDBObjectType},
4201  {{"ALTER"s, DatabaseDBObjectType},
4203 
4204  {{"SELECT"s, TableDBObjectType},
4206  {{"INSERT"s, TableDBObjectType},
4208  {{"TRUNCATE"s, TableDBObjectType},
4210  {{"UPDATE"s, TableDBObjectType},
4212  {{"DELETE"s, TableDBObjectType},
4214  {{"DROP"s, TableDBObjectType},
4216  {{"ALTER"s, TableDBObjectType},
4218 
4219  {{"CREATE VIEW"s, DatabaseDBObjectType},
4221  {{"SELECT VIEW"s, DatabaseDBObjectType},
4223  {{"DROP VIEW"s, DatabaseDBObjectType},
4225  {{"SELECT"s, ViewDBObjectType},
4228 
4229  {{"CREATE DASHBOARD"s, DatabaseDBObjectType},
4231  {{"EDIT DASHBOARD"s, DatabaseDBObjectType},
4233  {{"VIEW DASHBOARD"s, DatabaseDBObjectType},
4235  {{"DELETE DASHBOARD"s, DatabaseDBObjectType},
4237  {{"VIEW"s, DashboardDBObjectType},
4239  {{"EDIT"s, DashboardDBObjectType},
4241  {{"DELETE"s, DashboardDBObjectType},
4243 
4244  {{"CREATE SERVER"s, DatabaseDBObjectType},
4246  {{"DROP SERVER"s, DatabaseDBObjectType},
4248  {{"DROP"s, ServerDBObjectType},
4250  {{"ALTER SERVER"s, DatabaseDBObjectType},
4252  {{"ALTER"s, ServerDBObjectType},
4254 
4255  {{"VIEW SQL EDITOR"s, DatabaseDBObjectType},
4257  {{"ACCESS"s, DatabaseDBObjectType},
4259 
4260  auto result = privileges_lookup.find(std::make_pair(privs, objectType));
4261  if (result == privileges_lookup.end()) {
4262  throw std::runtime_error("Privileges " + privs + " on DB object " + object_name +
4263  " are not correct.");
4264  }
4265  return result->second;
4266 }
static const AccessPrivileges VIEW_SQL_EDITOR
Definition: DBObject.h:153
static const AccessPrivileges VIEW_DASHBOARD
Definition: DBObject.h:172
static const AccessPrivileges DROP_SERVER
Definition: DBObject.h:190
static const AccessPrivileges ALL_DATABASE
Definition: DBObject.h:152
static const AccessPrivileges ALTER_TABLE
Definition: DBObject.h:166
static const AccessPrivileges TRUNCATE_TABLE
Definition: DBObject.h:165
static const AccessPrivileges INSERT_INTO_TABLE
Definition: DBObject.h:162
static const AccessPrivileges CREATE_DASHBOARD
Definition: DBObject.h:171
static const AccessPrivileges SELECT_FROM_TABLE
Definition: DBObject.h:161
static const AccessPrivileges ALL_VIEW
Definition: DBObject.h:178
static const AccessPrivileges ALTER_SERVER
Definition: DBObject.h:191
static const AccessPrivileges DROP_TABLE
Definition: DBObject.h:160
static const AccessPrivileges ALL_SERVER
Definition: DBObject.h:188
static const AccessPrivileges CREATE_SERVER
Definition: DBObject.h:189
static const AccessPrivileges DELETE_FROM_TABLE
Definition: DBObject.h:164
static const AccessPrivileges CREATE_TABLE
Definition: DBObject.h:159
static const AccessPrivileges SELECT_FROM_VIEW
Definition: DBObject.h:181
static const AccessPrivileges ALL_DASHBOARD
Definition: DBObject.h:170
static const AccessPrivileges ACCESS
Definition: DBObject.h:154
static const AccessPrivileges ALL_TABLE
Definition: DBObject.h:158
static const AccessPrivileges DROP_VIEW
Definition: DBObject.h:180
static const AccessPrivileges CREATE_VIEW
Definition: DBObject.h:179
static const AccessPrivileges DELETE_DASHBOARD
Definition: DBObject.h:174
static const AccessPrivileges EDIT_DASHBOARD
Definition: DBObject.h:173
static const AccessPrivileges UPDATE_IN_TABLE
Definition: DBObject.h:163

+ Here is the caller graph for this function:

static bool Parser::readBooleanLiteral ( const std::string &  option_name,
const std::unique_ptr< NameValueAssign > &  p 
)
static

Definition at line 4924 of file ParserNode.cpp.

References CHECK.

Referenced by Parser::CreateUserStmt::execute(), and Parser::AlterUserStmt::execute().

4925  {
4926  CHECK(p);
4927  const std::string* str =
4928  static_cast<const StringLiteral*>(p->get_value())->get_stringval();
4929  if (boost::iequals(*str, "true")) {
4930  return true;
4931  } else if (boost::iequals(*str, "false")) {
4932  return false;
4933  } else {
4934  throw std::runtime_error("Value to " + option_name + " must be TRUE or FALSE.");
4935  }
4936 }
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the caller graph for this function:

std::vector<std::string> Parser::splitObjectHierName ( const std::string &  hierName)

Definition at line 4129 of file ParserNode.cpp.

References split().

Referenced by extractObjectNameFromHierName().

4129  {
4130  std::vector<std::string> componentNames;
4131  boost::split(componentNames, hierName, boost::is_any_of("."));
4132  return componentNames;
4133 }
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

+ Here is the call graph for this function:

+ Here is the caller graph for this function: