2013-08-07 13:07:42 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
|
#include <Parsers/IAST.h>
|
2015-08-05 21:38:31 +00:00
|
|
|
|
|
2013-08-07 13:07:42 +00:00
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/** ALTER запрос
|
|
|
|
|
* ALTER TABLE [db.]name_type
|
2017-04-01 07:20:54 +00:00
|
|
|
|
* ADD COLUMN col_name type [AFTER col_after],
|
|
|
|
|
* DROP COLUMN col_drop,
|
|
|
|
|
* MODIFY COLUMN col_name type,
|
|
|
|
|
* DROP PARTITION partition
|
|
|
|
|
* RESHARD [COPY] PARTITION partition
|
|
|
|
|
* TO '/path/to/zookeeper/table' [WEIGHT w], ...
|
|
|
|
|
* USING expression
|
|
|
|
|
* [COORDINATE WITH 'coordinator_id']
|
2013-08-07 13:07:42 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class ASTAlterQuery : public IAST
|
|
|
|
|
{
|
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
|
enum ParameterType
|
|
|
|
|
{
|
|
|
|
|
ADD_COLUMN,
|
|
|
|
|
DROP_COLUMN,
|
|
|
|
|
MODIFY_COLUMN,
|
|
|
|
|
MODIFY_PRIMARY_KEY,
|
2016-05-05 18:28:46 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
DROP_PARTITION,
|
|
|
|
|
ATTACH_PARTITION,
|
|
|
|
|
FETCH_PARTITION,
|
|
|
|
|
FREEZE_PARTITION,
|
|
|
|
|
RESHARD_PARTITION,
|
2016-05-05 18:28:46 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
NO_TYPE,
|
|
|
|
|
};
|
2013-08-07 13:07:42 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
struct Parameters
|
|
|
|
|
{
|
|
|
|
|
Parameters();
|
2016-01-28 01:00:27 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
int type = NO_TYPE;
|
2013-08-07 13:07:42 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
/** В запросе ADD COLUMN здесь хранится имя и тип добавляемого столбца
|
|
|
|
|
* В запросе DROP это поле не используется
|
|
|
|
|
* В запросе MODIFY здесь хранится имя столбца и новый тип
|
|
|
|
|
*/
|
|
|
|
|
ASTPtr col_decl;
|
2014-07-10 10:16:50 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
/** В запросе ADD COLUMN здесь опционально хранится имя столбца, следующее после AFTER
|
|
|
|
|
* В запросе DROP здесь хранится имя столбца для удаления
|
|
|
|
|
*/
|
|
|
|
|
ASTPtr column;
|
2013-08-07 13:07:42 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
/** Для MODIFY PRIMARY KEY
|
|
|
|
|
*/
|
|
|
|
|
ASTPtr primary_key;
|
2016-05-05 18:28:46 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
/** В запросах DROP PARTITION и RESHARD PARTITION здесь хранится имя partition'а.
|
|
|
|
|
*/
|
|
|
|
|
ASTPtr partition;
|
|
|
|
|
bool detach = false; /// true для DETACH PARTITION.
|
2014-08-06 09:24:30 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
bool part = false; /// true для ATTACH [UNREPLICATED] PART
|
|
|
|
|
bool unreplicated = false; /// true для ATTACH UNREPLICATED, DROP UNREPLICATED ...
|
2014-08-07 11:46:01 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
bool do_copy = false; /// для RESHARD PARTITION.
|
2016-03-25 11:48:45 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
/** Для FETCH PARTITION - путь в ZK к шарду, с которого скачивать партицию.
|
|
|
|
|
*/
|
|
|
|
|
String from;
|
2014-10-09 20:28:33 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
/** Для RESHARD PARTITION.
|
|
|
|
|
*/
|
|
|
|
|
ASTPtr last_partition;
|
|
|
|
|
ASTPtr weighted_zookeeper_paths;
|
|
|
|
|
ASTPtr sharding_key_expr;
|
|
|
|
|
ASTPtr coordinator;
|
2016-01-28 01:00:27 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
/** For FREEZE PARTITION - place local backup to directory with specified name.
|
|
|
|
|
*/
|
|
|
|
|
String with_name;
|
2016-06-28 20:50:37 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
/// deep copy
|
|
|
|
|
void clone(Parameters & p) const;
|
|
|
|
|
};
|
2016-01-28 01:00:27 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
using ParameterContainer = std::vector<Parameters>;
|
|
|
|
|
ParameterContainer parameters;
|
|
|
|
|
String database;
|
|
|
|
|
String table;
|
2013-08-07 13:07:42 +00:00
|
|
|
|
|
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
void addParameters(const Parameters & params);
|
2014-08-06 09:24:30 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
ASTAlterQuery(StringRange range_ = StringRange());
|
2013-08-07 13:07:42 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
/** Получить текст, который идентифицирует этот элемент. */
|
|
|
|
|
String getID() const override;
|
2013-08-07 13:07:42 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
ASTPtr clone() const override;
|
2015-08-05 21:38:31 +00:00
|
|
|
|
|
|
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
|
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
|
2013-08-07 13:07:42 +00:00
|
|
|
|
};
|
2015-08-05 21:38:31 +00:00
|
|
|
|
|
2013-08-07 13:07:42 +00:00
|
|
|
|
}
|