#pragma once #include #include #include #include #include #include #include #include namespace DB { namespace { Block createSampleBlock(const DictionaryStructure & dict_struct, const Context & context) { Block block{ ColumnWithNameAndType{ new ColumnUInt64, new DataTypeUInt64, dict_struct.id_name } }; for (const auto & attribute : dict_struct.attributes) { const auto & type = context.getDataTypeFactory().get(attribute.type); block.insert(ColumnWithNameAndType{ type->createColumn(), type, attribute.name }); } return block; } } class DictionarySourceFactory : public Singleton { public: DictionarySourcePtr create(Poco::Util::AbstractConfiguration & config, const std::string & config_prefix, const DictionaryStructure & dict_struct, const Context & context) const { auto sample_block = createSampleBlock(dict_struct, context); if (config.has(config_prefix + "file")) { const auto & filename = config.getString(config_prefix + "file.path"); const auto & format = config.getString(config_prefix + "file.format"); return ext::make_unique(filename, format, sample_block, context); } else if (config.has(config_prefix + "mysql")) { return ext::make_unique(config, config_prefix + "mysql.", sample_block, context); } else if (config.has(config_prefix + "clickhouse")) { return ext::make_unique(config, config_prefix + "clickhouse.", sample_block, context); } throw Exception{"unsupported source type"}; } }; }