This commit is contained in:
Evgeniy Gatov 2015-08-19 18:34:02 +03:00
commit dbcb5a1813
7 changed files with 51 additions and 39 deletions

View File

@ -31,7 +31,7 @@ public:
{ {
if (!this->source_ptr->supportsSelectiveLoad()) if (!this->source_ptr->supportsSelectiveLoad())
throw Exception{ throw Exception{
"Source cannot be used with CacheDictionary", name + ": source cannot be used with CacheDictionary",
ErrorCodes::UNSUPPORTED_METHOD ErrorCodes::UNSUPPORTED_METHOD
}; };
@ -98,7 +98,7 @@ public:
auto & attribute = getAttribute(attribute_name);\ auto & attribute = getAttribute(attribute_name);\
if (attribute.type != AttributeUnderlyingType::TYPE)\ if (attribute.type != AttributeUnderlyingType::TYPE)\
throw Exception{\ throw Exception{\
"Type mismatch: attribute " + attribute_name + " has type " + toString(attribute.type),\ name + ": type mismatch: attribute " + attribute_name + " has type " + toString(attribute.type),\
ErrorCodes::TYPE_MISMATCH\ ErrorCodes::TYPE_MISMATCH\
};\ };\
\ \
@ -120,7 +120,7 @@ public:
auto & attribute = getAttribute(attribute_name); auto & attribute = getAttribute(attribute_name);
if (attribute.type != AttributeUnderlyingType::String) if (attribute.type != AttributeUnderlyingType::String)
throw Exception{ throw Exception{
"Type mismatch: attribute " + attribute_name + " has type " + toString(attribute.type), name + ": type mismatch: attribute " + attribute_name + " has type " + toString(attribute.type),
ErrorCodes::TYPE_MISMATCH ErrorCodes::TYPE_MISMATCH
}; };
@ -173,7 +173,7 @@ private:
if (hierarchical_attribute->type != AttributeUnderlyingType::UInt64) if (hierarchical_attribute->type != AttributeUnderlyingType::UInt64)
throw Exception{ throw Exception{
"Hierarchical attribute must be UInt64.", name + ": hierarchical attribute must be UInt64.",
ErrorCodes::TYPE_MISMATCH ErrorCodes::TYPE_MISMATCH
}; };
} }
@ -422,7 +422,7 @@ private:
const auto id_column = typeid_cast<const ColumnVector<UInt64> *>(block.getByPosition(0).column.get()); const auto id_column = typeid_cast<const ColumnVector<UInt64> *>(block.getByPosition(0).column.get());
if (!id_column) if (!id_column)
throw Exception{ throw Exception{
"Id column has type different from UInt64.", name + ": id column has type different from UInt64.",
ErrorCodes::TYPE_MISMATCH ErrorCodes::TYPE_MISMATCH
}; };
@ -576,7 +576,7 @@ private:
const auto it = attribute_index_by_name.find(attribute_name); const auto it = attribute_index_by_name.find(attribute_name);
if (it == std::end(attribute_index_by_name)) if (it == std::end(attribute_index_by_name))
throw Exception{ throw Exception{
"No such attribute '" + attribute_name + "'", name + ": no such attribute '" + attribute_name + "'",
ErrorCodes::BAD_ARGUMENTS ErrorCodes::BAD_ARGUMENTS
}; };

View File

@ -39,16 +39,15 @@ Block createSampleBlock(const DictionaryStructure & dict_struct)
class DictionarySourceFactory : public Singleton<DictionarySourceFactory> class DictionarySourceFactory : public Singleton<DictionarySourceFactory>
{ {
public: public:
DictionarySourcePtr create(Poco::Util::AbstractConfiguration & config, DictionarySourcePtr create(
const std::string & config_prefix, const std::string & name, Poco::Util::AbstractConfiguration & config, const std::string & config_prefix,
const DictionaryStructure & dict_struct, const DictionaryStructure & dict_struct, Context & context) const
Context & context) const
{ {
Poco::Util::AbstractConfiguration::Keys keys; Poco::Util::AbstractConfiguration::Keys keys;
config.keys(config_prefix, keys); config.keys(config_prefix, keys);
if (keys.size() != 1) if (keys.size() != 1)
throw Exception{ throw Exception{
"Element dictionary.source should have exactly one child element", name +": element dictionary.source should have exactly one child element",
ErrorCodes::EXCESSIVE_ELEMENT_IN_CONFIG ErrorCodes::EXCESSIVE_ELEMENT_IN_CONFIG
}; };
@ -73,7 +72,7 @@ public:
} }
throw Exception{ throw Exception{
"Unknown dictionary source type: " + source_type, name + ": unknown dictionary source type: " + source_type,
ErrorCodes::UNKNOWN_ELEMENT_IN_CONFIG ErrorCodes::UNKNOWN_ELEMENT_IN_CONFIG
}; };
} }

View File

@ -93,7 +93,7 @@ public:
const auto & attribute = getAttribute(attribute_name);\ const auto & attribute = getAttribute(attribute_name);\
if (attribute.type != AttributeUnderlyingType::TYPE)\ if (attribute.type != AttributeUnderlyingType::TYPE)\
throw Exception{\ throw Exception{\
"Type mismatch: attribute " + attribute_name + " has type " + toString(attribute.type),\ name + ": type mismatch: attribute " + attribute_name + " has type " + toString(attribute.type),\
ErrorCodes::TYPE_MISMATCH\ ErrorCodes::TYPE_MISMATCH\
};\ };\
\ \
@ -115,7 +115,7 @@ public:
const auto & attribute = getAttribute(attribute_name); const auto & attribute = getAttribute(attribute_name);
if (attribute.type != AttributeUnderlyingType::String) if (attribute.type != AttributeUnderlyingType::String)
throw Exception{ throw Exception{
"Type mismatch: attribute " + attribute_name + " has type " + toString(attribute.type), name + ": type mismatch: attribute " + attribute_name + " has type " + toString(attribute.type),
ErrorCodes::TYPE_MISMATCH ErrorCodes::TYPE_MISMATCH
}; };
@ -170,7 +170,7 @@ private:
if (hierarchical_attribute->type != AttributeUnderlyingType::UInt64) if (hierarchical_attribute->type != AttributeUnderlyingType::UInt64)
throw Exception{ throw Exception{
"Hierarchical attribute must be UInt64.", name + ": hierarchical attribute must be UInt64.",
ErrorCodes::TYPE_MISMATCH ErrorCodes::TYPE_MISMATCH
}; };
} }
@ -201,7 +201,10 @@ private:
stream->readSuffix(); stream->readSuffix();
if (require_nonempty && 0 == element_count) if (require_nonempty && 0 == element_count)
throw Exception("Dictionary source is empty and 'require_nonempty' property is set.", ErrorCodes::DICTIONARY_IS_EMPTY); throw Exception{
name + ": dictionary source is empty and 'require_nonempty' property is set.",
ErrorCodes::DICTIONARY_IS_EMPTY
};
} }
template <typename T> template <typename T>
@ -307,7 +310,7 @@ private:
{ {
if (id >= max_array_size) if (id >= max_array_size)
throw Exception{ throw Exception{
"Identifier should be less than " + toString(max_array_size), name + ": identifier should be less than " + toString(max_array_size),
ErrorCodes::ARGUMENT_OUT_OF_BOUND ErrorCodes::ARGUMENT_OUT_OF_BOUND
}; };
@ -341,7 +344,7 @@ private:
const auto it = attribute_index_by_name.find(attribute_name); const auto it = attribute_index_by_name.find(attribute_name);
if (it == std::end(attribute_index_by_name)) if (it == std::end(attribute_index_by_name))
throw Exception{ throw Exception{
"No such attribute '" + attribute_name + "'", name + ": no such attribute '" + attribute_name + "'",
ErrorCodes::BAD_ARGUMENTS ErrorCodes::BAD_ARGUMENTS
}; };

View File

@ -91,7 +91,7 @@ public:
const auto & attribute = getAttribute(attribute_name);\ const auto & attribute = getAttribute(attribute_name);\
if (attribute.type != AttributeUnderlyingType::TYPE)\ if (attribute.type != AttributeUnderlyingType::TYPE)\
throw Exception{\ throw Exception{\
"Type mismatch: attribute " + attribute_name + " has type " + toString(attribute.type),\ name + ": type mismatch: attribute " + attribute_name + " has type " + toString(attribute.type),\
ErrorCodes::TYPE_MISMATCH\ ErrorCodes::TYPE_MISMATCH\
};\ };\
\ \
@ -113,7 +113,7 @@ public:
const auto & attribute = getAttribute(attribute_name); const auto & attribute = getAttribute(attribute_name);
if (attribute.type != AttributeUnderlyingType::String) if (attribute.type != AttributeUnderlyingType::String)
throw Exception{ throw Exception{
"Type mismatch: attribute " + attribute_name + " has type " + toString(attribute.type), name + ": type mismatch: attribute " + attribute_name + " has type " + toString(attribute.type),
ErrorCodes::TYPE_MISMATCH ErrorCodes::TYPE_MISMATCH
}; };
@ -168,7 +168,7 @@ private:
if (hierarchical_attribute->type != AttributeUnderlyingType::UInt64) if (hierarchical_attribute->type != AttributeUnderlyingType::UInt64)
throw Exception{ throw Exception{
"Hierarchical attribute must be UInt64.", name + ": hierarchical attribute must be UInt64.",
ErrorCodes::TYPE_MISMATCH ErrorCodes::TYPE_MISMATCH
}; };
} }
@ -199,7 +199,10 @@ private:
stream->readSuffix(); stream->readSuffix();
if (require_nonempty && 0 == element_count) if (require_nonempty && 0 == element_count)
throw Exception("Dictionary source is empty and 'require_nonempty' property is set.", ErrorCodes::DICTIONARY_IS_EMPTY); throw Exception{
name + ": dictionary source is empty and 'require_nonempty' property is set.",
ErrorCodes::DICTIONARY_IS_EMPTY
};
} }
template <typename T> template <typename T>
@ -327,7 +330,7 @@ private:
const auto it = attribute_index_by_name.find(attribute_name); const auto it = attribute_index_by_name.find(attribute_name);
if (it == std::end(attribute_index_by_name)) if (it == std::end(attribute_index_by_name))
throw Exception{ throw Exception{
"No such attribute '" + attribute_name + "'", name + ": no such attribute '" + attribute_name + "'",
ErrorCodes::BAD_ARGUMENTS ErrorCodes::BAD_ARGUMENTS
}; };

View File

@ -187,7 +187,7 @@ private:
if (attribute.hierarchical) if (attribute.hierarchical)
throw Exception{ throw Exception{
"Hierarchical attributes not supported by " + getName() + " dictionary.", name + ": hierarchical attributes not supported by " + getName() + " dictionary.",
ErrorCodes::BAD_ARGUMENTS ErrorCodes::BAD_ARGUMENTS
}; };
} }
@ -221,7 +221,10 @@ private:
stream->readSuffix(); stream->readSuffix();
if (require_nonempty && 0 == element_count) if (require_nonempty && 0 == element_count)
throw Exception("Dictionary source is empty and 'require_nonempty' property is set.", ErrorCodes::DICTIONARY_IS_EMPTY); throw Exception{
name + ": dictionary source is empty and 'require_nonempty' property is set.",
ErrorCodes::DICTIONARY_IS_EMPTY
};
} }
template <typename T> template <typename T>
@ -391,7 +394,7 @@ private:
const auto it = attribute_index_by_name.find(attribute_name); const auto it = attribute_index_by_name.find(attribute_name);
if (it == std::end(attribute_index_by_name)) if (it == std::end(attribute_index_by_name))
throw Exception{ throw Exception{
"No such attribute '" + attribute_name + "'", name + ": no such attribute '" + attribute_name + "'",
ErrorCodes::BAD_ARGUMENTS ErrorCodes::BAD_ARGUMENTS
}; };
@ -403,7 +406,7 @@ private:
const auto & attribute = getAttribute(name); const auto & attribute = getAttribute(name);
if (attribute.type != type) if (attribute.type != type)
throw Exception{ throw Exception{
"Type mismatch: attribute " + name + " has type " + toString(attribute.type), name + ": type mismatch: attribute " + name + " has type " + toString(attribute.type),
ErrorCodes::TYPE_MISMATCH ErrorCodes::TYPE_MISMATCH
}; };

View File

@ -20,14 +20,14 @@ DictionaryPtr DictionaryFactory::create(const std::string & name, Poco::Util::Ab
config.keys(layout_prefix, keys); config.keys(layout_prefix, keys);
if (keys.size() != 1) if (keys.size() != 1)
throw Exception{ throw Exception{
"Element dictionary.layout should have exactly one child element", name + ": element dictionary.layout should have exactly one child element",
ErrorCodes::EXCESSIVE_ELEMENT_IN_CONFIG ErrorCodes::EXCESSIVE_ELEMENT_IN_CONFIG
}; };
const DictionaryStructure dict_struct{config, config_prefix + ".structure"}; const DictionaryStructure dict_struct{config, config_prefix + ".structure"};
auto source_ptr = DictionarySourceFactory::instance().create( auto source_ptr = DictionarySourceFactory::instance().create(
config, config_prefix + ".source", dict_struct, context); name, config, config_prefix + ".source", dict_struct, context);
const DictionaryLifetime dict_lifetime{config, config_prefix + ".lifetime"}; const DictionaryLifetime dict_lifetime{config, config_prefix + ".lifetime"};
@ -39,7 +39,7 @@ DictionaryPtr DictionaryFactory::create(const std::string & name, Poco::Util::Ab
{ {
if (dict_struct.range_min.empty() || dict_struct.range_min.empty()) if (dict_struct.range_min.empty() || dict_struct.range_min.empty())
throw Exception{ throw Exception{
"Dictionary of layout 'range_hashed' requires .structure.range_min and .structure.range_max", name + ": dictionary of layout 'range_hashed' requires .structure.range_min and .structure.range_max",
ErrorCodes::BAD_ARGUMENTS ErrorCodes::BAD_ARGUMENTS
}; };
@ -49,9 +49,10 @@ DictionaryPtr DictionaryFactory::create(const std::string & name, Poco::Util::Ab
{ {
if (!dict_struct.range_min.empty() || !dict_struct.range_min.empty()) if (!dict_struct.range_min.empty() || !dict_struct.range_min.empty())
throw Exception{ throw Exception{
"Elements .structure.range_min and .structure.range_max should be defined only " name + ": elements .structure.range_min and .structure.range_max should be defined only "
"for a dictionary of layout 'range_hashed'", "for a dictionary of layout 'range_hashed'",
ErrorCodes::BAD_ARGUMENTS}; ErrorCodes::BAD_ARGUMENTS
};
if ("flat" == layout_type) if ("flat" == layout_type)
{ {
@ -66,20 +67,22 @@ DictionaryPtr DictionaryFactory::create(const std::string & name, Poco::Util::Ab
const auto size = config.getInt(layout_prefix + ".cache.size_in_cells"); const auto size = config.getInt(layout_prefix + ".cache.size_in_cells");
if (size == 0) if (size == 0)
throw Exception{ throw Exception{
"Dictionary of layout 'cache' cannot have 0 cells", name + ": dictionary of layout 'cache' cannot have 0 cells",
ErrorCodes::TOO_SMALL_BUFFER_SIZE}; ErrorCodes::TOO_SMALL_BUFFER_SIZE
};
if (require_nonempty) if (require_nonempty)
throw Exception{ throw Exception{
"Dictionary of layout 'cache' cannot have 'require_nonempty' attribute set", name + ": dictionary of layout 'cache' cannot have 'require_nonempty' attribute set",
ErrorCodes::BAD_ARGUMENTS}; ErrorCodes::BAD_ARGUMENTS
};
return std::make_unique<CacheDictionary>(name, dict_struct, std::move(source_ptr), dict_lifetime, size); return std::make_unique<CacheDictionary>(name, dict_struct, std::move(source_ptr), dict_lifetime, size);
} }
} }
throw Exception{ throw Exception{
"Unknown dictionary layout type: " + layout_type, name + ": unknown dictionary layout type: " + layout_type,
ErrorCodes::UNKNOWN_ELEMENT_IN_CONFIG ErrorCodes::UNKNOWN_ELEMENT_IN_CONFIG
}; };
}; };

View File

@ -128,11 +128,12 @@ BlockInputStreams StorageSystemDictionaries::read(
} }
catch (const Exception & e) catch (const Exception & e)
{ {
col_last_exception.column->insert("DB::Exception. Code " + toString(e.code()) + ". " + e.message()); col_last_exception.column->insert("DB::Exception. Code " + toString(e.code()) + ". " +
std::string{e.displayText()});
} }
catch (const Poco::Exception & e) catch (const Poco::Exception & e)
{ {
col_last_exception.column->insert("Poco::Exception. " + e.message()); col_last_exception.column->insert("Poco::Exception. " + std::string{e.displayText()});
} }
catch (const std::exception & e) catch (const std::exception & e)
{ {