OmniSciDB  5ade3759e0
Parser::anonymous_namespace{ParserNode.cpp} Namespace Reference

Functions

bool expr_is_null (const Analyzer::Expr *expr)
 
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 TableDefFuncPtrtableDefFuncMap
 

Function Documentation

◆ expr_is_null()

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

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

880  {
881  if (expr->get_type_info().get_type() == kNULLT) {
882  return true;
883  }
884  const auto const_expr = dynamic_cast<const Analyzer::Constant*>(expr);
885  return const_expr && const_expr->get_is_null();
886 }
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:323
bool get_is_null() const
Definition: Analyzer.h:327
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:

◆ get_frag_size_def()

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

Definition at line 2026 of file ParserNode.cpp.

2028  {
2029  return get_property_value<IntLiteral>(p,
2030  [&td](const auto val) { td.maxFragRows = val; });
2031 }

◆ get_max_chunk_size_def()

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

2035  {
2036  return get_property_value<IntLiteral>(p,
2037  [&td](const auto val) { td.maxChunkSize = val; });
2038 }

◆ get_max_rows_def()

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

Definition at line 2046 of file ParserNode.cpp.

2048  {
2049  return get_property_value<IntLiteral>(p, [&td](const auto val) { td.maxRows = val; });
2050 }

◆ get_page_size_def()

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

Definition at line 2040 of file ParserNode.cpp.

2042  {
2043  return get_property_value<IntLiteral>(p,
2044  [&td](const auto val) { td.fragPageSize = val; });
2045 }

◆ get_partions_def()

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

Definition at line 2051 of file ParserNode.cpp.

2053  {
2054  return get_property_value<StringLiteral>(p, [&td](const auto partitions_uc) {
2055  if (partitions_uc != "SHARDED" && partitions_uc != "REPLICATED") {
2056  throw std::runtime_error("PARTITIONS must be SHARDED or REPLICATED");
2057  }
2058  if (td.shardedColumnId != 0 && partitions_uc == "REPLICATED") {
2059  throw std::runtime_error(
2060  "A table cannot be sharded and replicated at the same time");
2061  };
2062  td.partitions = partitions_uc;
2063  });
2064 }
std::string partitions

◆ get_property_value()

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

2021  {
2022  const auto val = validate(p);
2023  return op(val);
2024 }

◆ get_shard_count_def()

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

Definition at line 2065 of file ParserNode.cpp.

References g_leaf_count.

2067  {
2068  if (!td.shardedColumnId) {
2069  throw std::runtime_error("SHARD KEY must be defined.");
2070  }
2071  return get_property_value<IntLiteral>(p, [&td](const auto shard_count) {
2072  if (g_leaf_count && shard_count % g_leaf_count) {
2073  throw std::runtime_error(
2074  "SHARD_COUNT must be a multiple of the number of leaves in the cluster.");
2075  }
2076  td.nShards = g_leaf_count ? shard_count / g_leaf_count : shard_count;
2077  if (!td.shardedColumnId && !td.nShards) {
2078  throw std::runtime_error(
2079  "Must specify the number of shards through the SHARD_COUNT option");
2080  };
2081  });
2082 }
size_t g_leaf_count
Definition: ParserNode.cpp:63

◆ get_sort_column_def()

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

Definition at line 2095 of file ParserNode.cpp.

References sort_column_index().

2097  {
2098  return get_property_value<StringLiteral>(p, [&td, &columns](const auto sort_upper) {
2099  td.sortedColumnId = sort_column_index(sort_upper, columns);
2100  if (!td.sortedColumnId) {
2101  throw std::runtime_error("Specified sort column " + sort_upper + " doesn't exist");
2102  }
2103  });
2104 }
size_t sort_column_index(const std::string &name, const std::list< ColumnDescriptor > &columns)
+ Here is the call graph for this function:

◆ get_table_definitions()

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

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

2118  {
2119  const auto it = tableDefFuncMap.find(boost::to_lower_copy<std::string>(*p->get_name()));
2120  if (it == tableDefFuncMap.end()) {
2121  throw std::runtime_error("Invalid CREATE TABLE option " + *p->get_name() +
2122  ". Should be FRAGMENT_SIZE, PAGE_SIZE, MAX_ROWS, "
2123  "PARTITIONS, VACUUM, SORT_COLUMN or SHARD_COUNT.");
2124  }
2125  return it->second(td, p.get(), columns);
2126 }
static const std::map< const std::string, const TableDefFuncPtr > tableDefFuncMap
+ Here is the caller graph for this function:

◆ get_vacuum_def()

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

Definition at line 2084 of file ParserNode.cpp.

2086  {
2087  return get_property_value<StringLiteral>(p, [&td](const auto vacuum_uc) {
2088  if (vacuum_uc != "IMMEDIATE" && vacuum_uc != "DELAYED") {
2089  throw std::runtime_error("VACUUM must be IMMEDIATE or DELAYED");
2090  }
2091  td.hasDeletedCol = boost::iequals(vacuum_uc, "IMMEDIATE") ? false : true;
2092  });
2093 }

◆ serialize_key_metainfo()

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

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

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

1988  {
1989  rapidjson::Document document;
1990  auto& allocator = document.GetAllocator();
1991  rapidjson::Value arr(rapidjson::kArrayType);
1992  if (shard_key_def) {
1993  rapidjson::Value shard_key_obj(rapidjson::kObjectType);
1994  set_string_field(shard_key_obj, "type", "SHARD KEY", document);
1995  set_string_field(shard_key_obj, "name", shard_key_def->get_column(), document);
1996  arr.PushBack(shard_key_obj, allocator);
1997  }
1998  for (const auto& shared_dict_def : shared_dict_defs) {
1999  rapidjson::Value shared_dict_obj(rapidjson::kObjectType);
2000  set_string_field(shared_dict_obj, "type", "SHARED DICTIONARY", document);
2001  set_string_field(shared_dict_obj, "name", shared_dict_def.get_column(), document);
2003  shared_dict_obj, "foreign_table", shared_dict_def.get_foreign_table(), document);
2004  set_string_field(shared_dict_obj,
2005  "foreign_column",
2006  shared_dict_def.get_foreign_column(),
2007  document);
2008  arr.PushBack(shared_dict_obj, allocator);
2009  }
2010  rapidjson::StringBuffer buffer;
2011  rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
2012  arr.Accept(writer);
2013  return buffer.GetString();
2014 }
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:

◆ set_string_field()

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

Referenced by serialize_key_metainfo().

1976  {
1977  rapidjson::Value field_name_json_str;
1978  field_name_json_str.SetString(
1979  field_name.c_str(), field_name.size(), document.GetAllocator());
1980  rapidjson::Value field_value_json_str;
1981  field_value_json_str.SetString(
1982  field_value.c_str(), field_value.size(), document.GetAllocator());
1983  obj.AddMember(field_name_json_str, field_value_json_str, document.GetAllocator());
1984 }
+ Here is the caller graph for this function:

◆ shard_column_index()

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

Definition at line 1940 of file ParserNode.cpp.

References validate_shard_column_type().

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

1941  {
1942  size_t index = 1;
1943  for (const auto& cd : columns) {
1944  if (cd.columnName == name) {
1946  return index;
1947  }
1948  ++index;
1949  if (cd.columnType.is_geometry()) {
1950  index += cd.columnType.get_physical_cols();
1951  }
1952  }
1953  // Not found, return 0
1954  return 0;
1955 }
void validate_shard_column_type(const ColumnDescriptor &cd)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sort_column_index()

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

Definition at line 1957 of file ParserNode.cpp.

Referenced by get_sort_column_def().

1958  {
1959  size_t index = 1;
1960  for (const auto& cd : columns) {
1961  if (boost::to_upper_copy<std::string>(cd.columnName) == name) {
1962  return index;
1963  }
1964  ++index;
1965  if (cd.columnType.is_geometry()) {
1966  index += cd.columnType.get_physical_cols();
1967  }
1968  }
1969  // Not found, return 0
1970  return 0;
1971 }
+ Here is the caller graph for this function:

◆ validate_shard_column_type()

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

Definition at line 1929 of file ParserNode.cpp.

References ColumnDescriptor::columnType, and kENCODING_DICT.

Referenced by shard_column_index().

1929  {
1930  const auto& col_ti = cd.columnType;
1931  if (col_ti.is_integer() ||
1932  (col_ti.is_string() && col_ti.get_compression() == kENCODING_DICT) ||
1933  col_ti.is_time()) {
1934  return;
1935  }
1936  throw std::runtime_error("Cannot shard on type " + col_ti.get_type_name() +
1937  ", encoding " + col_ti.get_compression_name());
1938 }
SQLTypeInfo columnType
+ Here is the caller graph for this function:

Variable Documentation

◆ tableDefFuncMap

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