OmniSciDB  085a039ca4
 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  ShowCreateTableStmt
 
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
 
struct  ShouldInvalidateSessionsByDB
 
struct  ShouldInvalidateSessionsByUser
 
struct  ShouldInvalidateSessionsByDB< DropDBStmt >
 
struct  ShouldInvalidateSessionsByUser< DropUserStmt >
 
struct  ShouldInvalidateSessionsByDB< RenameDBStmt >
 
struct  ShouldInvalidateSessionsByUser< RenameUserStmt >
 

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)
 
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 4716 of file ParserNode.cpp.

Function Documentation

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

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

4629  {
4630  if (session.get_currentUser().isSuper ||
4631  session.get_currentUser().userId == td->userId) {
4632  return;
4633  }
4634  std::vector<DBObject> privObjects;
4635  DBObject dbObject(td->tableName, TableDBObjectType);
4636  dbObject.loadKey(session.getCatalog());
4637  dbObject.setPrivileges(AccessPrivileges::ALTER_TABLE);
4638  privObjects.push_back(dbObject);
4639  if (!SysCatalog::instance().checkPrivileges(session.get_currentUser(), privObjects)) {
4640  throw std::runtime_error("Current user does not have the privilege to alter table: " +
4641  td->tableName);
4642  }
4643 }
std::string tableName
static const AccessPrivileges ALTER_TABLE
Definition: DBObject.h:167
Catalog & getCatalog() const
Definition: SessionInfo.h:65
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:71
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 104 of file ParserNode.cpp.

References g_enable_non_kernel_time_query_interrupt.

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

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

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

References CHECK.

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

6367  {
6368  CHECK(p);
6369  if (!dynamic_cast<const StringLiteral*>(p->get_value())) {
6370  throw std::runtime_error(option_name + " option must be a string literal.");
6371  }
6372 }
#define CHECK(condition)
Definition: Logger.h:223

+ 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 347 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().

349  {
350  CHECK(lhs_type_info.is_string());
351  CHECK(rhs_type_info.is_string());
352  const auto lhs_comp_param = lhs_type_info.get_comp_param();
353  const auto rhs_comp_param = rhs_type_info.get_comp_param();
354  if (lhs_type_info.is_dict_encoded_string() && rhs_type_info.is_dict_encoded_string()) {
355  if (lhs_comp_param == rhs_comp_param ||
356  lhs_comp_param == TRANSIENT_DICT(rhs_comp_param)) {
357  return lhs_comp_param <= rhs_comp_param ? lhs_type_info : rhs_type_info;
358  }
359  return get_str_dict_cast_type(lhs_type_info, rhs_type_info, executor);
360  }
361  CHECK(lhs_type_info.is_none_encoded_string() || rhs_type_info.is_none_encoded_string());
362  SQLTypeInfo ret_ti =
363  rhs_type_info.is_none_encoded_string() ? lhs_type_info : rhs_type_info;
364  if (ret_ti.is_none_encoded_string()) {
365  ret_ti.set_dimension(
366  std::max(lhs_type_info.get_dimension(), rhs_type_info.get_dimension()));
367  }
368  return ret_ti;
369 }
void set_dimension(int d)
Definition: sqltypes.h:431
bool is_none_encoded_string() const
Definition: sqltypes.h:552
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:331
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:338
#define CHECK(condition)
Definition: Logger.h:223
bool is_dict_encoded_string() const
Definition: sqltypes.h:548
bool is_string() const
Definition: sqltypes.h:510
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:260
SQLTypeInfo const & get_str_dict_cast_type(const SQLTypeInfo &lhs_type_info, const SQLTypeInfo &rhs_type_info, const Executor *executor)
Definition: ParserNode.cpp:324

+ 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 6755 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().

6755  {
6756  CHECK(!query_json.empty());
6757  VLOG(2) << "Parsing JSON DDL from Calcite: " << query_json;
6758  rapidjson::Document ddl_query;
6759  ddl_query.Parse(query_json);
6760  CHECK(ddl_query.IsObject());
6761  CHECK(ddl_query.HasMember("payload"));
6762  CHECK(ddl_query["payload"].IsObject());
6763  const auto& payload = ddl_query["payload"].GetObject();
6764  CHECK(payload.HasMember("command"));
6765  CHECK(payload["command"].IsString());
6766 
6767  const auto& ddl_command = std::string_view(payload["command"].GetString());
6768 
6769  Parser::Stmt* stmt = nullptr;
6770  if (ddl_command == "CREATE_TABLE") {
6771  stmt = new Parser::CreateTableStmt(payload);
6772  } else if (ddl_command == "DROP_TABLE") {
6773  stmt = new Parser::DropTableStmt(payload);
6774  } else if (ddl_command == "RENAME_TABLE") {
6775  stmt = new Parser::RenameTableStmt(payload);
6776  } else if (ddl_command == "ALTER_TABLE") {
6777  std::unique_ptr<Parser::DDLStmt> ddlStmt;
6778  ddlStmt = Parser::AlterTableStmt::delegate(payload);
6779  if (ddlStmt != nullptr) {
6780  stmt = ddlStmt.get();
6781  ddlStmt.release();
6782  }
6783  } else if (ddl_command == "TRUNCATE_TABLE") {
6784  stmt = new Parser::TruncateTableStmt(payload);
6785  } else if (ddl_command == "DUMP_TABLE") {
6786  stmt = new Parser::DumpTableStmt(payload);
6787  } else if (ddl_command == "RESTORE_TABLE") {
6788  stmt = new Parser::RestoreTableStmt(payload);
6789  } else if (ddl_command == "OPTIMIZE_TABLE") {
6790  stmt = new Parser::OptimizeTableStmt(payload);
6791  } else if (ddl_command == "SHOW_CREATE_TABLE") {
6792  stmt = new Parser::ShowCreateTableStmt(payload);
6793  } else if (ddl_command == "COPY_TABLE") {
6794  stmt = new Parser::CopyTableStmt(payload);
6795  } else if (ddl_command == "EXPORT_QUERY") {
6796  stmt = new Parser::ExportQueryStmt(payload);
6797  } else if (ddl_command == "CREATE_VIEW") {
6798  stmt = new Parser::CreateViewStmt(payload);
6799  } else if (ddl_command == "DROP_VIEW") {
6800  stmt = new Parser::DropViewStmt(payload);
6801  } else if (ddl_command == "CREATE_DB") {
6802  stmt = new Parser::CreateDBStmt(payload);
6803  } else if (ddl_command == "DROP_DB") {
6804  stmt = new Parser::DropDBStmt(payload);
6805  } else if (ddl_command == "RENAME_DB") {
6806  stmt = new Parser::RenameDBStmt(payload);
6807  } else if (ddl_command == "CREATE_USER") {
6808  stmt = new Parser::CreateUserStmt(payload);
6809  } else if (ddl_command == "DROP_USER") {
6810  stmt = new Parser::DropUserStmt(payload);
6811  } else if (ddl_command == "ALTER_USER") {
6812  stmt = new Parser::AlterUserStmt(payload);
6813  } else if (ddl_command == "RENAME_USER") {
6814  stmt = new Parser::RenameUserStmt(payload);
6815  } else if (ddl_command == "CREATE_ROLE") {
6816  stmt = new Parser::CreateRoleStmt(payload);
6817  } else if (ddl_command == "DROP_ROLE") {
6818  stmt = new Parser::DropRoleStmt(payload);
6819  } else if (ddl_command == "GRANT_ROLE") {
6820  stmt = new Parser::GrantRoleStmt(payload);
6821  } else if (ddl_command == "REVOKE_ROLE") {
6822  stmt = new Parser::RevokeRoleStmt(payload);
6823  } else if (ddl_command == "GRANT_PRIVILEGE") {
6824  stmt = new Parser::GrantPrivilegesStmt(payload);
6825  } else if (ddl_command == "REVOKE_PRIVILEGE") {
6826  stmt = new Parser::RevokePrivilegesStmt(payload);
6827  } else if (ddl_command == "CREATE_DATAFRAME") {
6828  stmt = new Parser::CreateDataframeStmt(payload);
6829  } else if (ddl_command == "VALIDATE_SYSTEM") {
6830  // VALIDATE should have been excuted in outer context before it reaches here
6831  UNREACHABLE(); // not-implemented alterType
6832  } else {
6833  throw std::runtime_error("Unsupported DDL command");
6834  }
6835  return std::unique_ptr<Parser::Stmt>(stmt);
6836 }
#define UNREACHABLE()
Definition: Logger.h:267
#define CHECK(condition)
Definition: Logger.h:223
#define VLOG(n)
Definition: Logger.h:317
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 6733 of file ParserNode.cpp.

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

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

6735  {
6736  auto session_copy = session_info;
6737  auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
6738  &session_copy, boost::null_deleter());
6739  auto query_state = query_state::QueryState::create(session_ptr, queryStr);
6740  const auto& cat = session_info.getCatalog();
6741  auto calcite_mgr = cat.getCalciteMgr();
6742  const auto calciteQueryParsingOption =
6743  calcite_mgr->getCalciteQueryParsingOption(true, false, true);
6744  const auto calciteOptimizationOption =
6745  calcite_mgr->getCalciteOptimizationOption(false, g_enable_watchdog, {});
6746  const auto query_json = calcite_mgr
6747  ->process(query_state->createQueryStateProxy(),
6748  pg_shim(queryStr),
6749  calciteQueryParsingOption,
6750  calciteOptimizationOption)
6751  .plan_result;
6752  return create_stmt_for_json(query_json);
6753 }
std::string cat(Ts &&...args)
static std::shared_ptr< QueryState > create(ARGS &&...args)
Definition: QueryState.h:145
std::unique_ptr< Parser::Stmt > create_stmt_for_json(const std::string &query_json)
bool g_enable_watchdog
Catalog & getCatalog() const
Definition: SessionInfo.h:65
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 5612 of file ParserNode.cpp.

References DashboardDBObjectType.

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

5612  {
5613  if (objectType == DashboardDBObjectType) {
5614  int32_t dashboard_id = -1;
5615  if (!objectName.empty()) {
5616  try {
5617  dashboard_id = stoi(objectName);
5618  } catch (const std::exception&) {
5619  throw std::runtime_error(
5620  "Privileges on dashboards should be changed via integer dashboard ID");
5621  }
5622  }
5623  return DBObject(dashboard_id, objectType);
5624  } else {
5625  return DBObject(objectName, objectType);
5626  }
5627 }

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

Definition at line 6838 of file ParserNode.cpp.

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

6840  {
6841  std::unique_ptr<Parser::Stmt> stmt = create_stmt_for_json(query_json);
6842  auto ddl = dynamic_cast<Parser::DDLStmt*>(stmt.get());
6843  if (ddl != nullptr) {
6844  (*ddl).execute(*session_ptr);
6845  }
6846 }
std::unique_ptr< Parser::Stmt > create_stmt_for_json(const std::string &query_json)
virtual void execute(const Catalog_Namespace::SessionInfo &session)=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 313 of file ParserNode.cpp.

References CHECK.

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

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

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

References splitObjectHierName().

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

5477  {
5478  std::string objectName;
5479  std::vector<std::string> componentNames = splitObjectHierName(objectHierName);
5480  if (objectType.compare("DATABASE") == 0) {
5481  if (componentNames.size() == 1) {
5482  objectName = componentNames[0];
5483  } else {
5484  throw std::runtime_error("DB object name is not correct " + objectHierName);
5485  }
5486  } else {
5487  if (objectType.compare("TABLE") == 0 || objectType.compare("DASHBOARD") == 0 ||
5488  objectType.compare("VIEW") == 0 || objectType.compare("SERVER") == 0) {
5489  switch (componentNames.size()) {
5490  case (1): {
5491  objectName = componentNames[0];
5492  break;
5493  }
5494  case (2): {
5495  objectName = componentNames[1];
5496  break;
5497  }
5498  default: {
5499  throw std::runtime_error("DB object name is not correct " + objectHierName);
5500  }
5501  }
5502  } else {
5503  throw std::runtime_error("DB object type " + objectType + " is not supported.");
5504  }
5505  }
5506  return objectName;
5507 }
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 324 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().

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

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

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

3357  {},
3358  bool allow_interrupt = false) {
3359  auto const session = query_state_proxy.getQueryState().getConstSessionInfo();
3360  auto& catalog = session->getCatalog();
3361 
3363 #ifdef HAVE_CUDA
3364  const auto device_type = session->get_executor_device_type();
3365 #else
3366  const auto device_type = ExecutorDeviceType::CPU;
3367 #endif // HAVE_CUDA
3368  auto calcite_mgr = catalog.getCalciteMgr();
3369 
3370  // TODO MAT this should actually get the global or the session parameter for
3371  // view optimization
3372  const auto calciteQueryParsingOption =
3373  calcite_mgr->getCalciteQueryParsingOption(true, false, true);
3374  const auto calciteOptimizationOption =
3375  calcite_mgr->getCalciteOptimizationOption(false, g_enable_watchdog, {});
3376  const auto query_ra = calcite_mgr
3377  ->process(query_state_proxy,
3378  pg_shim(select_stmt),
3379  calciteQueryParsingOption,
3380  calciteOptimizationOption)
3381  .plan_result;
3382  RelAlgExecutor ra_executor(executor.get(),
3383  catalog,
3384  query_ra,
3385  query_state_proxy.getQueryState().shared_from_this());
3387  // TODO(adb): Need a better method of dropping constants into this ExecutionOptions
3388  // struct
3389  ExecutionOptions eo = {false,
3390  false,
3391  true,
3392  false,
3393  true,
3394  false,
3395  false,
3396  validate_only,
3397  false,
3398  10000,
3399  false,
3400  false,
3401  1000,
3402  allow_interrupt,
3406  outer_fragment_indices};
3407 
3408  ExecutionResult result{std::make_shared<ResultSet>(std::vector<TargetInfo>{},
3411  nullptr,
3412  nullptr,
3413  0,
3414  0),
3415  {}};
3416  result = ra_executor.executeRelAlgQuery(co, eo, false, nullptr);
3417  targets = result.getTargetsMeta();
3418 
3419  return result.getRows();
3420 }
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:483
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 115 of file ParserNode.cpp.

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

116  {
117  std::vector<int> table_chunk_key_prefix;
118  if (td) {
119  if (td->fragmenter) {
120  table_chunk_key_prefix = td->fragmenter->getFragmentsForQuery().chunkKeyPrefix;
121  } else {
122  table_chunk_key_prefix.push_back(catalog.getCurrentDB().dbId);
123  table_chunk_key_prefix.push_back(td->tableId);
124  }
125  }
126  return table_chunk_key_prefix;
127 }
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:228
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 1574 of file ParserNode.h.

References CHECK.

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

1575  {
1576  CHECK(l);
1577  for (auto str : *l) {
1578  v.push_back(*str);
1579  delete str;
1580  }
1581  delete l;
1582 }
#define CHECK(condition)
Definition: Logger.h:223

+ 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 5509 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().

5512  {
5513  static const std::map<std::pair<const std::string, const DBObjectType>,
5514  std::pair<const AccessPrivileges, const DBObjectType>>
5515  privileges_lookup{
5516  {{"ALL"s, DatabaseDBObjectType},
5519  {{"ALL"s, DashboardDBObjectType},
5522  {{"ALL"s, ServerDBObjectType},
5524 
5525  {{"CREATE TABLE"s, DatabaseDBObjectType},
5527  {{"CREATE"s, DatabaseDBObjectType},
5529  {{"SELECT"s, DatabaseDBObjectType},
5531  {{"INSERT"s, DatabaseDBObjectType},
5533  {{"TRUNCATE"s, DatabaseDBObjectType},
5535  {{"UPDATE"s, DatabaseDBObjectType},
5537  {{"DELETE"s, DatabaseDBObjectType},
5539  {{"DROP"s, DatabaseDBObjectType},
5541  {{"ALTER"s, DatabaseDBObjectType},
5543 
5544  {{"SELECT"s, TableDBObjectType},
5546  {{"INSERT"s, TableDBObjectType},
5548  {{"TRUNCATE"s, TableDBObjectType},
5550  {{"UPDATE"s, TableDBObjectType},
5552  {{"DELETE"s, TableDBObjectType},
5554  {{"DROP"s, TableDBObjectType},
5556  {{"ALTER"s, TableDBObjectType},
5558 
5559  {{"CREATE VIEW"s, DatabaseDBObjectType},
5561  {{"SELECT VIEW"s, DatabaseDBObjectType},
5563  {{"DROP VIEW"s, DatabaseDBObjectType},
5565  {{"SELECT"s, ViewDBObjectType},
5568 
5569  {{"CREATE DASHBOARD"s, DatabaseDBObjectType},
5571  {{"EDIT DASHBOARD"s, DatabaseDBObjectType},
5573  {{"VIEW DASHBOARD"s, DatabaseDBObjectType},
5575  {{"DELETE DASHBOARD"s, DatabaseDBObjectType},
5577  {{"VIEW"s, DashboardDBObjectType},
5579  {{"EDIT"s, DashboardDBObjectType},
5581  {{"DELETE"s, DashboardDBObjectType},
5583 
5584  {{"CREATE SERVER"s, DatabaseDBObjectType},
5586  {{"DROP SERVER"s, DatabaseDBObjectType},
5588  {{"DROP"s, ServerDBObjectType},
5590  {{"ALTER SERVER"s, DatabaseDBObjectType},
5592  {{"ALTER"s, ServerDBObjectType},
5594  {{"USAGE"s, ServerDBObjectType},
5596  {{"SERVER USAGE"s, DatabaseDBObjectType},
5598 
5599  {{"VIEW SQL EDITOR"s, DatabaseDBObjectType},
5601  {{"ACCESS"s, DatabaseDBObjectType},
5603 
5604  auto result = privileges_lookup.find(std::make_pair(privs, objectType));
5605  if (result == privileges_lookup.end()) {
5606  throw std::runtime_error("Privileges " + privs + " on DB object " + object_name +
5607  " are not correct.");
5608  }
5609  return result->second;
5610 }
static const AccessPrivileges VIEW_SQL_EDITOR
Definition: DBObject.h:154
static const AccessPrivileges VIEW_DASHBOARD
Definition: DBObject.h:173
static const AccessPrivileges DROP_SERVER
Definition: DBObject.h:191
static const AccessPrivileges ALL_DATABASE
Definition: DBObject.h:153
static const AccessPrivileges ALTER_TABLE
Definition: DBObject.h:167
static const AccessPrivileges TRUNCATE_TABLE
Definition: DBObject.h:166
static const AccessPrivileges INSERT_INTO_TABLE
Definition: DBObject.h:163
static const AccessPrivileges CREATE_DASHBOARD
Definition: DBObject.h:172
static const AccessPrivileges SERVER_USAGE
Definition: DBObject.h:193
static const AccessPrivileges SELECT_FROM_TABLE
Definition: DBObject.h:162
static const AccessPrivileges ALL_VIEW
Definition: DBObject.h:179
static const AccessPrivileges ALTER_SERVER
Definition: DBObject.h:192
static const AccessPrivileges DROP_TABLE
Definition: DBObject.h:161
static const AccessPrivileges ALL_SERVER
Definition: DBObject.h:189
static const AccessPrivileges CREATE_SERVER
Definition: DBObject.h:190
static const AccessPrivileges DELETE_FROM_TABLE
Definition: DBObject.h:165
static const AccessPrivileges CREATE_TABLE
Definition: DBObject.h:160
static const AccessPrivileges SELECT_FROM_VIEW
Definition: DBObject.h:182
static const AccessPrivileges ALL_DASHBOARD
Definition: DBObject.h:171
static const AccessPrivileges ACCESS
Definition: DBObject.h:155
static const AccessPrivileges ALL_TABLE
Definition: DBObject.h:159
static const AccessPrivileges DROP_VIEW
Definition: DBObject.h:181
static const AccessPrivileges CREATE_VIEW
Definition: DBObject.h:180
static const AccessPrivileges DELETE_DASHBOARD
Definition: DBObject.h:175
static const AccessPrivileges EDIT_DASHBOARD
Definition: DBObject.h:174
static const AccessPrivileges UPDATE_IN_TABLE
Definition: DBObject.h:164

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

References CHECK.

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

6455  {
6456  CHECK(p);
6457  const std::string* str =
6458  static_cast<const StringLiteral*>(p->get_value())->get_stringval();
6459  if (boost::iequals(*str, "true")) {
6460  return true;
6461  } else if (boost::iequals(*str, "false")) {
6462  return false;
6463  } else {
6464  throw std::runtime_error("Value to " + option_name + " must be TRUE or FALSE.");
6465  }
6466 }
#define CHECK(condition)
Definition: Logger.h:223

+ Here is the caller graph for this function:

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

Definition at line 4584 of file ParserNode.cpp.

References CHECK.

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

4584  {
4585  for (const auto& opt : options) {
4586  if (boost::iequals(*opt->get_name(), "REPAIR_TYPE")) {
4587  const auto repair_type =
4588  static_cast<const StringLiteral*>(opt->get_value())->get_stringval();
4589  CHECK(repair_type);
4590  if (boost::iequals(*repair_type, "REMOVE")) {
4591  return true;
4592  } else {
4593  throw std::runtime_error("REPAIR_TYPE must be REMOVE.");
4594  }
4595  } else {
4596  throw std::runtime_error("The only VALIDATE WITH options is REPAIR_TYPE.");
4597  }
4598  }
4599  return false;
4600 }
bool repair_type(std::list< std::unique_ptr< NameValueAssign >> &options)
#define CHECK(condition)
Definition: Logger.h:223

+ Here is the caller graph for this function:

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

Definition at line 5469 of file ParserNode.cpp.

References split().

Referenced by extractObjectNameFromHierName().

5469  {
5470  std::vector<std::string> componentNames;
5471  boost::split(componentNames, hierName, boost::is_any_of("."));
5472  return componentNames;
5473 }
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 5631 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().

5634  {
5635  if (objectType == TableDBObjectType) {
5636  auto td = sessionCatalog.getMetadataForTable(objectName, false);
5637  if (!td || td->isView) {
5638  // expected TABLE, found VIEW
5639  throw std::runtime_error(command + " failed. Object '" + objectName + "' of type " +
5640  DBObjectTypeToString(objectType) + " not found.");
5641  }
5642 
5643  } else if (objectType == ViewDBObjectType) {
5644  auto td = sessionCatalog.getMetadataForTable(objectName, false);
5645  if (!td || !td->isView) {
5646  // expected VIEW, found TABLE
5647  throw std::runtime_error(command + " failed. Object '" + objectName + "' of type " +
5648  DBObjectTypeToString(objectType) + " not found.");
5649  }
5650  }
5651 }
std::string DBObjectTypeToString(DBObjectType type)
Definition: DBObject.cpp:83
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: