OmniSciDB  29e35f4d58
Parser Namespace Reference

Namespaces

 anonymous_namespace{ParserNode.cpp}
 

Classes

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

Typedefs

using dbl = std::numeric_limits< double >
 

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)
 
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, DBObjectTypeparseStringPrivs (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)
 

Typedef Documentation

◆ dbl

using Parser::dbl = typedef std::numeric_limits<double>

Definition at line 4137 of file ParserNode.cpp.

Function Documentation

◆ check_alter_table_privilege()

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

Definition at line 2914 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(), and Parser::RenameColumnStmt::execute().

2915  {
2916  if (session.get_currentUser().isSuper ||
2917  session.get_currentUser().userId == td->userId) {
2918  return;
2919  }
2920  std::vector<DBObject> privObjects;
2921  DBObject dbObject(td->tableName, TableDBObjectType);
2922  dbObject.loadKey(session.getCatalog());
2923  dbObject.setPrivileges(AccessPrivileges::ALTER_TABLE);
2924  privObjects.push_back(dbObject);
2925  if (!SysCatalog::instance().checkPrivileges(session.get_currentUser(), privObjects)) {
2926  throw std::runtime_error("Current user does not have the privilege to alter table: " +
2927  td->tableName);
2928  }
2929 }
std::string tableName
static const AccessPrivileges ALTER_TABLE
Definition: DBObject.h:158
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93
Catalog & getCatalog() const
Definition: SessionInfo.h:90
std::atomic< bool > isSuper
Definition: SysCatalog.h:97
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkStringLiteral()

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

Definition at line 4452 of file ParserNode.cpp.

References CHECK.

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

4453  {
4454  CHECK(p);
4455  if (!dynamic_cast<const StringLiteral*>(p->get_value())) {
4456  throw std::runtime_error(option_name + " option must be a string literal.");
4457  }
4458 }
#define CHECK(condition)
Definition: Logger.h:193
+ Here is the caller graph for this function:

◆ createObject()

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

Definition at line 3941 of file ParserNode.cpp.

References DashboardDBObjectType.

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

3941  {
3942  if (objectType == DashboardDBObjectType) {
3943  int32_t dashboard_id = -1;
3944  if (!objectName.empty()) {
3945  try {
3946  dashboard_id = stoi(objectName);
3947  } catch (const std::exception&) {
3948  throw std::runtime_error(
3949  "Privileges on dashboards should be changed via integer dashboard ID");
3950  }
3951  }
3952  return DBObject(dashboard_id, objectType);
3953  } else {
3954  return DBObject(objectName, objectType);
3955  }
3956 }
+ Here is the caller graph for this function:

◆ extractObjectNameFromHierName()

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

Definition at line 3821 of file ParserNode.cpp.

References splitObjectHierName().

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

3823  {
3824  std::string objectName;
3825  std::vector<std::string> componentNames = splitObjectHierName(objectHierName);
3826  if (objectType.compare("DATABASE") == 0) {
3827  if (componentNames.size() == 1) {
3828  objectName = componentNames[0];
3829  } else {
3830  throw std::runtime_error("DB object name is not correct " + objectHierName);
3831  }
3832  } else {
3833  if (objectType.compare("TABLE") == 0 || objectType.compare("DASHBOARD") == 0 ||
3834  objectType.compare("VIEW") == 0) {
3835  switch (componentNames.size()) {
3836  case (1): {
3837  objectName = componentNames[0];
3838  break;
3839  }
3840  case (2): {
3841  objectName = componentNames[1];
3842  break;
3843  }
3844  default: {
3845  throw std::runtime_error("DB object name is not correct " + objectHierName);
3846  }
3847  }
3848  } else {
3849  throw std::runtime_error("DB object type " + objectType + " is not supported.");
3850  }
3851  }
3852  return objectName;
3853 }
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:

◆ getResultSet()

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

Definition at line 2248 of file ParserNode.cpp.

References CPU, query_state::QueryState::getConstSessionInfo(), Executor::getExecutor(), query_state::QueryStateProxy::getQueryState(), LoopStrengthReduction, pg_shim(), and run_benchmark_import::result.

Referenced by Parser::ExportQueryStmt::execute(), and Parser::InsertIntoTableAsSelectStmt::LocalConnector::query().

2251  {
2252  auto const session = query_state_proxy.getQueryState().getConstSessionInfo();
2253  auto& catalog = session->getCatalog();
2254 
2255  auto executor = Executor::getExecutor(catalog.getCurrentDB().dbId);
2256 
2257 #ifdef HAVE_CUDA
2258  const auto device_type = session->get_executor_device_type();
2259 #else
2260  const auto device_type = ExecutorDeviceType::CPU;
2261 #endif // HAVE_CUDA
2262  auto calcite_mgr = catalog.getCalciteMgr();
2263 
2264  // TODO MAT this should actually get the global or the session parameter for
2265  // view optimization
2266  const auto query_ra =
2267  calcite_mgr
2268  ->process(query_state_proxy, pg_shim(select_stmt), {}, true, false, false)
2269  .plan_result;
2270  CompilationOptions co = {
2271  device_type, true, ExecutorOptLevel::LoopStrengthReduction, false};
2272  // TODO(adb): Need a better method of dropping constants into this ExecutionOptions
2273  // struct
2274  ExecutionOptions eo = {false,
2275  true,
2276  false,
2277  true,
2278  false,
2279  false,
2280  validate_only,
2281  false,
2282  10000,
2283  false,
2284  false,
2285  0.9};
2286  RelAlgExecutor ra_executor(executor.get(), catalog, query_ra);
2287  ExecutionResult result{std::make_shared<ResultSet>(std::vector<TargetInfo>{},
2290  nullptr,
2291  nullptr),
2292  {}};
2293  result = ra_executor.executeRelAlgQuery(co, eo, nullptr);
2294  targets = result.getTargetsMeta();
2295 
2296  return result.getRows();
2297 }
static std::shared_ptr< Executor > getExecutor(const int db_id, const std::string &debug_dir="", const std::string &debug_file="", const MapDParameters mapd_parameters=MapDParameters())
Definition: Execute.cpp:127
QueryState & getQueryState()
Definition: QueryState.h:172
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:75
std::string pg_shim(const std::string &query)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseDDL()

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 }

◆ parser_slistval_to_vector()

void Parser::parser_slistval_to_vector ( std::list< std::string *> *  l,
std::vector< std::string > &  v 
)
inline

Definition at line 1448 of file ParserNode.h.

References CHECK.

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

1449  {
1450  CHECK(l);
1451  for (auto str : *l) {
1452  v.push_back(*str);
1453  delete str;
1454  }
1455  delete l;
1456 }
#define CHECK(condition)
Definition: Logger.h:193
+ Here is the caller graph for this function:

◆ parseStringPrivs()

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

Definition at line 3855 of file ParserNode.cpp.

References AccessPrivileges::ACCESS, AccessPrivileges::ALL_DASHBOARD, AccessPrivileges::ALL_DATABASE, AccessPrivileges::ALL_TABLE, AccessPrivileges::ALL_VIEW, AccessPrivileges::ALTER_TABLE, AccessPrivileges::CREATE_DASHBOARD, AccessPrivileges::CREATE_TABLE, AccessPrivileges::CREATE_VIEW, DashboardDBObjectType, DatabaseDBObjectType, AccessPrivileges::DELETE_DASHBOARD, AccessPrivileges::DELETE_FROM_TABLE, 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, 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().

3858  {
3859  static const std::map<std::pair<const std::string, const DBObjectType>,
3860  std::pair<const AccessPrivileges, const DBObjectType>>
3861  privileges_lookup{
3862  {{"ALL"s, DatabaseDBObjectType},
3863  {AccessPrivileges::ALL_DATABASE, DatabaseDBObjectType}},
3864  {{"ALL"s, TableDBObjectType}, {AccessPrivileges::ALL_TABLE, TableDBObjectType}},
3865  {{"ALL"s, DashboardDBObjectType},
3866  {AccessPrivileges::ALL_DASHBOARD, DashboardDBObjectType}},
3867  {{"ALL"s, ViewDBObjectType}, {AccessPrivileges::ALL_VIEW, ViewDBObjectType}},
3868 
3869  {{"CREATE TABLE"s, DatabaseDBObjectType},
3870  {AccessPrivileges::CREATE_TABLE, TableDBObjectType}},
3871  {{"CREATE"s, DatabaseDBObjectType},
3872  {AccessPrivileges::CREATE_TABLE, TableDBObjectType}},
3873  {{"SELECT"s, DatabaseDBObjectType},
3874  {AccessPrivileges::SELECT_FROM_TABLE, TableDBObjectType}},
3875  {{"INSERT"s, DatabaseDBObjectType},
3876  {AccessPrivileges::INSERT_INTO_TABLE, TableDBObjectType}},
3877  {{"TRUNCATE"s, DatabaseDBObjectType},
3878  {AccessPrivileges::TRUNCATE_TABLE, TableDBObjectType}},
3879  {{"UPDATE"s, DatabaseDBObjectType},
3880  {AccessPrivileges::UPDATE_IN_TABLE, TableDBObjectType}},
3881  {{"DELETE"s, DatabaseDBObjectType},
3882  {AccessPrivileges::DELETE_FROM_TABLE, TableDBObjectType}},
3883  {{"DROP"s, DatabaseDBObjectType},
3884  {AccessPrivileges::DROP_TABLE, TableDBObjectType}},
3885  {{"ALTER"s, DatabaseDBObjectType},
3886  {AccessPrivileges::ALTER_TABLE, TableDBObjectType}},
3887 
3888  {{"SELECT"s, TableDBObjectType},
3889  {AccessPrivileges::SELECT_FROM_TABLE, TableDBObjectType}},
3890  {{"INSERT"s, TableDBObjectType},
3891  {AccessPrivileges::INSERT_INTO_TABLE, TableDBObjectType}},
3892  {{"TRUNCATE"s, TableDBObjectType},
3893  {AccessPrivileges::TRUNCATE_TABLE, TableDBObjectType}},
3894  {{"UPDATE"s, TableDBObjectType},
3895  {AccessPrivileges::UPDATE_IN_TABLE, TableDBObjectType}},
3896  {{"DELETE"s, TableDBObjectType},
3897  {AccessPrivileges::DELETE_FROM_TABLE, TableDBObjectType}},
3898  {{"DROP"s, TableDBObjectType},
3899  {AccessPrivileges::DROP_TABLE, TableDBObjectType}},
3900  {{"ALTER"s, TableDBObjectType},
3901  {AccessPrivileges::ALTER_TABLE, TableDBObjectType}},
3902 
3903  {{"CREATE VIEW"s, DatabaseDBObjectType},
3904  {AccessPrivileges::CREATE_VIEW, ViewDBObjectType}},
3905  {{"SELECT VIEW"s, DatabaseDBObjectType},
3906  {AccessPrivileges::SELECT_FROM_VIEW, ViewDBObjectType}},
3907  {{"DROP VIEW"s, DatabaseDBObjectType},
3908  {AccessPrivileges::DROP_VIEW, ViewDBObjectType}},
3909  {{"SELECT"s, ViewDBObjectType},
3910  {AccessPrivileges::SELECT_FROM_VIEW, ViewDBObjectType}},
3911  {{"DROP"s, ViewDBObjectType}, {AccessPrivileges::DROP_VIEW, ViewDBObjectType}},
3912 
3913  {{"CREATE DASHBOARD"s, DatabaseDBObjectType},
3914  {AccessPrivileges::CREATE_DASHBOARD, DashboardDBObjectType}},
3915  {{"EDIT DASHBOARD"s, DatabaseDBObjectType},
3916  {AccessPrivileges::EDIT_DASHBOARD, DashboardDBObjectType}},
3917  {{"VIEW DASHBOARD"s, DatabaseDBObjectType},
3918  {AccessPrivileges::VIEW_DASHBOARD, DashboardDBObjectType}},
3919  {{"DELETE DASHBOARD"s, DatabaseDBObjectType},
3920  {AccessPrivileges::DELETE_DASHBOARD, DashboardDBObjectType}},
3921  {{"VIEW"s, DashboardDBObjectType},
3922  {AccessPrivileges::VIEW_DASHBOARD, DashboardDBObjectType}},
3923  {{"EDIT"s, DashboardDBObjectType},
3924  {AccessPrivileges::EDIT_DASHBOARD, DashboardDBObjectType}},
3925  {{"DELETE"s, DashboardDBObjectType},
3926  {AccessPrivileges::DELETE_DASHBOARD, DashboardDBObjectType}},
3927 
3928  {{"VIEW SQL EDITOR"s, DatabaseDBObjectType},
3929  {AccessPrivileges::VIEW_SQL_EDITOR, DatabaseDBObjectType}},
3930  {{"ACCESS"s, DatabaseDBObjectType},
3931  {AccessPrivileges::ACCESS, DatabaseDBObjectType}}};
3932 
3933  auto result = privileges_lookup.find(std::make_pair(privs, objectType));
3934  if (result == privileges_lookup.end()) {
3935  throw std::runtime_error("Privileges " + privs + " on DB object " + object_name +
3936  " are not correct.");
3937  }
3938  return result->second;
3939 }
static const AccessPrivileges VIEW_SQL_EDITOR
Definition: DBObject.h:145
static const AccessPrivileges VIEW_DASHBOARD
Definition: DBObject.h:164
static const AccessPrivileges ALL_DATABASE
Definition: DBObject.h:144
static const AccessPrivileges ALTER_TABLE
Definition: DBObject.h:158
static const AccessPrivileges TRUNCATE_TABLE
Definition: DBObject.h:157
static const AccessPrivileges INSERT_INTO_TABLE
Definition: DBObject.h:154
static const AccessPrivileges CREATE_DASHBOARD
Definition: DBObject.h:163
static const AccessPrivileges SELECT_FROM_TABLE
Definition: DBObject.h:153
static const AccessPrivileges ALL_VIEW
Definition: DBObject.h:170
static const AccessPrivileges DROP_TABLE
Definition: DBObject.h:152
static const AccessPrivileges DELETE_FROM_TABLE
Definition: DBObject.h:156
static const AccessPrivileges CREATE_TABLE
Definition: DBObject.h:151
static const AccessPrivileges SELECT_FROM_VIEW
Definition: DBObject.h:173
static const AccessPrivileges ALL_DASHBOARD
Definition: DBObject.h:162
static const AccessPrivileges ACCESS
Definition: DBObject.h:146
static const AccessPrivileges ALL_TABLE
Definition: DBObject.h:150
static const AccessPrivileges DROP_VIEW
Definition: DBObject.h:172
static const AccessPrivileges CREATE_VIEW
Definition: DBObject.h:171
static const AccessPrivileges DELETE_DASHBOARD
Definition: DBObject.h:166
static const AccessPrivileges EDIT_DASHBOARD
Definition: DBObject.h:165
static const AccessPrivileges UPDATE_IN_TABLE
Definition: DBObject.h:155
+ Here is the caller graph for this function:

◆ readBooleanLiteral()

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

Definition at line 4510 of file ParserNode.cpp.

References CHECK.

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

4511  {
4512  CHECK(p);
4513  const std::string* str =
4514  static_cast<const StringLiteral*>(p->get_value())->get_stringval();
4515  if (boost::iequals(*str, "true")) {
4516  return true;
4517  } else if (boost::iequals(*str, "false")) {
4518  return false;
4519  } else {
4520  throw std::runtime_error("Value to " + option_name + " must be TRUE or FALSE.");
4521  }
4522 }
#define CHECK(condition)
Definition: Logger.h:193
+ Here is the caller graph for this function:

◆ splitObjectHierName()

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

Definition at line 3815 of file ParserNode.cpp.

References split().

Referenced by extractObjectNameFromHierName().

3815  {
3816  std::vector<std::string> componentNames;
3817  boost::split(componentNames, hierName, boost::is_any_of("."));
3818  return componentNames;
3819 }
std::vector< std::string > split(const std::string &str, const std::string &delim)
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: