Better semantic of sharing columns: development [#CLICKHOUSE-2].

This commit is contained in:
Alexey Milovidov 2017-12-17 13:14:12 +03:00
parent 75c0ad10ab
commit 6f7d2b99ea
3 changed files with 37 additions and 9 deletions

View File

@ -33,7 +33,7 @@ std::ostream & operator<<(std::ostream & stream, const DB::NameAndTypePair & wha
std::ostream & operator<<(std::ostream & stream, const DB::IDataType & what) std::ostream & operator<<(std::ostream & stream, const DB::IDataType & what)
{ {
stream << "IDataType(name = " << what.getName() << ", default = " << what.getDefault(); stream << "IDataType(name = " << what.getName() << ", default = " << what.getDefault() << ")";
return stream; return stream;
} }
@ -67,17 +67,34 @@ std::ostream & operator<<(std::ostream & stream, const DB::Block & what)
return stream; return stream;
} }
#include <Common/COWPtr.h>
template <typename T>
std::ostream & printCOWPtr(std::ostream & stream, const typename COWPtr<T>::Ptr & what)
{
stream << "COWPtr::Ptr(" << what.get();
if (what)
stream << ", use_count = " << what->use_count();
stream << ") {";
if (what)
stream << *what;
else
stream << "nullptr";
stream << "}";
return stream;
}
std::ostream & operator<<(std::ostream & stream, const DB::ColumnWithTypeAndName & what) std::ostream & operator<<(std::ostream & stream, const DB::ColumnWithTypeAndName & what)
{ {
stream << "ColumnWithTypeAndName(name = " << what.name << ", type = " << what.type << ", column = " << what.column << ")"; stream << "ColumnWithTypeAndName(name = " << what.name << ", type = " << what.type << ", column = ";
return stream; return printCOWPtr<DB::IColumn>(stream, what.column) << ")";
} }
std::ostream & operator<<(std::ostream & stream, const DB::IColumn & what) std::ostream & operator<<(std::ostream & stream, const DB::IColumn & what)
{ {
stream << "IColumn(name = " << what.getName() stream << "IColumn(" << what.dumpStructure() << ")";
// TODO: maybe many flags here
<< ")";
return stream; return stream;
} }
@ -116,7 +133,7 @@ std::ostream & operator<<(std::ostream & stream, const DB::IAST & what)
std::ostream & operator<<(std::ostream & stream, const DB::ExpressionAnalyzer & what) std::ostream & operator<<(std::ostream & stream, const DB::ExpressionAnalyzer & what)
{ {
stream << "ExpressionAnalyzer{" stream << "ExpressionAnalyzer{"
<< "hasAggregation="<<what.hasAggregation() << "hasAggregation=" << what.hasAggregation()
<< ", RequiredColumns=" << what.getRequiredColumns() << ", RequiredColumns=" << what.getRequiredColumns()
<< ", SubqueriesForSet=" << what.getSubqueriesForSets() << ", SubqueriesForSet=" << what.getSubqueriesForSets()
<< ", ExternalTables=" << what.getExternalTables() << ", ExternalTables=" << what.getExternalTables()

View File

@ -227,7 +227,18 @@ void ExpressionAction::prepare(Block & sample_block)
/// If the result is not a constant, just in case, we will consider the result as unknown. /// If the result is not a constant, just in case, we will consider the result as unknown.
ColumnWithTypeAndName & col = sample_block.safeGetByPosition(result_position); ColumnWithTypeAndName & col = sample_block.safeGetByPosition(result_position);
if (!col.column->isColumnConst()) if (!col.column->isColumnConst())
{
col.column = nullptr; col.column = nullptr;
}
else
{
/// All constant (literal) columns in block are added with size 1.
/// But if there was no columns in block before executing a function, the result has size 0.
/// Change the size to 1.
if (col.column->empty())
col.column = col.column->cloneResized(1);
}
} }
else else
{ {

View File

@ -144,7 +144,7 @@ std::ostream & operator<<(std::ostream & stream, const std::chrono::time_point<c
template <typename T> template <typename T>
std::ostream & operator<<(std::ostream & stream, const std::shared_ptr<T> & what) std::ostream & operator<<(std::ostream & stream, const std::shared_ptr<T> & what)
{ {
stream << "shared_ptr("<< what.get() <<", use_count = " << what.use_count() << ") {"; stream << "shared_ptr(" << what.get() <<", use_count = " << what.use_count() << ") {";
if (what) if (what)
stream << *what; stream << *what;
else else
@ -156,7 +156,7 @@ std::ostream & operator<<(std::ostream & stream, const std::shared_ptr<T> & what
template <typename T> template <typename T>
std::ostream & operator<<(std::ostream & stream, const std::unique_ptr<T> & what) std::ostream & operator<<(std::ostream & stream, const std::unique_ptr<T> & what)
{ {
stream << "unique_ptr("<< what.get() <<") {"; stream << "unique_ptr(" << what.get() <<") {";
if (what) if (what)
stream << *what; stream << *what;
else else