| 243 | |
| 244 | void registerDatabaseFilesystem(DatabaseFactory & factory); |
| 245 | void registerDatabaseFilesystem(DatabaseFactory & factory) |
| 246 | { |
| 247 | auto create_fn = [](const DatabaseFactory::Arguments & args) |
| 248 | { |
| 249 | auto * engine_define = args.create_query.storage; |
| 250 | const ASTFunction * engine = engine_define->engine; |
| 251 | const String & engine_name = engine_define->engine->name; |
| 252 | |
| 253 | /// If init_path is empty, then the current path will be used |
| 254 | std::string init_path; |
| 255 | |
| 256 | if (engine->arguments && !engine->arguments->children.empty()) |
| 257 | { |
| 258 | if (engine->arguments->children.size() != 1) |
| 259 | throw Exception(ErrorCodes::BAD_ARGUMENTS, "Filesystem database requires at most 1 argument: filesystem_path"); |
| 260 | |
| 261 | const auto & arguments = engine->arguments->children; |
| 262 | init_path = safeGetLiteralValue<String>(arguments[0], engine_name); |
| 263 | } |
| 264 | |
| 265 | return std::make_shared<DatabaseFilesystem>(args.database_name, init_path, args.context); |
| 266 | }; |
| 267 | factory.registerDatabase("Filesystem", create_fn, { |
| 268 | .supports_arguments = true, |
| 269 | .is_external = true, |
| 270 | .source_access_type = AccessTypeObjects::Source::FILE, |
| 271 | }, Documentation{ |
| 272 | .description = "A read-only database that exposes files in a directory on the local filesystem as tables, queryable by their path.", |
| 273 | .syntax = "ENGINE = Filesystem([path])", |
| 274 | .related = {"S3", "HDFS"}}); |
| 275 | } |
| 276 | } |
no test coverage detected