diff options
| author | vitalyisaev <[email protected]> | 2023-11-14 09:58:56 +0300 |
|---|---|---|
| committer | vitalyisaev <[email protected]> | 2023-11-14 10:20:20 +0300 |
| commit | c2b2dfd9827a400a8495e172a56343462e3ceb82 (patch) | |
| tree | cd4e4f597d01bede4c82dffeb2d780d0a9046bd0 /contrib/clickhouse/src/TableFunctions/TableFunctionSQLite.cpp | |
| parent | d4ae8f119e67808cb0cf776ba6e0cf95296f2df7 (diff) | |
YQ Connector: move tests from yql to ydb (OSS)
Перенос папки с тестами на Коннектор из папки yql в папку ydb (синхронизируется с github).
Diffstat (limited to 'contrib/clickhouse/src/TableFunctions/TableFunctionSQLite.cpp')
| -rw-r--r-- | contrib/clickhouse/src/TableFunctions/TableFunctionSQLite.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/contrib/clickhouse/src/TableFunctions/TableFunctionSQLite.cpp b/contrib/clickhouse/src/TableFunctions/TableFunctionSQLite.cpp new file mode 100644 index 00000000000..36525ef9226 --- /dev/null +++ b/contrib/clickhouse/src/TableFunctions/TableFunctionSQLite.cpp @@ -0,0 +1,80 @@ +#include <TableFunctions/TableFunctionSQLite.h> + +#if USE_SQLITE + +#include <Common/Exception.h> +#include <Common/quoteString.h> + +#error #include <Databases/SQLite/SQLiteUtils.h> +#include "registerTableFunctions.h" + +#include <Interpreters/evaluateConstantExpression.h> + +#include <Parsers/ASTFunction.h> + +#include <TableFunctions/ITableFunction.h> +#include <TableFunctions/TableFunctionFactory.h> + +#include <Storages/checkAndGetLiteralArgument.h> + + +namespace DB +{ + +namespace ErrorCodes +{ + extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; + extern const int BAD_ARGUMENTS; +} + + +StoragePtr TableFunctionSQLite::executeImpl(const ASTPtr & /*ast_function*/, + ContextPtr context, const String & table_name, ColumnsDescription cached_columns, bool /*is_insert_query*/) const +{ + auto storage = std::make_shared<StorageSQLite>(StorageID(getDatabaseName(), table_name), + sqlite_db, + database_path, + remote_table_name, + cached_columns, ConstraintsDescription{}, context); + + storage->startup(); + return storage; +} + + +ColumnsDescription TableFunctionSQLite::getActualTableStructure(ContextPtr /* context */, bool /*is_insert_query*/) const +{ + return StorageSQLite::getTableStructureFromData(sqlite_db, remote_table_name); +} + + +void TableFunctionSQLite::parseArguments(const ASTPtr & ast_function, ContextPtr context) +{ + const auto & func_args = ast_function->as<ASTFunction &>(); + + if (!func_args.arguments) + throw Exception(ErrorCodes::BAD_ARGUMENTS, "Table function 'sqlite' must have arguments."); + + ASTs & args = func_args.arguments->children; + + if (args.size() != 2) + throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "SQLite database requires 2 arguments: database path, table name"); + + for (auto & arg : args) + arg = evaluateConstantExpressionOrIdentifierAsLiteral(arg, context); + + database_path = checkAndGetLiteralArgument<String>(args[0], "database_path"); + remote_table_name = checkAndGetLiteralArgument<String>(args[1], "table_name"); + + sqlite_db = openSQLiteDB(database_path, context); +} + + +void registerTableFunctionSQLite(TableFunctionFactory & factory) +{ + factory.registerFunction<TableFunctionSQLite>(); +} + +} + +#endif |
