fixes/style

This commit is contained in:
bobrovskij artemij 2020-05-06 02:42:44 +03:00
parent 0cc3d780b3
commit a2916c23a5
3 changed files with 24 additions and 16 deletions

View File

@ -3,17 +3,20 @@
#include <common/logger_useful.h> #include <common/logger_useful.h>
#include <Core/Field.h> #include <Core/Field.h>
#include <common/LocalDate.h> #include <common/LocalDate.h>
#include <common/LocalDateTime.h>
namespace DB namespace DB
{ {
namespace { namespace
{
using ValueType = ExternalResultDescription::ValueType; using ValueType = ExternalResultDescription::ValueType;
std::string commaSeparateColumnNames(const ColumnsWithTypeAndName & columns) std::string commaSeparateColumnNames(const ColumnsWithTypeAndName & columns)
{ {
std::string result = "("; std::string result = "(";
for (size_t i = 0; i < columns.size(); ++i) { for (size_t i = 0; i < columns.size(); ++i)
{
if (i > 0) if (i > 0)
result += ","; result += ",";
result += columns[i].name; result += columns[i].name;
@ -24,7 +27,8 @@ namespace {
std::string getQuestionMarks(size_t n) std::string getQuestionMarks(size_t n)
{ {
std::string result = "("; std::string result = "(";
for (size_t i = 0; i < n; ++i) { for (size_t i = 0; i < n; ++i)
{
if (i > 0) if (i > 0)
result += ","; result += ",";
result += "?"; result += "?";
@ -34,21 +38,22 @@ namespace {
Poco::Dynamic::Var getVarFromField(const Field & field, const ValueType type) Poco::Dynamic::Var getVarFromField(const Field & field, const ValueType type)
{ {
switch (type) { switch (type)
{
case ValueType::vtUInt8: case ValueType::vtUInt8:
return Poco::Dynamic::Var(static_cast<UInt64>(field.get<UInt8>())).convert<UInt64>(); return Poco::Dynamic::Var(static_cast<UInt64>(field.get<UInt64>())).convert<UInt64>();
case ValueType::vtUInt16: case ValueType::vtUInt16:
return Poco::Dynamic::Var(static_cast<UInt64>(field.get<UInt16>())).convert<UInt64>(); return Poco::Dynamic::Var(static_cast<UInt64>(field.get<UInt64>())).convert<UInt64>();
case ValueType::vtUInt32: case ValueType::vtUInt32:
return Poco::Dynamic::Var(static_cast<UInt64>(field.get<UInt32>())).convert<UInt64>(); return Poco::Dynamic::Var(static_cast<UInt64>(field.get<UInt64>())).convert<UInt64>();
case ValueType::vtUInt64: case ValueType::vtUInt64:
return Poco::Dynamic::Var(field.get<UInt64>()).convert<UInt64>(); return Poco::Dynamic::Var(field.get<UInt64>()).convert<UInt64>();
case ValueType::vtInt8: case ValueType::vtInt8:
return Poco::Dynamic::Var(static_cast<Int64>(field.get<Int8>())).convert<Int64>(); return Poco::Dynamic::Var(static_cast<Int64>(field.get<Int64>())).convert<Int64>();
case ValueType::vtInt16: case ValueType::vtInt16:
return Poco::Dynamic::Var(static_cast<Int64>(field.get<Int16>())).convert<Int64>(); return Poco::Dynamic::Var(static_cast<Int64>(field.get<Int64>())).convert<Int64>();
case ValueType::vtInt32: case ValueType::vtInt32:
return Poco::Dynamic::Var(static_cast<Int64>(field.get<Int32>())).convert<Int64>(); return Poco::Dynamic::Var(static_cast<Int64>(field.get<Int64>())).convert<Int64>();
case ValueType::vtInt64: case ValueType::vtInt64:
return Poco::Dynamic::Var(field.get<Int64>()).convert<Int64>(); return Poco::Dynamic::Var(field.get<Int64>()).convert<Int64>();
case ValueType::vtFloat32: case ValueType::vtFloat32:
@ -58,9 +63,9 @@ namespace {
case ValueType::vtString: case ValueType::vtString:
return Poco::Dynamic::Var(field.get<String>()).convert<String>(); return Poco::Dynamic::Var(field.get<String>()).convert<String>();
case ValueType::vtDate: case ValueType::vtDate:
return Poco::Dynamic::Var(LocalDate(DayNum(field.get<UInt16>())).toString()).convert<String>(); return Poco::Dynamic::Var(LocalDate(DayNum(field.get<UInt64>())).toString()).convert<String>();
case ValueType::vtDateTime: case ValueType::vtDateTime:
return Poco::Dynamic::Var(LocalDate(time_t(field.get<UInt32>())).toString()).convert<String>(); return Poco::Dynamic::Var(std::to_string(LocalDateTime(time_t(field.get<UInt64>())))).convert<String>();
case ValueType::vtUUID: case ValueType::vtUUID:
return Poco::Dynamic::Var(UUID(field.get<UInt128>()).toUnderType().toHexString()).convert<std::string>(); return Poco::Dynamic::Var(UUID(field.get<UInt128>()).toUnderType().toHexString()).convert<std::string>();
} }

View File

@ -5,8 +5,10 @@
#include <Poco/Data/Session.h> #include <Poco/Data/Session.h>
#include <Core/ExternalResultDescription.h> #include <Core/ExternalResultDescription.h>
namespace DB{ namespace DB
class ODBCBlockOutputStream : public IBlockOutputStream { {
class ODBCBlockOutputStream : public IBlockOutputStream
{
public: public:
ODBCBlockOutputStream(Poco::Data::Session && session_, const std::string & remote_database_name_, ODBCBlockOutputStream(Poco::Data::Session && session_, const std::string & remote_database_name_,
const std::string & remote_table_name_, const Block & sample_block_); const std::string & remote_table_name_, const Block & sample_block_);

View File

@ -95,10 +95,10 @@ Pipes StorageXDBC::read(const Names & column_names,
return IStorageURLBase::read(column_names, query_info, context, processed_stage, max_block_size, num_streams); return IStorageURLBase::read(column_names, query_info, context, processed_stage, max_block_size, num_streams);
} }
BlockOutputStreamPtr StorageXDBC::write(const ASTPtr & /*query*/, const Context & context) { BlockOutputStreamPtr StorageXDBC::write(const ASTPtr & /*query*/, const Context & context)
{
bridge_helper->startBridgeSync(); bridge_helper->startBridgeSync();
// some copypaste
NamesAndTypesList cols; NamesAndTypesList cols;
Poco::URI request_uri = uri; Poco::URI request_uri = uri;
request_uri.setPath("/write"); request_uri.setPath("/write");
@ -112,6 +112,7 @@ BlockOutputStreamPtr StorageXDBC::write(const ASTPtr & /*query*/, const Context
request_uri.addQueryParameter(param, value); request_uri.addQueryParameter(param, value);
request_uri.addQueryParameter("db_name", remote_database_name); request_uri.addQueryParameter("db_name", remote_database_name);
request_uri.addQueryParameter("table_name", remote_table_name); request_uri.addQueryParameter("table_name", remote_table_name);
request_uri.addQueryParameter("format_name", format_name);
return std::make_shared<StorageURLBlockOutputStream>( return std::make_shared<StorageURLBlockOutputStream>(
request_uri, format_name, getSampleBlock(), context, request_uri, format_name, getSampleBlock(), context,