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

Namespaces

 anonymous_namespace{ParserNode.cpp}
 
 Compress
 

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  WidthBucketExpr
 
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
 
class  QueryConnector
 
class  LocalQueryConnector
 
class  CreateDataframeStmt
 
class  InsertIntoTableAsSelectStmt
 
class  CreateTableAsSelectStmt
 
class  AlterTableStmt
 
class  DropTableStmt
 
class  TruncateTableStmt
 
class  OptimizeTableStmt
 
class  ValidateStmt
 
class  RenameDBStmt
 
class  RenameUserStmt
 
class  RenameTableStmt
 
class  RenameColumnStmt
 
class  AddColumnStmt
 
class  DropColumnStmt
 
class  AlterTableParamStmt
 
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  ExportQueryStmt
 
class  CreateViewStmt
 
class  DropViewStmt
 
class  CreateDBStmt
 
class  DropDBStmt
 
class  CreateUserStmt
 
class  AlterUserStmt
 
class  DropUserStmt
 
class  InsertStmt
 
class  ValuesList
 
class  InsertValuesStmt
 
class  Assignment
 
class  UpdateStmt
 
class  DeleteStmt
 
struct  DefaultValidate
 
struct  DefaultValidate< IntLiteral >
 
struct  PositiveOrZeroValidate
 
struct  DefaultValidate< StringLiteral >
 
struct  CaseSensitiveValidate
 

Typedefs

using SubstituteMap = std::map< std::string, std::string >
 

Functions

bool check_session_interrupted (const QuerySessionId &query_session, Executor *executor)
 
std::vector< int > getTableChunkKey (const TableDescriptor *td, Catalog_Namespace::Catalog &catalog)
 
bool exprs_share_one_and_same_rte_idx (const std::shared_ptr< Analyzer::Expr > &lhs_expr, const std::shared_ptr< Analyzer::Expr > &rhs_expr)
 
SQLTypeInfo const & get_str_dict_cast_type (const SQLTypeInfo &lhs_type_info, const SQLTypeInfo &rhs_type_info, const Executor *executor)
 
SQLTypeInfo common_string_type (const SQLTypeInfo &lhs_type_info, const SQLTypeInfo &rhs_type_info, const Executor *executor)
 
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={}, bool allow_interrupt=false)
 
bool repair_type (std::list< std::unique_ptr< NameValueAssign >> &options)
 
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 verifyObject (Catalog_Namespace::Catalog &sessionCatalog, const std::string &objectName, DBObjectType objectType, const std::string &command)
 
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)
 
std::unique_ptr< Parser::Stmtcreate_stmt_for_query (const std::string &queryStr, const Catalog_Namespace::SessionInfo &session_info)
 
std::unique_ptr< Parser::Stmtcreate_stmt_for_json (const std::string &query_json)
 
void execute_stmt_for_json (const std::string &query_json, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr, bool read_only_mode)
 
void parser_slistval_to_vector (std::list< std::string * > *l, std::vector< std::string > &v)
 

Typedef Documentation

using Parser::SubstituteMap = typedef std::map<std::string, std::string>

Definition at line 4824 of file ParserNode.cpp.

Function Documentation

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

Definition at line 4727 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(), Parser::DropColumnStmt::execute(), and Parser::AlterTableParamStmt::execute().

4728  {
4729  if (session.get_currentUser().isSuper ||
4730  session.get_currentUser().userId == td->userId) {
4731  return;
4732  }
4733  std::vector<DBObject> privObjects;
4734  DBObject dbObject(td->tableName, TableDBObjectType);
4735  dbObject.loadKey(session.getCatalog());
4736  dbObject.setPrivileges(AccessPrivileges::ALTER_TABLE);
4737  privObjects.push_back(dbObject);
4738  if (!SysCatalog::instance().checkPrivileges(session.get_currentUser(), privObjects)) {
4739  throw std::runtime_error("Current user does not have the privilege to alter table: " +
4740  td->tableName);
4741  }
4742 }
std::string tableName
static const AccessPrivileges ALTER_TABLE
Definition: DBObject.h:165
Catalog & getCatalog() const
Definition: SessionInfo.h:75
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:88
std::atomic< bool > isSuper
Definition: SysCatalog.h:107

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Parser::check_session_interrupted ( const QuerySessionId query_session,
Executor executor 
)

Definition at line 102 of file ParserNode.cpp.

References g_enable_non_kernel_time_query_interrupt.

Referenced by Parser::InsertIntoTableAsSelectStmt::populateData().

102  {
103  // we call this function with unitary executor but is okay since
104  // we know the exact session info from a global session map object
105  // in the executor
108  executor->getSessionLock());
109  return executor->checkIsQuerySessionInterrupted(query_session, session_read_lock);
110  }
111  return false;
112 }
bool g_enable_non_kernel_time_query_interrupt
Definition: Execute.cpp:126
std::shared_lock< T > shared_lock

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

References CHECK.

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

6511  {
6512  CHECK(p);
6513  if (!dynamic_cast<const StringLiteral*>(p->get_value())) {
6514  throw std::runtime_error(option_name + " option must be a string literal.");
6515  }
6516 }
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the caller graph for this function:

SQLTypeInfo Parser::common_string_type ( const SQLTypeInfo lhs_type_info,
const SQLTypeInfo rhs_type_info,
const Executor executor 
)

Definition at line 346 of file ParserNode.cpp.

References CHECK, SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_dimension(), get_str_dict_cast_type(), SQLTypeInfo::is_dict_encoded_string(), SQLTypeInfo::is_none_encoded_string(), SQLTypeInfo::is_string(), SQLTypeInfo::set_dimension(), and TRANSIENT_DICT.

Referenced by Parser::CaseExpr::normalize().

348  {
349  CHECK(lhs_type_info.is_string());
350  CHECK(rhs_type_info.is_string());
351  const auto lhs_comp_param = lhs_type_info.get_comp_param();
352  const auto rhs_comp_param = rhs_type_info.get_comp_param();
353  if (lhs_type_info.is_dict_encoded_string() && rhs_type_info.is_dict_encoded_string()) {
354  if (lhs_comp_param == rhs_comp_param ||
355  lhs_comp_param == TRANSIENT_DICT(rhs_comp_param)) {
356  return lhs_comp_param <= rhs_comp_param ? lhs_type_info : rhs_type_info;
357  }
358  return get_str_dict_cast_type(lhs_type_info, rhs_type_info, executor);
359  }
360  CHECK(lhs_type_info.is_none_encoded_string() || rhs_type_info.is_none_encoded_string());
361  SQLTypeInfo ret_ti =
362  rhs_type_info.is_none_encoded_string() ? lhs_type_info : rhs_type_info;
363  if (ret_ti.is_none_encoded_string()) {
364  ret_ti.set_dimension(
365  std::max(lhs_type_info.get_dimension(), rhs_type_info.get_dimension()));
366  }
367  return ret_ti;
368 }
void set_dimension(int d)
Definition: sqltypes.h:491
bool is_none_encoded_string() const
Definition: sqltypes.h:631
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:381
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:388
#define CHECK(condition)
Definition: Logger.h:222
bool is_dict_encoded_string() const
Definition: sqltypes.h:627
bool is_string() const
Definition: sqltypes.h:575
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:310
SQLTypeInfo const & get_str_dict_cast_type(const SQLTypeInfo &lhs_type_info, const SQLTypeInfo &rhs_type_info, const Executor *executor)
Definition: ParserNode.cpp:323

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::unique_ptr< Parser::Stmt > Parser::create_stmt_for_json ( const std::string &  query_json)

Definition at line 6931 of file ParserNode.cpp.

References CHECK, Parser::AlterTableStmt::delegate(), UNREACHABLE, and VLOG.

Referenced by create_stmt_for_query(), QueryRunner::QueryRunner::createStatement(), and execute_stmt_for_json().

6931  {
6932  CHECK(!query_json.empty());
6933  VLOG(2) << "Parsing JSON DDL from Calcite: " << query_json;
6934  rapidjson::Document ddl_query;
6935  ddl_query.Parse(query_json);
6936  CHECK(ddl_query.IsObject());
6937  CHECK(ddl_query.HasMember("payload"));
6938  CHECK(ddl_query["payload"].IsObject());
6939  const auto& payload = ddl_query["payload"].GetObject();
6940  CHECK(payload.HasMember("command"));
6941  CHECK(payload["command"].IsString());
6942 
6943  const auto& ddl_command = std::string_view(payload["command"].GetString());
6944 
6945  Parser::Stmt* stmt = nullptr;
6946  if (ddl_command == "CREATE_TABLE") {
6947  stmt = new Parser::CreateTableStmt(payload);
6948  } else if (ddl_command == "DROP_TABLE") {
6949  stmt = new Parser::DropTableStmt(payload);
6950  } else if (ddl_command == "RENAME_TABLE") {
6951  stmt = new Parser::RenameTableStmt(payload);
6952  } else if (ddl_command == "ALTER_TABLE") {
6953  std::unique_ptr<Parser::DDLStmt> ddlStmt;
6954  ddlStmt = Parser::AlterTableStmt::delegate(payload);
6955  if (ddlStmt != nullptr) {
6956  stmt = ddlStmt.get();
6957  ddlStmt.release();
6958  }
6959  } else if (ddl_command == "TRUNCATE_TABLE") {
6960  stmt = new Parser::TruncateTableStmt(payload);
6961  } else if (ddl_command == "DUMP_TABLE") {
6962  stmt = new Parser::DumpTableStmt(payload);
6963  } else if (ddl_command == "RESTORE_TABLE") {
6964  stmt = new Parser::RestoreTableStmt(payload);
6965  } else if (ddl_command == "OPTIMIZE_TABLE") {
6966  stmt = new Parser::OptimizeTableStmt(payload);
6967  } else if (ddl_command == "COPY_TABLE") {
6968  stmt = new Parser::CopyTableStmt(payload);
6969  } else if (ddl_command == "EXPORT_QUERY") {
6970  stmt = new Parser::ExportQueryStmt(payload);
6971  } else if (ddl_command == "CREATE_VIEW") {
6972  stmt = new Parser::CreateViewStmt(payload);
6973  } else if (ddl_command == "DROP_VIEW") {
6974  stmt = new Parser::DropViewStmt(payload);
6975  } else if (ddl_command == "CREATE_DB") {
6976  stmt = new Parser::CreateDBStmt(payload);
6977  } else if (ddl_command == "DROP_DB") {
6978  stmt = new Parser::DropDBStmt(payload);
6979  } else if (ddl_command == "RENAME_DB") {
6980  stmt = new Parser::RenameDBStmt(payload);
6981  } else if (ddl_command == "CREATE_USER") {
6982  stmt = new Parser::CreateUserStmt(payload);
6983  } else if (ddl_command == "DROP_USER") {
6984  stmt = new Parser::DropUserStmt(payload);
6985  } else if (ddl_command == "ALTER_USER") {
6986  stmt = new Parser::AlterUserStmt(payload);
6987  } else if (ddl_command == "RENAME_USER") {
6988  stmt = new Parser::RenameUserStmt(payload);
6989  } else if (ddl_command == "CREATE_ROLE") {
6990  stmt = new Parser::CreateRoleStmt(payload);
6991  } else if (ddl_command == "DROP_ROLE") {
6992  stmt = new Parser::DropRoleStmt(payload);
6993  } else if (ddl_command == "GRANT_ROLE") {
6994  stmt = new Parser::GrantRoleStmt(payload);
6995  } else if (ddl_command == "REVOKE_ROLE") {
6996  stmt = new Parser::RevokeRoleStmt(payload);
6997  } else if (ddl_command == "GRANT_PRIVILEGE") {
6998  stmt = new Parser::GrantPrivilegesStmt(payload);
6999  } else if (ddl_command == "REVOKE_PRIVILEGE") {
7000  stmt = new Parser::RevokePrivilegesStmt(payload);
7001  } else if (ddl_command == "CREATE_DATAFRAME") {
7002  stmt = new Parser::CreateDataframeStmt(payload);
7003  } else if (ddl_command == "VALIDATE_SYSTEM") {
7004  // VALIDATE should have been excuted in outer context before it reaches here
7005  UNREACHABLE(); // not-implemented alterType
7006  } else {
7007  throw std::runtime_error("Unsupported DDL command");
7008  }
7009  return std::unique_ptr<Parser::Stmt>(stmt);
7010 }
#define UNREACHABLE()
Definition: Logger.h:266
#define CHECK(condition)
Definition: Logger.h:222
#define VLOG(n)
Definition: Logger.h:316
static std::unique_ptr< Parser::DDLStmt > delegate(const rapidjson::Value &payload)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::unique_ptr< Parser::Stmt > Parser::create_stmt_for_query ( const std::string &  queryStr,
const Catalog_Namespace::SessionInfo session_info 
)

Helper functions 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 6906 of file ParserNode.cpp.

References cat(), query_state::QueryState::create(), create_stmt_for_json(), g_enable_watchdog, Catalog_Namespace::SessionInfo::getCatalog(), Catalog_Namespace::SysCatalog::instance(), Catalog_Namespace::SysCatalog::isAggregator(), and pg_shim().

Referenced by TableArchiver::restoreTable(), and DBHandler::sql_execute_impl().

6908  {
6909  auto session_copy = session_info;
6910  auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
6911  &session_copy, boost::null_deleter());
6912  auto query_state = query_state::QueryState::create(session_ptr, queryStr);
6913  const auto& cat = session_info.getCatalog();
6914  auto calcite_mgr = cat.getCalciteMgr();
6915  const auto calciteQueryParsingOption =
6916  calcite_mgr->getCalciteQueryParsingOption(true, false, true);
6917  const auto calciteOptimizationOption = calcite_mgr->getCalciteOptimizationOption(
6918  false,
6920  {},
6922  const auto query_json = calcite_mgr
6923  ->process(query_state->createQueryStateProxy(),
6924  pg_shim(queryStr),
6925  calciteQueryParsingOption,
6926  calciteOptimizationOption)
6927  .plan_result;
6928  return create_stmt_for_json(query_json);
6929 }
std::string cat(Ts &&...args)
static std::shared_ptr< QueryState > create(ARGS &&...args)
Definition: QueryState.h:145
static SysCatalog & instance()
Definition: SysCatalog.h:341
std::unique_ptr< Parser::Stmt > create_stmt_for_json(const std::string &query_json)
bool g_enable_watchdog
Catalog & getCatalog() const
Definition: SessionInfo.h: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:

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

Definition at line 5763 of file ParserNode.cpp.

References DashboardDBObjectType.

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

5763  {
5764  if (objectType == DashboardDBObjectType) {
5765  int32_t dashboard_id = -1;
5766  if (!objectName.empty()) {
5767  try {
5768  dashboard_id = stoi(objectName);
5769  } catch (const std::exception&) {
5770  throw std::runtime_error(
5771  "Privileges on dashboards should be changed via integer dashboard ID");
5772  }
5773  }
5774  return DBObject(dashboard_id, objectType);
5775  } else {
5776  return DBObject(objectName, objectType);
5777  }
5778 }

+ Here is the caller graph for this function:

void Parser::execute_stmt_for_json ( const std::string &  query_json,
std::shared_ptr< Catalog_Namespace::SessionInfo const >  session_ptr,
bool  read_only_mode 
)

Definition at line 7012 of file ParserNode.cpp.

References create_stmt_for_json(), and Parser::DDLStmt::execute().

7015  {
7016  std::unique_ptr<Parser::Stmt> stmt = create_stmt_for_json(query_json);
7017  auto ddl = dynamic_cast<Parser::DDLStmt*>(stmt.get());
7018  if (ddl != nullptr) {
7019  (*ddl).execute(*session_ptr, read_only_mode);
7020  }
7021 }
std::unique_ptr< Parser::Stmt > create_stmt_for_json(const std::string &query_json)
virtual void execute(const Catalog_Namespace::SessionInfo &session, bool read_only_mode)=0

+ Here is the call graph for this function:

bool Parser::exprs_share_one_and_same_rte_idx ( const std::shared_ptr< Analyzer::Expr > &  lhs_expr,
const std::shared_ptr< Analyzer::Expr > &  rhs_expr 
)

Definition at line 312 of file ParserNode.cpp.

References CHECK.

Referenced by Parser::OperExpr::normalize().

313  {
314  std::set<int> lhs_rte_idx;
315  lhs_expr->collect_rte_idx(lhs_rte_idx);
316  CHECK(!lhs_rte_idx.empty());
317  std::set<int> rhs_rte_idx;
318  rhs_expr->collect_rte_idx(rhs_rte_idx);
319  CHECK(!rhs_rte_idx.empty());
320  return lhs_rte_idx.size() == 1UL && lhs_rte_idx == rhs_rte_idx;
321 }
#define CHECK(condition)
Definition: Logger.h:222

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

References splitObjectHierName().

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

5628  {
5629  std::string objectName;
5630  std::vector<std::string> componentNames = splitObjectHierName(objectHierName);
5631  if (objectType.compare("DATABASE") == 0) {
5632  if (componentNames.size() == 1) {
5633  objectName = componentNames[0];
5634  } else {
5635  throw std::runtime_error("DB object name is not correct " + objectHierName);
5636  }
5637  } else {
5638  if (objectType.compare("TABLE") == 0 || objectType.compare("DASHBOARD") == 0 ||
5639  objectType.compare("VIEW") == 0 || objectType.compare("SERVER") == 0) {
5640  switch (componentNames.size()) {
5641  case (1): {
5642  objectName = componentNames[0];
5643  break;
5644  }
5645  case (2): {
5646  objectName = componentNames[1];
5647  break;
5648  }
5649  default: {
5650  throw std::runtime_error("DB object name is not correct " + objectHierName);
5651  }
5652  }
5653  } else {
5654  throw std::runtime_error("DB object type " + objectType + " is not supported.");
5655  }
5656  }
5657  return objectName;
5658 }
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:

SQLTypeInfo const& Parser::get_str_dict_cast_type ( const SQLTypeInfo lhs_type_info,
const SQLTypeInfo rhs_type_info,
const Executor executor 
)

Definition at line 323 of file ParserNode.cpp.

References CHECK, CHECK_NE, SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), SQLTypeInfo::is_string(), kENCODING_DICT, and TRANSIENT_DICT_ID.

Referenced by common_string_type(), and Parser::OperExpr::normalize().

325  {
326  CHECK(lhs_type_info.is_string());
327  CHECK(lhs_type_info.get_compression() == kENCODING_DICT);
328  CHECK(rhs_type_info.is_string());
329  CHECK(rhs_type_info.get_compression() == kENCODING_DICT);
330  const auto lhs_comp_param = lhs_type_info.get_comp_param();
331  const auto rhs_comp_param = rhs_type_info.get_comp_param();
332  CHECK_NE(lhs_comp_param, rhs_comp_param);
333  if (lhs_type_info.get_comp_param() == TRANSIENT_DICT_ID) {
334  return rhs_type_info;
335  }
336  if (rhs_type_info.get_comp_param() == TRANSIENT_DICT_ID) {
337  return lhs_type_info;
338  }
339  // If here then neither lhs or rhs type was transient, we should see which
340  // type has the largest dictionary and make that the destination type
341  const auto lhs_sdp = executor->getStringDictionaryProxy(lhs_comp_param, true);
342  const auto rhs_sdp = executor->getStringDictionaryProxy(rhs_comp_param, true);
343  return lhs_sdp->entryCount() >= rhs_sdp->entryCount() ? lhs_type_info : rhs_type_info;
344 }
#define CHECK_NE(x, y)
Definition: Logger.h:231
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:309
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:387
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:388
#define CHECK(condition)
Definition: Logger.h:222
bool is_string() const
Definition: sqltypes.h:575

+ 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 = {},
bool  allow_interrupt = false 
)

Definition at line 3389 of file ParserNode.cpp.

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

3393  {},
3394  bool allow_interrupt = false) {
3395  auto const session = query_state_proxy.getQueryState().getConstSessionInfo();
3396  auto& catalog = session->getCatalog();
3397 
3399 #ifdef HAVE_CUDA
3400  const auto device_type = session->get_executor_device_type();
3401 #else
3402  const auto device_type = ExecutorDeviceType::CPU;
3403 #endif // HAVE_CUDA
3404  auto calcite_mgr = catalog.getCalciteMgr();
3405 
3406  // TODO MAT this should actually get the global or the session parameter for
3407  // view optimization
3408  const auto calciteQueryParsingOption =
3409  calcite_mgr->getCalciteQueryParsingOption(true, false, true);
3410  const auto calciteOptimizationOption = calcite_mgr->getCalciteOptimizationOption(
3411  false,
3413  {},
3415  const auto query_ra = calcite_mgr
3416  ->process(query_state_proxy,
3417  pg_shim(select_stmt),
3418  calciteQueryParsingOption,
3419  calciteOptimizationOption)
3420  .plan_result;
3421  RelAlgExecutor ra_executor(executor.get(),
3422  catalog,
3423  query_ra,
3424  query_state_proxy.getQueryState().shared_from_this());
3426  // TODO(adb): Need a better method of dropping constants into this ExecutionOptions
3427  // struct
3428  ExecutionOptions eo = {false,
3429  false,
3430  true,
3431  false,
3432  true,
3433  false,
3434  false,
3435  validate_only,
3436  false,
3437  10000,
3438  false,
3439  false,
3440  1000,
3441  allow_interrupt,
3445  outer_fragment_indices};
3446 
3447  ExecutionResult result{std::make_shared<ResultSet>(std::vector<TargetInfo>{},
3450  nullptr,
3451  nullptr,
3452  0,
3453  0),
3454  {}};
3455  result = ra_executor.executeRelAlgQuery(co, eo, false, nullptr);
3456  targets = result.getTargetsMeta();
3457 
3458  return result.getRows();
3459 }
double g_running_query_interrupt_freq
Definition: Execute.cpp:129
unsigned g_pending_query_interrupt_freq
Definition: Execute.cpp:128
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:477
static SysCatalog & instance()
Definition: SysCatalog.h:341
QueryState & getQueryState()
Definition: QueryState.h:181
bool g_enable_watchdog
static CompilationOptions defaults(const ExecutorDeviceType device_type=ExecutorDeviceType::GPU)
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:88
std::string pg_shim(const std::string &query)
static const ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:376

+ Here is the caller graph for this function:

std::vector<int> Parser::getTableChunkKey ( const TableDescriptor td,
Catalog_Namespace::Catalog catalog 
)

Definition at line 114 of file ParserNode.cpp.

References Catalog_Namespace::DBMetadata::dbId, TableDescriptor::fragmenter, Catalog_Namespace::Catalog::getCurrentDB(), and TableDescriptor::tableId.

115  {
116  std::vector<int> table_chunk_key_prefix;
117  if (td) {
118  if (td->fragmenter) {
119  table_chunk_key_prefix = td->fragmenter->getFragmentsForQuery().chunkKeyPrefix;
120  } else {
121  table_chunk_key_prefix.push_back(catalog.getCurrentDB().dbId);
122  table_chunk_key_prefix.push_back(td->tableId);
123  }
124  }
125  return table_chunk_key_prefix;
126 }
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:242
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter

+ Here is the call graph for this function:

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

Definition at line 1598 of file ParserNode.h.

References CHECK.

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

1599  {
1600  CHECK(l);
1601  for (auto str : *l) {
1602  v.push_back(*str);
1603  delete str;
1604  }
1605  delete l;
1606 }
#define CHECK(condition)
Definition: Logger.h:222

+ 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 5660 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, AccessPrivileges::SERVER_USAGE, 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().

5663  {
5664  static const std::map<std::pair<const std::string, const DBObjectType>,
5665  std::pair<const AccessPrivileges, const DBObjectType>>
5666  privileges_lookup{
5667  {{"ALL"s, DatabaseDBObjectType},
5670  {{"ALL"s, DashboardDBObjectType},
5673  {{"ALL"s, ServerDBObjectType},
5675 
5676  {{"CREATE TABLE"s, DatabaseDBObjectType},
5678  {{"CREATE"s, DatabaseDBObjectType},
5680  {{"SELECT"s, DatabaseDBObjectType},
5682  {{"INSERT"s, DatabaseDBObjectType},
5684  {{"TRUNCATE"s, DatabaseDBObjectType},
5686  {{"UPDATE"s, DatabaseDBObjectType},
5688  {{"DELETE"s, DatabaseDBObjectType},
5690  {{"DROP"s, DatabaseDBObjectType},
5692  {{"ALTER"s, DatabaseDBObjectType},
5694 
5695  {{"SELECT"s, TableDBObjectType},
5697  {{"INSERT"s, TableDBObjectType},
5699  {{"TRUNCATE"s, TableDBObjectType},
5701  {{"UPDATE"s, TableDBObjectType},
5703  {{"DELETE"s, TableDBObjectType},
5705  {{"DROP"s, TableDBObjectType},
5707  {{"ALTER"s, TableDBObjectType},
5709 
5710  {{"CREATE VIEW"s, DatabaseDBObjectType},
5712  {{"SELECT VIEW"s, DatabaseDBObjectType},
5714  {{"DROP VIEW"s, DatabaseDBObjectType},
5716  {{"SELECT"s, ViewDBObjectType},
5719 
5720  {{"CREATE DASHBOARD"s, DatabaseDBObjectType},
5722  {{"EDIT DASHBOARD"s, DatabaseDBObjectType},
5724  {{"VIEW DASHBOARD"s, DatabaseDBObjectType},
5726  {{"DELETE DASHBOARD"s, DatabaseDBObjectType},
5728  {{"VIEW"s, DashboardDBObjectType},
5730  {{"EDIT"s, DashboardDBObjectType},
5732  {{"DELETE"s, DashboardDBObjectType},
5734 
5735  {{"CREATE SERVER"s, DatabaseDBObjectType},
5737  {{"DROP SERVER"s, DatabaseDBObjectType},
5739  {{"DROP"s, ServerDBObjectType},
5741  {{"ALTER SERVER"s, DatabaseDBObjectType},
5743  {{"ALTER"s, ServerDBObjectType},
5745  {{"USAGE"s, ServerDBObjectType},
5747  {{"SERVER USAGE"s, DatabaseDBObjectType},
5749 
5750  {{"VIEW SQL EDITOR"s, DatabaseDBObjectType},
5752  {{"ACCESS"s, DatabaseDBObjectType},
5754 
5755  auto result = privileges_lookup.find(std::make_pair(privs, objectType));
5756  if (result == privileges_lookup.end()) {
5757  throw std::runtime_error("Privileges " + privs + " on DB object " + object_name +
5758  " are not correct.");
5759  }
5760  return result->second;
5761 }
static const AccessPrivileges VIEW_SQL_EDITOR
Definition: DBObject.h:152
static const AccessPrivileges VIEW_DASHBOARD
Definition: DBObject.h:171
static const AccessPrivileges DROP_SERVER
Definition: DBObject.h:189
static const AccessPrivileges ALL_DATABASE
Definition: DBObject.h:151
static const AccessPrivileges ALTER_TABLE
Definition: DBObject.h:165
static const AccessPrivileges TRUNCATE_TABLE
Definition: DBObject.h:164
static const AccessPrivileges INSERT_INTO_TABLE
Definition: DBObject.h:161
static const AccessPrivileges CREATE_DASHBOARD
Definition: DBObject.h:170
static const AccessPrivileges SERVER_USAGE
Definition: DBObject.h:191
static const AccessPrivileges SELECT_FROM_TABLE
Definition: DBObject.h:160
static const AccessPrivileges ALL_VIEW
Definition: DBObject.h:177
static const AccessPrivileges ALTER_SERVER
Definition: DBObject.h:190
static const AccessPrivileges DROP_TABLE
Definition: DBObject.h:159
static const AccessPrivileges ALL_SERVER
Definition: DBObject.h:187
static const AccessPrivileges CREATE_SERVER
Definition: DBObject.h:188
static const AccessPrivileges DELETE_FROM_TABLE
Definition: DBObject.h:163
static const AccessPrivileges CREATE_TABLE
Definition: DBObject.h:158
static const AccessPrivileges SELECT_FROM_VIEW
Definition: DBObject.h:180
static const AccessPrivileges ALL_DASHBOARD
Definition: DBObject.h:169
static const AccessPrivileges ACCESS
Definition: DBObject.h:153
static const AccessPrivileges ALL_TABLE
Definition: DBObject.h:157
static const AccessPrivileges DROP_VIEW
Definition: DBObject.h:179
static const AccessPrivileges CREATE_VIEW
Definition: DBObject.h:178
static const AccessPrivileges DELETE_DASHBOARD
Definition: DBObject.h:173
static const AccessPrivileges EDIT_DASHBOARD
Definition: DBObject.h:172
static const AccessPrivileges UPDATE_IN_TABLE
Definition: DBObject.h:162

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

References CHECK.

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

6609  {
6610  CHECK(p);
6611  const std::string* str =
6612  static_cast<const StringLiteral*>(p->get_value())->get_stringval();
6613  if (boost::iequals(*str, "true")) {
6614  return true;
6615  } else if (boost::iequals(*str, "false")) {
6616  return false;
6617  } else {
6618  throw std::runtime_error("Value to " + option_name + " must be TRUE or FALSE.");
6619  }
6620 }
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the caller graph for this function:

bool Parser::repair_type ( std::list< std::unique_ptr< NameValueAssign >> &  options)

Definition at line 4683 of file ParserNode.cpp.

References CHECK.

Referenced by Parser::ValidateStmt::ValidateStmt().

4683  {
4684  for (const auto& opt : options) {
4685  if (boost::iequals(*opt->get_name(), "REPAIR_TYPE")) {
4686  const auto repair_type =
4687  static_cast<const StringLiteral*>(opt->get_value())->get_stringval();
4688  CHECK(repair_type);
4689  if (boost::iequals(*repair_type, "REMOVE")) {
4690  return true;
4691  } else {
4692  throw std::runtime_error("REPAIR_TYPE must be REMOVE.");
4693  }
4694  } else {
4695  throw std::runtime_error("The only VALIDATE WITH options is REPAIR_TYPE.");
4696  }
4697  }
4698  return false;
4699 }
bool repair_type(std::list< std::unique_ptr< NameValueAssign >> &options)
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the caller graph for this function:

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

Definition at line 5620 of file ParserNode.cpp.

References split().

Referenced by extractObjectNameFromHierName().

5620  {
5621  std::vector<std::string> componentNames;
5622  boost::split(componentNames, hierName, boost::is_any_of("."));
5623  return componentNames;
5624 }
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:

static void Parser::verifyObject ( Catalog_Namespace::Catalog sessionCatalog,
const std::string &  objectName,
DBObjectType  objectType,
const std::string &  command 
)
static

Definition at line 5782 of file ParserNode.cpp.

References DBObjectTypeToString(), Catalog_Namespace::Catalog::getMetadataForTable(), TableDescriptor::isView, TableDBObjectType, and ViewDBObjectType.

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

5785  {
5786  if (objectType == TableDBObjectType) {
5787  auto td = sessionCatalog.getMetadataForTable(objectName, false);
5788  if (!td || td->isView) {
5789  // expected TABLE, found VIEW
5790  throw std::runtime_error(command + " failed. Object '" + objectName + "' of type " +
5791  DBObjectTypeToString(objectType) + " not found.");
5792  }
5793 
5794  } else if (objectType == ViewDBObjectType) {
5795  auto td = sessionCatalog.getMetadataForTable(objectName, false);
5796  if (!td || !td->isView) {
5797  // expected VIEW, found TABLE
5798  throw std::runtime_error(command + " failed. Object '" + objectName + "' of type " +
5799  DBObjectTypeToString(objectType) + " not found.");
5800  }
5801  }
5802 }
std::string DBObjectTypeToString(DBObjectType type)
Definition: DBObject.cpp:92
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.

+ Here is the call graph for this function:

+ Here is the caller graph for this function: