void ITableDeclaration::check(const NamesAndTypesList & columns, const Names & column_names) const { const NamesAndTypesList & available_columns = getColumnsList(); const auto available_columns_map = getColumnsMap(available_columns); const NamesAndTypesMap & provided_columns_map = getColumnsMap(columns); if (column_names.empty()) throw Exception("Empty list of columns queried. There are columns: " + listOfColumns(available_columns), ErrorCodes::EMPTY_LIST_OF_COLUMNS_QUERIED); using UniqueStrings = google::dense_hash_set<StringRef, StringRefHash>; UniqueStrings unique_names; unique_names.set_empty_key(StringRef()); for (const String & name : column_names) { NamesAndTypesMap::const_iterator it = provided_columns_map.find(name); if (provided_columns_map.end() == it) continue; NamesAndTypesMap::const_iterator jt = available_columns_map.find(name); if (available_columns_map.end() == jt) throw Exception("There is no column with name " + name + ". There are columns: " + listOfColumns(available_columns), ErrorCodes::NO_SUCH_COLUMN_IN_TABLE); if (it->second->getName() != jt->second->getName()) throw Exception("Type mismatch for column " + name + ". Column has type " + jt->second->getName() + ", got type " + it->second->getName(), ErrorCodes::TYPE_MISMATCH); if (unique_names.end() != unique_names.find(name)) throw Exception("Column " + name + " queried more than once", ErrorCodes::COLUMN_QUERIED_MORE_THAN_ONCE); unique_names.insert(name); } }
void ITableDeclaration::check(const NamesAndTypesList & columns) const { const NamesAndTypesList & available_columns = getColumnsList(); const auto columns_map = getColumnsMap(available_columns); using UniqueStrings = google::dense_hash_set<StringRef, StringRefHash>; UniqueStrings unique_names; unique_names.set_empty_key(StringRef()); for (const NameAndTypePair & column : columns) { NamesAndTypesMap::const_iterator it = columns_map.find(column.name); if (columns_map.end() == it) throw Exception("There is no column with name " + column.name + ". There are columns: " + listOfColumns(available_columns), ErrorCodes::NO_SUCH_COLUMN_IN_TABLE); if (column.type->getName() != it->second->getName()) throw Exception("Type mismatch for column " + column.name + ". Column has type " + it->second->getName() + ", got type " + column.type->getName(), ErrorCodes::TYPE_MISMATCH); if (unique_names.end() != unique_names.find(column.name)) throw Exception("Column " + column.name + " queried more than once", ErrorCodes::COLUMN_QUERIED_MORE_THAN_ONCE); unique_names.insert(column.name); } }
void ITableDeclaration::check(const Names & column_names) const { const NamesAndTypesList & available_columns = getColumnsList(); if (column_names.empty()) throw Exception("Empty list of columns queried. There are columns: " + listOfColumns(available_columns), ErrorCodes::EMPTY_LIST_OF_COLUMNS_QUERIED); const auto columns_map = getColumnsMap(available_columns); using UniqueStrings = google::dense_hash_set<StringRef, StringRefHash>; UniqueStrings unique_names; unique_names.set_empty_key(StringRef()); for (const auto & name : column_names) { if (columns_map.end() == columns_map.find(name)) throw Exception("There is no column with name " + name + " in table. There are columns: " + listOfColumns(available_columns), ErrorCodes::NO_SUCH_COLUMN_IN_TABLE); if (unique_names.end() != unique_names.find(name)) throw Exception("Column " + name + " queried more than once", ErrorCodes::COLUMN_QUERIED_MORE_THAN_ONCE); unique_names.insert(name); } }
QString View::getCodeDefinition(unsigned def_type) { QString code_def=getCachedCode(def_type, false); if(!code_def.isEmpty()) return(code_def); attributes[ParsersAttributes::CTE_EXPRESSION]=cte_expression; attributes[ParsersAttributes::MATERIALIZED]=(materialized ? ParsersAttributes::_TRUE_ : QString()); attributes[ParsersAttributes::RECURSIVE]=(recursive ? ParsersAttributes::_TRUE_ : QString()); attributes[ParsersAttributes::WITH_NO_DATA]=(with_no_data ? ParsersAttributes::_TRUE_ : QString()); attributes[ParsersAttributes::COLUMNS]=QString(); attributes[ParsersAttributes::TAG]=QString(); setSQLObjectAttribute(); if(recursive) attributes[ParsersAttributes::COLUMNS]=getColumnsList().join(','); if(tag && def_type==SchemaParser::XML_DEFINITION) attributes[ParsersAttributes::TAG]=tag->getCodeDefinition(def_type, true); if(def_type==SchemaParser::SQL_DEFINITION) setDeclarationAttribute(); else { setPositionAttribute(); setReferencesAttribute(); } return(BaseObject::__getCodeDefinition(def_type)); }
QString View::getCodeDefinition(unsigned def_type) { unsigned count, i; attributes[ParsersAttributes::CTE_EXPRESSION]=cte_expression; attributes[ParsersAttributes::MATERIALIZED]=(materialized ? "1" : ""); attributes[ParsersAttributes::RECURSIVE]=(recursive ? "1" : ""); attributes[ParsersAttributes::WITH_NO_DATA]=(with_no_data ? "1" : ""); attributes[ParsersAttributes::COLUMNS]=""; attributes[ParsersAttributes::TAG]=""; if(materialized) attributes[ParsersAttributes::SQL_OBJECT]="MATERIALIZED " + BaseObject::getSQLName(OBJ_VIEW); if(recursive) attributes[ParsersAttributes::COLUMNS]=getColumnsList().join(","); if(tag && def_type==SchemaParser::XML_DEFINITION) attributes[ParsersAttributes::TAG]=tag->getCodeDefinition(def_type, true); if(def_type==SchemaParser::SQL_DEFINITION) setDeclarationAttribute(); else { setPositionAttribute(); setReferencesAttribute(); } count=triggers.size(); for(i=0; i < count; i++) attributes[ParsersAttributes::TRIGGERS]+=triggers[i]->getCodeDefinition(def_type); count=rules.size(); for(i=0; i < count; i++) attributes[ParsersAttributes::RULES]+=rules[i]->getCodeDefinition(def_type); return(BaseObject::__getCodeDefinition(def_type)); }
void ITableDeclaration::check(const Block & block, bool need_all) const { const NamesAndTypesList & available_columns = getColumnsList(); const auto columns_map = getColumnsMap(available_columns); using NameSet = std::unordered_set<String>; NameSet names_in_block; for (size_t i = 0; i < block.columns(); ++i) { const ColumnWithTypeAndName & column = block.getByPosition(i); if (names_in_block.count(column.name)) throw Exception("Duplicate column " + column.name + " in block", ErrorCodes::DUPLICATE_COLUMN); names_in_block.insert(column.name); NamesAndTypesMap::const_iterator it = columns_map.find(column.name); if (columns_map.end() == it) throw Exception("There is no column with name " + column.name + ". There are columns: " + listOfColumns(available_columns), ErrorCodes::NO_SUCH_COLUMN_IN_TABLE); if (column.type->getName() != it->second->getName()) throw Exception("Type mismatch for column " + column.name + ". Column has type " + it->second->getName() + ", got type " + column.type->getName(), ErrorCodes::TYPE_MISMATCH); } if (need_all && names_in_block.size() < columns_map.size()) { for (NamesAndTypesList::const_iterator it = available_columns.begin(); it != available_columns.end(); ++it) { if (!names_in_block.count(it->name)) throw Exception("Expected column " + it->name, ErrorCodes::NOT_FOUND_COLUMN_IN_BLOCK); } } }