MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / MongoDBSource

Method MongoDBSource

src/Processors/Sources/MongoDBSource.cpp:156–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154
155
156MongoDBSource::MongoDBSource(
157 const mongocxx::uri & uri,
158 const std::string & collection_name,
159 const bsoncxx::document::view_or_value & query,
160 const mongocxx::options::find & options,
161 SharedHeader sample_block_,
162 const UInt64 & max_block_size_)
163 : ISource{sample_block_}
164 , client{uri}
165 , database{client.database(uri.database())}
166 , collection{database.collection(collection_name)}
167 , cursor{collection.find(query, options)}
168 , sample_block{*sample_block_}
169 , max_block_size{max_block_size_}
170 , db_json_format_settings{.json= {.max_depth = 0, .quote_64bit_integers = false}}
171 , json_format_settings{db_json_format_settings, 0, true, true}
172{
173 for (const auto & idx : collections::range(0, sample_block.columns()))
174 {
175 auto & sample_column = sample_block.getByPosition(idx);
176
177 /// If default value for column was not provided, use default from data type.
178 if (sample_column.column->empty())
179 sample_column.column = sample_column.type->createColumnConstWithDefaultValue(1)->convertToFullColumnIfConst();
180
181 if (sample_column.type->getTypeId() == TypeIndex::Array)
182 {
183 auto type = assert_cast<const DataTypeArray &>(*sample_column.type).getNestedType();
184 size_t dimensions = 0;
185 while (type->getTypeId() == TypeIndex::Array)
186 {
187 type = assert_cast<const DataTypeArray &>(*type).getNestedType();
188 ++dimensions;
189 }
190 if (type->isNullable())
191 {
192 type = assert_cast<const DataTypeNullable &>(*type).getNestedType();
193 arrays_info[idx] = {std::move(dimensions), {std::move(type), Null()}};
194 }
195 else
196 arrays_info[idx] = {std::move(dimensions), {std::move(type), type->getDefault()}};
197 }
198 }
199}
200
201
202MongoDBSource::~MongoDBSource() = default;

Callers

nothing calls this directly

Calls 12

rangeFunction · 0.85
databaseMethod · 0.80
columnsMethod · 0.80
getNestedTypeMethod · 0.80
NullClass · 0.50
findMethod · 0.45
emptyMethod · 0.45
getTypeIdMethod · 0.45
isNullableMethod · 0.45
getDefaultMethod · 0.45

Tested by

no test coverage detected