Skip to content

Commit

Permalink
Merge pull request #3836 from nightweb/3835-add-with-totals-support
Browse files Browse the repository at this point in the history
#3835 Add totals row for WITH TOTALS query
  • Loading branch information
alexey-milovidov authored Dec 14, 2018
2 parents 7380abf + b6feafe commit dd8c947
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
34 changes: 33 additions & 1 deletion dbms/src/Formats/ODBCDriver2BlockOutputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void ODBCDriver2BlockOutputStream::write(const Block & block)
{
for (size_t j = 0; j < columns; ++j)
{
text_value.resize(0);
text_value.clear();
const ColumnWithTypeAndName & col = block.getByPosition(j);

if (col.column->isNullAt(i))
Expand All @@ -56,6 +56,38 @@ void ODBCDriver2BlockOutputStream::write(const Block & block)
}
}

void ODBCDriver2BlockOutputStream::writeSuffix()
{
writeTotals();
}

void ODBCDriver2BlockOutputStream::writeTotals()
{
const size_t totals_columns = totals.columns();
String text_value;
if (totals)
{
for (size_t i = 0; i < totals_columns; ++i)
{
text_value.clear();
const ColumnWithTypeAndName & column = totals.safeGetByPosition(i);

if (column.column->isNullAt(i))
{
writeIntBinary(Int32(-1), out);
}
else
{
{
WriteBufferFromString text_out(text_value);
column.type->serializeText(*column.column, i, text_out, format_settings);
}
writeODBCString(out, text_value);
}
}
}
}

void ODBCDriver2BlockOutputStream::writePrefix()
{
const size_t columns = header.columns();
Expand Down
7 changes: 7 additions & 0 deletions dbms/src/Formats/ODBCDriver2BlockOutputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,24 @@ class ODBCDriver2BlockOutputStream : public IBlockOutputStream
}
void write(const Block & block) override;
void writePrefix() override;
void writeSuffix() override;

void flush() override;
std::string getContentType() const override
{
return "application/octet-stream";
}
void setTotals(const Block & totals_) override { totals = totals_; }

private:
WriteBuffer & out;
const Block header;
const FormatSettings format_settings;
protected:
void writeTotals();
Block totals;
};



}

0 comments on commit dd8c947

Please sign in to comment.