github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/parsers/tree/drop.go (about)

     1  // Copyright 2021 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package tree
    16  
    17  import "github.com/matrixorigin/matrixone/pkg/common/reuse"
    18  
    19  func init() {
    20  	reuse.CreatePool[DropDatabase](
    21  		func() *DropDatabase { return &DropDatabase{} },
    22  		func(d *DropDatabase) { d.reset() },
    23  		reuse.DefaultOptions[DropDatabase](), //.
    24  	) //WithEnableChecker()
    25  
    26  	reuse.CreatePool[DropTable](
    27  		func() *DropTable { return &DropTable{} },
    28  		func(d *DropTable) { d.reset() },
    29  		reuse.DefaultOptions[DropTable](), //.
    30  	) //WithEnableChecker()
    31  
    32  	reuse.CreatePool[DropView](
    33  		func() *DropView { return &DropView{} },
    34  		func(d *DropView) { d.reset() },
    35  		reuse.DefaultOptions[DropView](), //.
    36  	) //WithEnableChecker()
    37  
    38  	reuse.CreatePool[DropIndex](
    39  		func() *DropIndex { return &DropIndex{} },
    40  		func(d *DropIndex) { d.reset() },
    41  		reuse.DefaultOptions[DropIndex](), //.
    42  	) //WithEnableChecker()
    43  
    44  	reuse.CreatePool[DropRole](
    45  		func() *DropRole { return &DropRole{} },
    46  		func(d *DropRole) { d.reset() },
    47  		reuse.DefaultOptions[DropRole](), //.
    48  	) //WithEnableChecker()
    49  
    50  	reuse.CreatePool[DropUser](
    51  		func() *DropUser { return &DropUser{} },
    52  		func(d *DropUser) { d.reset() },
    53  		reuse.DefaultOptions[DropUser](), //.
    54  	) //WithEnableChecker()
    55  
    56  	reuse.CreatePool[DropAccount](
    57  		func() *DropAccount { return &DropAccount{} },
    58  		func(d *DropAccount) { d.reset() },
    59  		reuse.DefaultOptions[DropAccount](), //.
    60  	) //WithEnableChecker()
    61  
    62  	reuse.CreatePool[DropPublication](
    63  		func() *DropPublication { return &DropPublication{} },
    64  		func(d *DropPublication) { d.reset() },
    65  		reuse.DefaultOptions[DropPublication](), //.
    66  	) //WithEnableChecker()
    67  }
    68  
    69  // DROP Database statement
    70  type DropDatabase struct {
    71  	statementImpl
    72  	Name     Identifier
    73  	IfExists bool
    74  }
    75  
    76  func (node *DropDatabase) Format(ctx *FmtCtx) {
    77  	ctx.WriteString("drop database")
    78  	if node.IfExists {
    79  		ctx.WriteByte(' ')
    80  		ctx.WriteString("if exists")
    81  	}
    82  	if node.Name != "" {
    83  		ctx.WriteByte(' ')
    84  		ctx.WriteString(string(node.Name))
    85  	}
    86  }
    87  
    88  func (node *DropDatabase) GetStatementType() string { return "Drop Database" }
    89  func (node *DropDatabase) GetQueryType() string     { return QueryTypeDDL }
    90  
    91  func (node *DropDatabase) Free() {
    92  	reuse.Free[DropDatabase](node, nil)
    93  }
    94  
    95  func (node *DropDatabase) reset() {
    96  	*node = DropDatabase{}
    97  }
    98  
    99  func (node DropDatabase) TypeName() string { return "tree.DropDatabase" }
   100  
   101  func NewDropDatabase(n Identifier, i bool) *DropDatabase {
   102  	dropDatabase := reuse.Alloc[DropDatabase](nil)
   103  	dropDatabase.Name = n
   104  	dropDatabase.IfExists = i
   105  	return dropDatabase
   106  }
   107  
   108  // DROP Table statement
   109  type DropTable struct {
   110  	statementImpl
   111  	IfExists bool
   112  	Names    TableNames
   113  }
   114  
   115  func (node *DropTable) Format(ctx *FmtCtx) {
   116  	ctx.WriteString("drop table")
   117  	if node.IfExists {
   118  		ctx.WriteString(" if exists")
   119  	}
   120  	ctx.WriteByte(' ')
   121  	node.Names.Format(ctx)
   122  }
   123  
   124  func (node *DropTable) GetStatementType() string { return "Drop Table" }
   125  func (node *DropTable) GetQueryType() string     { return QueryTypeDDL }
   126  
   127  func (node *DropTable) Free() {
   128  	reuse.Free[DropTable](node, nil)
   129  }
   130  
   131  func (node *DropTable) reset() {
   132  	*node = DropTable{}
   133  }
   134  
   135  func (node DropTable) TypeName() string { return "tree.DropTable" }
   136  
   137  func NewDropTable(i bool, n TableNames) *DropTable {
   138  	dropTable := reuse.Alloc[DropTable](nil)
   139  	dropTable.IfExists = i
   140  	dropTable.Names = n
   141  	return dropTable
   142  }
   143  
   144  // DropView DROP View statement
   145  type DropView struct {
   146  	statementImpl
   147  	IfExists bool
   148  	Names    TableNames
   149  }
   150  
   151  func (node *DropView) Format(ctx *FmtCtx) {
   152  	ctx.WriteString("drop view")
   153  	if node.IfExists {
   154  		ctx.WriteString(" if exists")
   155  	}
   156  	ctx.WriteByte(' ')
   157  	node.Names.Format(ctx)
   158  }
   159  
   160  func (node *DropView) GetStatementType() string { return "Drop View" }
   161  func (node *DropView) GetQueryType() string     { return QueryTypeDDL }
   162  
   163  func (node *DropView) Free() {
   164  	reuse.Free[DropView](node, nil)
   165  }
   166  
   167  func (node *DropView) reset() {
   168  	*node = DropView{}
   169  }
   170  
   171  func (node DropView) TypeName() string { return "tree.DropView" }
   172  
   173  func NewDropView(i bool, n TableNames) *DropView {
   174  	dropView := reuse.Alloc[DropView](nil)
   175  	dropView.IfExists = i
   176  	dropView.Names = n
   177  	return dropView
   178  }
   179  
   180  type DropIndex struct {
   181  	statementImpl
   182  	Name       Identifier
   183  	TableName  *TableName
   184  	IfExists   bool
   185  	MiscOption []MiscOption
   186  }
   187  
   188  func (node *DropIndex) Format(ctx *FmtCtx) {
   189  	ctx.WriteString("drop index")
   190  	if node.IfExists {
   191  		ctx.WriteString(" if exists")
   192  	}
   193  	ctx.WriteByte(' ')
   194  	ctx.WriteString(string(node.Name))
   195  
   196  	ctx.WriteString(" on ")
   197  	node.TableName.Format(ctx)
   198  }
   199  
   200  func (node *DropIndex) GetStatementType() string { return "Drop Index" }
   201  func (node *DropIndex) GetQueryType() string     { return QueryTypeDDL }
   202  
   203  func (node *DropIndex) Free() {
   204  	reuse.Free[DropIndex](node, nil)
   205  }
   206  
   207  func (node *DropIndex) reset() {
   208  	// if node.TableName != nil {
   209  	// 	reuse.Free[TableName](node.TableName, nil)
   210  	// }
   211  	// if node.MiscOption != nil {
   212  	// 	for _, item := range node.MiscOption {
   213  	// 		reuse.Free[MiscOption](item, nil)
   214  	// 	}
   215  	// }
   216  	*node = DropIndex{}
   217  }
   218  
   219  func (node DropIndex) TypeName() string { return "tree.DropIndex" }
   220  
   221  func NewDropIndex(i Identifier, t *TableName, ife bool) *DropIndex {
   222  	dropIndex := reuse.Alloc[DropIndex](nil)
   223  	dropIndex.Name = i
   224  	dropIndex.TableName = t
   225  	dropIndex.IfExists = ife
   226  	return dropIndex
   227  }
   228  
   229  type DropRole struct {
   230  	statementImpl
   231  	IfExists bool
   232  	Roles    []*Role
   233  }
   234  
   235  func (node *DropRole) Format(ctx *FmtCtx) {
   236  	ctx.WriteString("drop role")
   237  	if node.IfExists {
   238  		ctx.WriteString(" if exists")
   239  	}
   240  	prefix := " "
   241  	for _, r := range node.Roles {
   242  		ctx.WriteString(prefix)
   243  		r.Format(ctx)
   244  		prefix = ", "
   245  	}
   246  }
   247  
   248  func (node *DropRole) GetStatementType() string { return "Drop Role" }
   249  func (node *DropRole) GetQueryType() string     { return QueryTypeDCL }
   250  
   251  func (node *DropRole) Free() {
   252  	reuse.Free[DropRole](node, nil)
   253  }
   254  
   255  func (node *DropRole) reset() {
   256  	if node.Roles != nil {
   257  		for _, role := range node.Roles {
   258  			role.Free()
   259  		}
   260  	}
   261  	*node = DropRole{}
   262  }
   263  
   264  func (node DropRole) TypeName() string { return "tree.DropRole" }
   265  
   266  func NewDropRole(ife bool, r []*Role) *DropRole {
   267  	dropRole := reuse.Alloc[DropRole](nil)
   268  	dropRole.IfExists = ife
   269  	dropRole.Roles = r
   270  	return dropRole
   271  }
   272  
   273  type DropUser struct {
   274  	statementImpl
   275  	IfExists bool
   276  	Users    []*User
   277  }
   278  
   279  func (node *DropUser) Format(ctx *FmtCtx) {
   280  	ctx.WriteString("drop user")
   281  	if node.IfExists {
   282  		ctx.WriteString(" if exists")
   283  	}
   284  	prefix := " "
   285  	for _, u := range node.Users {
   286  		ctx.WriteString(prefix)
   287  		u.Format(ctx)
   288  		prefix = ", "
   289  	}
   290  }
   291  
   292  func (node *DropUser) GetStatementType() string { return "Drop User" }
   293  func (node *DropUser) GetQueryType() string     { return QueryTypeDCL }
   294  
   295  func (node *DropUser) Free() {
   296  	reuse.Free[DropUser](node, nil)
   297  }
   298  
   299  func (node *DropUser) reset() {
   300  	if node.Users != nil {
   301  		for _, item := range node.Users {
   302  			item.Free()
   303  		}
   304  	}
   305  	*node = DropUser{}
   306  }
   307  
   308  func (node DropUser) TypeName() string { return "tree.DropUser" }
   309  
   310  func NewDropUser(ife bool, u []*User) *DropUser {
   311  	dropUser := reuse.Alloc[DropUser](nil)
   312  	dropUser.IfExists = ife
   313  	dropUser.Users = u
   314  	return dropUser
   315  }
   316  
   317  type DropAccount struct {
   318  	statementImpl
   319  	IfExists bool
   320  	Name     Expr
   321  }
   322  
   323  func (node *DropAccount) Format(ctx *FmtCtx) {
   324  	ctx.WriteString("drop account")
   325  	if node.IfExists {
   326  		ctx.WriteString(" if exists")
   327  	}
   328  	ctx.WriteString(" ")
   329  	node.Name.Format(ctx)
   330  }
   331  
   332  func (node *DropAccount) GetStatementType() string { return "Drop Account" }
   333  func (node *DropAccount) GetQueryType() string     { return QueryTypeDCL }
   334  
   335  func (node *DropAccount) Free() {
   336  	reuse.Free[DropAccount](node, nil)
   337  }
   338  
   339  func (node *DropAccount) reset() {
   340  	*node = DropAccount{}
   341  }
   342  
   343  func (node DropAccount) TypeName() string { return "tree.DropAccount" }
   344  
   345  func NewDropAccount(ife bool, n Expr) *DropAccount {
   346  	dropAccount := reuse.Alloc[DropAccount](nil)
   347  	dropAccount.IfExists = ife
   348  	dropAccount.Name = n
   349  	return dropAccount
   350  }
   351  
   352  type DropPublication struct {
   353  	statementImpl
   354  	Name     Identifier
   355  	IfExists bool
   356  }
   357  
   358  func NewDropPublication(ife bool, n Identifier) *DropPublication {
   359  	dropPublication := reuse.Alloc[DropPublication](nil)
   360  	dropPublication.IfExists = ife
   361  	dropPublication.Name = n
   362  	return dropPublication
   363  }
   364  
   365  func (node *DropPublication) Format(ctx *FmtCtx) {
   366  	ctx.WriteString("drop publication")
   367  	if node.IfExists {
   368  		ctx.WriteString(" if exists")
   369  	}
   370  	ctx.WriteByte(' ')
   371  	node.Name.Format(ctx)
   372  }
   373  
   374  func (node *DropPublication) GetStatementType() string { return "Drop Publication" }
   375  func (node *DropPublication) GetQueryType() string     { return QueryTypeDCL }
   376  
   377  func (node *DropPublication) Free() {
   378  	reuse.Free[DropPublication](node, nil)
   379  }
   380  
   381  func (node *DropPublication) reset() {
   382  	*node = DropPublication{}
   383  }
   384  
   385  func (node DropPublication) TypeName() string { return "tree.DropPublication" }