2013-08-07 13:07:42 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/IAST.h>
|
2017-08-03 17:00:41 +00:00
|
|
|
#include <Parsers/ASTQueryWithOutput.h>
|
2017-04-21 12:39:28 +00:00
|
|
|
#include <Parsers/ASTQueryWithOnCluster.h>
|
2015-08-05 21:38:31 +00:00
|
|
|
|
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
|
2017-04-01 07:20:54 +00:00
|
|
|
* 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,
|
2013-08-07 13:07:42 +00:00
|
|
|
*/
|
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
class ASTAlterCommand : public IAST
|
2013-08-07 13:07:42 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-06-09 15:53:14 +00:00
|
|
|
enum Type
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
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,
|
2018-05-21 13:49:54 +00:00
|
|
|
REPLACE_PARTITION,
|
2017-04-01 07:20:54 +00:00
|
|
|
FETCH_PARTITION,
|
|
|
|
FREEZE_PARTITION,
|
2016-05-05 18:28:46 +00:00
|
|
|
|
2018-02-02 16:02:43 +00:00
|
|
|
DELETE,
|
2018-08-07 13:58:11 +00:00
|
|
|
UPDATE,
|
2018-02-02 16:02:43 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
NO_TYPE,
|
|
|
|
};
|
2013-08-07 13:07:42 +00:00
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
Type type = NO_TYPE;
|
2016-01-28 01:00:27 +00:00
|
|
|
|
2018-06-09 15:53:14 +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;
|
2013-08-07 13:07:42 +00:00
|
|
|
|
2018-06-09 15:53:14 +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;
|
2014-07-10 10:16:50 +00:00
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
/** For MODIFY PRIMARY KEY
|
|
|
|
*/
|
|
|
|
ASTPtr primary_key;
|
2013-08-07 13:07:42 +00:00
|
|
|
|
2018-06-13 20:00:10 +00:00
|
|
|
/** Used in DROP PARTITION and ATTACH PARTITION FROM queries.
|
2018-06-09 15:53:14 +00:00
|
|
|
* The value or ID of the partition is stored here.
|
|
|
|
*/
|
|
|
|
ASTPtr partition;
|
2016-05-05 18:28:46 +00:00
|
|
|
|
2018-08-07 13:58:11 +00:00
|
|
|
/// For DELETE/UPDATE WHERE: the predicate that filters the rows to delete/update.
|
2018-06-09 15:53:14 +00:00
|
|
|
ASTPtr predicate;
|
2017-09-06 20:34:26 +00:00
|
|
|
|
2018-08-07 13:58:11 +00:00
|
|
|
/// A list of expressions of the form `column = expr` for the UPDATE command.
|
|
|
|
ASTPtr update_assignments;
|
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
bool detach = false; /// true for DETACH PARTITION
|
2018-02-02 16:02:43 +00:00
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
bool part = false; /// true for ATTACH PART
|
2014-08-06 09:24:30 +00:00
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
bool clear_column = false; /// for CLEAR COLUMN (do not drop column from metadata)
|
2017-06-22 11:01:30 +00:00
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
/** For FETCH PARTITION - the path in ZK to the shard, from which to download the partition.
|
|
|
|
*/
|
|
|
|
String from;
|
2016-03-25 11:48:45 +00:00
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
/** For FREEZE PARTITION - place local backup to directory with specified name.
|
|
|
|
*/
|
|
|
|
String with_name;
|
2014-10-09 20:28:33 +00:00
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
/// REPLACE(ATTACH) PARTITION partition FROM db.table
|
|
|
|
String from_database;
|
|
|
|
String from_table;
|
|
|
|
/// To distinguish REPLACE and ATTACH PARTITION partition FROM db.table
|
|
|
|
bool replace = true;
|
2016-06-28 20:50:37 +00:00
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
String getID() const override { return "AlterCommand_" + std::to_string(static_cast<int>(type)); }
|
2018-05-21 13:49:54 +00:00
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
ASTPtr clone() const override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ASTAlterCommandList : public IAST
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::vector<ASTAlterCommand *> commands;
|
|
|
|
|
|
|
|
void add(const ASTPtr & command)
|
|
|
|
{
|
|
|
|
commands.push_back(static_cast<ASTAlterCommand *>(command.get()));
|
|
|
|
children.push_back(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
String getID() const override { return "AlterCommandList"; }
|
|
|
|
|
|
|
|
ASTPtr clone() const override;
|
2016-01-28 01:00:27 +00:00
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
protected:
|
|
|
|
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ASTAlterQuery : public ASTQueryWithOutput, public ASTQueryWithOnCluster
|
|
|
|
{
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
String database;
|
|
|
|
String table;
|
2013-08-07 13:07:42 +00:00
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
ASTAlterCommandList * command_list = nullptr;
|
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
|
|
|
|
2017-08-03 17:00:41 +00:00
|
|
|
ASTPtr getRewrittenASTWithoutOnCluster(const std::string & new_database) const override;
|
2017-04-21 12:39:28 +00:00
|
|
|
|
2015-08-05 21:38:31 +00:00
|
|
|
protected:
|
2017-08-03 17:00:41 +00:00
|
|
|
void formatQueryImpl(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
|
|
|
}
|