OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parser::anonymous_namespace{ParserNode.cpp} Namespace Reference

Functions

bool expr_is_null (const Analyzer::Expr *expr)
 
bool bool_from_string_literal (const Parser::StringLiteral *str_literal)
 
std::string unescape (std::string s)
 
void parse_options (const rapidjson::Value &payload, std::list< std::unique_ptr< NameValueAssign >> &nameValueList, bool stringToNull=false, bool stringToInteger=false)
 
void validate_shard_column_type (const ColumnDescriptor &cd)
 
size_t shard_column_index (const std::string &name, const std::list< ColumnDescriptor > &columns)
 
size_t sort_column_index (const std::string &name, const std::list< ColumnDescriptor > &columns)
 
void set_string_field (rapidjson::Value &obj, const std::string &field_name, const std::string &field_value, rapidjson::Document &document)
 
std::string serialize_key_metainfo (const ShardKeyDef *shard_key_def, const std::vector< SharedDictionaryDef > &shared_dict_defs)
 
template<typename LITERAL_TYPE , typename ASSIGNMENT , typename VALIDATE = DefaultValidate<LITERAL_TYPE>>
decltype(auto) get_property_value (const NameValueAssign *p, ASSIGNMENT op, VALIDATE validate=VALIDATE())
 
decltype(auto) get_storage_type (TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
 
decltype(auto) get_frag_size_def (TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
 
decltype(auto) get_frag_size_dataframe_def (DataframeTableDescriptor &df_td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
 
decltype(auto) get_max_chunk_size_def (TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
 
decltype(auto) get_max_chunk_size_dataframe_def (DataframeTableDescriptor &df_td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
 
decltype(auto) get_delimiter_def (DataframeTableDescriptor &df_td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
 
decltype(auto) get_header_def (DataframeTableDescriptor &df_td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
 
decltype(auto) get_page_size_def (TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
 
decltype(auto) get_max_rows_def (TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
 
decltype(auto) get_skip_rows_def (DataframeTableDescriptor &df_td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
 
decltype(auto) get_partions_def (TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
 
decltype(auto) get_shard_count_def (TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
 
decltype(auto) get_vacuum_def (TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
 
decltype(auto) get_sort_column_def (TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
 
decltype(auto) get_max_rollback_epochs_def (TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
 
void get_table_definitions (TableDescriptor &td, const std::unique_ptr< NameValueAssign > &p, const std::list< ColumnDescriptor > &columns)
 
void get_table_definitions_for_ctas (TableDescriptor &td, const std::unique_ptr< NameValueAssign > &p, const std::list< ColumnDescriptor > &columns)
 
void get_dataframe_definitions (DataframeTableDescriptor &df_td, const std::unique_ptr< NameValueAssign > &p, const std::list< ColumnDescriptor > &columns)
 
std::unique_ptr< ColumnDefcolumn_from_json (const rapidjson::Value &element)
 
void parse_elements (const rapidjson::Value &payload, std::string element_name, std::string &table_name, std::list< std::unique_ptr< TableElement >> &table_element_list)
 
bool user_can_access_table (const Catalog_Namespace::SessionInfo &session_info, const TableDescriptor *td, const AccessPrivileges access_priv)
 
std::string generateUniqueTableName (std::string name)
 
void recordRename (SubstituteMap &sMap, std::string oldName, std::string newName)
 
std::string loadTable (Catalog_Namespace::Catalog &catalog, SubstituteMap &sMap, std::string tableName)
 
bool hasData (SubstituteMap &sMap, std::string tableName)
 
void checkNameSubstition (SubstituteMap &sMap)
 
void disable_foreign_tables (const TableDescriptor *td)
 

Variables

static const std::map< const
std::string, const
TableDefFuncPtr
tableDefFuncMap
 
static const std::map< const
std::string, const
DataframeDefFuncPtr
dataframeDefFuncMap
 
static constexpr char constEMPTY_NAME {""}
 

Function Documentation

bool Parser::anonymous_namespace{ParserNode.cpp}::bool_from_string_literal ( const Parser::StringLiteral str_literal)

Definition at line 950 of file ParserNode.cpp.

References Parser::StringLiteral::get_stringval().

Referenced by Parser::CopyTableStmt::execute(), and Parser::ExportQueryStmt::parseOptions().

950  {
951  const std::string* s = str_literal->get_stringval();
952  if (*s == "t" || *s == "true" || *s == "T" || *s == "True") {
953  return true;
954  } else if (*s == "f" || *s == "false" || *s == "F" || *s == "False") {
955  return false;
956  } else {
957  throw std::runtime_error("Invalid string for boolean " + *s);
958  }
959 }
const std::string * get_stringval() const
Definition: ParserNode.h:136

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Parser::anonymous_namespace{ParserNode.cpp}::checkNameSubstition ( SubstituteMap &  sMap)

Definition at line 4136 of file ParserNode.cpp.

References EMPTY_NAME.

Referenced by Parser::RenameTableStmt::execute().

4136  {
4137  // Substition map should be clean at end of rename:
4138  // all items in map must (map to self) or (map to EMPTY_STRING) by end
4139 
4140  for (auto it : sMap) {
4141  if ((it.second) != EMPTY_NAME && (it.first) != (it.second)) {
4142  throw std::runtime_error(
4143  "Error: Attempted to overwrite and lose data in table: \'" + (it.first) + "\'");
4144  }
4145  }
4146 }
static constexpr char const * EMPTY_NAME

+ Here is the caller graph for this function:

std::unique_ptr<ColumnDef> Parser::anonymous_namespace{ParserNode.cpp}::column_from_json ( const rapidjson::Value &  element)

Definition at line 2354 of file ParserNode.cpp.

References CHECK, json_bool(), json_i64(), json_str(), and to_sql_type().

Referenced by Parser::AlterTableStmt::delegate(), and parse_elements().

2354  {
2355  CHECK(element.HasMember("name"));
2356  auto col_name = std::make_unique<std::string>(json_str(element["name"]));
2357  CHECK(element.HasMember("sqltype"));
2358  const auto sql_types = to_sql_type(json_str(element["sqltype"]));
2359 
2360  // decimal / numeric precision / scale
2361  int precision = -1;
2362  int scale = -1;
2363  if (element.HasMember("precision")) {
2364  precision = json_i64(element["precision"]);
2365  }
2366  if (element.HasMember("scale")) {
2367  scale = json_i64(element["scale"]);
2368  }
2369 
2370  std::optional<int64_t> array_size;
2371  if (element.HasMember("arraySize")) {
2372  // We do not yet support geo arrays
2373  array_size = json_i64(element["arraySize"]);
2374  }
2375  std::unique_ptr<SQLType> sql_type;
2376  if (element.HasMember("subtype")) {
2377  CHECK(element.HasMember("coordinateSystem"));
2378  const auto subtype_sql_types = to_sql_type(json_str(element["subtype"]));
2379  sql_type =
2380  std::make_unique<SQLType>(subtype_sql_types,
2381  static_cast<int>(sql_types),
2382  static_cast<int>(json_i64(element["coordinateSystem"])),
2383  false);
2384  } else if (precision > 0 && scale > 0) {
2385  sql_type = std::make_unique<SQLType>(sql_types,
2386  precision,
2387  scale,
2388  /*is_array=*/array_size.has_value(),
2389  array_size ? *array_size : -1);
2390  } else if (precision > 0) {
2391  sql_type = std::make_unique<SQLType>(sql_types,
2392  precision,
2393  0,
2394  /*is_array=*/array_size.has_value(),
2395  array_size ? *array_size : -1);
2396  } else {
2397  sql_type = std::make_unique<SQLType>(sql_types,
2398  /*is_array=*/array_size.has_value(),
2399  array_size ? *array_size : -1);
2400  }
2401  CHECK(sql_type);
2402 
2403  CHECK(element.HasMember("nullable"));
2404  const auto nullable = json_bool(element["nullable"]);
2405  std::unique_ptr<ColumnConstraintDef> constraint_def;
2406  StringLiteral* str_literal = nullptr;
2407  if (element.HasMember("default") && !element["default"].IsNull()) {
2408  std::string* defaultval = new std::string(json_str(element["default"]));
2409  boost::algorithm::trim_if(*defaultval, boost::is_any_of(" \"'`"));
2410  str_literal = new StringLiteral(defaultval);
2411  }
2412 
2413  constraint_def = std::make_unique<ColumnConstraintDef>(/*notnull=*/!nullable,
2414  /*unique=*/false,
2415  /*primarykey=*/false,
2416  /*defaultval=*/str_literal);
2417  std::unique_ptr<CompressDef> compress_def;
2418  if (element.HasMember("encodingType") && !element["encodingType"].IsNull()) {
2419  std::string encoding_type = json_str(element["encodingType"]);
2420  CHECK(element.HasMember("encodingSize"));
2421  auto encoding_name = std::make_unique<std::string>(json_str(element["encodingType"]));
2422  compress_def = std::make_unique<CompressDef>(encoding_name.release(),
2423  json_i64(element["encodingSize"]));
2424  }
2425  return std::make_unique<ColumnDef>(col_name.release(),
2426  sql_type.release(),
2427  compress_def ? compress_def.release() : nullptr,
2428  constraint_def ? constraint_def.release() : nullptr);
2429 }
SQLTypes to_sql_type(const std::string &type_name)
const bool json_bool(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:49
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
const int64_t json_i64(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:39
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Parser::anonymous_namespace{ParserNode.cpp}::disable_foreign_tables ( const TableDescriptor td)

Definition at line 4150 of file ParserNode.cpp.

References StorageType::FOREIGN_TABLE, TableDescriptor::storageType, and TableDescriptor::tableName.

Referenced by Parser::RenameTableStmt::execute().

4150  {
4152  throw std::runtime_error(td->tableName + " is a foreign table. " +
4153  "Use ALTER FOREIGN TABLE.");
4154  }
4155 }
std::string tableName
std::string storageType
static constexpr char const * FOREIGN_TABLE

+ Here is the caller graph for this function:

bool Parser::anonymous_namespace{ParserNode.cpp}::expr_is_null ( const Analyzer::Expr expr)

Definition at line 942 of file ParserNode.cpp.

References Analyzer::Constant::get_is_null(), SQLTypeInfo::get_type(), Analyzer::Expr::get_type_info(), and kNULLT.

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

942  {
943  if (expr->get_type_info().get_type() == kNULLT) {
944  return true;
945  }
946  const auto const_expr = dynamic_cast<const Analyzer::Constant*>(expr);
947  return const_expr && const_expr->get_is_null();
948 }
bool get_is_null() const
Definition: Analyzer.h:333
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:77

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string Parser::anonymous_namespace{ParserNode.cpp}::generateUniqueTableName ( std::string  name)

Definition at line 4101 of file ParserNode.cpp.

References run_benchmark_import::result, and to_string().

Referenced by Parser::RenameTableStmt::execute().

4101  {
4102  // TODO - is there a "better" way to create a tmp name for the table
4103  std::time_t result = std::time(nullptr);
4104  return name + "_tmp" + std::to_string(result);
4105 }
string name
Definition: setup.in.py:72
std::string to_string(char const *&&v)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Parser::anonymous_namespace{ParserNode.cpp}::get_dataframe_definitions ( DataframeTableDescriptor df_td,
const std::unique_ptr< NameValueAssign > &  p,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2341 of file ParserNode.cpp.

Referenced by Parser::CreateDataframeStmt::execute().

2343  {
2344  const auto it =
2345  dataframeDefFuncMap.find(boost::to_lower_copy<std::string>(*p->get_name()));
2346  if (it == dataframeDefFuncMap.end()) {
2347  throw std::runtime_error(
2348  "Invalid CREATE DATAFRAME option " + *p->get_name() +
2349  ". Should be FRAGMENT_SIZE, MAX_CHUNK_SIZE, SKIP_ROWS, DELIMITER or HEADER.");
2350  }
2351  return it->second(df_td, p.get(), columns);
2352 }
static const std::map< const std::string, const DataframeDefFuncPtr > dataframeDefFuncMap

+ Here is the caller graph for this function:

decltype(auto) Parser::anonymous_namespace{ParserNode.cpp}::get_delimiter_def ( DataframeTableDescriptor df_td,
const NameValueAssign *  p,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2181 of file ParserNode.cpp.

2183  {
2184  return get_property_value<StringLiteral>(p, [&df_td](const auto val) {
2185  if (val.size() != 1) {
2186  throw std::runtime_error("Length of DELIMITER must be equal to 1.");
2187  }
2188  df_td.delimiter = val;
2189  });
2190 }
decltype(auto) Parser::anonymous_namespace{ParserNode.cpp}::get_frag_size_dataframe_def ( DataframeTableDescriptor df_td,
const NameValueAssign *  p,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2159 of file ParserNode.cpp.

2161  {
2162  return get_property_value<IntLiteral>(
2163  p, [&df_td](const auto val) { df_td.maxFragRows = val; });
2164 }
decltype(auto) Parser::anonymous_namespace{ParserNode.cpp}::get_frag_size_def ( TableDescriptor td,
const NameValueAssign *  p,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2152 of file ParserNode.cpp.

2154  {
2155  return get_property_value<IntLiteral>(p,
2156  [&td](const auto val) { td.maxFragRows = val; });
2157 }
decltype(auto) Parser::anonymous_namespace{ParserNode.cpp}::get_header_def ( DataframeTableDescriptor df_td,
const NameValueAssign *  p,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2192 of file ParserNode.cpp.

2194  {
2195  return get_property_value<StringLiteral>(p, [&df_td](const auto val) {
2196  if (val == "FALSE") {
2197  df_td.hasHeader = false;
2198  } else if (val == "TRUE") {
2199  df_td.hasHeader = true;
2200  } else {
2201  throw std::runtime_error("Option HEADER support only 'true' or 'false' values.");
2202  }
2203  });
2204 }
decltype(auto) Parser::anonymous_namespace{ParserNode.cpp}::get_max_chunk_size_dataframe_def ( DataframeTableDescriptor df_td,
const NameValueAssign *  p,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2173 of file ParserNode.cpp.

2176  {
2177  return get_property_value<IntLiteral>(
2178  p, [&df_td](const auto val) { df_td.maxChunkSize = val; });
2179 }
decltype(auto) Parser::anonymous_namespace{ParserNode.cpp}::get_max_chunk_size_def ( TableDescriptor td,
const NameValueAssign *  p,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2166 of file ParserNode.cpp.

2168  {
2169  return get_property_value<IntLiteral>(p,
2170  [&td](const auto val) { td.maxChunkSize = val; });
2171 }
decltype(auto) Parser::anonymous_namespace{ParserNode.cpp}::get_max_rollback_epochs_def ( TableDescriptor td,
const NameValueAssign *  p,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2280 of file ParserNode.cpp.

2282  {
2283  auto assignment = [&td](const auto val) {
2284  td.maxRollbackEpochs =
2285  val < 0 ? -1 : val; // Anything < 0 means unlimited rollbacks. Note that 0
2286  // still means keeping a shadow copy of data/metdata
2287  // between epochs so bad writes can be rolled back
2288  };
2289  return get_property_value<IntLiteral, decltype(assignment), PositiveOrZeroValidate>(
2290  p, assignment);
2291 }
int32_t maxRollbackEpochs
decltype(auto) Parser::anonymous_namespace{ParserNode.cpp}::get_max_rows_def ( TableDescriptor td,
const NameValueAssign *  p,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2212 of file ParserNode.cpp.

2214  {
2215  return get_property_value<IntLiteral>(p, [&td](const auto val) { td.maxRows = val; });
2216 }
decltype(auto) Parser::anonymous_namespace{ParserNode.cpp}::get_page_size_def ( TableDescriptor td,
const NameValueAssign *  p,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2206 of file ParserNode.cpp.

2208  {
2209  return get_property_value<IntLiteral>(p,
2210  [&td](const auto val) { td.fragPageSize = val; });
2211 }
decltype(auto) Parser::anonymous_namespace{ParserNode.cpp}::get_partions_def ( TableDescriptor td,
const NameValueAssign *  p,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2225 of file ParserNode.cpp.

2227  {
2228  return get_property_value<StringLiteral>(p, [&td](const auto partitions_uc) {
2229  if (partitions_uc != "SHARDED" && partitions_uc != "REPLICATED") {
2230  throw std::runtime_error("PARTITIONS must be SHARDED or REPLICATED");
2231  }
2232  if (td.shardedColumnId != 0 && partitions_uc == "REPLICATED") {
2233  throw std::runtime_error(
2234  "A table cannot be sharded and replicated at the same time");
2235  };
2236  td.partitions = partitions_uc;
2237  });
2238 }
std::string partitions
template<typename LITERAL_TYPE , typename ASSIGNMENT , typename VALIDATE = DefaultValidate<LITERAL_TYPE>>
decltype(auto) Parser::anonymous_namespace{ParserNode.cpp}::get_property_value ( const NameValueAssign *  p,
ASSIGNMENT  op,
VALIDATE  validate = VALIDATE() 
)

Definition at line 2137 of file ParserNode.cpp.

2139  {
2140  const auto val = validate(p);
2141  return op(val);
2142 }
decltype(auto) Parser::anonymous_namespace{ParserNode.cpp}::get_shard_count_def ( TableDescriptor td,
const NameValueAssign *  p,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2239 of file ParserNode.cpp.

References g_leaf_count.

2241  {
2242  if (!td.shardedColumnId) {
2243  throw std::runtime_error("SHARD KEY must be defined.");
2244  }
2245  return get_property_value<IntLiteral>(p, [&td](const auto shard_count) {
2246  if (g_leaf_count && shard_count % g_leaf_count) {
2247  throw std::runtime_error(
2248  "SHARD_COUNT must be a multiple of the number of leaves in the cluster.");
2249  }
2250  td.nShards = g_leaf_count ? shard_count / g_leaf_count : shard_count;
2251  if (!td.shardedColumnId && !td.nShards) {
2252  throw std::runtime_error(
2253  "Must specify the number of shards through the SHARD_COUNT option");
2254  };
2255  });
2256 }
size_t g_leaf_count
Definition: ParserNode.cpp:78
decltype(auto) Parser::anonymous_namespace{ParserNode.cpp}::get_skip_rows_def ( DataframeTableDescriptor df_td,
const NameValueAssign *  p,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2218 of file ParserNode.cpp.

2220  {
2221  return get_property_value<IntLiteral>(
2222  p, [&df_td](const auto val) { df_td.skipRows = val; });
2223 }
decltype(auto) Parser::anonymous_namespace{ParserNode.cpp}::get_sort_column_def ( TableDescriptor td,
const NameValueAssign *  p,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2269 of file ParserNode.cpp.

References sort_column_index().

2271  {
2272  return get_property_value<StringLiteral>(p, [&td, &columns](const auto sort_upper) {
2273  td.sortedColumnId = sort_column_index(sort_upper, columns);
2274  if (!td.sortedColumnId) {
2275  throw std::runtime_error("Specified sort column " + sort_upper + " doesn't exist");
2276  }
2277  });
2278 }
size_t sort_column_index(const std::string &name, const std::list< ColumnDescriptor > &columns)

+ Here is the call graph for this function:

decltype(auto) Parser::anonymous_namespace{ParserNode.cpp}::get_storage_type ( TableDescriptor td,
const NameValueAssign *  p,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2144 of file ParserNode.cpp.

2146  {
2147  auto assignment = [&td](const auto val) { td.storageType = val; };
2148  return get_property_value<StringLiteral, decltype(assignment), CaseSensitiveValidate>(
2149  p, assignment);
2150 }
std::string storageType
void Parser::anonymous_namespace{ParserNode.cpp}::get_table_definitions ( TableDescriptor td,
const std::unique_ptr< NameValueAssign > &  p,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2305 of file ParserNode.cpp.

Referenced by Parser::CreateTableStmt::executeDryRun().

2307  {
2308  const auto it = tableDefFuncMap.find(boost::to_lower_copy<std::string>(*p->get_name()));
2309  if (it == tableDefFuncMap.end()) {
2310  throw std::runtime_error(
2311  "Invalid CREATE TABLE option " + *p->get_name() +
2312  ". Should be FRAGMENT_SIZE, MAX_CHUNK_SIZE, PAGE_SIZE, MAX_ROLLBACK_EPOCHS, "
2313  "MAX_ROWS, "
2314  "PARTITIONS, SHARD_COUNT, VACUUM, SORT_COLUMN, STORAGE_TYPE.");
2315  }
2316  return it->second(td, p.get(), columns);
2317 }
static const std::map< const std::string, const TableDefFuncPtr > tableDefFuncMap

+ Here is the caller graph for this function:

void Parser::anonymous_namespace{ParserNode.cpp}::get_table_definitions_for_ctas ( TableDescriptor td,
const std::unique_ptr< NameValueAssign > &  p,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2319 of file ParserNode.cpp.

Referenced by Parser::CreateTableAsSelectStmt::execute().

2321  {
2322  const auto it = tableDefFuncMap.find(boost::to_lower_copy<std::string>(*p->get_name()));
2323  if (it == tableDefFuncMap.end()) {
2324  throw std::runtime_error(
2325  "Invalid CREATE TABLE AS option " + *p->get_name() +
2326  ". Should be FRAGMENT_SIZE, MAX_CHUNK_SIZE, PAGE_SIZE, MAX_ROLLBACK_EPOCHS, "
2327  "MAX_ROWS, "
2328  "PARTITIONS, SHARD_COUNT, VACUUM, SORT_COLUMN, STORAGE_TYPE or "
2329  "USE_SHARED_DICTIONARIES.");
2330  }
2331  return it->second(td, p.get(), columns);
2332 }
static const std::map< const std::string, const TableDefFuncPtr > tableDefFuncMap

+ Here is the caller graph for this function:

decltype(auto) Parser::anonymous_namespace{ParserNode.cpp}::get_vacuum_def ( TableDescriptor td,
const NameValueAssign *  p,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2258 of file ParserNode.cpp.

2260  {
2261  return get_property_value<StringLiteral>(p, [&td](const auto vacuum_uc) {
2262  if (vacuum_uc != "IMMEDIATE" && vacuum_uc != "DELAYED") {
2263  throw std::runtime_error("VACUUM must be IMMEDIATE or DELAYED");
2264  }
2265  td.hasDeletedCol = boost::iequals(vacuum_uc, "IMMEDIATE") ? false : true;
2266  });
2267 }
bool Parser::anonymous_namespace{ParserNode.cpp}::hasData ( SubstituteMap &  sMap,
std::string  tableName 
)

Definition at line 4131 of file ParserNode.cpp.

References EMPTY_NAME.

Referenced by Parser::RenameTableStmt::execute().

4131  {
4132  // assumes loadTable has been previously called
4133  return (sMap[tableName] != EMPTY_NAME);
4134 }
static constexpr char const * EMPTY_NAME

+ Here is the caller graph for this function:

std::string Parser::anonymous_namespace{ParserNode.cpp}::loadTable ( Catalog_Namespace::Catalog catalog,
SubstituteMap &  sMap,
std::string  tableName 
)

Definition at line 4111 of file ParserNode.cpp.

References EMPTY_NAME, and Catalog_Namespace::Catalog::getMetadataForTable().

Referenced by Parser::RenameTableStmt::execute().

4113  {
4114  if (sMap.find(tableName) != sMap.end()) {
4115  if (sMap[tableName] == EMPTY_NAME) {
4116  return tableName;
4117  }
4118  return sMap[tableName];
4119  } else {
4120  // lookup table in src catalog
4121  const TableDescriptor* td = catalog.getMetadataForTable(tableName);
4122  if (td) {
4123  sMap[tableName] = tableName;
4124  } else {
4125  sMap[tableName] = EMPTY_NAME;
4126  }
4127  }
4128  return tableName;
4129 }
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.
static constexpr char const * EMPTY_NAME

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Parser::anonymous_namespace{ParserNode.cpp}::parse_elements ( const rapidjson::Value &  payload,
std::string  element_name,
std::string &  table_name,
std::list< std::unique_ptr< TableElement >> &  table_element_list 
)

Definition at line 2431 of file ParserNode.cpp.

References CHECK, column_from_json(), logger::FATAL, json_str(), and LOG.

Referenced by Parser::CreateDataframeStmt::CreateDataframeStmt(), and Parser::CreateTableStmt::CreateTableStmt().

2434  {
2435  const auto elements = payload[element_name].GetArray();
2436  for (const auto& element : elements) {
2437  CHECK(element.IsObject());
2438  CHECK(element.HasMember("type"));
2439  if (json_str(element["type"]) == "SQL_COLUMN_DECLARATION") {
2440  auto col_def = column_from_json(element);
2441  table_element_list.emplace_back(std::move(col_def));
2442  } else if (json_str(element["type"]) == "SQL_COLUMN_CONSTRAINT") {
2443  CHECK(element.HasMember("name"));
2444  if (json_str(element["name"]) == "SHARD_KEY") {
2445  CHECK(element.HasMember("columns"));
2446  CHECK(element["columns"].IsArray());
2447  const auto& columns = element["columns"].GetArray();
2448  if (columns.Size() != size_t(1)) {
2449  throw std::runtime_error("Only one shard column is currently supported.");
2450  }
2451  auto shard_key_def = std::make_unique<ShardKeyDef>(json_str(columns[0]));
2452  table_element_list.emplace_back(std::move(shard_key_def));
2453  } else if (json_str(element["name"]) == "SHARED_DICT") {
2454  CHECK(element.HasMember("columns"));
2455  CHECK(element["columns"].IsArray());
2456  const auto& columns = element["columns"].GetArray();
2457  if (columns.Size() != size_t(1)) {
2458  throw std::runtime_error(
2459  R"(Only one column per shared dictionary entry is currently supported. Use multiple SHARED DICT statements to share dictionaries from multiple columns.)");
2460  }
2461  CHECK(element.HasMember("references") && element["references"].IsObject());
2462  const auto& references = element["references"].GetObject();
2463  std::string references_table_name;
2464  if (references.HasMember("table")) {
2465  references_table_name = json_str(references["table"]);
2466  } else {
2467  references_table_name = table_name;
2468  }
2469  CHECK(references.HasMember("column"));
2470 
2471  auto shared_dict_def = std::make_unique<SharedDictionaryDef>(
2472  json_str(columns[0]), references_table_name, json_str(references["column"]));
2473  table_element_list.emplace_back(std::move(shared_dict_def));
2474 
2475  } else {
2476  LOG(FATAL) << "Unsupported type for SQL_COLUMN_CONSTRAINT: "
2477  << json_str(element["name"]);
2478  }
2479  } else {
2480  LOG(FATAL) << "Unsupported element type for CREATE TABLE: "
2481  << element["type"].GetString();
2482  }
2483  }
2484 }
#define LOG(tag)
Definition: Logger.h:203
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
std::unique_ptr< ColumnDef > column_from_json(const rapidjson::Value &element)
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Parser::anonymous_namespace{ParserNode.cpp}::parse_options ( const rapidjson::Value &  payload,
std::list< std::unique_ptr< NameValueAssign >> &  nameValueList,
bool  stringToNull = false,
bool  stringToInteger = false 
)

Definition at line 1287 of file ParserNode.cpp.

References CHECK, json_i64(), and unescape().

Referenced by Parser::AlterUserStmt::AlterUserStmt(), Parser::CopyTableStmt::CopyTableStmt(), Parser::CreateDataframeStmt::CreateDataframeStmt(), Parser::CreateDBStmt::CreateDBStmt(), Parser::CreateTableAsSelectStmt::CreateTableAsSelectStmt(), Parser::CreateTableStmt::CreateTableStmt(), Parser::CreateUserStmt::CreateUserStmt(), Parser::DumpRestoreTableStmtBase::DumpRestoreTableStmtBase(), Parser::ExportQueryStmt::ExportQueryStmt(), Parser::OptimizeTableStmt::OptimizeTableStmt(), and Parser::ValidateStmt::ValidateStmt().

1290  {
1291  if (payload.HasMember("options") && payload["options"].IsObject()) {
1292  for (const auto& option : payload["options"].GetObject()) {
1293  auto option_name = std::make_unique<std::string>(option.name.GetString());
1294  std::unique_ptr<Literal> literal_value;
1295  if (option.value.IsString()) {
1296  std::string str = option.value.GetString();
1297  if (stringToNull && str == "") {
1298  literal_value = std::make_unique<NullLiteral>();
1299  } else if (stringToInteger && std::all_of(str.begin(), str.end(), ::isdigit)) {
1300  int iVal = std::stoi(str);
1301  literal_value = std::make_unique<IntLiteral>(iVal);
1302  } else {
1303  // Rapidjson will deliberately provide escape'd strings when accessed
1304  // ... but the literal should have a copy of the raw unescaped string
1305  auto unique_literal_string = std::make_unique<std::string>(unescape(str));
1306  literal_value =
1307  std::make_unique<StringLiteral>(unique_literal_string.release());
1308  }
1309  } else if (option.value.IsInt() || option.value.IsInt64()) {
1310  literal_value = std::make_unique<IntLiteral>(json_i64(option.value));
1311  } else if (option.value.IsNull()) {
1312  literal_value = std::make_unique<NullLiteral>();
1313  } else {
1314  throw std::runtime_error("Unable to handle literal for " + *option_name);
1315  }
1316  CHECK(literal_value);
1317 
1318  nameValueList.emplace_back(std::make_unique<NameValueAssign>(
1319  option_name.release(), literal_value.release()));
1320  }
1321  }
1322 }
const int64_t json_i64(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:39
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Parser::anonymous_namespace{ParserNode.cpp}::recordRename ( SubstituteMap &  sMap,
std::string  oldName,
std::string  newName 
)

Definition at line 4107 of file ParserNode.cpp.

Referenced by Parser::RenameTableStmt::execute().

4107  {
4108  sMap[oldName] = newName;
4109 }

+ Here is the caller graph for this function:

std::string Parser::anonymous_namespace{ParserNode.cpp}::serialize_key_metainfo ( const ShardKeyDef *  shard_key_def,
const std::vector< SharedDictionaryDef > &  shared_dict_defs 
)

Definition at line 2104 of file ParserNode.cpp.

References Parser::ShardKeyDef::get_column(), and set_string_field().

Referenced by Parser::CreateDataframeStmt::execute(), Parser::CreateTableAsSelectStmt::execute(), and Parser::CreateTableStmt::executeDryRun().

2106  {
2107  rapidjson::Document document;
2108  auto& allocator = document.GetAllocator();
2109  rapidjson::Value arr(rapidjson::kArrayType);
2110  if (shard_key_def) {
2111  rapidjson::Value shard_key_obj(rapidjson::kObjectType);
2112  set_string_field(shard_key_obj, "type", "SHARD KEY", document);
2113  set_string_field(shard_key_obj, "name", shard_key_def->get_column(), document);
2114  arr.PushBack(shard_key_obj, allocator);
2115  }
2116  for (const auto& shared_dict_def : shared_dict_defs) {
2117  rapidjson::Value shared_dict_obj(rapidjson::kObjectType);
2118  set_string_field(shared_dict_obj, "type", "SHARED DICTIONARY", document);
2119  set_string_field(shared_dict_obj, "name", shared_dict_def.get_column(), document);
2121  shared_dict_obj, "foreign_table", shared_dict_def.get_foreign_table(), document);
2122  set_string_field(shared_dict_obj,
2123  "foreign_column",
2124  shared_dict_def.get_foreign_column(),
2125  document);
2126  arr.PushBack(shared_dict_obj, allocator);
2127  }
2128  rapidjson::StringBuffer buffer;
2129  rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
2130  arr.Accept(writer);
2131  return buffer.GetString();
2132 }
void set_string_field(rapidjson::Value &obj, const std::string &field_name, const std::string &field_value, rapidjson::Document &document)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Parser::anonymous_namespace{ParserNode.cpp}::set_string_field ( rapidjson::Value &  obj,
const std::string &  field_name,
const std::string &  field_value,
rapidjson::Document &  document 
)

Definition at line 2091 of file ParserNode.cpp.

Referenced by serialize_key_metainfo().

2094  {
2095  rapidjson::Value field_name_json_str;
2096  field_name_json_str.SetString(
2097  field_name.c_str(), field_name.size(), document.GetAllocator());
2098  rapidjson::Value field_value_json_str;
2099  field_value_json_str.SetString(
2100  field_value.c_str(), field_value.size(), document.GetAllocator());
2101  obj.AddMember(field_name_json_str, field_value_json_str, document.GetAllocator());
2102 }

+ Here is the caller graph for this function:

size_t Parser::anonymous_namespace{ParserNode.cpp}::shard_column_index ( const std::string &  name,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2058 of file ParserNode.cpp.

References validate_shard_column_type().

Referenced by Parser::CreateTableStmt::executeDryRun().

2059  {
2060  size_t index = 1;
2061  for (const auto& cd : columns) {
2062  if (cd.columnName == name) {
2064  return index;
2065  }
2066  ++index;
2067  if (cd.columnType.is_geometry()) {
2068  index += cd.columnType.get_physical_cols();
2069  }
2070  }
2071  // Not found, return 0
2072  return 0;
2073 }
string name
Definition: setup.in.py:72
void validate_shard_column_type(const ColumnDescriptor &cd)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t Parser::anonymous_namespace{ParserNode.cpp}::sort_column_index ( const std::string &  name,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2075 of file ParserNode.cpp.

Referenced by get_sort_column_def().

2076  {
2077  size_t index = 1;
2078  for (const auto& cd : columns) {
2079  if (boost::to_upper_copy<std::string>(cd.columnName) == name) {
2080  return index;
2081  }
2082  ++index;
2083  if (cd.columnType.is_geometry()) {
2084  index += cd.columnType.get_physical_cols();
2085  }
2086  }
2087  // Not found, return 0
2088  return 0;
2089 }
string name
Definition: setup.in.py:72

+ Here is the caller graph for this function:

std::string Parser::anonymous_namespace{ParserNode.cpp}::unescape ( std::string  s)

Definition at line 1279 of file ParserNode.cpp.

Referenced by omnisci._samlutils::get_saml_response(), and parse_options().

1279  {
1280  boost::replace_all(s, "\\\\t", "\t");
1281  boost::replace_all(s, "\\t", "\t");
1282  boost::replace_all(s, "\\\\n", "\n");
1283  boost::replace_all(s, "\\n", "\n");
1284  return s;
1285 }

+ Here is the caller graph for this function:

bool Parser::anonymous_namespace{ParserNode.cpp}::user_can_access_table ( const Catalog_Namespace::SessionInfo session_info,
const TableDescriptor td,
const AccessPrivileges  access_priv 
)

Definition at line 3917 of file ParserNode.cpp.

References cat(), CHECK, Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::SessionInfo::getCatalog(), DBObject::loadKey(), DBObject::setPrivileges(), TableDBObjectType, and TableDescriptor::tableName.

Referenced by Parser::OptimizeTableStmt::execute().

3919  {
3920  CHECK(td);
3921  auto& cat = session_info.getCatalog();
3922  std::vector<DBObject> privObjects;
3923  DBObject dbObject(td->tableName, TableDBObjectType);
3924  dbObject.loadKey(cat);
3925  dbObject.setPrivileges(access_priv);
3926  privObjects.push_back(dbObject);
3927  return SysCatalog::instance().checkPrivileges(session_info.get_currentUser(),
3928  privObjects);
3929 };
std::string cat(Ts &&...args)
std::string tableName
Catalog & getCatalog() const
Definition: SessionInfo.h:67
#define CHECK(condition)
Definition: Logger.h:209
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:73

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Parser::anonymous_namespace{ParserNode.cpp}::validate_shard_column_type ( const ColumnDescriptor cd)

Definition at line 2044 of file ParserNode.cpp.

References ColumnDescriptor::columnType, ColumnDescriptor::default_value, and kENCODING_DICT.

Referenced by shard_column_index().

2044  {
2045  const auto& col_ti = cd.columnType;
2046  if (col_ti.is_integer() ||
2047  (col_ti.is_string() && col_ti.get_compression() == kENCODING_DICT) ||
2048  col_ti.is_time()) {
2049  if (cd.default_value.has_value()) {
2050  throw std::runtime_error("Default values for shard keys are not supported yet.");
2051  }
2052  } else {
2053  throw std::runtime_error("Cannot shard on type " + col_ti.get_type_name() +
2054  ", encoding " + col_ti.get_compression_name());
2055  }
2056 }
std::optional< std::string > default_value
SQLTypeInfo columnType

+ Here is the caller graph for this function:

Variable Documentation

const std::map<const std::string, const DataframeDefFuncPtr> Parser::anonymous_namespace{ParserNode.cpp}::dataframeDefFuncMap
static
Initial value:
=
{{"fragment_size"s, get_frag_size_dataframe_def},
{"max_chunk_size"s, get_max_chunk_size_dataframe_def},
{"skip_rows"s, get_skip_rows_def},
{"delimiter"s, get_delimiter_def},
{"header"s, get_header_def}}
decltype(auto) get_skip_rows_def(DataframeTableDescriptor &df_td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
decltype(auto) get_header_def(DataframeTableDescriptor &df_td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
decltype(auto) get_max_chunk_size_dataframe_def(DataframeTableDescriptor &df_td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
decltype(auto) get_frag_size_dataframe_def(DataframeTableDescriptor &df_td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
decltype(auto) get_delimiter_def(DataframeTableDescriptor &df_td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)

Definition at line 2334 of file ParserNode.cpp.

constexpr char const* Parser::anonymous_namespace{ParserNode.cpp}::EMPTY_NAME {""}
static
const std::map<const std::string, const TableDefFuncPtr> Parser::anonymous_namespace{ParserNode.cpp}::tableDefFuncMap
static
Initial value:
= {
{"fragment_size"s, get_frag_size_def},
{"max_chunk_size"s, get_max_chunk_size_def},
{"page_size"s, get_page_size_def},
{"max_rows"s, get_max_rows_def},
{"partitions"s, get_partions_def},
{"shard_count"s, get_shard_count_def},
{"vacuum"s, get_vacuum_def},
{"sort_column"s, get_sort_column_def},
{"storage_type"s, get_storage_type},
{"max_rollback_epochs", get_max_rollback_epochs_def}}
decltype(auto) get_max_rows_def(TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
decltype(auto) get_max_chunk_size_def(TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
decltype(auto) get_vacuum_def(TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
decltype(auto) get_shard_count_def(TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
decltype(auto) get_sort_column_def(TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
decltype(auto) get_frag_size_def(TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
decltype(auto) get_partions_def(TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
decltype(auto) get_page_size_def(TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
decltype(auto) get_max_rollback_epochs_def(TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)
decltype(auto) get_storage_type(TableDescriptor &td, const NameValueAssign *p, const std::list< ColumnDescriptor > &columns)

Definition at line 2293 of file ParserNode.cpp.