| 72 | } |
| 73 | |
| 74 | void TableFunctionMongoDB::parseArguments(const ASTPtr & ast_function, ContextPtr context) |
| 75 | { |
| 76 | const auto & func_args = ast_function->as<ASTFunction &>(); |
| 77 | if (!func_args.arguments) |
| 78 | throw Exception(ErrorCodes::BAD_ARGUMENTS, "Table function 'mongodb' must have arguments."); |
| 79 | |
| 80 | ASTs & args = func_args.arguments->children; |
| 81 | |
| 82 | if (auto named_collection = tryGetNamedCollectionWithOverrides(args, context)) |
| 83 | { |
| 84 | if (!named_collection->has("structure")) |
| 85 | throw Exception(ErrorCodes::BAD_ARGUMENTS, "Required key (structure) is not specified."); |
| 86 | |
| 87 | structure = named_collection->get<String>("structure"); |
| 88 | named_collection->remove("structure"); |
| 89 | configuration = std::make_shared<MongoDBConfiguration>(StorageMongoDB::getConfigurationFromCollection(named_collection, context)); |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | if ((args.size() < 3 || args.size() > 4) && (args.size() < 6 || args.size() > 8)) |
| 94 | throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, |
| 95 | "Incorrect argument count for table function '{}'. Usage: " |
| 96 | "mongodb('host:port', database, collection, user, password, structure[, options[, oid_columns]]) or mongodb(uri, collection, structure[, oid_columns]).", |
| 97 | getName()); |
| 98 | |
| 99 | ASTs main_arguments; |
| 100 | main_arguments.reserve(args.size() - 1); |
| 101 | const size_t structure_position = args.size() <= 4 ? 2 : 5; |
| 102 | for (size_t i = 0; i < args.size(); ++i) |
| 103 | { |
| 104 | if (const auto * ast_func = typeid_cast<const ASTFunction *>(args[i].get())) |
| 105 | { |
| 106 | const auto & [arg_name, arg_value] = getKeyValueMongoDBArgument(ast_func); |
| 107 | if (arg_name == "structure") |
| 108 | structure = checkAndGetLiteralArgument<String>(arg_value, arg_name); |
| 109 | else if (arg_name == "options" || arg_name == "oid_columns") |
| 110 | main_arguments.push_back(arg_value); |
| 111 | } |
| 112 | else if (i == structure_position) |
| 113 | structure = checkAndGetLiteralArgument<String>(args[i], "structure"); |
| 114 | else |
| 115 | main_arguments.push_back(args[i]); |
| 116 | } |
| 117 | |
| 118 | configuration = std::make_shared<MongoDBConfiguration>(StorageMongoDB::getConfiguration(main_arguments, context)); |
| 119 | } |
| 120 | |
| 121 | } |
| 122 |
nothing calls this directly
no test coverage detected