mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
Remove XMLRowOutputStream.
This commit is contained in:
parent
6e3274ef98
commit
a92f086600
@ -223,7 +223,6 @@ void registerOutputFormatProcessorProtobuf(FormatFactory & factory);
|
||||
|
||||
/// Output only (presentational) formats.
|
||||
|
||||
void registerOutputFormatXML(FormatFactory & factory);
|
||||
void registerOutputFormatNull(FormatFactory & factory);
|
||||
|
||||
void registerOutputFormatProcessorPretty(FormatFactory & factory);
|
||||
@ -269,7 +268,6 @@ FormatFactory::FormatFactory()
|
||||
registerOutputFormatProcessorParquet(*this);
|
||||
|
||||
|
||||
registerOutputFormatXML(*this);
|
||||
registerOutputFormatNull(*this);
|
||||
|
||||
registerOutputFormatProcessorPretty(*this);
|
||||
|
@ -1,240 +0,0 @@
|
||||
#include <IO/WriteHelpers.h>
|
||||
#include <IO/WriteBufferValidUTF8.h>
|
||||
#include <Formats/XMLRowOutputStream.h>
|
||||
#include <Formats/FormatFactory.h>
|
||||
#include <Formats/BlockOutputStreamFromRowOutputStream.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
XMLRowOutputStream::XMLRowOutputStream(WriteBuffer & ostr_, const Block & sample_, const FormatSettings & format_settings)
|
||||
: dst_ostr(ostr_), format_settings(format_settings)
|
||||
{
|
||||
NamesAndTypesList columns(sample_.getNamesAndTypesList());
|
||||
fields.assign(columns.begin(), columns.end());
|
||||
field_tag_names.resize(sample_.columns());
|
||||
|
||||
bool need_validate_utf8 = false;
|
||||
for (size_t i = 0; i < sample_.columns(); ++i)
|
||||
{
|
||||
if (!sample_.getByPosition(i).type->textCanContainOnlyValidUTF8())
|
||||
need_validate_utf8 = true;
|
||||
|
||||
/// As element names, we will use the column name if it has a valid form, or "field", otherwise.
|
||||
/// The condition below is more strict than the XML standard requires.
|
||||
bool is_column_name_suitable = true;
|
||||
const char * begin = fields[i].name.data();
|
||||
const char * end = begin + fields[i].name.size();
|
||||
for (const char * pos = begin; pos != end; ++pos)
|
||||
{
|
||||
char c = *pos;
|
||||
if (!(isAlphaASCII(c)
|
||||
|| (pos != begin && isNumericASCII(c))
|
||||
|| c == '_'
|
||||
|| c == '-'
|
||||
|| c == '.'))
|
||||
{
|
||||
is_column_name_suitable = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
field_tag_names[i] = is_column_name_suitable
|
||||
? fields[i].name
|
||||
: "field";
|
||||
}
|
||||
|
||||
if (need_validate_utf8)
|
||||
{
|
||||
validating_ostr = std::make_unique<WriteBufferValidUTF8>(dst_ostr);
|
||||
ostr = validating_ostr.get();
|
||||
}
|
||||
else
|
||||
ostr = &dst_ostr;
|
||||
}
|
||||
|
||||
|
||||
void XMLRowOutputStream::writePrefix()
|
||||
{
|
||||
writeCString("<?xml version='1.0' encoding='UTF-8' ?>\n", *ostr);
|
||||
writeCString("<result>\n", *ostr);
|
||||
writeCString("\t<meta>\n", *ostr);
|
||||
writeCString("\t\t<columns>\n", *ostr);
|
||||
|
||||
for (size_t i = 0; i < fields.size(); ++i)
|
||||
{
|
||||
writeCString("\t\t\t<column>\n", *ostr);
|
||||
|
||||
writeCString("\t\t\t\t<name>", *ostr);
|
||||
writeXMLString(fields[i].name, *ostr);
|
||||
writeCString("</name>\n", *ostr);
|
||||
writeCString("\t\t\t\t<type>", *ostr);
|
||||
writeXMLString(fields[i].type->getName(), *ostr);
|
||||
writeCString("</type>\n", *ostr);
|
||||
|
||||
writeCString("\t\t\t</column>\n", *ostr);
|
||||
}
|
||||
|
||||
writeCString("\t\t</columns>\n", *ostr);
|
||||
writeCString("\t</meta>\n", *ostr);
|
||||
writeCString("\t<data>\n", *ostr);
|
||||
}
|
||||
|
||||
|
||||
void XMLRowOutputStream::writeField(const IColumn & column, const IDataType & type, size_t row_num)
|
||||
{
|
||||
writeCString("\t\t\t<", *ostr);
|
||||
writeString(field_tag_names[field_number], *ostr);
|
||||
writeCString(">", *ostr);
|
||||
type.serializeAsTextXML(column, row_num, *ostr, format_settings);
|
||||
writeCString("</", *ostr);
|
||||
writeString(field_tag_names[field_number], *ostr);
|
||||
writeCString(">\n", *ostr);
|
||||
++field_number;
|
||||
}
|
||||
|
||||
|
||||
void XMLRowOutputStream::writeRowStartDelimiter()
|
||||
{
|
||||
writeCString("\t\t<row>\n", *ostr);
|
||||
}
|
||||
|
||||
|
||||
void XMLRowOutputStream::writeRowEndDelimiter()
|
||||
{
|
||||
writeCString("\t\t</row>\n", *ostr);
|
||||
field_number = 0;
|
||||
++row_count;
|
||||
}
|
||||
|
||||
|
||||
void XMLRowOutputStream::writeSuffix()
|
||||
{
|
||||
writeCString("\t</data>\n", *ostr);
|
||||
|
||||
writeTotals();
|
||||
writeExtremes();
|
||||
|
||||
writeCString("\t<rows>", *ostr);
|
||||
writeIntText(row_count, *ostr);
|
||||
writeCString("</rows>\n", *ostr);
|
||||
|
||||
writeRowsBeforeLimitAtLeast();
|
||||
|
||||
if (format_settings.write_statistics)
|
||||
writeStatistics();
|
||||
|
||||
writeCString("</result>\n", *ostr);
|
||||
ostr->next();
|
||||
}
|
||||
|
||||
void XMLRowOutputStream::writeRowsBeforeLimitAtLeast()
|
||||
{
|
||||
if (applied_limit)
|
||||
{
|
||||
writeCString("\t<rows_before_limit_at_least>", *ostr);
|
||||
writeIntText(rows_before_limit, *ostr);
|
||||
writeCString("</rows_before_limit_at_least>\n", *ostr);
|
||||
}
|
||||
}
|
||||
|
||||
void XMLRowOutputStream::writeTotals()
|
||||
{
|
||||
if (totals)
|
||||
{
|
||||
writeCString("\t<totals>\n", *ostr);
|
||||
|
||||
size_t totals_columns = totals.columns();
|
||||
for (size_t i = 0; i < totals_columns; ++i)
|
||||
{
|
||||
const ColumnWithTypeAndName & column = totals.safeGetByPosition(i);
|
||||
|
||||
writeCString("\t\t<", *ostr);
|
||||
writeString(field_tag_names[i], *ostr);
|
||||
writeCString(">", *ostr);
|
||||
column.type->serializeAsTextXML(*column.column.get(), 0, *ostr, format_settings);
|
||||
writeCString("</", *ostr);
|
||||
writeString(field_tag_names[i], *ostr);
|
||||
writeCString(">\n", *ostr);
|
||||
}
|
||||
|
||||
writeCString("\t</totals>\n", *ostr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void writeExtremesElement(
|
||||
const char * title, const Block & extremes, size_t row_num, const Names & field_tag_names, WriteBuffer & ostr, const FormatSettings & format_settings)
|
||||
{
|
||||
writeCString("\t\t<", ostr);
|
||||
writeCString(title, ostr);
|
||||
writeCString(">\n", ostr);
|
||||
|
||||
size_t extremes_columns = extremes.columns();
|
||||
for (size_t i = 0; i < extremes_columns; ++i)
|
||||
{
|
||||
const ColumnWithTypeAndName & column = extremes.safeGetByPosition(i);
|
||||
|
||||
writeCString("\t\t\t<", ostr);
|
||||
writeString(field_tag_names[i], ostr);
|
||||
writeCString(">", ostr);
|
||||
column.type->serializeAsTextXML(*column.column.get(), row_num, ostr, format_settings);
|
||||
writeCString("</", ostr);
|
||||
writeString(field_tag_names[i], ostr);
|
||||
writeCString(">\n", ostr);
|
||||
}
|
||||
|
||||
writeCString("\t\t</", ostr);
|
||||
writeCString(title, ostr);
|
||||
writeCString(">\n", ostr);
|
||||
}
|
||||
|
||||
void XMLRowOutputStream::writeExtremes()
|
||||
{
|
||||
if (extremes)
|
||||
{
|
||||
writeCString("\t<extremes>\n", *ostr);
|
||||
writeExtremesElement("min", extremes, 0, field_tag_names, *ostr, format_settings);
|
||||
writeExtremesElement("max", extremes, 1, field_tag_names, *ostr, format_settings);
|
||||
writeCString("\t</extremes>\n", *ostr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void XMLRowOutputStream::onProgress(const Progress & value)
|
||||
{
|
||||
progress.incrementPiecewiseAtomically(value);
|
||||
}
|
||||
|
||||
|
||||
void XMLRowOutputStream::writeStatistics()
|
||||
{
|
||||
writeCString("\t<statistics>\n", *ostr);
|
||||
writeCString("\t\t<elapsed>", *ostr);
|
||||
writeText(watch.elapsedSeconds(), *ostr);
|
||||
writeCString("</elapsed>\n", *ostr);
|
||||
writeCString("\t\t<rows_read>", *ostr);
|
||||
writeText(progress.read_rows.load(), *ostr);
|
||||
writeCString("</rows_read>\n", *ostr);
|
||||
writeCString("\t\t<bytes_read>", *ostr);
|
||||
writeText(progress.read_bytes.load(), *ostr);
|
||||
writeCString("</bytes_read>\n", *ostr);
|
||||
writeCString("\t</statistics>\n", *ostr);
|
||||
}
|
||||
|
||||
|
||||
void registerOutputFormatXML(FormatFactory & factory)
|
||||
{
|
||||
factory.registerOutputFormat("XML", [](
|
||||
WriteBuffer & buf,
|
||||
const Block & sample,
|
||||
const Context &,
|
||||
const FormatSettings & settings)
|
||||
{
|
||||
return std::make_shared<BlockOutputStreamFromRowOutputStream>(
|
||||
std::make_shared<XMLRowOutputStream>(buf, sample, settings), sample);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Core/Block.h>
|
||||
#include <IO/Progress.h>
|
||||
#include <IO/WriteBuffer.h>
|
||||
#include <Common/Stopwatch.h>
|
||||
#include <Formats/FormatSettings.h>
|
||||
#include <Formats/IRowOutputStream.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
/** A stream for outputting data in XML format.
|
||||
*/
|
||||
class XMLRowOutputStream : public IRowOutputStream
|
||||
{
|
||||
public:
|
||||
XMLRowOutputStream(WriteBuffer & ostr_, const Block & sample_, const FormatSettings & format_settings);
|
||||
|
||||
void writeField(const IColumn & column, const IDataType & type, size_t row_num) override;
|
||||
void writeRowStartDelimiter() override;
|
||||
void writeRowEndDelimiter() override;
|
||||
void writePrefix() override;
|
||||
void writeSuffix() override;
|
||||
|
||||
void flush() override
|
||||
{
|
||||
ostr->next();
|
||||
|
||||
if (validating_ostr)
|
||||
dst_ostr.next();
|
||||
}
|
||||
|
||||
void setRowsBeforeLimit(size_t rows_before_limit_) override
|
||||
{
|
||||
applied_limit = true;
|
||||
rows_before_limit = rows_before_limit_;
|
||||
}
|
||||
|
||||
void setTotals(const Block & totals_) override { totals = totals_; }
|
||||
void setExtremes(const Block & extremes_) override { extremes = extremes_; }
|
||||
|
||||
void onProgress(const Progress & value) override;
|
||||
|
||||
String getContentType() const override { return "application/xml; charset=UTF-8"; }
|
||||
|
||||
protected:
|
||||
|
||||
void writeRowsBeforeLimitAtLeast();
|
||||
virtual void writeTotals();
|
||||
virtual void writeExtremes();
|
||||
void writeStatistics();
|
||||
|
||||
WriteBuffer & dst_ostr;
|
||||
std::unique_ptr<WriteBuffer> validating_ostr; /// Validates UTF-8 sequences, replaces bad sequences with replacement character.
|
||||
WriteBuffer * ostr;
|
||||
|
||||
size_t field_number = 0;
|
||||
size_t row_count = 0;
|
||||
bool applied_limit = false;
|
||||
size_t rows_before_limit = 0;
|
||||
NamesAndTypes fields;
|
||||
Names field_tag_names;
|
||||
Block totals;
|
||||
Block extremes;
|
||||
|
||||
Progress progress;
|
||||
Stopwatch watch;
|
||||
const FormatSettings format_settings;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user