mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
show defaulted columns info in DESC TABLE query output. [#METR-12739]
This commit is contained in:
parent
8052020218
commit
34dba980c7
@ -10,6 +10,8 @@
|
||||
#include <DB/DataTypes/DataTypesNumberFixed.h>
|
||||
#include <DB/DataTypes/DataTypeString.h>
|
||||
#include <DB/Columns/ColumnString.h>
|
||||
#include <DB/Parsers/formatAST.h>
|
||||
|
||||
|
||||
|
||||
namespace DB
|
||||
@ -59,13 +61,18 @@ private:
|
||||
col.name = "name";
|
||||
col.type = new DataTypeString;
|
||||
col.column = col.type->createColumn();
|
||||
|
||||
block.insert(col);
|
||||
|
||||
col.name = "type";
|
||||
|
||||
block.insert(col);
|
||||
|
||||
col.name = "default_type";
|
||||
block.insert(col);
|
||||
|
||||
col.name = "default_expression";
|
||||
block.insert(col);
|
||||
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
@ -74,27 +81,48 @@ private:
|
||||
const ASTDescribeQuery & ast = typeid_cast<const ASTDescribeQuery &>(*query_ptr);
|
||||
|
||||
NamesAndTypesList columns;
|
||||
ColumnDefaults column_defaults;
|
||||
|
||||
{
|
||||
StoragePtr table = context.getTable(ast.database, ast.table);
|
||||
auto table_lock = table->lockStructure(false);
|
||||
columns = table->getColumnsList();
|
||||
columns.insert(std::end(columns), std::begin(table->alias_columns), std::end(table->alias_columns));
|
||||
column_defaults = table->column_defaults;
|
||||
}
|
||||
|
||||
ColumnString * name_column = new ColumnString;
|
||||
ColumnString * type_column = new ColumnString;
|
||||
ColumnWithNameAndType name_column{new ColumnString, new DataTypeString, "name"};
|
||||
ColumnWithNameAndType type_column{new ColumnString, new DataTypeString, "type" };
|
||||
ColumnWithNameAndType default_type_column{new ColumnString, new DataTypeString, "default_type" };
|
||||
ColumnWithNameAndType default_expression_column{new ColumnString, new DataTypeString, "default_expression" };;
|
||||
|
||||
Block block;
|
||||
block.insert(ColumnWithNameAndType(name_column, new DataTypeString, "name"));
|
||||
block.insert(ColumnWithNameAndType(type_column, new DataTypeString, "type"));
|
||||
|
||||
for (NamesAndTypesList::iterator it = columns.begin(); it != columns.end(); ++it)
|
||||
auto has_defaults = false;
|
||||
for (const auto column : columns)
|
||||
{
|
||||
name_column->insert(it->name);
|
||||
type_column->insert(it->type->getName());
|
||||
name_column.column->insert(column.name);
|
||||
type_column.column->insert(column.type->getName());
|
||||
|
||||
const auto it = column_defaults.find(column.name);
|
||||
if (it == std::end(column_defaults))
|
||||
{
|
||||
default_type_column.column->insertDefault();
|
||||
default_expression_column.column->insertDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
has_defaults = true;
|
||||
default_type_column.column->insert(toString(it->second.type));
|
||||
default_expression_column.column->insert(queryToString(
|
||||
setAlias(it->second.expression->clone(), "")));
|
||||
}
|
||||
}
|
||||
|
||||
return new OneBlockInputStream(block);
|
||||
|
||||
return new OneBlockInputStream{
|
||||
has_defaults
|
||||
? Block{name_column, type_column, default_type_column, default_expression_column}
|
||||
: Block{name_column, type_column}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -73,4 +73,12 @@ void formatAST(const ASTShowProcesslistQuery & ast, std::ostream & s,
|
||||
String formatColumnsForCreateQuery(NamesAndTypesList & columns);
|
||||
String backQuoteIfNeed(const String & x);
|
||||
|
||||
inline String queryToString(const ASTPtr & query)
|
||||
{
|
||||
std::ostringstream out;
|
||||
formatAST(*query, out, 0, false, true);
|
||||
|
||||
return out.str();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <DB/Storages/StorageDistributed.h>
|
||||
#include <DB/Storages/Distributed/queryToString.h>
|
||||
|
||||
#include <DB/Parsers/formatAST.h>
|
||||
|
||||
#include <DB/IO/WriteBufferFromFile.h>
|
||||
#include <DB/IO/CompressedWriteBuffer.h>
|
||||
|
@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <DB/Parsers/formatAST.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
inline std::string queryToString(const ASTPtr & query)
|
||||
{
|
||||
std::ostringstream s;
|
||||
formatAST(*query, s, 0, false, true);
|
||||
|
||||
return s.str();
|
||||
}
|
||||
}
|
@ -5,7 +5,6 @@
|
||||
#include <DB/Storages/VirtualColumnFactory.h>
|
||||
#include <DB/Storages/Distributed/DistributedBlockOutputStream.h>
|
||||
#include <DB/Storages/Distributed/DirectoryMonitor.h>
|
||||
#include <DB/Storages/Distributed/queryToString.h>
|
||||
#include <DB/Common/escapeForFileName.h>
|
||||
|
||||
#include <DB/Interpreters/InterpreterSelectQuery.h>
|
||||
|
Loading…
Reference in New Issue
Block a user