github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/parsers/tree/stmt_test.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 ( 18 "testing" 19 20 "github.com/stretchr/testify/require" 21 ) 22 23 func TestQueryType(t *testing.T) { 24 type fields struct { 25 types map[StatementType]string 26 } 27 type args struct { 28 } 29 tests := []struct { 30 name string 31 fields fields 32 args args 33 }{ 34 { 35 name: "normal", 36 fields: fields{ 37 types: map[StatementType]string{ 38 &Select{}: QueryTypeDQL, 39 &SelectClause{}: QueryTypeDQL, 40 &MoDump{}: QueryTypeDQL, 41 &ValuesStatement{}: QueryTypeDQL, 42 &With{}: QueryTypeDQL, 43 // DDL 44 &CreateDatabase{}: QueryTypeDDL, 45 &CreateTable{}: QueryTypeDDL, 46 &CreateView{}: QueryTypeDDL, 47 &CreateIndex{}: QueryTypeDDL, 48 &CreateFunction{}: QueryTypeDDL, 49 &AlterView{}: QueryTypeDDL, 50 &AlterDataBaseConfig{}: QueryTypeDDL, 51 &DropDatabase{}: QueryTypeDDL, 52 &DropTable{}: QueryTypeDDL, 53 &DropView{}: QueryTypeDDL, 54 &DropIndex{}: QueryTypeDDL, 55 &DropFunction{}: QueryTypeDDL, 56 &TruncateTable{}: QueryTypeDDL, 57 // DML 58 &Insert{}: QueryTypeDML, 59 &Update{}: QueryTypeDML, 60 &Delete{}: QueryTypeDML, 61 &Load{}: QueryTypeDML, 62 // DCL 63 &CreateAccount{}: QueryTypeDCL, 64 &CreateRole{}: QueryTypeDCL, 65 &CreateUser{}: QueryTypeDCL, 66 &Grant{}: QueryTypeDCL, 67 &GrantPrivilege{}: QueryTypeDCL, 68 &GrantProxy{}: QueryTypeDCL, 69 &GrantRole{}: QueryTypeDCL, 70 &Revoke{}: QueryTypeDCL, 71 &RevokePrivilege{}: QueryTypeDCL, 72 &RevokeRole{}: QueryTypeDCL, 73 &AlterAccount{}: QueryTypeDCL, 74 &AlterUser{}: QueryTypeDCL, 75 &DropAccount{}: QueryTypeDCL, 76 &DropRole{}: QueryTypeDCL, 77 &DropUser{}: QueryTypeDCL, 78 &CreatePublication{}: QueryTypeDCL, 79 &DropPublication{}: QueryTypeDCL, 80 &AlterPublication{}: QueryTypeDCL, 81 82 // TCL 83 &BeginTransaction{}: QueryTypeTCL, 84 &CommitTransaction{}: QueryTypeTCL, 85 &RollbackTransaction{}: QueryTypeTCL, 86 // Other 87 &AnalyzeStmt{}: QueryTypeOth, 88 &ExplainAnalyze{}: QueryTypeOth, 89 &ExplainFor{}: QueryTypeOth, 90 &ExplainStmt{}: QueryTypeOth, 91 &SetVar{}: QueryTypeOth, 92 &SetDefaultRole{}: QueryTypeOth, 93 &SetRole{}: QueryTypeOth, 94 &SetPassword{}: QueryTypeOth, 95 &Declare{}: QueryTypeOth, 96 &Do{}: QueryTypeOth, 97 &TableFunction{}: QueryTypeOth, 98 &Use{}: QueryTypeOth, 99 &PrepareStmt{}: QueryTypeOth, 100 &Execute{}: QueryTypeOth, 101 &Deallocate{}: QueryTypeOth, 102 &Kill{}: QueryTypeOth, 103 // 'Show' prefix statement 104 &ShowProcessList{}: QueryTypeOth, 105 &ShowTableStatus{}: QueryTypeOth, 106 &ShowCreateDatabase{}: QueryTypeOth, 107 &ShowCreateView{}: QueryTypeOth, 108 &ShowCreateTable{}: QueryTypeOth, 109 &ShowAccounts{}: QueryTypeOth, 110 &ShowCollation{}: QueryTypeOth, 111 &ShowDatabases{}: QueryTypeOth, 112 &ShowErrors{}: QueryTypeOth, 113 &ShowFunctionOrProcedureStatus{}: QueryTypeOth, 114 &ShowGrants{}: QueryTypeOth, 115 &ShowIndex{}: QueryTypeOth, 116 &ShowLocks{}: QueryTypeOth, 117 &ShowNodeList{}: QueryTypeOth, 118 &ShowStatus{}: QueryTypeOth, 119 &ShowTableNumber{}: QueryTypeOth, 120 &ShowTables{}: QueryTypeOth, 121 &ShowTarget{}: QueryTypeOth, 122 &ShowVariables{}: QueryTypeOth, 123 &ShowWarnings{}: QueryTypeOth, 124 &ShowColumns{}: QueryTypeOth, 125 &ShowCreatePublications{}: QueryTypeOth, 126 &ShowPublications{}: QueryTypeOth, 127 &ShowSubscriptions{}: QueryTypeOth, 128 &ShowBackendServers{}: QueryTypeOth, 129 }, 130 }, 131 }, 132 } 133 for _, tt := range tests { 134 t.Run(tt.name, func(t1 *testing.T) { 135 for stmt, queryType := range tt.fields.types { 136 require.Equalf(t1, queryType, stmt.GetQueryType(), "statement_type: %s", stmt.GetStatementType()) 137 } 138 }) 139 } 140 141 }