github.com/matrixorigin/matrixone@v0.7.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  	"github.com/stretchr/testify/require"
    19  	"testing"
    20  )
    21  
    22  func TestQueryType(t *testing.T) {
    23  	type fields struct {
    24  		types map[StatementType]string
    25  	}
    26  	type args struct {
    27  	}
    28  	tests := []struct {
    29  		name   string
    30  		fields fields
    31  		args   args
    32  	}{
    33  		{
    34  			name: "normal",
    35  			fields: fields{
    36  				types: map[StatementType]string{
    37  					&Select{}:          QueryTypeDQL,
    38  					&SelectClause{}:    QueryTypeDQL,
    39  					&MoDump{}:          QueryTypeDQL,
    40  					&ValuesStatement{}: QueryTypeDQL,
    41  					&With{}:            QueryTypeDQL,
    42  					// DDL
    43  					&CreateDatabase{}:      QueryTypeDDL,
    44  					&CreateTable{}:         QueryTypeDDL,
    45  					&CreateView{}:          QueryTypeDDL,
    46  					&CreateIndex{}:         QueryTypeDDL,
    47  					&CreateFunction{}:      QueryTypeDDL,
    48  					&AlterView{}:           QueryTypeDDL,
    49  					&AlterDataBaseConfig{}: QueryTypeDDL,
    50  					&DropDatabase{}:        QueryTypeDDL,
    51  					&DropTable{}:           QueryTypeDDL,
    52  					&DropView{}:            QueryTypeDDL,
    53  					&DropIndex{}:           QueryTypeDDL,
    54  					&DropFunction{}:        QueryTypeDDL,
    55  					&TruncateTable{}:       QueryTypeDDL,
    56  					// DML
    57  					&Insert{}: QueryTypeDML,
    58  					&Update{}: QueryTypeDML,
    59  					&Delete{}: QueryTypeDML,
    60  					&Load{}:   QueryTypeDML,
    61  					&Import{}: 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  					// TCL
    79  					&BeginTransaction{}:    QueryTypeTCL,
    80  					&CommitTransaction{}:   QueryTypeTCL,
    81  					&RollbackTransaction{}: QueryTypeTCL,
    82  					// Other
    83  					&AnalyzeStmt{}:    QueryTypeOth,
    84  					&ExplainAnalyze{}: QueryTypeOth,
    85  					&ExplainFor{}:     QueryTypeOth,
    86  					&ExplainStmt{}:    QueryTypeOth,
    87  					&SetVar{}:         QueryTypeOth,
    88  					&SetDefaultRole{}: QueryTypeOth,
    89  					&SetRole{}:        QueryTypeOth,
    90  					&SetPassword{}:    QueryTypeOth,
    91  					&Declare{}:        QueryTypeOth,
    92  					&Do{}:             QueryTypeOth,
    93  					&TableFunction{}:  QueryTypeOth,
    94  					&Use{}:            QueryTypeOth,
    95  					&PrepareStmt{}:    QueryTypeOth,
    96  					&Execute{}:        QueryTypeOth,
    97  					&Deallocate{}:     QueryTypeOth,
    98  					&Kill{}:           QueryTypeOth,
    99  					// 'Show' prefix statement
   100  					&ShowProcessList{}:    QueryTypeOth,
   101  					&ShowTableStatus{}:    QueryTypeOth,
   102  					&ShowCreateDatabase{}: QueryTypeOth,
   103  					&ShowCreateView{}:     QueryTypeOth,
   104  					&ShowCreateTable{}:    QueryTypeOth,
   105  					&ShowAccounts{}:       QueryTypeOth,
   106  					&ShowCollation{}:      QueryTypeOth,
   107  					&ShowDatabases{}:      QueryTypeOth,
   108  					&ShowErrors{}:         QueryTypeOth,
   109  					&ShowFunctionStatus{}: QueryTypeOth,
   110  					&ShowGrants{}:         QueryTypeOth,
   111  					&ShowIndex{}:          QueryTypeOth,
   112  					&ShowLocks{}:          QueryTypeOth,
   113  					&ShowNodeList{}:       QueryTypeOth,
   114  					&ShowStatus{}:         QueryTypeOth,
   115  					&ShowTableNumber{}:    QueryTypeOth,
   116  					&ShowTables{}:         QueryTypeOth,
   117  					&ShowTarget{}:         QueryTypeOth,
   118  					&ShowVariables{}:      QueryTypeOth,
   119  					&ShowWarnings{}:       QueryTypeOth,
   120  					&ShowColumns{}:        QueryTypeOth,
   121  				},
   122  			},
   123  		},
   124  	}
   125  	for _, tt := range tests {
   126  		t.Run(tt.name, func(t1 *testing.T) {
   127  			for stmt, queryType := range tt.fields.types {
   128  				require.Equalf(t1, queryType, stmt.GetQueryType(), "statement_type: %s", stmt.GetStatementType())
   129  			}
   130  		})
   131  	}
   132  
   133  }