2014-03-09 17:36:01 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#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
|
|
|
|
2015-02-22 15:31:39 +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
|
|
|
*/
|
2014-03-19 10:45:13 +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.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
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.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
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.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
virtual Names getColumnNamesList() const;
|
2014-03-13 15:00:06 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/** Get a description of the real (non-virtual) column by its name.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
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.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
virtual bool hasRealColumn(const String & column_name) const;
|
2014-03-09 17:36:01 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
NameAndTypePair getMaterializedColumn(const String & column_name) const;
|
|
|
|
bool hasMaterializedColumn(const String & column_name) const;
|
2014-09-30 03:08:47 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/** Get a description of any column by its name.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
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.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
virtual bool hasColumn(const String & column_name) const;
|
2014-03-09 17:36:01 +00:00
|
|
|
|
2017-04-01 07:20:54 +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.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
Block getSampleBlock() const;
|
|
|
|
Block getSampleBlockNonMaterialized() 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)
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
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.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
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.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
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.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
void check(const Block & block, bool need_all = false) const;
|
2014-10-03 15:30:10 +00:00
|
|
|
|
2014-03-09 17:36:01 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
virtual ~ITableDeclaration() = default;
|
2014-09-30 03:08:47 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ITableDeclaration() = default;
|
|
|
|
ITableDeclaration(
|
|
|
|
const NamesAndTypesList & materialized_columns,
|
|
|
|
const NamesAndTypesList & alias_columns,
|
|
|
|
const ColumnDefaults & column_defaults)
|
|
|
|
: materialized_columns{materialized_columns},
|
|
|
|
alias_columns{alias_columns},
|
|
|
|
column_defaults{column_defaults}
|
|
|
|
{}
|
2014-09-30 03:08:47 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
NamesAndTypesList materialized_columns{};
|
|
|
|
NamesAndTypesList alias_columns{};
|
|
|
|
ColumnDefaults column_defaults{};
|
2014-10-10 15:45:43 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
virtual const NamesAndTypesList & getColumnsListImpl() const = 0;
|
2015-02-22 15:31:39 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|