2013-08-07 13:07:42 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <DB/Parsers/IAST.h>
|
2015-08-05 21:38:31 +00:00
|
|
|
|
|
2013-08-07 13:07:42 +00:00
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
2016-01-11 21:46:36 +00:00
|
|
|
|
namespace ErrorCodes
|
|
|
|
|
{
|
|
|
|
|
extern const int UNEXPECTED_AST_STRUCTURE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-07 13:07:42 +00:00
|
|
|
|
/** ALTER запрос
|
|
|
|
|
* ALTER TABLE [db.]name_type
|
|
|
|
|
* ADD COLUMN col_name type [AFTER col_after],
|
|
|
|
|
* DROP COLUMN col_drop,
|
2014-08-06 09:24:30 +00:00
|
|
|
|
* MODIFY COLUMN col_name type,
|
|
|
|
|
* DROP PARTITION partition
|
2016-03-25 11:48:45 +00:00
|
|
|
|
* RESHARD [COPY] PARTITION partition
|
2016-03-01 17:47:53 +00:00
|
|
|
|
* 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:
|
|
|
|
|
enum ParameterType
|
|
|
|
|
{
|
2014-08-06 09:24:30 +00:00
|
|
|
|
ADD_COLUMN,
|
|
|
|
|
DROP_COLUMN,
|
|
|
|
|
MODIFY_COLUMN,
|
2016-05-05 18:28:46 +00:00
|
|
|
|
MODIFY_PRIMARY_KEY,
|
|
|
|
|
|
2014-08-06 09:24:30 +00:00
|
|
|
|
DROP_PARTITION,
|
2014-08-07 11:46:01 +00:00
|
|
|
|
ATTACH_PARTITION,
|
2014-10-09 20:28:33 +00:00
|
|
|
|
FETCH_PARTITION,
|
2014-11-11 04:11:07 +00:00
|
|
|
|
FREEZE_PARTITION,
|
2016-01-28 01:00:27 +00:00
|
|
|
|
RESHARD_PARTITION,
|
2016-05-05 18:28:46 +00:00
|
|
|
|
|
|
|
|
|
NO_TYPE,
|
2013-08-07 13:07:42 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Parameters
|
|
|
|
|
{
|
2016-01-28 01:00:27 +00:00
|
|
|
|
Parameters();
|
|
|
|
|
|
2014-08-07 09:23:55 +00:00
|
|
|
|
int type = NO_TYPE;
|
2013-08-07 13:07:42 +00:00
|
|
|
|
|
2013-08-13 08:27:37 +00:00
|
|
|
|
/** В запросе ADD COLUMN здесь хранится имя и тип добавляемого столбца
|
2014-07-10 10:16:50 +00:00
|
|
|
|
* В запросе DROP это поле не используется
|
|
|
|
|
* В запросе MODIFY здесь хранится имя столбца и новый тип
|
|
|
|
|
*/
|
2014-10-07 09:09:59 +00:00
|
|
|
|
ASTPtr col_decl;
|
2014-07-10 10:16:50 +00:00
|
|
|
|
|
2013-08-13 08:27:37 +00:00
|
|
|
|
/** В запросе ADD COLUMN здесь опционально хранится имя столбца, следующее после AFTER
|
2014-07-10 10:16:50 +00:00
|
|
|
|
* В запросе DROP здесь хранится имя столбца для удаления
|
|
|
|
|
*/
|
2013-08-07 13:07:42 +00:00
|
|
|
|
ASTPtr column;
|
|
|
|
|
|
2016-05-05 18:28:46 +00:00
|
|
|
|
/** Для MODIFY PRIMARY KEY
|
|
|
|
|
*/
|
|
|
|
|
ASTPtr primary_key;
|
|
|
|
|
|
2016-01-28 01:00:27 +00:00
|
|
|
|
/** В запросах DROP PARTITION и RESHARD PARTITION здесь хранится имя partition'а.
|
2014-08-06 09:24:30 +00:00
|
|
|
|
*/
|
|
|
|
|
ASTPtr partition;
|
2014-08-07 09:23:55 +00:00
|
|
|
|
bool detach = false; /// true для DETACH PARTITION.
|
2014-08-06 09:24:30 +00:00
|
|
|
|
|
2014-08-07 11:46:01 +00:00
|
|
|
|
bool part = false; /// true для ATTACH [UNREPLICATED] PART
|
2015-04-21 13:10:08 +00:00
|
|
|
|
bool unreplicated = false; /// true для ATTACH UNREPLICATED, DROP UNREPLICATED ...
|
2014-08-07 11:46:01 +00:00
|
|
|
|
|
2016-03-25 11:48:45 +00:00
|
|
|
|
bool do_copy = false; /// для RESHARD PARTITION.
|
|
|
|
|
|
2014-10-09 20:28:33 +00:00
|
|
|
|
/** Для FETCH PARTITION - путь в ZK к шарду, с которого скачивать партицию.
|
|
|
|
|
*/
|
|
|
|
|
String from;
|
|
|
|
|
|
2016-01-28 01:00:27 +00:00
|
|
|
|
/** Для RESHARD PARTITION.
|
|
|
|
|
*/
|
|
|
|
|
ASTPtr last_partition;
|
|
|
|
|
ASTPtr weighted_zookeeper_paths;
|
2016-01-28 01:00:42 +00:00
|
|
|
|
ASTPtr sharding_key_expr;
|
2016-03-01 17:47:53 +00:00
|
|
|
|
ASTPtr coordinator;
|
2016-01-28 01:00:27 +00:00
|
|
|
|
|
2013-08-07 13:07:42 +00:00
|
|
|
|
/// deep copy
|
2016-01-28 01:00:27 +00:00
|
|
|
|
void clone(Parameters & p) const;
|
2013-08-07 13:07:42 +00:00
|
|
|
|
};
|
2016-01-28 01:00:27 +00:00
|
|
|
|
|
2013-08-07 13:07:42 +00:00
|
|
|
|
typedef std::vector<Parameters> ParameterContainer;
|
|
|
|
|
ParameterContainer parameters;
|
|
|
|
|
String database;
|
|
|
|
|
String table;
|
|
|
|
|
|
|
|
|
|
|
2016-01-28 01:00:27 +00:00
|
|
|
|
void addParameters(const Parameters & params);
|
2014-08-06 09:24:30 +00:00
|
|
|
|
|
2016-01-28 01:00:27 +00:00
|
|
|
|
ASTAlterQuery(StringRange range_ = StringRange());
|
2013-08-07 13:07:42 +00:00
|
|
|
|
|
|
|
|
|
/** Получить текст, который идентифицирует этот элемент. */
|
2016-01-28 01:00:27 +00:00
|
|
|
|
String getID() const override;
|
2013-08-07 13:07:42 +00:00
|
|
|
|
|
2016-01-28 01:00:27 +00:00
|
|
|
|
ASTPtr clone() const override;
|
2015-08-05 21:38:31 +00:00
|
|
|
|
|
|
|
|
|
protected:
|
2016-01-28 01:00:27 +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
|
|
|
|
}
|