mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
Merge pull request #34551 from ClickHouse/xdbc-constraints
Allow constraints for ODBC and JDBC tables
This commit is contained in:
commit
7cd4619d9f
@ -27,11 +27,11 @@ StorageXDBC::StorageXDBC(
|
||||
const StorageID & table_id_,
|
||||
const std::string & remote_database_name_,
|
||||
const std::string & remote_table_name_,
|
||||
const ColumnsDescription & columns_,
|
||||
ColumnsDescription columns_,
|
||||
ConstraintsDescription constraints_,
|
||||
const String & comment,
|
||||
ContextPtr context_,
|
||||
const BridgeHelperPtr bridge_helper_)
|
||||
/// Please add support for constraints as soon as StorageODBC or JDBC will support insertion.
|
||||
: IStorageURLBase(
|
||||
"",
|
||||
context_,
|
||||
@ -39,7 +39,7 @@ StorageXDBC::StorageXDBC(
|
||||
IXDBCBridgeHelper::DEFAULT_FORMAT,
|
||||
getFormatSettings(context_),
|
||||
columns_,
|
||||
ConstraintsDescription{},
|
||||
constraints_,
|
||||
comment,
|
||||
"" /* CompressionMethod */)
|
||||
, bridge_helper(bridge_helper_)
|
||||
@ -179,6 +179,7 @@ namespace
|
||||
checkAndGetLiteralArgument<String>(engine_args[1], "database_name"),
|
||||
checkAndGetLiteralArgument<String>(engine_args[2], "table_name"),
|
||||
args.columns,
|
||||
args.constraints,
|
||||
args.comment,
|
||||
args.getContext(),
|
||||
bridge_helper);
|
||||
|
@ -32,7 +32,8 @@ public:
|
||||
const StorageID & table_id_,
|
||||
const std::string & remote_database_name,
|
||||
const std::string & remote_table_name,
|
||||
const ColumnsDescription & columns_,
|
||||
ColumnsDescription columns_,
|
||||
ConstraintsDescription constraints_,
|
||||
const String & comment,
|
||||
ContextPtr context_,
|
||||
BridgeHelperPtr bridge_helper_);
|
||||
|
@ -1,9 +1,6 @@
|
||||
#include <type_traits>
|
||||
#include <base/scope_guard.h>
|
||||
|
||||
#include <Core/Defines.h>
|
||||
#include <DataTypes/DataTypeFactory.h>
|
||||
#include <IO/ReadHelpers.h>
|
||||
#include <IO/WriteHelpers.h>
|
||||
#include <IO/ReadWriteBufferFromHTTP.h>
|
||||
#include <IO/ConnectionTimeoutsContext.h>
|
||||
#include <Interpreters/evaluateConstantExpression.h>
|
||||
@ -16,10 +13,9 @@
|
||||
#include <TableFunctions/TableFunctionFactory.h>
|
||||
#include <Poco/Net/HTTPRequest.h>
|
||||
#include <Common/Exception.h>
|
||||
#include <Common/typeid_cast.h>
|
||||
#include <Poco/NumberFormatter.h>
|
||||
#include "registerTableFunctions.h"
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
namespace ErrorCodes
|
||||
@ -33,13 +29,12 @@ void ITableFunctionXDBC::parseArguments(const ASTPtr & ast_function, ContextPtr
|
||||
const auto & args_func = ast_function->as<ASTFunction &>();
|
||||
|
||||
if (!args_func.arguments)
|
||||
throw Exception("Table function '" + getName() + "' must have arguments.", ErrorCodes::LOGICAL_ERROR);
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Table function '{}' must have arguments.", getName());
|
||||
|
||||
ASTs & args = args_func.arguments->children;
|
||||
if (args.size() != 2 && args.size() != 3)
|
||||
throw Exception("Table function '" + getName() + "' requires 2 or 3 arguments: " + getName() + "('DSN', table) or " + getName()
|
||||
+ "('DSN', schema, table)",
|
||||
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
||||
throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH,
|
||||
"Table function '{0}' requires 2 or 3 arguments: {0}('DSN', table) or {0}('DSN', schema, table)", getName());
|
||||
|
||||
for (auto & arg : args)
|
||||
arg = evaluateConstantExpressionOrIdentifierAsLiteral(arg, context);
|
||||
@ -61,7 +56,6 @@ void ITableFunctionXDBC::startBridgeIfNot(ContextPtr context) const
|
||||
{
|
||||
if (!helper)
|
||||
{
|
||||
/// Have to const_cast, because bridges store their commands inside context
|
||||
helper = createBridgeHelper(context, context->getSettingsRef().http_receive_timeout.value, connection_string);
|
||||
helper->startBridgeSync();
|
||||
}
|
||||
@ -71,16 +65,15 @@ ColumnsDescription ITableFunctionXDBC::getActualTableStructure(ContextPtr contex
|
||||
{
|
||||
startBridgeIfNot(context);
|
||||
|
||||
/* Infer external table structure */
|
||||
/// Infer external table structure.
|
||||
Poco::URI columns_info_uri = helper->getColumnsInfoURI();
|
||||
columns_info_uri.addQueryParameter("connection_string", connection_string);
|
||||
if (!schema_name.empty())
|
||||
columns_info_uri.addQueryParameter("schema", schema_name);
|
||||
columns_info_uri.addQueryParameter("table", remote_table_name);
|
||||
|
||||
const auto use_nulls = context->getSettingsRef().external_table_functions_use_nulls;
|
||||
columns_info_uri.addQueryParameter("external_table_functions_use_nulls",
|
||||
Poco::NumberFormatter::format(use_nulls));
|
||||
bool use_nulls = context->getSettingsRef().external_table_functions_use_nulls;
|
||||
columns_info_uri.addQueryParameter("external_table_functions_use_nulls", toString(use_nulls));
|
||||
|
||||
Poco::Net::HTTPBasicCredentials credentials{};
|
||||
ReadWriteBufferFromHTTP buf(columns_info_uri, Poco::Net::HTTPRequest::HTTP_POST, {}, ConnectionTimeouts::getHTTPTimeouts(context), credentials);
|
||||
@ -97,7 +90,7 @@ StoragePtr ITableFunctionXDBC::executeImpl(const ASTPtr & /*ast_function*/, Cont
|
||||
startBridgeIfNot(context);
|
||||
auto columns = getActualTableStructure(context);
|
||||
auto result = std::make_shared<StorageXDBC>(
|
||||
StorageID(getDatabaseName(), table_name), schema_name, remote_table_name, columns, String{}, context, helper);
|
||||
StorageID(getDatabaseName(), table_name), schema_name, remote_table_name, columns, ConstraintsDescription{}, String{}, context, helper);
|
||||
result->startup();
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user