@@ -90,18 +90,18 @@ func validateAlterTable(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.S
90
90
switch n := n .(type ) {
91
91
case * plan.RenameTable :
92
92
for _ , name := range n .NewNames {
93
- err = validateIdentifier (name )
93
+ err = ValidateIdentifier (name )
94
94
if err != nil {
95
95
return false
96
96
}
97
97
}
98
98
case * plan.CreateCheck :
99
- err = validateIdentifier (n .Check .Name )
99
+ err = ValidateIdentifier (n .Check .Name )
100
100
if err != nil {
101
101
return false
102
102
}
103
103
case * plan.CreateForeignKey :
104
- err = validateIdentifier (n .FkDef .Name )
104
+ err = ValidateIdentifier (n .FkDef .Name )
105
105
if err != nil {
106
106
return false
107
107
}
@@ -177,7 +177,7 @@ func resolveAlterColumn(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.S
177
177
validator = sv
178
178
}
179
179
}
180
- keyedColumns , err = getTableIndexColumns (ctx , n .Table )
180
+ keyedColumns , err = GetTableIndexColumns (ctx , n .Table )
181
181
return false
182
182
case * plan.RenameColumn :
183
183
if rt , ok := n .Table .(* plan.ResolvedTable ); ok {
@@ -192,7 +192,7 @@ func resolveAlterColumn(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.S
192
192
validator = sv
193
193
}
194
194
}
195
- keyedColumns , err = getTableIndexColumns (ctx , n .Table )
195
+ keyedColumns , err = GetTableIndexColumns (ctx , n .Table )
196
196
return false
197
197
case * plan.DropColumn :
198
198
if rt , ok := n .Table .(* plan.ResolvedTable ); ok {
@@ -207,7 +207,7 @@ func resolveAlterColumn(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.S
207
207
validator = sv
208
208
}
209
209
}
210
- indexes , err = getTableIndexNames (ctx , a , n .Table )
210
+ indexes , err = GetTableIndexNames (ctx , a , n .Table )
211
211
default :
212
212
}
213
213
return true
@@ -237,7 +237,7 @@ func resolveAlterColumn(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.S
237
237
return nil , transform .SameTree , err
238
238
}
239
239
240
- sch , err = validateModifyColumn (ctx , initialSch , sch , n .(* plan.ModifyColumn ), keyedColumns )
240
+ sch , err = ValidateModifyColumn (ctx , initialSch , sch , n .(* plan.ModifyColumn ), keyedColumns )
241
241
if err != nil {
242
242
return nil , transform .SameTree , err
243
243
}
@@ -247,7 +247,7 @@ func resolveAlterColumn(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.S
247
247
if err != nil {
248
248
return nil , transform .SameTree , err
249
249
}
250
- sch , err = validateRenameColumn (initialSch , sch , n .(* plan.RenameColumn ))
250
+ sch , err = ValidateRenameColumn (initialSch , sch , n .(* plan.RenameColumn ))
251
251
if err != nil {
252
252
return nil , transform .SameTree , err
253
253
}
@@ -270,7 +270,7 @@ func resolveAlterColumn(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.S
270
270
if err != nil {
271
271
return nil , transform .SameTree , err
272
272
}
273
- sch , err = validateDropColumn (initialSch , sch , n .(* plan.DropColumn ))
273
+ sch , err = ValidateDropColumn (initialSch , sch , n .(* plan.DropColumn ))
274
274
if err != nil {
275
275
return nil , transform .SameTree , err
276
276
}
@@ -287,7 +287,7 @@ func resolveAlterColumn(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.S
287
287
return nil , transform .SameTree , err
288
288
}
289
289
290
- keyedColumns = updateKeyedColumns (keyedColumns , nn )
290
+ keyedColumns = UpdateKeyedColumns (keyedColumns , nn )
291
291
return n , transform .NewTree , nil
292
292
case * plan.AlterPK :
293
293
n , err := nn .WithTargetSchema (sch .Copy ())
@@ -304,7 +304,7 @@ func resolveAlterColumn(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.S
304
304
if err != nil {
305
305
return nil , transform .SameTree , err
306
306
}
307
- sch , err = validateAlterDefault (initialSch , sch , n .(* plan.AlterDefaultSet ))
307
+ sch , err = ValidateAlterDefault (initialSch , sch , n .(* plan.AlterDefaultSet ))
308
308
if err != nil {
309
309
return nil , transform .SameTree , err
310
310
}
@@ -314,7 +314,7 @@ func resolveAlterColumn(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.S
314
314
if err != nil {
315
315
return nil , transform .SameTree , err
316
316
}
317
- sch , err = validateDropDefault (initialSch , sch , n .(* plan.AlterDefaultDrop ))
317
+ sch , err = ValidateDropDefault (initialSch , sch , n .(* plan.AlterDefaultDrop ))
318
318
if err != nil {
319
319
return nil , transform .SameTree , err
320
320
}
@@ -345,8 +345,8 @@ func resolveAlterColumn(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.S
345
345
return n , same , nil
346
346
}
347
347
348
- // updateKeyedColumns updates the keyedColumns map based on the action of the AlterIndex node
349
- func updateKeyedColumns (keyedColumns map [string ]bool , n * plan.AlterIndex ) map [string ]bool {
348
+ // UpdateKeyedColumns updates the keyedColumns map based on the action of the AlterIndex node
349
+ func UpdateKeyedColumns (keyedColumns map [string ]bool , n * plan.AlterIndex ) map [string ]bool {
350
350
switch n .Action {
351
351
case plan .IndexAction_Create :
352
352
for _ , col := range n .Columns {
@@ -361,16 +361,16 @@ func updateKeyedColumns(keyedColumns map[string]bool, n *plan.AlterIndex) map[st
361
361
return keyedColumns
362
362
}
363
363
364
- // validateRenameColumn checks that a DDL RenameColumn node can be safely executed (e.g. no collision with other
364
+ // ValidateRenameColumn checks that a DDL RenameColumn node can be safely executed (e.g. no collision with other
365
365
// column names, doesn't invalidate any table check constraints).
366
366
//
367
367
// Note that schema is passed in twice, because one version is the initial version before the alter column expressions
368
368
// are applied, and the second version is the current schema that is being modified as multiple nodes are processed.
369
- func validateRenameColumn (initialSch , sch sql.Schema , rc * plan.RenameColumn ) (sql.Schema , error ) {
369
+ func ValidateRenameColumn (initialSch , sch sql.Schema , rc * plan.RenameColumn ) (sql.Schema , error ) {
370
370
table := rc .Table
371
371
nameable := table .(sql.Nameable )
372
372
373
- err := validateIdentifier (rc .NewColumnName )
373
+ err := ValidateIdentifier (rc .NewColumnName )
374
374
if err != nil {
375
375
return nil , err
376
376
}
@@ -387,7 +387,7 @@ func validateRenameColumn(initialSch, sch sql.Schema, rc *plan.RenameColumn) (sq
387
387
return nil , sql .ErrTableColumnNotFound .New (nameable .Name (), rc .ColumnName )
388
388
}
389
389
390
- err = validateColumnNotUsedInCheckConstraint (rc .ColumnName , rc .Checks ())
390
+ err = ValidateColumnNotUsedInCheckConstraint (rc .ColumnName , rc .Checks ())
391
391
if err != nil {
392
392
return nil , err
393
393
}
@@ -402,7 +402,7 @@ func ValidateAddColumn(schema sql.Schema, ac *plan.AddColumn) (sql.Schema, error
402
402
table := ac .Table
403
403
nameable := table .(sql.Nameable )
404
404
405
- err := validateIdentifier (ac .Column ().Name )
405
+ err := ValidateIdentifier (ac .Column ().Name )
406
406
if err != nil {
407
407
return nil , err
408
408
}
@@ -449,7 +449,7 @@ func isStrictMysqlCompatibilityEnabled(ctx *sql.Context) (bool, error) {
449
449
return i == 1 , nil
450
450
}
451
451
452
- func validateModifyColumn (ctx * sql.Context , initialSch sql.Schema , schema sql.Schema , mc * plan.ModifyColumn , keyedColumns map [string ]bool ) (sql.Schema , error ) {
452
+ func ValidateModifyColumn (ctx * sql.Context , initialSch sql.Schema , schema sql.Schema , mc * plan.ModifyColumn , keyedColumns map [string ]bool ) (sql.Schema , error ) {
453
453
table := mc .Table
454
454
tableName := table .(sql.Nameable ).Name ()
455
455
@@ -461,7 +461,7 @@ func validateModifyColumn(ctx *sql.Context, initialSch sql.Schema, schema sql.Sc
461
461
}
462
462
463
463
newCol := mc .NewColumn ()
464
- if err := validateIdentifier (newCol .Name ); err != nil {
464
+ if err := ValidateIdentifier (newCol .Name ); err != nil {
465
465
return nil , err
466
466
}
467
467
@@ -522,14 +522,14 @@ func validateModifyColumn(ctx *sql.Context, initialSch sql.Schema, schema sql.Sc
522
522
return newSch , nil
523
523
}
524
524
525
- func validateIdentifier (name string ) error {
525
+ func ValidateIdentifier (name string ) error {
526
526
if len (name ) > sql .MaxIdentifierLength {
527
527
return sql .ErrInvalidIdentifier .New (name )
528
528
}
529
529
return nil
530
530
}
531
531
532
- func validateDropColumn (initialSch , sch sql.Schema , dc * plan.DropColumn ) (sql.Schema , error ) {
532
+ func ValidateDropColumn (initialSch , sch sql.Schema , dc * plan.DropColumn ) (sql.Schema , error ) {
533
533
table := dc .Table
534
534
nameable := table .(sql.Nameable )
535
535
@@ -550,9 +550,9 @@ func validateDropColumn(initialSch, sch sql.Schema, dc *plan.DropColumn) (sql.Sc
550
550
return newSch , nil
551
551
}
552
552
553
- // validateColumnNotUsedInCheckConstraint validates that the specified column name is not referenced in any of
553
+ // ValidateColumnNotUsedInCheckConstraint validates that the specified column name is not referenced in any of
554
554
// the specified table check constraints.
555
- func validateColumnNotUsedInCheckConstraint (columnName string , checks sql.CheckConstraints ) error {
555
+ func ValidateColumnNotUsedInCheckConstraint (columnName string , checks sql.CheckConstraints ) error {
556
556
var err error
557
557
for _ , check := range checks {
558
558
_ = transform .InspectExpr (check .Expr , func (e sql.Expression ) bool {
@@ -626,7 +626,7 @@ func validateColumnSafeToDropWithCheckConstraint(columnName string, checks sql.C
626
626
func validateAlterIndex (ctx * sql.Context , initialSch , sch sql.Schema , ai * plan.AlterIndex , indexes []string ) ([]string , error ) {
627
627
switch ai .Action {
628
628
case plan .IndexAction_Create :
629
- err := validateIdentifier (ai .IndexName )
629
+ err := ValidateIdentifier (ai .IndexName )
630
630
if err != nil {
631
631
return nil , err
632
632
}
@@ -662,7 +662,7 @@ func validateAlterIndex(ctx *sql.Context, initialSch, sch sql.Schema, ai *plan.A
662
662
// Remove the index from the list
663
663
return append (indexes [:savedIdx ], indexes [savedIdx + 1 :]... ), nil
664
664
case plan .IndexAction_Rename :
665
- err := validateIdentifier (ai .IndexName )
665
+ err := ValidateIdentifier (ai .IndexName )
666
666
if err != nil {
667
667
return nil , err
668
668
}
@@ -917,8 +917,8 @@ func validateIndex(ctx *sql.Context, colMap map[string]*sql.Column, idxDef *sql.
917
917
return nil
918
918
}
919
919
920
- // getTableIndexColumns returns the columns over which indexes are defined
921
- func getTableIndexColumns (ctx * sql.Context , table sql.Node ) (map [string ]bool , error ) {
920
+ // GetTableIndexColumns returns the columns over which indexes are defined
921
+ func GetTableIndexColumns (ctx * sql.Context , table sql.Node ) (map [string ]bool , error ) {
922
922
ia , err := newIndexAnalyzerForNode (ctx , table )
923
923
if err != nil {
924
924
return nil , err
@@ -937,8 +937,8 @@ func getTableIndexColumns(ctx *sql.Context, table sql.Node) (map[string]bool, er
937
937
return keyedColumns , nil
938
938
}
939
939
940
- // getTableIndexNames returns the names of indexes associated with a table.
941
- func getTableIndexNames (ctx * sql.Context , _ * Analyzer , table sql.Node ) ([]string , error ) {
940
+ // GetTableIndexNames returns the names of indexes associated with a table.
941
+ func GetTableIndexNames (ctx * sql.Context , _ * Analyzer , table sql.Node ) ([]string , error ) {
942
942
ia , err := newIndexAnalyzerForNode (ctx , table )
943
943
if err != nil {
944
944
return nil , err
@@ -951,7 +951,7 @@ func getTableIndexNames(ctx *sql.Context, _ *Analyzer, table sql.Node) ([]string
951
951
names [i ] = index .ID ()
952
952
}
953
953
954
- if hasPrimaryKeys (table .Schema ()) {
954
+ if HasPrimaryKeys (table .Schema ()) {
955
955
names = append (names , "PRIMARY" )
956
956
}
957
957
@@ -963,7 +963,7 @@ func validatePrimaryKey(ctx *sql.Context, initialSch, sch sql.Schema, ai *plan.A
963
963
tableName := getTableName (ai .Table )
964
964
switch ai .Action {
965
965
case plan .PrimaryKeyAction_Create :
966
- if hasPrimaryKeys (sch ) {
966
+ if HasPrimaryKeys (sch ) {
967
967
return nil , sql .ErrMultiplePrimaryKeysDefined .New ()
968
968
}
969
969
@@ -996,7 +996,7 @@ func validatePrimaryKey(ctx *sql.Context, initialSch, sch sql.Schema, ai *plan.A
996
996
997
997
return sch , nil
998
998
case plan .PrimaryKeyAction_Drop :
999
- if ! hasPrimaryKeys (sch ) {
999
+ if ! HasPrimaryKeys (sch ) {
1000
1000
return nil , sql .ErrCantDropFieldOrKey .New ("PRIMARY" )
1001
1001
}
1002
1002
@@ -1012,8 +1012,8 @@ func validatePrimaryKey(ctx *sql.Context, initialSch, sch sql.Schema, ai *plan.A
1012
1012
}
1013
1013
}
1014
1014
1015
- // validateAlterDefault validates the addition of a default value to a column.
1016
- func validateAlterDefault (initialSch , sch sql.Schema , as * plan.AlterDefaultSet ) (sql.Schema , error ) {
1015
+ // ValidateAlterDefault validates the addition of a default value to a column.
1016
+ func ValidateAlterDefault (initialSch , sch sql.Schema , as * plan.AlterDefaultSet ) (sql.Schema , error ) {
1017
1017
idx := sch .IndexOf (as .ColumnName , getTableName (as .Table ))
1018
1018
if idx == - 1 {
1019
1019
return nil , sql .ErrTableColumnNotFound .New (as .ColumnName )
@@ -1029,8 +1029,8 @@ func validateAlterDefault(initialSch, sch sql.Schema, as *plan.AlterDefaultSet)
1029
1029
return sch , err
1030
1030
}
1031
1031
1032
- // validateDropDefault validates the dropping of a default value.
1033
- func validateDropDefault (initialSch , sch sql.Schema , ad * plan.AlterDefaultDrop ) (sql.Schema , error ) {
1032
+ // ValidateDropDefault validates the dropping of a default value.
1033
+ func ValidateDropDefault (initialSch , sch sql.Schema , ad * plan.AlterDefaultDrop ) (sql.Schema , error ) {
1034
1034
idx := sch .IndexOf (ad .ColumnName , getTableName (ad .Table ))
1035
1035
if idx == - 1 {
1036
1036
return nil , sql .ErrTableColumnNotFound .New (ad .ColumnName )
@@ -1041,7 +1041,7 @@ func validateDropDefault(initialSch, sch sql.Schema, ad *plan.AlterDefaultDrop)
1041
1041
return sch , nil
1042
1042
}
1043
1043
1044
- func hasPrimaryKeys (sch sql.Schema ) bool {
1044
+ func HasPrimaryKeys (sch sql.Schema ) bool {
1045
1045
for _ , c := range sch {
1046
1046
if c .PrimaryKey {
1047
1047
return true
0 commit comments