github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/plan/build_alter_table_test.go (about)

     1  // Copyright 2023 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 plan
    16  
    17  import "testing"
    18  
    19  func TestAlterTable1(t *testing.T) {
    20  	//sql := "ALTER TABLE t1 ADD (d TIMESTAMP, e INT not null);"
    21  	//sql := "ALTER TABLE t1 ADD d INT NOT NULL PRIMARY KEY;"
    22  	sql := "ALTER TABLE t1 MODIFY b INT;"
    23  	mock := NewMockOptimizer(false)
    24  	logicPlan, err := buildSingleStmt(mock, t, sql)
    25  	if err != nil {
    26  		t.Fatalf("%+v", err)
    27  	}
    28  	outPutPlan(logicPlan, true, t)
    29  }
    30  
    31  func TestAlterTableAddColumns(t *testing.T) {
    32  	mock := NewMockOptimizer(false)
    33  	// CREATE TABLE t1 (a INTEGER, b CHAR(10));
    34  	sqls := []string{
    35  		`ALTER TABLE t1 ADD d TIMESTAMP;`,
    36  		//`ALTER TABLE t1 ADD (d TIMESTAMP, e INT not null);`,
    37  		//`ALTER TABLE t2 ADD c INT PRIMARY KEY;`,
    38  		//`ALTER TABLE t2 ADD c INT PRIMARY KEY PRIMARY KEY;`,
    39  		//`ALTER TABLE t2 ADD c INT PRIMARY KEY PRIMARY KEY PRIMARY KEY;`,
    40  	}
    41  	runTestShouldPass(mock, t, sqls, false, false)
    42  }