ClickHouse/dbms/src/Storages/ITableDeclaration.h

110 lines
3.5 KiB
C++
Raw Normal View History

2014-03-09 17:36:01 +00:00
#pragma once
#include <Core/Names.h>
#include <Core/NamesAndTypes.h>
#include <Common/Exception.h>
#include <Core/Block.h>
#include <Storages/ColumnDefault.h>
2014-03-09 17:36:01 +00:00
#include <boost/range/iterator_range.hpp>
#include <boost/range/join.hpp>
2014-03-09 17:36:01 +00:00
namespace DB
{
class Context;
2017-04-16 15:00:33 +00:00
/** Description of the table.
* Do not thread safe. See IStorage::lockStructure ().
2014-03-09 17:36:01 +00:00
*/
class ITableDeclaration
2014-03-09 17:36:01 +00:00
{
public:
2017-04-16 15:00:33 +00:00
/** The name of the table.
*/
virtual std::string getTableName() const = 0;
2014-03-09 17:36:01 +00:00
2017-04-16 15:00:33 +00:00
/** Get a list of names and table column types, only non-virtual.
*/
NamesAndTypesList getColumnsList() const;
const NamesAndTypesList & getColumnsListNonMaterialized() const { return getColumnsListImpl(); }
2014-03-09 17:36:01 +00:00
2017-04-16 15:00:33 +00:00
/** Get a list of column table names, only non-virtual.
*/
virtual Names getColumnNamesList() const;
2017-04-16 15:00:33 +00:00
/** Get a description of the real (non-virtual) column by its name.
*/
virtual NameAndTypePair getRealColumn(const String & column_name) const;
2014-03-09 17:36:01 +00:00
2017-04-16 15:00:33 +00:00
/** Is there a real (non-virtual) column with that name.
*/
virtual bool hasRealColumn(const String & column_name) const;
2014-03-09 17:36:01 +00:00
NameAndTypePair getMaterializedColumn(const String & column_name) const;
bool hasMaterializedColumn(const String & column_name) const;
2017-04-16 15:00:33 +00:00
/** Get a description of any column by its name.
*/
virtual NameAndTypePair getColumn(const String & column_name) const;
2014-03-09 17:36:01 +00:00
2017-04-16 15:00:33 +00:00
/** Is there a column with that name.
*/
virtual bool hasColumn(const String & column_name) const;
2014-03-09 17:36:01 +00:00
const DataTypePtr getDataTypeByName(const String & column_name) const;
2014-03-09 17:36:01 +00:00
2017-04-16 15:00:33 +00:00
/** The same, but in the form of a block-sample.
*/
Block getSampleBlock() const;
Block getSampleBlockNonMaterialized() const;
Block getSampleBlockForColumns(const Names & column_names) const;
2014-03-09 17:36:01 +00:00
2017-04-16 15:00:33 +00:00
/** Verify that all the requested names are in the table and are set correctly.
* (the list of names is not empty and the names do not repeat)
*/
void check(const Names & column_names) const;
2014-03-09 17:36:01 +00:00
2017-04-16 15:00:33 +00:00
/** Check that all the requested names are in the table and have the correct types.
*/
void check(const NamesAndTypesList & columns) const;
2014-07-14 14:07:47 +00:00
2017-04-16 15:00:33 +00:00
/** Check that all names from the intersection of `names` and `columns` are in the table and have the same types.
*/
void check(const NamesAndTypesList & columns, const Names & column_names) const;
2014-07-14 14:07:47 +00:00
2017-04-16 15:00:33 +00:00
/** Check that the data block for the record contains all the columns of the table with the correct types,
* contains only the columns of the table, and all the columns are different.
* If need_all, still checks that all the columns of the table are in the block.
*/
void check(const Block & block, bool need_all = false) const;
2014-03-09 17:36:01 +00:00
virtual ~ITableDeclaration() = default;
ITableDeclaration() = default;
ITableDeclaration(
const NamesAndTypesList & columns,
const NamesAndTypesList & materialized_columns,
const NamesAndTypesList & alias_columns,
const ColumnDefaults & column_defaults);
NamesAndTypesList columns;
2018-02-28 00:07:39 +00:00
NamesAndTypesList materialized_columns;
NamesAndTypesList alias_columns;
ColumnDefaults column_defaults;
private:
virtual const NamesAndTypesList & getColumnsListImpl() const
{
return columns;
}
using ColumnsListRange = boost::range::joined_range<const NamesAndTypesList, const NamesAndTypesList>;
/// Returns a lazily joined range of table's ordinary and materialized columns, without unnecessary copying
ColumnsListRange getColumnsListRange() const;
2014-03-09 17:36:01 +00:00
};
}