Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3835 Add totals row for WITH TOTALS query #3836

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy paste.

{
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;
};



}