OmniSciDB  c1a53651b2
 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 4851 of file ParserNode.cpp.

Function Documentation

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

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

4755  {
4756  if (session.get_currentUser().isSuper ||
4757  session.get_currentUser().userId == td->userId) {
4758  return;
4759  }
4760  std::vector<DBObject> privObjects;
4761  DBObject dbObject(td->tableName, TableDBObjectType);
4762  dbObject.loadKey(session.getCatalog());
4763  dbObject.setPrivileges(AccessPrivileges::ALTER_TABLE);
4764  privObjects.push_back(dbObject);
4765  if (!SysCatalog::instance().checkPrivileges(session.get_currentUser(), privObjects)) {
4766  throw std::runtime_error("Current user does not have the privilege to alter table: " +
4767  td->tableName);
4768  }
4769 }
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 103 of file ParserNode.cpp.

References g_enable_non_kernel_time_query_interrupt.

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

103  {
104  // we call this function with unitary executor but is okay since
105  // we know the exact session info from a global session map object
106  // in the executor
109  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
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 6537 of file ParserNode.cpp.

References CHECK.

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

6538  {
6539  CHECK(p);
6540  if (!dynamic_cast<const StringLiteral*>(p->get_value())) {
6541  throw std::runtime_error(option_name + " option must be a string literal.");
6542  }
6543 }
#define CHECK(condition)
Definition: Logger.h:291

+ 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, shared::StringDictKey::dict_id, SQLTypeInfo::get_dimension(), get_str_dict_cast_type(), SQLTypeInfo::getStringDictKey(), 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  if (lhs_type_info.is_dict_encoded_string() && rhs_type_info.is_dict_encoded_string()) {
353  const auto& lhs_dict_key = lhs_type_info.getStringDictKey();
354  const auto& rhs_dict_key = rhs_type_info.getStringDictKey();
355  if (lhs_dict_key == rhs_dict_key ||
356  (lhs_dict_key.db_id == rhs_dict_key.db_id &&
357  lhs_dict_key.dict_id == TRANSIENT_DICT(rhs_dict_key.dict_id))) {
358  return lhs_dict_key.dict_id <= rhs_dict_key.dict_id ? lhs_type_info : rhs_type_info;
359  }
360  return get_str_dict_cast_type(lhs_type_info, rhs_type_info, executor);
361  }
362  CHECK(lhs_type_info.is_none_encoded_string() || rhs_type_info.is_none_encoded_string());
363  SQLTypeInfo ret_ti =
364  rhs_type_info.is_none_encoded_string() ? lhs_type_info : rhs_type_info;
365  if (ret_ti.is_none_encoded_string()) {
366  ret_ti.set_dimension(
367  std::max(lhs_type_info.get_dimension(), rhs_type_info.get_dimension()));
368  }
369  return ret_ti;
370 }
void set_dimension(int d)
Definition: sqltypes.h:495
bool is_none_encoded_string() const
Definition: sqltypes.h:636
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:383
#define CHECK(condition)
Definition: Logger.h:291
bool is_dict_encoded_string() const
Definition: sqltypes.h:632
bool is_string() const
Definition: sqltypes.h:580
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:312
SQLTypeInfo const & get_str_dict_cast_type(const SQLTypeInfo &lhs_type_info, const SQLTypeInfo &rhs_type_info, const Executor *executor)
Definition: ParserNode.cpp:324
const shared::StringDictKey & getStringDictKey() const
Definition: sqltypes.h:1021

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

6993  {
6994  CHECK(!query_json.empty());
6995  VLOG(2) << "Parsing JSON DDL from Calcite: " << query_json;
6996  rapidjson::Document ddl_query;
6997  ddl_query.Parse(query_json);
6998  CHECK(ddl_query.IsObject());
6999  CHECK(ddl_query.HasMember("payload"));
7000  CHECK(ddl_query["payload"].IsObject());
7001  const auto& payload = ddl_query["payload"].GetObject();
7002  CHECK(payload.HasMember("command"));
7003  CHECK(payload["command"].IsString());
7004 
7005  const auto& ddl_command = std::string_view(payload["command"].GetString());
7006 
7007  Parser::Stmt* stmt = nullptr;
7008  if (ddl_command == "CREATE_TABLE") {
7009  stmt = new Parser::CreateTableStmt(payload);
7010  } else if (ddl_command == "DROP_TABLE") {
7011  stmt = new Parser::DropTableStmt(payload);
7012  } else if (ddl_command == "RENAME_TABLE") {
7013  stmt = new Parser::RenameTableStmt(payload);
7014  } else if (ddl_command == "ALTER_TABLE") {
7015  std::unique_ptr<Parser::DDLStmt> ddlStmt;
7016  ddlStmt = Parser::AlterTableStmt::delegate(payload);
7017  if (ddlStmt != nullptr) {
7018  stmt = ddlStmt.get();
7019  ddlStmt.release();
7020  }
7021  } else if (ddl_command == "TRUNCATE_TABLE") {
7022  stmt = new Parser::TruncateTableStmt(payload);
7023  } else if (ddl_command == "DUMP_TABLE") {
7024  stmt = new Parser::DumpTableStmt(payload);
7025  } else if (ddl_command == "RESTORE_TABLE") {
7026  stmt = new Parser::RestoreTableStmt(payload);
7027  } else if (ddl_command == "OPTIMIZE_TABLE") {
7028  stmt = new Parser::OptimizeTableStmt(payload);
7029  } else if (ddl_command == "COPY_TABLE") {
7030  stmt = new Parser::CopyTableStmt(payload);
7031  } else if (ddl_command == "EXPORT_QUERY") {
7032  stmt = new Parser::ExportQueryStmt(payload);
7033  } else if (ddl_command == "CREATE_VIEW") {
7034  stmt = new Parser::CreateViewStmt(payload);
7035  } else if (ddl_command == "DROP_VIEW") {
7036  stmt = new Parser::DropViewStmt(payload);
7037  } else if (ddl_command == "CREATE_DB") {
7038  stmt = new Parser::CreateDBStmt(payload);
7039  } else if (ddl_command == "DROP_DB") {
7040  stmt = new Parser::DropDBStmt(payload);
7041  } else if (ddl_command == "RENAME_DB") {
7042  stmt = new Parser::RenameDBStmt(payload);
7043  } else if (ddl_command == "CREATE_USER") {
7044  stmt = new Parser::CreateUserStmt(payload);
7045  } else if (ddl_command == "DROP_USER") {
7046  stmt = new Parser::DropUserStmt(payload);
7047  } else if (ddl_command == "ALTER_USER") {
7048  stmt = new Parser::AlterUserStmt(payload);
7049  } else if (ddl_command == "RENAME_USER") {
7050  stmt = new Parser::RenameUserStmt(payload);
7051  } else if (ddl_command == "CREATE_ROLE") {
7052  stmt = new Parser::CreateRoleStmt(payload);
7053  } else if (ddl_command == "DROP_ROLE") {
7054  stmt = new Parser::DropRoleStmt(payload);
7055  } else if (ddl_command == "GRANT_ROLE") {
7056  stmt = new Parser::GrantRoleStmt(payload);
7057  } else if (ddl_command == "REVOKE_ROLE") {
7058  stmt = new Parser::RevokeRoleStmt(payload);
7059  } else if (ddl_command == "GRANT_PRIVILEGE") {
7060  stmt = new Parser::GrantPrivilegesStmt(payload);
7061  } else if (ddl_command == "REVOKE_PRIVILEGE") {
7062  stmt = new Parser::RevokePrivilegesStmt(payload);
7063  } else if (ddl_command == "CREATE_DATAFRAME") {
7064  stmt = new Parser::CreateDataframeStmt(payload);
7065  } else if (ddl_command == "VALIDATE_SYSTEM") {
7066  // VALIDATE should have been excuted in outer context before it reaches here
7067  UNREACHABLE(); // not-implemented alterType
7068  } else {
7069  throw std::runtime_error("Unsupported DDL command");
7070  }
7071  return std::unique_ptr<Parser::Stmt>(stmt);
7072 }
#define UNREACHABLE()
Definition: Logger.h:337
#define CHECK(condition)
Definition: Logger.h:291
#define VLOG(n)
Definition: Logger.h:387
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 6968 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().

6970  {
6971  auto session_copy = session_info;
6972  auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
6973  &session_copy, boost::null_deleter());
6974  auto query_state = query_state::QueryState::create(session_ptr, queryStr);
6975  const auto& cat = session_info.getCatalog();
6976  auto calcite_mgr = cat.getCalciteMgr();
6977  const auto calciteQueryParsingOption =
6978  calcite_mgr->getCalciteQueryParsingOption(true, false, true);
6979  const auto calciteOptimizationOption = calcite_mgr->getCalciteOptimizationOption(
6980  false,
6982  {},
6984  const auto query_json = calcite_mgr
6985  ->process(query_state->createQueryStateProxy(),
6986  pg_shim(queryStr),
6987  calciteQueryParsingOption,
6988  calciteOptimizationOption)
6989  .plan_result;
6990  return create_stmt_for_json(query_json);
6991 }
std::string cat(Ts &&...args)
static std::shared_ptr< QueryState > create(ARGS &&...args)
Definition: QueryState.h:148
static SysCatalog & instance()
Definition: SysCatalog.h:343
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 5790 of file ParserNode.cpp.

References DashboardDBObjectType.

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

5790  {
5791  if (objectType == DashboardDBObjectType) {
5792  int32_t dashboard_id = -1;
5793  if (!objectName.empty()) {
5794  try {
5795  dashboard_id = stoi(objectName);
5796  } catch (const std::exception&) {
5797  throw std::runtime_error(
5798  "Privileges on dashboards should be changed via integer dashboard ID");
5799  }
5800  }
5801  return DBObject(dashboard_id, objectType);
5802  } else {
5803  return DBObject(objectName, objectType);
5804  }
5805 }

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

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

7077  {
7078  std::unique_ptr<Parser::Stmt> stmt = create_stmt_for_json(query_json);
7079  auto ddl = dynamic_cast<Parser::DDLStmt*>(stmt.get());
7080  if (ddl != nullptr) {
7081  (*ddl).execute(*session_ptr, read_only_mode);
7082  }
7083 }
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 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:291

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

References splitObjectHierName().

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

5655  {
5656  std::string objectName;
5657  std::vector<std::string> componentNames = splitObjectHierName(objectHierName);
5658  if (objectType.compare("DATABASE") == 0) {
5659  if (componentNames.size() == 1) {
5660  objectName = componentNames[0];
5661  } else {
5662  throw std::runtime_error("DB object name is not correct " + objectHierName);
5663  }
5664  } else {
5665  if (objectType.compare("TABLE") == 0 || objectType.compare("DASHBOARD") == 0 ||
5666  objectType.compare("VIEW") == 0 || objectType.compare("SERVER") == 0) {
5667  switch (componentNames.size()) {
5668  case (1): {
5669  objectName = componentNames[0];
5670  break;
5671  }
5672  case (2): {
5673  objectName = componentNames[1];
5674  break;
5675  }
5676  default: {
5677  throw std::runtime_error("DB object name is not correct " + objectHierName);
5678  }
5679  }
5680  } else {
5681  throw std::runtime_error("DB object type " + objectType + " is not supported.");
5682  }
5683  }
5684  return objectName;
5685 }
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_compression(), SQLTypeInfo::getStringDictKey(), SQLTypeInfo::is_string(), and kENCODING_DICT.

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_dict_key = lhs_type_info.getStringDictKey();
332  const auto& rhs_dict_key = rhs_type_info.getStringDictKey();
333  CHECK_NE(lhs_dict_key, rhs_dict_key);
334  if (lhs_dict_key.isTransientDict()) {
335  return rhs_type_info;
336  }
337  if (rhs_dict_key.isTransientDict()) {
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_dict_key, true);
343  const auto rhs_sdp = executor->getStringDictionaryProxy(rhs_dict_key, true);
344  return lhs_sdp->entryCount() >= rhs_sdp->entryCount() ? lhs_type_info : rhs_type_info;
345 }
#define CHECK_NE(x, y)
Definition: Logger.h:302
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:389
#define CHECK(condition)
Definition: Logger.h:291
bool is_string() const
Definition: sqltypes.h:580
const shared::StringDictKey & getStringDictKey() const
Definition: sqltypes.h:1021

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

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

3405  {},
3406  bool allow_interrupt = false) {
3407  auto const session = query_state_proxy->getConstSessionInfo();
3408  auto& catalog = session->getCatalog();
3409 
3411 #ifdef HAVE_CUDA
3412  const auto device_type = session->get_executor_device_type();
3413 #else
3414  const auto device_type = ExecutorDeviceType::CPU;
3415 #endif // HAVE_CUDA
3416  auto calcite_mgr = catalog.getCalciteMgr();
3417 
3418  // TODO MAT this should actually get the global or the session parameter for
3419  // view optimization
3420  const auto calciteQueryParsingOption =
3421  calcite_mgr->getCalciteQueryParsingOption(true, false, true);
3422  const auto calciteOptimizationOption = calcite_mgr->getCalciteOptimizationOption(
3423  false,
3425  {},
3427  const auto query_ra = calcite_mgr
3428  ->process(query_state_proxy,
3429  pg_shim(select_stmt),
3430  calciteQueryParsingOption,
3431  calciteOptimizationOption)
3432  .plan_result;
3433  RelAlgExecutor ra_executor(
3434  executor.get(), query_ra, query_state_proxy->shared_from_this());
3436  // TODO(adb): Need a better method of dropping constants into this ExecutionOptions
3437  // struct
3438  ExecutionOptions eo = {false,
3439  false,
3440  true,
3441  false,
3442  true,
3443  false,
3444  false,
3445  validate_only,
3446  false,
3447  10000,
3448  false,
3449  false,
3450  1000,
3451  allow_interrupt,
3455  std::numeric_limits<size_t>::max(),
3457  outer_fragment_indices};
3458 
3459  ExecutionResult result{std::make_shared<ResultSet>(std::vector<TargetInfo>{},
3462  nullptr,
3463  0,
3464  0),
3465  {}};
3466  result = ra_executor.executeRelAlgQuery(co, eo, false, nullptr);
3467  targets = result.getTargetsMeta();
3468 
3469  return result.getRows();
3470 }
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:475
static SysCatalog & instance()
Definition: SysCatalog.h:343
bool g_enable_watchdog
bool g_optimize_cuda_block_and_grid_sizes
Definition: Execute.cpp:157
static CompilationOptions defaults(const ExecutorDeviceType device_type=ExecutorDeviceType::GPU)
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:84
std::string pg_shim(const std::string &query)
static const ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:373

+ 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:248
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 1554 of file ParserNode.h.

References CHECK.

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

1555  {
1556  CHECK(l);
1557  for (auto str : *l) {
1558  v.push_back(*str);
1559  delete str;
1560  }
1561  delete l;
1562 }
#define CHECK(condition)
Definition: Logger.h:291

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

5690  {
5691  static const std::map<std::pair<const std::string, const DBObjectType>,
5692  std::pair<const AccessPrivileges, const DBObjectType>>
5693  privileges_lookup{
5694  {{"ALL"s, DatabaseDBObjectType},
5697  {{"ALL"s, DashboardDBObjectType},
5700  {{"ALL"s, ServerDBObjectType},
5702 
5703  {{"CREATE TABLE"s, DatabaseDBObjectType},
5705  {{"CREATE"s, DatabaseDBObjectType},
5707  {{"SELECT"s, DatabaseDBObjectType},
5709  {{"INSERT"s, DatabaseDBObjectType},
5711  {{"TRUNCATE"s, DatabaseDBObjectType},
5713  {{"UPDATE"s, DatabaseDBObjectType},
5715  {{"DELETE"s, DatabaseDBObjectType},
5717  {{"DROP"s, DatabaseDBObjectType},
5719  {{"ALTER"s, DatabaseDBObjectType},
5721 
5722  {{"SELECT"s, TableDBObjectType},
5724  {{"INSERT"s, TableDBObjectType},
5726  {{"TRUNCATE"s, TableDBObjectType},
5728  {{"UPDATE"s, TableDBObjectType},
5730  {{"DELETE"s, TableDBObjectType},
5732  {{"DROP"s, TableDBObjectType},
5734  {{"ALTER"s, TableDBObjectType},
5736 
5737  {{"CREATE VIEW"s, DatabaseDBObjectType},
5739  {{"SELECT VIEW"s, DatabaseDBObjectType},
5741  {{"DROP VIEW"s, DatabaseDBObjectType},
5743  {{"SELECT"s, ViewDBObjectType},
5746 
5747  {{"CREATE DASHBOARD"s, DatabaseDBObjectType},
5749  {{"EDIT DASHBOARD"s, DatabaseDBObjectType},
5751  {{"VIEW DASHBOARD"s, DatabaseDBObjectType},
5753  {{"DELETE DASHBOARD"s, DatabaseDBObjectType},
5755  {{"VIEW"s, DashboardDBObjectType},
5757  {{"EDIT"s, DashboardDBObjectType},
5759  {{"DELETE"s, DashboardDBObjectType},
5761 
5762  {{"CREATE SERVER"s, DatabaseDBObjectType},
5764  {{"DROP SERVER"s, DatabaseDBObjectType},
5766  {{"DROP"s, ServerDBObjectType},
5768  {{"ALTER SERVER"s, DatabaseDBObjectType},
5770  {{"ALTER"s, ServerDBObjectType},
5772  {{"USAGE"s, ServerDBObjectType},
5774  {{"SERVER USAGE"s, DatabaseDBObjectType},
5776 
5777  {{"VIEW SQL EDITOR"s, DatabaseDBObjectType},
5779  {{"ACCESS"s, DatabaseDBObjectType},
5781 
5782  auto result = privileges_lookup.find(std::make_pair(privs, objectType));
5783  if (result == privileges_lookup.end()) {
5784  throw std::runtime_error("Privileges " + privs + " on DB object " + object_name +
5785  " are not correct.");
5786  }
5787  return result->second;
5788 }
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 6635 of file ParserNode.cpp.

References CHECK.

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

6636  {
6637  CHECK(p);
6638  const std::string* str =
6639  static_cast<const StringLiteral*>(p->get_value())->get_stringval();
6640  if (boost::iequals(*str, "true")) {
6641  return true;
6642  } else if (boost::iequals(*str, "false")) {
6643  return false;
6644  } else {
6645  throw std::runtime_error("Value to " + option_name + " must be TRUE or FALSE.");
6646  }
6647 }
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

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

Definition at line 4710 of file ParserNode.cpp.

References CHECK.

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

4710  {
4711  for (const auto& opt : options) {
4712  if (boost::iequals(*opt->get_name(), "REPAIR_TYPE")) {
4713  const auto repair_type =
4714  static_cast<const StringLiteral*>(opt->get_value())->get_stringval();
4715  CHECK(repair_type);
4716  if (boost::iequals(*repair_type, "REMOVE")) {
4717  return true;
4718  } else {
4719  throw std::runtime_error("REPAIR_TYPE must be REMOVE.");
4720  }
4721  } else {
4722  throw std::runtime_error("The only VALIDATE WITH options is REPAIR_TYPE.");
4723  }
4724  }
4725  return false;
4726 }
bool repair_type(std::list< std::unique_ptr< NameValueAssign >> &options)
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

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

Definition at line 5647 of file ParserNode.cpp.

References split().

Referenced by extractObjectNameFromHierName().

5647  {
5648  std::vector<std::string> componentNames;
5649  boost::split(componentNames, hierName, boost::is_any_of("."));
5650  return componentNames;
5651 }
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 5809 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().

5812  {
5813  if (objectType == TableDBObjectType) {
5814  auto td = sessionCatalog.getMetadataForTable(objectName, false);
5815  if (!td || td->isView) {
5816  // expected TABLE, found VIEW
5817  throw std::runtime_error(command + " failed. Object '" + objectName + "' of type " +
5818  DBObjectTypeToString(objectType) + " not found.");
5819  }
5820 
5821  } else if (objectType == ViewDBObjectType) {
5822  auto td = sessionCatalog.getMetadataForTable(objectName, false);
5823  if (!td || !td->isView) {
5824  // expected VIEW, found TABLE
5825  throw std::runtime_error(command + " failed. Object '" + objectName + "' of type " +
5826  DBObjectTypeToString(objectType) + " not found.");
5827  }
5828  }
5829 }
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: