OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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)
 
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_frag_size_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_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_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)
 
void get_table_definitions (TableDescriptor &td, const std::unique_ptr< NameValueAssign > &p, const std::list< ColumnDescriptor > &columns)
 

Variables

static const std::map< const
std::string, const
TableDefFuncPtr
tableDefFuncMap
 

Function Documentation

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

Definition at line 892 of file ParserNode.cpp.

References Parser::StringLiteral::get_stringval().

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

892  {
893  const std::string* s = str_literal->get_stringval();
894  if (*s == "t" || *s == "true" || *s == "T" || *s == "True") {
895  return true;
896  } else if (*s == "f" || *s == "false" || *s == "F" || *s == "False") {
897  return false;
898  } else {
899  throw std::runtime_error("Invalid string for boolean " + *s);
900  }
901 }
const std::string * get_stringval() const
Definition: ParserNode.h:149

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 884 of file ParserNode.cpp.

References Analyzer::Constant::get_is_null(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), Analyzer::Expr::get_type_info(), and kNULLT.

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

884  {
885  if (expr->get_type_info().get_type() == kNULLT) {
886  return true;
887  }
888  const auto const_expr = dynamic_cast<const Analyzer::Constant*>(expr);
889  return const_expr && const_expr->get_is_null();
890 }
bool get_is_null() const
Definition: Analyzer.h:328
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:78

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 2041 of file ParserNode.cpp.

2043  {
2044  return get_property_value<IntLiteral>(p,
2045  [&td](const auto val) { td.maxFragRows = val; });
2046 }
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 2048 of file ParserNode.cpp.

2050  {
2051  return get_property_value<IntLiteral>(p,
2052  [&td](const auto val) { td.maxChunkSize = val; });
2053 }
decltype(auto) Parser::anonymous_namespace{ParserNode.cpp}::get_max_rows_def ( TableDescriptor td,
const NameValueAssign *  p,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2061 of file ParserNode.cpp.

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

Definition at line 2055 of file ParserNode.cpp.

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

Definition at line 2066 of file ParserNode.cpp.

2068  {
2069  return get_property_value<StringLiteral>(p, [&td](const auto partitions_uc) {
2070  if (partitions_uc != "SHARDED" && partitions_uc != "REPLICATED") {
2071  throw std::runtime_error("PARTITIONS must be SHARDED or REPLICATED");
2072  }
2073  if (td.shardedColumnId != 0 && partitions_uc == "REPLICATED") {
2074  throw std::runtime_error(
2075  "A table cannot be sharded and replicated at the same time");
2076  };
2077  td.partitions = partitions_uc;
2078  });
2079 }
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 2034 of file ParserNode.cpp.

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

Definition at line 2080 of file ParserNode.cpp.

References g_leaf_count.

2082  {
2083  if (!td.shardedColumnId) {
2084  throw std::runtime_error("SHARD KEY must be defined.");
2085  }
2086  return get_property_value<IntLiteral>(p, [&td](const auto shard_count) {
2087  if (g_leaf_count && shard_count % g_leaf_count) {
2088  throw std::runtime_error(
2089  "SHARD_COUNT must be a multiple of the number of leaves in the cluster.");
2090  }
2091  td.nShards = g_leaf_count ? shard_count / g_leaf_count : shard_count;
2092  if (!td.shardedColumnId && !td.nShards) {
2093  throw std::runtime_error(
2094  "Must specify the number of shards through the SHARD_COUNT option");
2095  };
2096  });
2097 }
size_t g_leaf_count
Definition: ParserNode.cpp:66
decltype(auto) Parser::anonymous_namespace{ParserNode.cpp}::get_sort_column_def ( TableDescriptor td,
const NameValueAssign *  p,
const std::list< ColumnDescriptor > &  columns 
)

Definition at line 2110 of file ParserNode.cpp.

References sort_column_index().

2112  {
2113  return get_property_value<StringLiteral>(p, [&td, &columns](const auto sort_upper) {
2114  td.sortedColumnId = sort_column_index(sort_upper, columns);
2115  if (!td.sortedColumnId) {
2116  throw std::runtime_error("Specified sort column " + sort_upper + " doesn't exist");
2117  }
2118  });
2119 }
size_t sort_column_index(const std::string &name, const std::list< ColumnDescriptor > &columns)

+ Here is the call graph for this function:

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

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

2133  {
2134  const auto it = tableDefFuncMap.find(boost::to_lower_copy<std::string>(*p->get_name()));
2135  if (it == tableDefFuncMap.end()) {
2136  throw std::runtime_error("Invalid CREATE TABLE option " + *p->get_name() +
2137  ". Should be FRAGMENT_SIZE, PAGE_SIZE, MAX_ROWS, "
2138  "PARTITIONS, VACUUM, SORT_COLUMN or SHARD_COUNT.");
2139  }
2140  return it->second(td, p.get(), columns);
2141 }
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 2099 of file ParserNode.cpp.

2101  {
2102  return get_property_value<StringLiteral>(p, [&td](const auto vacuum_uc) {
2103  if (vacuum_uc != "IMMEDIATE" && vacuum_uc != "DELAYED") {
2104  throw std::runtime_error("VACUUM must be IMMEDIATE or DELAYED");
2105  }
2106  td.hasDeletedCol = boost::iequals(vacuum_uc, "IMMEDIATE") ? false : true;
2107  });
2108 }
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 2001 of file ParserNode.cpp.

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

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

2003  {
2004  rapidjson::Document document;
2005  auto& allocator = document.GetAllocator();
2006  rapidjson::Value arr(rapidjson::kArrayType);
2007  if (shard_key_def) {
2008  rapidjson::Value shard_key_obj(rapidjson::kObjectType);
2009  set_string_field(shard_key_obj, "type", "SHARD KEY", document);
2010  set_string_field(shard_key_obj, "name", shard_key_def->get_column(), document);
2011  arr.PushBack(shard_key_obj, allocator);
2012  }
2013  for (const auto& shared_dict_def : shared_dict_defs) {
2014  rapidjson::Value shared_dict_obj(rapidjson::kObjectType);
2015  set_string_field(shared_dict_obj, "type", "SHARED DICTIONARY", document);
2016  set_string_field(shared_dict_obj, "name", shared_dict_def.get_column(), document);
2018  shared_dict_obj, "foreign_table", shared_dict_def.get_foreign_table(), document);
2019  set_string_field(shared_dict_obj,
2020  "foreign_column",
2021  shared_dict_def.get_foreign_column(),
2022  document);
2023  arr.PushBack(shared_dict_obj, allocator);
2024  }
2025  rapidjson::StringBuffer buffer;
2026  rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
2027  arr.Accept(writer);
2028  return buffer.GetString();
2029 }
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 1988 of file ParserNode.cpp.

Referenced by serialize_key_metainfo().

1991  {
1992  rapidjson::Value field_name_json_str;
1993  field_name_json_str.SetString(
1994  field_name.c_str(), field_name.size(), document.GetAllocator());
1995  rapidjson::Value field_value_json_str;
1996  field_value_json_str.SetString(
1997  field_value.c_str(), field_value.size(), document.GetAllocator());
1998  obj.AddMember(field_name_json_str, field_value_json_str, document.GetAllocator());
1999 }

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

References validate_shard_column_type().

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

1956  {
1957  size_t index = 1;
1958  for (const auto& cd : columns) {
1959  if (cd.columnName == name) {
1961  return index;
1962  }
1963  ++index;
1964  if (cd.columnType.is_geometry()) {
1965  index += cd.columnType.get_physical_cols();
1966  }
1967  }
1968  // Not found, return 0
1969  return 0;
1970 }
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 1972 of file ParserNode.cpp.

Referenced by get_sort_column_def().

1973  {
1974  size_t index = 1;
1975  for (const auto& cd : columns) {
1976  if (boost::to_upper_copy<std::string>(cd.columnName) == name) {
1977  return index;
1978  }
1979  ++index;
1980  if (cd.columnType.is_geometry()) {
1981  index += cd.columnType.get_physical_cols();
1982  }
1983  }
1984  // Not found, return 0
1985  return 0;
1986 }

+ Here is the caller graph for this function:

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

Definition at line 1944 of file ParserNode.cpp.

References ColumnDescriptor::columnType, and kENCODING_DICT.

Referenced by shard_column_index().

1944  {
1945  const auto& col_ti = cd.columnType;
1946  if (col_ti.is_integer() ||
1947  (col_ti.is_string() && col_ti.get_compression() == kENCODING_DICT) ||
1948  col_ti.is_time()) {
1949  return;
1950  }
1951  throw std::runtime_error("Cannot shard on type " + col_ti.get_type_name() +
1952  ", encoding " + col_ti.get_compression_name());
1953 }
SQLTypeInfo columnType

+ Here is the caller graph for this function:

Variable Documentation

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

Definition at line 2121 of file ParserNode.cpp.