ClickHouse/dbms/src/Parsers/ASTAlterQuery.h

113 lines
2.9 KiB
C++
Raw Normal View History

2013-08-07 13:07:42 +00:00
#pragma once
#include <Parsers/IAST.h>
2017-04-21 12:39:28 +00:00
#include <Parsers/ASTQueryWithOnCluster.h>
2013-08-07 13:07:42 +00:00
namespace DB
{
2017-04-21 12:39:28 +00:00
/** ALTER query:
2013-08-07 13:07:42 +00:00
* ALTER TABLE [db.]name_type
* ADD COLUMN col_name type [AFTER col_after],
2017-04-21 12:39:28 +00:00
* DROP COLUMN col_drop [FROM PARTITION partition],
* 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
*/
2017-04-21 12:39:28 +00:00
class ASTAlterQuery : public IAST, public ASTQueryWithOnCluster
2013-08-07 13:07:42 +00:00
{
public:
enum ParameterType
{
ADD_COLUMN,
DROP_COLUMN,
MODIFY_COLUMN,
MODIFY_PRIMARY_KEY,
DROP_PARTITION,
ATTACH_PARTITION,
FETCH_PARTITION,
FREEZE_PARTITION,
RESHARD_PARTITION,
NO_TYPE,
};
2013-08-07 13:07:42 +00:00
struct Parameters
{
Parameters();
2016-01-28 01:00:27 +00:00
int type = NO_TYPE;
2013-08-07 13:07:42 +00:00
2017-05-27 17:27:16 +00:00
/** The ADD COLUMN query stores the name and type of the column to add
* This field is not used in the DROP query
* In MODIFY query, the column name and the new type are stored here
*/
ASTPtr col_decl;
2014-07-10 10:16:50 +00:00
2017-05-27 17:27:16 +00:00
/** The ADD COLUMN query here optionally stores the name of the column following AFTER
* The DROP query stores the column name for deletion here
*/
ASTPtr column;
2013-08-07 13:07:42 +00:00
2017-05-27 17:27:16 +00:00
/** For MODIFY PRIMARY KEY
*/
ASTPtr primary_key;
2017-05-27 17:27:16 +00:00
/** In DROP PARTITION and RESHARD PARTITION queries, the name of the partition is stored here.
*/
ASTPtr partition;
bool detach = false; /// true for DETACH PARTITION
bool part = false; /// true for ATTACH PART
2014-08-07 11:46:01 +00:00
bool do_copy = false; /// for RESHARD PARTITION
bool clear_column = false; /// for CLEAR COLUMN (do not drop column from metadata)
2016-03-25 11:48:45 +00:00
2017-05-27 17:27:16 +00:00
/** For FETCH PARTITION - the path in ZK to the shard, from which to download the partition.
*/
String from;
2017-05-27 17:27:16 +00:00
/** For RESHARD PARTITION.
*/
ASTPtr weighted_zookeeper_paths;
ASTPtr sharding_key_expr;
ASTPtr coordinator;
2016-01-28 01:00:27 +00:00
/** For FREEZE PARTITION - place local backup to directory with specified name.
*/
String with_name;
/// deep copy
void clone(Parameters & p) const;
};
2016-01-28 01:00:27 +00:00
using ParameterContainer = std::vector<Parameters>;
ParameterContainer parameters;
String database;
String table;
2013-08-07 13:07:42 +00:00
void addParameters(const Parameters & params);
ASTAlterQuery(StringRange range_ = StringRange());
2013-08-07 13:07:42 +00:00
2017-05-27 17:27:16 +00:00
/** Get the text that identifies this element. */
String getID() const override;
2013-08-07 13:07:42 +00:00
ASTPtr clone() const override;
2017-04-21 12:39:28 +00:00
ASTPtr getRewrittenASTWithoutOnCluster(const std::string & new_database = {}) const override;
protected:
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
2013-08-07 13:07:42 +00:00
};
2013-08-07 13:07:42 +00:00
}