Fixed segfault [#METR-20155].

This commit is contained in:
Alexey Milovidov 2016-02-25 05:37:31 +03:00
parent dcce15052f
commit b5ac93cf0e
3 changed files with 181 additions and 13 deletions

View File

@ -16,7 +16,23 @@ public:
MaterializingBlockOutputStream(const BlockOutputStreamPtr & output)
: output{output} {}
void write(const Block & original_block) override
void write(const Block & block) override
{
output->write(materialize(block));
}
void flush() override { output->flush(); }
void writePrefix() override { output->writePrefix(); }
void writeSuffix() override { output->writeSuffix(); }
void setRowsBeforeLimit(size_t rows_before_limit) override { output->setRowsBeforeLimit(rows_before_limit); }
void setTotals(const Block & totals) override { output->setTotals(materialize(totals)); }
void setExtremes(const Block & extremes) override { output->setExtremes(materialize(extremes)); }
String getContentType() const override { return output->getContentType(); }
private:
BlockOutputStreamPtr output;
static Block materialize(const Block & original_block)
{
/// copy block to get rid of const
auto block = original_block;
@ -29,19 +45,8 @@ public:
src = converted;
}
output->write(block);
return block;
}
void flush() override { output->flush(); }
void writePrefix() override { output->writePrefix(); }
void writeSuffix() override { output->writeSuffix(); }
void setRowsBeforeLimit(size_t rows_before_limit) override { output->setRowsBeforeLimit(rows_before_limit); }
void setTotals(const Block & totals) override { output->setTotals(totals); }
void setExtremes(const Block & extremes) override { output->setExtremes(extremes); }
String getContentType() const override { return output->getContentType(); }
private:
BlockOutputStreamPtr output;
};
}

View File

@ -0,0 +1,154 @@
1 1
1 1
1 1
1 1
{
"meta":
[
{
"name": "k",
"type": "UInt64"
},
{
"name": "count()",
"type": "UInt64"
}
],
"data":
[
{
"k": "1234567890123",
"count()": "1"
}
],
"totals":
{
"k": "1234567890123",
"count()": "1"
},
"extremes":
{
"min":
{
"k": "1234567890123",
"count()": "1"
},
"max":
{
"k": "1234567890123",
"count()": "1"
}
},
"rows": 1
}
{
"meta":
[
{
"name": "k",
"type": "Float32"
},
{
"name": "count()",
"type": "UInt64"
}
],
"data":
[
[1.23, "1"]
],
"totals": [1.23,"1"],
"extremes":
{
"min": [1.23,"1"],
"max": [1.23,"1"]
},
"rows": 1
}
2010-01-01 1
2010-01-01 1
2010-01-01 1
2010-01-01 1
{
"meta":
[
{
"name": "k",
"type": "DateTime"
},
{
"name": "count()",
"type": "UInt64"
}
],
"data":
[
{
"k": "2010-01-01 01:02:03",
"count()": "1"
}
],
"totals":
{
"k": "2010-01-01 01:02:03",
"count()": "1"
},
"extremes":
{
"min":
{
"k": "2010-01-01 01:02:03",
"count()": "1"
},
"max":
{
"k": "2010-01-01 01:02:03",
"count()": "1"
}
},
"rows": 1
}
{
"meta":
[
{
"name": "k",
"type": "Float64"
},
{
"name": "count()",
"type": "UInt64"
}
],
"data":
[
[1.1, "1"]
],
"totals": [1.1,"1"],
"extremes":
{
"min": [1.1,"1"],
"max": [1.1,"1"]
},
"rows": 1
}

View File

@ -0,0 +1,9 @@
#!/bin/bash
curl -sS 'http://localhost:8123/?extremes=1' -d "SELECT 1 AS k, count() GROUP BY k WITH TOTALS";
curl -sS 'http://localhost:8123/?extremes=1' -d "SELECT 1234567890123 AS k, count() GROUP BY k WITH TOTALS FORMAT JSON";
curl -sS 'http://localhost:8123/?extremes=1' -d "SELECT toFloat32(1.23) AS k, count() GROUP BY k WITH TOTALS FORMAT JSONCompact";
curl -sS 'http://localhost:8123/?extremes=1' -d "SELECT toDate('2010-01-01') AS k, count() GROUP BY k WITH TOTALS";
curl -sS 'http://localhost:8123/?extremes=1' -d "SELECT toDateTime('2010-01-01 01:02:03') AS k, count() GROUP BY k WITH TOTALS FORMAT JSON";
curl -sS 'http://localhost:8123/?extremes=1' -d "SELECT 1.1 AS k, count() GROUP BY k WITH TOTALS FORMAT JSONCompact";