OmniSciDB  72180abbfe
 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 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 3155 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().

3156  {
3157  if (session.get_currentUser().isSuper ||
3158  session.get_currentUser().userId == td->userId) {
3159  return;
3160  }
3161  std::vector<DBObject> privObjects;
3162  DBObject dbObject(td->tableName, TableDBObjectType);
3163  dbObject.loadKey(session.getCatalog());
3164  dbObject.setPrivileges(AccessPrivileges::ALTER_TABLE);
3165  privObjects.push_back(dbObject);
3166  if (!SysCatalog::instance().checkPrivileges(session.get_currentUser(), privObjects)) {
3167  throw std::runtime_error("Current user does not have the privilege to alter table: " +
3168  td->tableName);
3169  }
3170 }
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:96

+ 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 4639 of file ParserNode.cpp.

References CHECK().

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

4640  {
4641  CHECK(p);
4642  if (!dynamic_cast<const StringLiteral*>(p->get_value())) {
4643  throw std::runtime_error(option_name + " option must be a string literal.");
4644  }
4645 }
CHECK(cgen_state)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4070 of file ParserNode.cpp.

References DashboardDBObjectType.

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

4070  {
4071  if (objectType == DashboardDBObjectType) {
4072  int32_t dashboard_id = -1;
4073  if (!objectName.empty()) {
4074  try {
4075  dashboard_id = stoi(objectName);
4076  } catch (const std::exception&) {
4077  throw std::runtime_error(
4078  "Privileges on dashboards should be changed via integer dashboard ID");
4079  }
4080  }
4081  return DBObject(dashboard_id, objectType);
4082  } else {
4083  return DBObject(objectName, objectType);
4084  }
4085 }

+ Here is the caller graph for this function:

std::string Parser::extractObjectNameFromHierName ( const std::string &  objectHierName,
const std::string &  objectType,
const Catalog_Namespace::Catalog cat 
)

Definition at line 3941 of file ParserNode.cpp.

References splitObjectHierName().

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

3943  {
3944  std::string objectName;
3945  std::vector<std::string> componentNames = splitObjectHierName(objectHierName);
3946  if (objectType.compare("DATABASE") == 0) {
3947  if (componentNames.size() == 1) {
3948  objectName = componentNames[0];
3949  } else {
3950  throw std::runtime_error("DB object name is not correct " + objectHierName);
3951  }
3952  } else {
3953  if (objectType.compare("TABLE") == 0 || objectType.compare("DASHBOARD") == 0 ||
3954  objectType.compare("VIEW") == 0 || objectType.compare("SERVER") == 0) {
3955  switch (componentNames.size()) {
3956  case (1): {
3957  objectName = componentNames[0];
3958  break;
3959  }
3960  case (2): {
3961  objectName = componentNames[1];
3962  break;
3963  }
3964  default: {
3965  throw std::runtime_error("DB object name is not correct " + objectHierName);
3966  }
3967  }
3968  } else {
3969  throw std::runtime_error("DB object type " + objectType + " is not supported.");
3970  }
3971  }
3972  return objectName;
3973 }
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 2348 of file ParserNode.cpp.

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

2352  {}) {
2353  auto const session = query_state_proxy.getQueryState().getConstSessionInfo();
2354  auto& catalog = session->getCatalog();
2355 
2357 #ifdef HAVE_CUDA
2358  const auto device_type = session->get_executor_device_type();
2359 #else
2360  const auto device_type = ExecutorDeviceType::CPU;
2361 #endif // HAVE_CUDA
2362  auto calcite_mgr = catalog.getCalciteMgr();
2363 
2364  // TODO MAT this should actually get the global or the session parameter for
2365  // view optimization
2366  const auto query_ra =
2367  calcite_mgr
2368  ->process(query_state_proxy, pg_shim(select_stmt), {}, true, false, false, true)
2369  .plan_result;
2370  RelAlgExecutor ra_executor(executor.get(), catalog, query_ra);
2372  const auto& query_hints = ra_executor.getParsedQueryHints();
2373  if (query_hints.cpu_mode) {
2374  co.device_type = ExecutorDeviceType::CPU;
2375  }
2377  // TODO(adb): Need a better method of dropping constants into this ExecutionOptions
2378  // struct
2379  ExecutionOptions eo = {false,
2380  true,
2381  false,
2382  true,
2383  false,
2384  false,
2385  validate_only,
2386  false,
2387  10000,
2388  false,
2389  false,
2390  0.9,
2391  false,
2392  1000,
2394  outer_fragment_indices};
2395  ExecutionResult result{std::make_shared<ResultSet>(std::vector<TargetInfo>{},
2398  nullptr,
2399  nullptr),
2400  {}};
2401  result = ra_executor.executeRelAlgQuery(co, eo, false, nullptr);
2402  targets = result.getTargetsMeta();
2403 
2404  return result.getRows();
2405 }
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:325

+ 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 1508 of file ParserNode.h.

References CHECK().

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

1509  {
1510  CHECK(l);
1511  for (auto str : *l) {
1512  v.push_back(*str);
1513  delete str;
1514  }
1515  delete l;
1516 }
CHECK(cgen_state)

+ Here is the call graph for this function:

+ 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 3975 of file ParserNode.cpp.

References AccessPrivileges::ACCESS, AccessPrivileges::ALL_DASHBOARD, AccessPrivileges::ALL_DATABASE, AccessPrivileges::ALL_SERVER, AccessPrivileges::ALL_TABLE, AccessPrivileges::ALL_VIEW, 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().

3978  {
3979  static const std::map<std::pair<const std::string, const DBObjectType>,
3980  std::pair<const AccessPrivileges, const DBObjectType>>
3981  privileges_lookup{
3982  {{"ALL"s, DatabaseDBObjectType},
3985  {{"ALL"s, DashboardDBObjectType},
3988  {{"ALL"s, ServerDBObjectType},
3990 
3991  {{"CREATE TABLE"s, DatabaseDBObjectType},
3993  {{"CREATE"s, DatabaseDBObjectType},
3995  {{"SELECT"s, DatabaseDBObjectType},
3997  {{"INSERT"s, DatabaseDBObjectType},
3999  {{"TRUNCATE"s, DatabaseDBObjectType},
4001  {{"UPDATE"s, DatabaseDBObjectType},
4003  {{"DELETE"s, DatabaseDBObjectType},
4005  {{"DROP"s, DatabaseDBObjectType},
4007  {{"ALTER"s, DatabaseDBObjectType},
4009 
4010  {{"SELECT"s, TableDBObjectType},
4012  {{"INSERT"s, TableDBObjectType},
4014  {{"TRUNCATE"s, TableDBObjectType},
4016  {{"UPDATE"s, TableDBObjectType},
4018  {{"DELETE"s, TableDBObjectType},
4020  {{"DROP"s, TableDBObjectType},
4022  {{"ALTER"s, TableDBObjectType},
4024 
4025  {{"CREATE VIEW"s, DatabaseDBObjectType},
4027  {{"SELECT VIEW"s, DatabaseDBObjectType},
4029  {{"DROP VIEW"s, DatabaseDBObjectType},
4031  {{"SELECT"s, ViewDBObjectType},
4034 
4035  {{"CREATE DASHBOARD"s, DatabaseDBObjectType},
4037  {{"EDIT DASHBOARD"s, DatabaseDBObjectType},
4039  {{"VIEW DASHBOARD"s, DatabaseDBObjectType},
4041  {{"DELETE DASHBOARD"s, DatabaseDBObjectType},
4043  {{"VIEW"s, DashboardDBObjectType},
4045  {{"EDIT"s, DashboardDBObjectType},
4047  {{"DELETE"s, DashboardDBObjectType},
4049 
4050  {{"CREATE SERVER"s, DatabaseDBObjectType},
4052  {{"DROP SERVER"s, DatabaseDBObjectType},
4054  {{"DROP"s, ServerDBObjectType},
4056 
4057  {{"VIEW SQL EDITOR"s, DatabaseDBObjectType},
4059  {{"ACCESS"s, DatabaseDBObjectType},
4061 
4062  auto result = privileges_lookup.find(std::make_pair(privs, objectType));
4063  if (result == privileges_lookup.end()) {
4064  throw std::runtime_error("Privileges " + privs + " on DB object " + object_name +
4065  " are not correct.");
4066  }
4067  return result->second;
4068 }
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 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 4707 of file ParserNode.cpp.

References CHECK().

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

4708  {
4709  CHECK(p);
4710  const std::string* str =
4711  static_cast<const StringLiteral*>(p->get_value())->get_stringval();
4712  if (boost::iequals(*str, "true")) {
4713  return true;
4714  } else if (boost::iequals(*str, "false")) {
4715  return false;
4716  } else {
4717  throw std::runtime_error("Value to " + option_name + " must be TRUE or FALSE.");
4718  }
4719 }
CHECK(cgen_state)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 3935 of file ParserNode.cpp.

References split().

Referenced by extractObjectNameFromHierName().

3935  {
3936  std::vector<std::string> componentNames;
3937  boost::split(componentNames, hierName, boost::is_any_of("."));
3938  return componentNames;
3939 }
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: