OmniSciDB  b24e664e58
 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  CreateTableStmt
 
class  InsertIntoTableAsSelectStmt
 
class  CreateTableAsSelectStmt
 
class  DropTableStmt
 
class  TruncateTableStmt
 
class  OptimizeTableStmt
 
class  ValidateStmt
 
class  RenameDatabaseStmt
 
class  RenameUserStmt
 
class  RenameTableStmt
 
class  RenameColumnStmt
 
class  AddColumnStmt
 
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  InsertQueryStmt
 
class  Assignment
 
class  UpdateStmt
 
class  DeleteStmt
 
struct  DefaultValidate
 
struct  DefaultValidate< IntLiteral >
 
struct  DefaultValidate< StringLiteral >
 
struct  ShouldInvalidateSessionsByDB
 
struct  ShouldInvalidateSessionsByUser
 
struct  ShouldInvalidateSessionsByDB< DropDBStmt >
 
struct  ShouldInvalidateSessionsByUser< DropUserStmt >
 
struct  ShouldInvalidateSessionsByDB< RenameDatabaseStmt >
 
struct  ShouldInvalidateSessionsByUser< RenameUserStmt >
 

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

Typedef Documentation

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

Definition at line 4138 of file ParserNode.cpp.

Function Documentation

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

Definition at line 2915 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().

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

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

References CHECK().

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

4454  {
4455  CHECK(p);
4456  if (!dynamic_cast<const StringLiteral*>(p->get_value())) {
4457  throw std::runtime_error(option_name + " option must be a string literal.");
4458  }
4459 }
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 3942 of file ParserNode.cpp.

References DashboardDBObjectType.

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

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

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

References splitObjectHierName().

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

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

Definition at line 2249 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().

2252  {
2253  auto const session = query_state_proxy.getQueryState().getConstSessionInfo();
2254  auto& catalog = session->getCatalog();
2255 
2256  auto executor = Executor::getExecutor(catalog.getCurrentDB().dbId);
2257 
2258 #ifdef HAVE_CUDA
2259  const auto device_type = session->get_executor_device_type();
2260 #else
2261  const auto device_type = ExecutorDeviceType::CPU;
2262 #endif // HAVE_CUDA
2263  auto calcite_mgr = catalog.getCalciteMgr();
2264 
2265  // TODO MAT this should actually get the global or the session parameter for
2266  // view optimization
2267  const auto query_ra =
2268  calcite_mgr
2269  ->process(query_state_proxy, pg_shim(select_stmt), {}, true, false, false)
2270  .plan_result;
2271  CompilationOptions co = {
2272  device_type, true, ExecutorOptLevel::LoopStrengthReduction, false};
2273  // TODO(adb): Need a better method of dropping constants into this ExecutionOptions
2274  // struct
2275  ExecutionOptions eo = {false,
2276  true,
2277  false,
2278  true,
2279  false,
2280  false,
2281  validate_only,
2282  false,
2283  10000,
2284  false,
2285  false,
2286  0.9};
2287  RelAlgExecutor ra_executor(executor.get(), catalog);
2288  ExecutionResult result{std::make_shared<ResultSet>(std::vector<TargetInfo>{},
2291  nullptr,
2292  nullptr),
2293  {}};
2294  result = ra_executor.executeRelAlgQuery(query_ra, co, eo, nullptr);
2295  targets = result.getTargetsMeta();
2296 
2297  return result.getRows();
2298 }
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(),::QueryRenderer::QueryRenderManager *render_manager=nullptr)
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:

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 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 }
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 3856 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().

3859  {
3860  static const std::map<std::pair<const std::string, const DBObjectType>,
3861  std::pair<const AccessPrivileges, const DBObjectType>>
3862  privileges_lookup{
3863  {{"ALL"s, DatabaseDBObjectType},
3866  {{"ALL"s, DashboardDBObjectType},
3869 
3870  {{"CREATE TABLE"s, DatabaseDBObjectType},
3872  {{"CREATE"s, DatabaseDBObjectType},
3874  {{"SELECT"s, DatabaseDBObjectType},
3876  {{"INSERT"s, DatabaseDBObjectType},
3878  {{"TRUNCATE"s, DatabaseDBObjectType},
3880  {{"UPDATE"s, DatabaseDBObjectType},
3882  {{"DELETE"s, DatabaseDBObjectType},
3884  {{"DROP"s, DatabaseDBObjectType},
3886  {{"ALTER"s, DatabaseDBObjectType},
3888 
3889  {{"SELECT"s, TableDBObjectType},
3891  {{"INSERT"s, TableDBObjectType},
3893  {{"TRUNCATE"s, TableDBObjectType},
3895  {{"UPDATE"s, TableDBObjectType},
3897  {{"DELETE"s, TableDBObjectType},
3899  {{"DROP"s, TableDBObjectType},
3901  {{"ALTER"s, TableDBObjectType},
3903 
3904  {{"CREATE VIEW"s, DatabaseDBObjectType},
3906  {{"SELECT VIEW"s, DatabaseDBObjectType},
3908  {{"DROP VIEW"s, DatabaseDBObjectType},
3910  {{"SELECT"s, ViewDBObjectType},
3913 
3914  {{"CREATE DASHBOARD"s, DatabaseDBObjectType},
3916  {{"EDIT DASHBOARD"s, DatabaseDBObjectType},
3918  {{"VIEW DASHBOARD"s, DatabaseDBObjectType},
3920  {{"DELETE DASHBOARD"s, DatabaseDBObjectType},
3922  {{"VIEW"s, DashboardDBObjectType},
3924  {{"EDIT"s, DashboardDBObjectType},
3926  {{"DELETE"s, DashboardDBObjectType},
3928 
3929  {{"VIEW SQL EDITOR"s, DatabaseDBObjectType},
3931  {{"ACCESS"s, DatabaseDBObjectType},
3933 
3934  auto result = privileges_lookup.find(std::make_pair(privs, objectType));
3935  if (result == privileges_lookup.end()) {
3936  throw std::runtime_error("Privileges " + privs + " on DB object " + object_name +
3937  " are not correct.");
3938  }
3939  return result->second;
3940 }
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:

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

Definition at line 4511 of file ParserNode.cpp.

References CHECK().

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

4512  {
4513  CHECK(p);
4514  const std::string* str =
4515  static_cast<const StringLiteral*>(p->get_value())->get_stringval();
4516  if (boost::iequals(*str, "true")) {
4517  return true;
4518  } else if (boost::iequals(*str, "false")) {
4519  return false;
4520  } else {
4521  throw std::runtime_error("Value to " + option_name + " must be TRUE or FALSE.");
4522  }
4523 }
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 3816 of file ParserNode.cpp.

References split().

Referenced by extractObjectNameFromHierName().

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