提交 ddbfe0ce 编写于 作者: H hexiaoting

Deprecate ODBCDriver format

上级 17eb8d24
......@@ -381,7 +381,6 @@ FormatFactory::FormatFactory()
registerOutputFormatProcessorJSON(*this);
registerOutputFormatProcessorJSONCompact(*this);
registerOutputFormatProcessorXML(*this);
registerOutputFormatProcessorODBCDriver(*this);
registerOutputFormatProcessorODBCDriver2(*this);
registerOutputFormatProcessorNull(*this);
registerOutputFormatProcessorMySQLWire(*this);
......
......@@ -199,7 +199,6 @@ void registerOutputFormatProcessorJSON(FormatFactory & factory);
void registerOutputFormatProcessorJSONCompact(FormatFactory & factory);
void registerOutputFormatProcessorJSONEachRowWithProgress(FormatFactory & factory);
void registerOutputFormatProcessorXML(FormatFactory & factory);
void registerOutputFormatProcessorODBCDriver(FormatFactory & factory);
void registerOutputFormatProcessorODBCDriver2(FormatFactory & factory);
void registerOutputFormatProcessorNull(FormatFactory & factory);
void registerOutputFormatProcessorMySQLWire(FormatFactory & factory);
......
#include <IO/WriteBuffer.h>
#include <IO/WriteHelpers.h>
#include <Core/Block.h>
#include <Processors/Formats/Impl/ODBCDriverBlockOutputFormat.h>
#include <Formats/FormatFactory.h>
namespace DB
{
ODBCDriverBlockOutputFormat::ODBCDriverBlockOutputFormat(WriteBuffer & out_, const Block & header_, const FormatSettings & format_settings_)
: IOutputFormat(header_, out_), format_settings(format_settings_)
{
}
void ODBCDriverBlockOutputFormat::consume(Chunk chunk)
{
writePrefixIfNot();
const size_t num_rows = chunk.getNumRows();
const size_t num_columns = chunk.getNumColumns();
const auto & columns = chunk.getColumns();
const auto & header = getPort(PortKind::Main).getHeader();
String text_value;
for (size_t i = 0; i < num_rows; ++i)
{
for (size_t j = 0; j < num_columns; ++j)
{
text_value.resize(0);
const auto & column = columns[j];
const auto & type = header.getByPosition(j).type;
{
WriteBufferFromString text_out(text_value);
type->serializeAsText(*column, i, text_out, format_settings);
}
writeStringBinary(text_value, out);
}
}
}
void ODBCDriverBlockOutputFormat::writePrefix()
{
const auto & header = getPort(PortKind::Main).getHeader();
const size_t columns = header.columns();
/// Number of columns.
writeVarUInt(columns, out);
/// Names and types of columns.
for (size_t i = 0; i < columns; ++i)
{
const ColumnWithTypeAndName & col = header.getByPosition(i);
writeStringBinary(col.name, out);
writeStringBinary(col.type->getName(), out);
}
}
void ODBCDriverBlockOutputFormat::finalize()
{
writePrefixIfNot();
}
void registerOutputFormatProcessorODBCDriver(FormatFactory & factory)
{
factory.registerOutputFormatProcessor("ODBCDriver", [](
WriteBuffer & buf,
const Block & sample,
FormatFactory::WriteCallback,
const FormatSettings & format_settings)
{
return std::make_shared<ODBCDriverBlockOutputFormat>(buf, sample, format_settings);
});
}
}
#pragma once
#include <string>
#include <Processors/Formats/IOutputFormat.h>
#include <Formats/FormatSettings.h>
#include <Core/Block.h>
namespace DB
{
class WriteBuffer;
/** A data format designed to simplify the implementation of the ODBC driver.
* ODBC driver is designed to be build for different platforms without dependencies from the main code,
* so the format is made that way so that it can be as easy as possible to parse it.
* A header is displayed with the required information.
* The data is then output in the order of the rows. Each value is displayed as follows: length in VarUInt format, then data in text form.
*/
class ODBCDriverBlockOutputFormat : public IOutputFormat
{
public:
ODBCDriverBlockOutputFormat(WriteBuffer & out_, const Block & header_, const FormatSettings & format_settings_);
String getName() const override { return "ODBCDriverBlockOutputFormat"; }
void consume(Chunk) override;
void finalize() override;
std::string getContentType() const override { return "application/octet-stream"; }
private:
const FormatSettings format_settings;
bool prefix_written = false;
void writePrefixIfNot()
{
if (!prefix_written)
writePrefix();
prefix_written = true;
}
void writePrefix();
};
}
......@@ -38,7 +38,6 @@ SRCS(
Formats/Impl/NativeFormat.cpp
Formats/Impl/NullFormat.cpp
Formats/Impl/ODBCDriver2BlockOutputFormat.cpp
Formats/Impl/ODBCDriverBlockOutputFormat.cpp
Formats/Impl/PostgreSQLOutputFormat.cpp
Formats/Impl/PrettyBlockOutputFormat.cpp
Formats/Impl/PrettyCompactBlockOutputFormat.cpp
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册