/
rule.go
1039 lines (914 loc) · 39.6 KB
/
rule.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright © 2020 Marvin
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed r. in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package o2m
import (
"encoding/json"
"fmt"
"github.com/valyala/fastjson"
"github.com/wentaojin/transferdb/common"
"github.com/wentaojin/transferdb/database/meta"
"go.uber.org/zap"
"regexp"
"strings"
)
type Rule struct {
*Table
*Info
}
type Info struct {
SourceTableDDL string `json:"-"` // 忽略
PrimaryKeyINFO []map[string]string `json:"primary_key_info"`
UniqueKeyINFO []map[string]string `json:"unique_key_info"`
ForeignKeyINFO []map[string]string `json:"foreign_key_info"`
CheckKeyINFO []map[string]string `json:"check_key_info"`
UniqueIndexINFO []map[string]string `json:"unique_index_info"`
NormalIndexINFO []map[string]string `json:"normal_index_info"`
TableCommentINFO []map[string]string `json:"table_comment_info"`
TableColumnINFO []map[string]string `json:"table_column_info"`
ColumnCommentINFO []map[string]string `json:"column_comment_info"`
}
func (r *Rule) GenCreateTableDDL() (interface{}, error) {
var (
tablePrefix, tableComment string
tableKeys, checkKeys, foreignKeys, compatibleDDL []string
)
targetSchema, targetTable := r.GenTablePrefix()
tableSuffix, err := r.GenTableSuffix()
if err != nil {
return nil, err
}
tableColumns, err := r.GenTableColumn()
if err != nil {
return nil, err
}
tableKeys, compatibleDDL, err = r.GenTableKeys()
if err != nil {
return nil, err
}
tablePrefix = fmt.Sprintf("CREATE TABLE `%s`.`%s`", targetSchema, targetTable)
checkKeys, err = r.GenTableCheckKey()
if err != nil {
return nil, err
}
foreignKeys, err = r.GenTableForeignKey()
if err != nil {
return nil, err
}
tableComment, err = r.GenTableComment()
if err != nil {
return nil, err
}
return &DDL{
SourceSchemaName: r.SourceSchemaName,
SourceTableName: r.SourceTableName,
SourceTableType: r.SourceTableType,
SourceTableDDL: r.SourceTableDDL,
TargetSchemaName: r.GenSchemaName(), // change schema name
TargetTableName: r.GenTableName(), // change table name
TargetDBType: r.TargetDBType,
TargetDBVersion: r.TargetDBVersion,
TablePrefix: tablePrefix,
TableColumns: tableColumns,
TableKeys: tableKeys,
TableSuffix: tableSuffix,
TableComment: tableComment,
TableCheckKeys: checkKeys,
TableForeignKeys: foreignKeys,
TableCompatibleDDL: compatibleDDL,
}, nil
}
func (r *Rule) GenTableKeys() (tableKeys []string, compatibilityIndexSQL []string, err error) {
// 唯一约束/普通索引/唯一索引
uniqueKeyMetas, err := r.GenTableUniqueKey()
if err != nil {
return tableKeys, compatibilityIndexSQL, fmt.Errorf("table json [%v], oracle db reverse table unique constraint failed: %v", r.String(), err)
}
normalIndexes, normalIndexCompSQL, err := r.GenTableNormalIndex()
if err != nil {
return tableKeys, compatibilityIndexSQL, fmt.Errorf("table json [%v], oracle db reverse table key non-unique index failed: %v", r.String(), err)
}
uniqueIndexes, uniqueIndexCompSQL, err := r.GenTableUniqueIndex()
if err != nil {
return tableKeys, compatibilityIndexSQL, fmt.Errorf("table json [%v], oracle db reverse table key unique index failed: %v", r.String(), err)
}
if len(normalIndexCompSQL) > 0 {
compatibilityIndexSQL = append(compatibilityIndexSQL, normalIndexCompSQL...)
}
if len(uniqueIndexCompSQL) > 0 {
compatibilityIndexSQL = append(compatibilityIndexSQL, uniqueIndexCompSQL...)
}
// 主键
primaryKeys, err := r.GenTablePrimaryKey()
if err != nil {
return tableKeys, compatibilityIndexSQL, err
}
if len(primaryKeys) > 0 {
tableKeys = append(tableKeys, primaryKeys...)
}
if len(uniqueKeyMetas) > 0 {
tableKeys = append(tableKeys, uniqueKeyMetas...)
}
if len(uniqueIndexes) > 0 {
tableKeys = append(tableKeys, uniqueIndexes...)
}
if len(normalIndexes) > 0 {
tableKeys = append(tableKeys, normalIndexes...)
}
return tableKeys, compatibilityIndexSQL, nil
}
func (r *Rule) GenTablePrefix() (string, string) {
targetSchema := r.GenSchemaName()
targetTable := r.GenTableName()
return targetSchema, targetTable
}
// O2M Special
func (r *Rule) GenTableSuffix() (string, error) {
var (
tableSuffix string
tableCollation string
primaryColumns []string
columnMetas []string
)
singleIntegerPK := false
if len(r.PrimaryKeyINFO) > 0 {
for _, col := range strings.Split(r.PrimaryKeyINFO[0]["COLUMN_LIST"], ",") {
primaryColumns = append(primaryColumns, fmt.Sprintf("`%s`", col))
}
}
columnMetas, err := r.GenTableColumn()
if err != nil {
return "", err
}
// 单列主键且整型主键
if len(primaryColumns) == 1 {
// 单列主键数据类型获取判断
for _, columnMeta := range columnMetas {
columnName := strings.Fields(columnMeta)[0]
columnType := strings.Fields(columnMeta)[1]
if strings.EqualFold(primaryColumns[0], columnName) {
// Map 规则转换后的字段对应数据类型
// columnMeta 视角 columnName columnType ....
for _, integerType := range common.TiDBIntegerPrimaryKeyList {
if find := strings.Contains(common.StringUPPER(columnType), common.StringUPPER(integerType)); find {
singleIntegerPK = true
}
}
}
}
}
// schema、db、table collation
if r.OracleCollation {
// table collation
if r.SourceTableCollation != "" {
if val, ok := common.OracleCollationMap[r.SourceTableCollation]; ok {
tableCollation = val
} else {
return tableSuffix, fmt.Errorf("oracle table collation [%v] isn't support", r.SourceTableCollation)
}
}
// schema collation
if r.SourceTableCollation == "" && r.SourceSchemaCollation != "" {
if val, ok := common.OracleCollationMap[r.SourceSchemaCollation]; ok {
tableCollation = val
} else {
return tableSuffix, fmt.Errorf("oracle schema collation [%v] table collation [%v] isn't support", r.SourceSchemaCollation, r.SourceTableCollation)
}
}
if r.SourceTableName == "" && r.SourceSchemaCollation == "" {
return tableSuffix, fmt.Errorf("oracle schema collation [%v] table collation [%v] isn't support", r.SourceSchemaCollation, r.SourceTableCollation)
}
} else {
// db collation
if val, ok := common.OracleCollationMap[r.SourceDBNLSComp]; ok {
tableCollation = val
} else {
return tableSuffix, fmt.Errorf("oracle db nls_comp [%v] nls_sort [%v] isn't support", r.SourceDBNLSComp, r.SourceDBNLSSort)
}
}
// table-option 表后缀可选项
if strings.EqualFold(r.TargetDBType, common.DatabaseTypeMySQL) || r.TargetTableOption == "" {
zap.L().Warn("reverse oracle table suffix",
zap.String("table", r.String()),
zap.String("table-option", "table-option is null, would be disabled"))
// table suffix
tableSuffix = fmt.Sprintf("ENGINE=InnoDB DEFAULT CHARSET=%s COLLATE=%s",
strings.ToLower(common.MySQLCharacterSet), tableCollation)
} else {
// TiDB
clusteredIdxVal, err := r.MySQL.GetTiDBClusteredIndexValue()
if err != nil {
return tableSuffix, err
}
switch common.StringUPPER(clusteredIdxVal) {
case common.TiDBClusteredIndexOFFValue:
zap.L().Warn("reverse oracle table suffix",
zap.String("table", r.String()),
zap.String("tidb_enable_clustered_index", common.TiDBClusteredIndexOFFValue),
zap.String("table-option", "tidb_enable_clustered_index is off, would be enabled"))
if r.TargetTableOption != "" {
tableSuffix = fmt.Sprintf("ENGINE=InnoDB DEFAULT CHARSET=%s COLLATE=%s %s",
strings.ToLower(common.MySQLCharacterSet), tableCollation, common.StringUPPER(r.TargetTableOption))
} else {
tableSuffix = fmt.Sprintf("ENGINE=InnoDB DEFAULT CHARSET=%s COLLATE=%s",
strings.ToLower(common.MySQLCharacterSet), tableCollation)
}
case common.TiDBClusteredIndexONValue:
zap.L().Warn("reverse oracle table suffix",
zap.String("table", r.String()),
zap.String("tidb_enable_clustered_index", common.TiDBClusteredIndexONValue),
zap.String("table-option", "tidb_enable_clustered_index is on, would be disabled"))
tableSuffix = fmt.Sprintf("ENGINE=InnoDB DEFAULT CHARSET=%s COLLATE=%s",
strings.ToLower(common.MySQLCharacterSet), tableCollation)
default:
// tidb_enable_clustered_index = int_only / tidb_enable_clustered_index 不存在值,等于空
pkVal, err := r.MySQL.GetTiDBAlterPKValue()
if err != nil {
return tableSuffix, err
}
if !fastjson.Exists([]byte(pkVal), "alter-primary-key") {
zap.L().Warn("reverse oracle table suffix",
zap.String("table", r.String()),
zap.String("tidb_enable_clustered_index", common.StringUPPER(clusteredIdxVal)),
zap.String("alter-primary-key", "not exist"),
zap.String("table-option", "alter-primary-key isn't exits, would be disable"))
tableSuffix = fmt.Sprintf("ENGINE=InnoDB DEFAULT CHARSET=%s COLLATE=%s",
strings.ToLower(common.MySQLCharacterSet), tableCollation)
} else {
var p fastjson.Parser
v, err := p.Parse(pkVal)
if err != nil {
return tableSuffix, err
}
isAlterPK := v.GetBool("alter-primary-key")
// alter-primary-key = false
// 整型主键 table-option 不生效
// 单列主键是整型
if !isAlterPK && len(primaryColumns) == 1 && singleIntegerPK {
zap.L().Warn("reverse oracle table suffix",
zap.String("table", r.String()),
zap.String("tidb_enable_clustered_index", common.StringUPPER(clusteredIdxVal)),
zap.Bool("alter-primary-key", isAlterPK),
zap.String("table-option", "integer primary key, would be disable"))
tableSuffix = fmt.Sprintf("ENGINE=InnoDB DEFAULT CHARSET=%s COLLATE=%s",
strings.ToLower(common.MySQLCharacterSet), tableCollation)
} else {
// table-option 生效
// alter-primary-key = true
// alter-primary-key = false && 联合主键 len(pkINFO)>1
// alter-primary-key = false && 非整型主键
if isAlterPK || (!isAlterPK && len(primaryColumns) > 1) || (!isAlterPK && !singleIntegerPK) {
zap.L().Warn("reverse oracle table suffix",
zap.String("table", r.String()),
zap.String("tidb_enable_clustered_index", common.StringUPPER(clusteredIdxVal)),
zap.Bool("alter-primary-key", isAlterPK),
zap.String("table-option", "enabled"))
if r.TargetTableOption != "" {
tableSuffix = fmt.Sprintf("ENGINE=InnoDB DEFAULT CHARSET=%s COLLATE=%s %s",
strings.ToLower(common.MySQLCharacterSet), tableCollation, common.StringUPPER(r.TargetTableOption))
} else {
tableSuffix = fmt.Sprintf("ENGINE=InnoDB DEFAULT CHARSET=%s COLLATE=%s",
strings.ToLower(common.MySQLCharacterSet), tableCollation)
}
} else {
zap.L().Error("reverse oracle table suffix",
zap.String("table", r.String()),
zap.String("tidb_enable_clustered_index", common.StringUPPER(clusteredIdxVal)),
zap.Bool("alter-primary-key", isAlterPK),
zap.String("table-option", "disabled"),
zap.Error(fmt.Errorf("not support")))
return tableSuffix, fmt.Errorf("reverse oracle table suffix error: table-option not support")
}
}
}
}
}
zap.L().Info("reverse oracle table suffix",
zap.String("table", r.String()),
zap.String("create table suffix", tableSuffix))
return tableSuffix, nil
}
func (r *Rule) GenTablePrimaryKey() (primaryKeys []string, err error) {
if len(r.PrimaryKeyINFO) > 1 {
return primaryKeys, fmt.Errorf("oracle schema [%s] table [%s] primary key exist multiple values: [%v]", r.SourceSchemaName, r.SourceTableName, r.PrimaryKeyINFO)
}
if len(r.PrimaryKeyINFO) > 0 {
var primaryColumns []string
for _, col := range strings.Split(r.PrimaryKeyINFO[0]["COLUMN_LIST"], ",") {
primaryColumns = append(primaryColumns, fmt.Sprintf("`%s`", col))
}
pk := fmt.Sprintf("PRIMARY KEY (%s)", strings.ToUpper(strings.Join(primaryColumns, ",")))
primaryKeys = append(primaryKeys, pk)
}
return primaryKeys, nil
}
func (r *Rule) GenTableUniqueKey() (uniqueKeys []string, err error) {
if len(r.UniqueKeyINFO) > 0 {
for _, rowUKCol := range r.UniqueKeyINFO {
var ukArr []string
for _, col := range strings.Split(rowUKCol["COLUMN_LIST"], ",") {
ukArr = append(ukArr, fmt.Sprintf("`%s`", col))
}
uk := fmt.Sprintf("UNIQUE KEY `%s` (%s)",
strings.ToUpper(rowUKCol["CONSTRAINT_NAME"]), strings.ToUpper(strings.Join(ukArr, ",")))
uniqueKeys = append(uniqueKeys, uk)
}
}
return uniqueKeys, nil
}
func (r *Rule) GenTableForeignKey() (foreignKeys []string, err error) {
if len(r.ForeignKeyINFO) > 0 {
for _, rowFKCol := range r.ForeignKeyINFO {
if rowFKCol["DELETE_RULE"] == "" || rowFKCol["DELETE_RULE"] == "NO ACTION" {
fk := fmt.Sprintf("CONSTRAINT `%s` FOREIGN KEY (%s) REFERENCES `%s`.`%s` (%s)",
strings.ToUpper(rowFKCol["CONSTRAINT_NAME"]),
strings.ToUpper(rowFKCol["COLUMN_LIST"]),
strings.ToUpper(rowFKCol["R_OWNER"]),
strings.ToUpper(rowFKCol["RTABLE_NAME"]),
strings.ToUpper(rowFKCol["RCOLUMN_LIST"]))
foreignKeys = append(foreignKeys, fk)
}
if rowFKCol["DELETE_RULE"] == "CASCADE" {
fk := fmt.Sprintf("CONSTRAINT `%s` FOREIGN KEY (%s) REFERENCES `%s`.`%s`(%s) ON DELETE CASCADE",
strings.ToUpper(rowFKCol["CONSTRAINT_NAME"]),
strings.ToUpper(rowFKCol["COLUMN_LIST"]),
strings.ToUpper(rowFKCol["R_OWNER"]),
strings.ToUpper(rowFKCol["RTABLE_NAME"]),
strings.ToUpper(rowFKCol["RCOLUMN_LIST"]))
foreignKeys = append(foreignKeys, fk)
}
if rowFKCol["DELETE_RULE"] == "SET NULL" {
fk := fmt.Sprintf("CONSTRAINT `%s` FOREIGN KEY(%s) REFERENCES `%s`.`%s`(%s) ON DELETE SET NULL",
strings.ToUpper(rowFKCol["CONSTRAINT_NAME"]),
strings.ToUpper(rowFKCol["COLUMN_LIST"]),
strings.ToUpper(rowFKCol["R_OWNER"]),
strings.ToUpper(rowFKCol["RTABLE_NAME"]),
strings.ToUpper(rowFKCol["RCOLUMN_LIST"]))
foreignKeys = append(foreignKeys, fk)
}
}
}
return foreignKeys, nil
}
func (r *Rule) GenTableCheckKey() (checkKeys []string, err error) {
if len(r.CheckKeyINFO) > 0 {
// 多个检查约束匹配
// 比如:"LOC" IS noT nUll and loc in ('a','b','c')
reg, err := regexp.Compile(`\s+(?i:AND)\s+|\s+(?i:OR)\s+`)
if err != nil {
return checkKeys, fmt.Errorf("check constraint regexp [AND/OR] failed: %v", err)
}
matchRex, err := regexp.Compile(`(^.*)(?i:IS NOT NULL)`)
if err != nil {
return checkKeys, fmt.Errorf("check constraint regexp match [IS NOT NULL] failed: %v", err)
}
checkRex, err := regexp.Compile(`(.*)(?i:IS NOT NULL)`)
if err != nil {
fmt.Printf("check constraint regexp check [IS NOT NULL] failed: %v", err)
}
for _, rowCKCol := range r.CheckKeyINFO {
// 排除非空约束检查
s := strings.TrimSpace(rowCKCol["SEARCH_CONDITION"])
if !reg.MatchString(s) {
if !matchRex.MatchString(s) {
checkKeys = append(checkKeys, fmt.Sprintf("CONSTRAINT `%s` CHECK (%s)",
strings.ToUpper(rowCKCol["CONSTRAINT_NAME"]),
rowCKCol["SEARCH_CONDITION"]))
}
} else {
strArray := strings.Fields(s)
var (
idxArray []int
checkArray []string
constraintArray []string
)
for idx, val := range strArray {
if strings.EqualFold(val, "AND") || strings.EqualFold(val, "OR") {
idxArray = append(idxArray, idx)
}
}
idxArray = append(idxArray, len(strArray))
for idx, val := range idxArray {
if idx == 0 {
checkArray = append(checkArray, strings.Join(strArray[0:val], " "))
} else {
checkArray = append(checkArray, strings.Join(strArray[idxArray[idx-1]:val], " "))
}
}
for _, val := range checkArray {
v := strings.TrimSpace(val)
if !checkRex.MatchString(v) {
constraintArray = append(constraintArray, v)
}
}
sd := strings.Join(constraintArray, " ")
d := strings.Fields(sd)
if strings.EqualFold(d[0], "AND") || strings.EqualFold(d[0], "OR") {
d = d[1:]
}
if strings.EqualFold(d[len(d)-1], "AND") || strings.EqualFold(d[len(d)-1], "OR") {
d = d[:len(d)-1]
}
checkKeys = append(checkKeys, fmt.Sprintf("CONSTRAINT `%s` CHECK (%s)",
strings.ToUpper(rowCKCol["CONSTRAINT_NAME"]),
strings.Join(d, " ")))
}
}
}
return checkKeys, nil
}
func (r *Rule) GenTableUniqueIndex() (uniqueIndexes []string, compatibilityIndexSQL []string, err error) {
if len(r.UniqueIndexINFO) > 0 {
for _, idxMeta := range r.UniqueIndexINFO {
if idxMeta["TABLE_NAME"] != "" && strings.ToUpper(idxMeta["UNIQUENESS"]) == "UNIQUE" {
switch idxMeta["INDEX_TYPE"] {
case "NORMAL":
var uniqueIndex []string
for _, col := range strings.Split(idxMeta["COLUMN_LIST"], ",") {
uniqueIndex = append(uniqueIndex, fmt.Sprintf("`%s`", col))
}
uniqueIDX := fmt.Sprintf("UNIQUE INDEX `%s` (%s)", strings.ToUpper(idxMeta["INDEX_NAME"]), strings.Join(uniqueIndex, ","))
uniqueIndexes = append(uniqueIndexes, uniqueIDX)
zap.L().Info("reverse unique index",
zap.String("schema", r.SourceSchemaName),
zap.String("table", idxMeta["TABLE_NAME"]),
zap.String("index name", idxMeta["INDEX_NAME"]),
zap.String("index type", idxMeta["INDEX_TYPE"]),
zap.String("index column list", idxMeta["COLUMN_LIST"]),
zap.String("unique index info", uniqueIDX))
continue
case "FUNCTION-BASED NORMAL":
sql := fmt.Sprintf("CREATE UNIQUE INDEX `%s` ON `%s`.`%s` (%s);",
strings.ToUpper(idxMeta["INDEX_NAME"]), r.TargetSchemaName, r.TargetTableName,
idxMeta["COLUMN_LIST"])
compatibilityIndexSQL = append(compatibilityIndexSQL, sql)
zap.L().Warn("reverse unique key",
zap.String("schema", r.SourceSchemaName),
zap.String("table", idxMeta["TABLE_NAME"]),
zap.String("index name", idxMeta["INDEX_NAME"]),
zap.String("index type", idxMeta["INDEX_TYPE"]),
zap.String("index column list", idxMeta["COLUMN_LIST"]),
zap.String("create unique index sql", sql),
zap.String("warn", "mysql not support"))
continue
default:
zap.L().Error("reverse unique index",
zap.String("schema", r.SourceSchemaName),
zap.String("table", idxMeta["TABLE_NAME"]),
zap.String("index name", idxMeta["INDEX_NAME"]),
zap.String("index type", idxMeta["INDEX_TYPE"]),
zap.String("index column list", idxMeta["COLUMN_LIST"]),
zap.String("error", "mysql not support"))
return uniqueIndexes, compatibilityIndexSQL, fmt.Errorf("[UNIQUE] oracle schema [%s] table [%s] reverse normal index panic, error: %v", r.SourceSchemaName, r.SourceTableName, idxMeta)
}
}
zap.L().Error("reverse unique key",
zap.String("schema", r.SourceSchemaName),
zap.String("table", idxMeta["TABLE_NAME"]),
zap.String("index name", idxMeta["INDEX_NAME"]),
zap.String("index type", idxMeta["INDEX_TYPE"]),
zap.String("index column list", idxMeta["COLUMN_LIST"]))
return uniqueIndexes, compatibilityIndexSQL,
fmt.Errorf("[NON-UNIQUE] oracle schema [%s] table [%s] panic, error: %v", r.SourceSchemaName, r.SourceTableName, idxMeta)
}
}
return uniqueIndexes, compatibilityIndexSQL, err
}
func (r *Rule) GenTableNormalIndex() (normalIndexes []string, compatibilityIndexSQL []string, err error) {
// 普通索引【普通索引、函数索引、位图索引、DOMAIN 索引】
if len(r.NormalIndexINFO) > 0 {
for _, idxMeta := range r.NormalIndexINFO {
if idxMeta["TABLE_NAME"] != "" && strings.ToUpper(idxMeta["UNIQUENESS"]) == "NONUNIQUE" {
switch idxMeta["INDEX_TYPE"] {
case "NORMAL":
var normalIndex []string
for _, col := range strings.Split(idxMeta["COLUMN_LIST"], ",") {
normalIndex = append(normalIndex, fmt.Sprintf("`%s`", col))
}
keyIndex := fmt.Sprintf("KEY `%s` (%s)", strings.ToUpper(idxMeta["INDEX_NAME"]), strings.Join(normalIndex, ","))
normalIndexes = append(normalIndexes, keyIndex)
zap.L().Info("reverse normal index",
zap.String("schema", r.SourceSchemaName),
zap.String("table", idxMeta["TABLE_NAME"]),
zap.String("index name", idxMeta["INDEX_NAME"]),
zap.String("index type", idxMeta["INDEX_TYPE"]),
zap.String("index column list", idxMeta["COLUMN_LIST"]),
zap.String("key index info", keyIndex))
continue
case "FUNCTION-BASED NORMAL":
sql := fmt.Sprintf("CREATE INDEX %s ON %s.%s (%s);",
strings.ToUpper(idxMeta["INDEX_NAME"]), r.TargetSchemaName, r.TargetTableName,
idxMeta["COLUMN_LIST"])
compatibilityIndexSQL = append(compatibilityIndexSQL, sql)
zap.L().Warn("reverse normal index",
zap.String("schema", r.SourceSchemaName),
zap.String("table", idxMeta["TABLE_NAME"]),
zap.String("index name", idxMeta["INDEX_NAME"]),
zap.String("index type", idxMeta["INDEX_TYPE"]),
zap.String("index column list", idxMeta["COLUMN_LIST"]),
zap.String("create normal index sql", sql),
zap.String("warn", "mysql not support"))
continue
case "BITMAP":
sql := fmt.Sprintf("CREATE BITMAP INDEX %s ON %s.%s (%s);",
strings.ToUpper(idxMeta["INDEX_NAME"]), r.TargetSchemaName, r.TargetTableName,
idxMeta["COLUMN_LIST"])
compatibilityIndexSQL = append(compatibilityIndexSQL, sql)
zap.L().Warn("reverse normal index",
zap.String("schema", r.SourceSchemaName),
zap.String("table", idxMeta["TABLE_NAME"]),
zap.String("index name", idxMeta["INDEX_NAME"]),
zap.String("index type", idxMeta["INDEX_TYPE"]),
zap.String("index column list", idxMeta["COLUMN_LIST"]),
zap.String("create normal index sql", sql),
zap.String("warn", "mysql not support"))
continue
case "FUNCTION-BASED BITMAP":
sql := fmt.Sprintf("CREATE BITMAP INDEX %s ON %s.%s (%s);",
strings.ToUpper(idxMeta["INDEX_NAME"]), r.TargetSchemaName, r.TargetTableName,
idxMeta["COLUMN_LIST"])
compatibilityIndexSQL = append(compatibilityIndexSQL, sql)
zap.L().Warn("reverse normal index",
zap.String("schema", r.SourceSchemaName),
zap.String("table", idxMeta["TABLE_NAME"]),
zap.String("index name", idxMeta["INDEX_NAME"]),
zap.String("index type", idxMeta["INDEX_TYPE"]),
zap.String("index column list", idxMeta["COLUMN_LIST"]),
zap.String("create normal index sql", sql),
zap.String("warn", "mysql not support"))
continue
case "DOMAIN":
sql := fmt.Sprintf("CREATE INDEX %s ON %s.%s (%s) INDEXTYPE IS %s.%s PARAMETERS ('%s');",
strings.ToUpper(idxMeta["INDEX_NAME"]), r.TargetSchemaName, r.TargetTableName,
idxMeta["COLUMN_LIST"],
strings.ToUpper(idxMeta["ITYP_OWNER"]),
strings.ToUpper(idxMeta["ITYP_NAME"]),
idxMeta["PARAMETERS"])
compatibilityIndexSQL = append(compatibilityIndexSQL, sql)
zap.L().Warn("reverse normal index",
zap.String("schema", r.SourceSchemaName),
zap.String("table", idxMeta["TABLE_NAME"]),
zap.String("index name", idxMeta["INDEX_NAME"]),
zap.String("index type", idxMeta["INDEX_TYPE"]),
zap.String("index column list", idxMeta["COLUMN_LIST"]),
zap.String("domain owner", idxMeta["ITYP_OWNER"]),
zap.String("domain index name", idxMeta["ITYP_NAME"]),
zap.String("domain parameters", idxMeta["PARAMETERS"]),
zap.String("create normal index sql", sql),
zap.String("warn", "mysql not support"))
continue
default:
zap.L().Error("reverse normal index",
zap.String("schema", r.SourceSchemaName),
zap.String("table", idxMeta["TABLE_NAME"]),
zap.String("index name", idxMeta["INDEX_NAME"]),
zap.String("index type", idxMeta["INDEX_TYPE"]),
zap.String("index column list", idxMeta["COLUMN_LIST"]),
zap.String("domain owner", idxMeta["ITYP_OWNER"]),
zap.String("domain index name", idxMeta["ITYP_NAME"]),
zap.String("domain parameters", idxMeta["PARAMETERS"]),
zap.String("error", "mysql not support"))
return normalIndexes, compatibilityIndexSQL, fmt.Errorf("[NORMAL] oracle schema [%s] table [%s] reverse normal index panic, error: %v", r.SourceSchemaName, r.SourceTableName, idxMeta)
}
}
zap.L().Error("reverse normal index",
zap.String("schema", r.SourceSchemaName),
zap.String("table", idxMeta["TABLE_NAME"]),
zap.String("index name", idxMeta["INDEX_NAME"]),
zap.String("index type", idxMeta["INDEX_TYPE"]),
zap.String("index column list", idxMeta["COLUMN_LIST"]),
zap.String("domain owner", idxMeta["ITYP_OWNER"]),
zap.String("domain index name", idxMeta["ITYP_NAME"]),
zap.String("domain parameters", idxMeta["PARAMETERS"]))
return normalIndexes, compatibilityIndexSQL, fmt.Errorf("[NON-NORMAL] oracle schema [%s] table [%s] reverse normal index panic, error: %v", r.SourceSchemaName, r.SourceTableName, idxMeta)
}
}
return normalIndexes, compatibilityIndexSQL, err
}
func (r *Rule) GenTableComment() (tableComment string, err error) {
if len(r.TableColumnINFO) > 0 && r.TableCommentINFO[0]["COMMENTS"] != "" {
tableComment = fmt.Sprintf("COMMENT='%s'", r.TableCommentINFO[0]["COMMENTS"])
}
return tableComment, err
}
func (r *Rule) GenTableColumn() (tableColumns []string, err error) {
for _, rowCol := range r.TableColumnINFO {
var (
columnCollation string
nullable string
comment string
dataDefault string
columnType string
)
if r.OracleCollation {
// 字段排序规则检查
if collationMapVal, ok := common.OracleCollationMap[strings.ToUpper(rowCol["COLLATION"])]; ok {
columnCollation = collationMapVal
} else {
// 字段数值数据类型不存在排序规则,排除忽略
if !strings.EqualFold(rowCol["COLLATION"], "") {
return tableColumns, fmt.Errorf(`error on check oracle column [%v] collation: %v`, rowCol["COLUMN_NAME"], rowCol["COLLATION"])
}
columnCollation = ""
}
} else {
// oracle 12.2 版本以下不支持,置空
columnCollation = ""
}
if val, ok := r.TableColumnDatatypeRule[rowCol["COLUMN_NAME"]]; ok {
columnType = val
} else {
return tableColumns, fmt.Errorf("oracle table [%s.%s] column [%s] data type isn't exist", r.SourceSchemaName, r.SourceTableName, rowCol["COLUMN_NAME"])
}
if strings.EqualFold(rowCol["NULLABLE"], "Y") {
nullable = "NULL"
} else {
nullable = "NOT NULL"
}
if !strings.EqualFold(rowCol["COMMENTS"], "") {
comment = "'" + common.SpecialLettersUsingMySQL([]byte(rowCol["COMMENTS"])) + "'"
} else {
comment = rowCol["COMMENTS"]
}
if val, ok := r.TableColumnDefaultValRule[rowCol["COLUMN_NAME"]]; ok {
dataDefault = val
} else {
return tableColumns, fmt.Errorf("oracle table [%s.%s] column [%s] default value isn't exist", r.SourceSchemaName, r.SourceTableName, rowCol["COLUMN_NAME"])
}
if nullable == "NULL" {
switch {
case columnCollation != "" && comment != "" && dataDefault != "":
tableColumns = append(tableColumns, fmt.Sprintf("`%s` %s COLLATE %s DEFAULT %s COMMENT %s", rowCol["COLUMN_NAME"], columnType, columnCollation, dataDefault, comment))
case columnCollation != "" && comment == "" && dataDefault != "":
tableColumns = append(tableColumns, fmt.Sprintf("`%s` %s COLLATE %s DEFAULT %s", rowCol["COLUMN_NAME"], columnType, columnCollation, dataDefault))
case columnCollation != "" && comment == "" && dataDefault == "":
tableColumns = append(tableColumns, fmt.Sprintf("`%s` %s COLLATE %s", rowCol["COLUMN_NAME"], columnType, columnCollation))
case columnCollation != "" && comment != "" && dataDefault == "":
tableColumns = append(tableColumns, fmt.Sprintf("`%s` %s COLLATE %s COMMENT %s", rowCol["COLUMN_NAME"], columnType, columnCollation, comment))
case columnCollation == "" && comment != "" && dataDefault != "":
tableColumns = append(tableColumns, fmt.Sprintf("`%s` %s DEFAULT %s COMMENT %s", rowCol["COLUMN_NAME"], columnType, dataDefault, comment))
case columnCollation == "" && comment == "" && dataDefault != "":
tableColumns = append(tableColumns, fmt.Sprintf("`%s` %s DEFAULT %s", rowCol["COLUMN_NAME"], columnType, dataDefault))
case columnCollation == "" && comment == "" && dataDefault == "":
tableColumns = append(tableColumns, fmt.Sprintf("`%s` %s", rowCol["COLUMN_NAME"], columnType))
case columnCollation == "" && comment != "" && dataDefault == "":
tableColumns = append(tableColumns, fmt.Sprintf("`%s` %s COMMENT %s", rowCol["COLUMN_NAME"], columnType, comment))
default:
return tableColumns, fmt.Errorf("error on gen oracle schema table column meta with nullable, rule: %v", r.String())
}
} else {
switch {
case columnCollation != "" && comment != "" && dataDefault != "":
tableColumns = append(tableColumns, fmt.Sprintf("`%s` %s COLLATE %s %s DEFAULT %s COMMENT %s",
rowCol["COLUMN_NAME"], columnType, columnCollation, nullable, dataDefault, comment))
case columnCollation != "" && comment != "" && dataDefault == "":
tableColumns = append(tableColumns, fmt.Sprintf("`%s` %s COLLATE %s %s COMMENT %s", rowCol["COLUMN_NAME"], columnType, columnCollation, nullable, comment))
case columnCollation != "" && comment == "" && dataDefault != "":
tableColumns = append(tableColumns, fmt.Sprintf("`%s` %s COLLATE %s %s DEFAULT %s", rowCol["COLUMN_NAME"], columnType, columnCollation, nullable, dataDefault))
case columnCollation != "" && comment == "" && dataDefault == "":
tableColumns = append(tableColumns, fmt.Sprintf("`%s` %s COLLATE %s %s", rowCol["COLUMN_NAME"], columnType, columnCollation, nullable))
case columnCollation == "" && comment != "" && dataDefault != "":
tableColumns = append(tableColumns, fmt.Sprintf("`%s` %s %s DEFAULT %s COMMENT %s", rowCol["COLUMN_NAME"], columnType, nullable, dataDefault, comment))
case columnCollation == "" && comment != "" && dataDefault == "":
tableColumns = append(tableColumns, fmt.Sprintf("`%s` %s %s COMMENT %s", rowCol["COLUMN_NAME"], columnType, nullable, comment))
case columnCollation == "" && comment == "" && dataDefault != "":
tableColumns = append(tableColumns, fmt.Sprintf("`%s` %s %s DEFAULT %s", rowCol["COLUMN_NAME"], columnType, nullable, dataDefault))
case columnCollation == "" && comment == "" && dataDefault == "":
tableColumns = append(tableColumns, fmt.Sprintf("`%s` %s %s", rowCol["COLUMN_NAME"], columnType, nullable))
default:
return tableColumns, fmt.Errorf("error on gen oracle schema table column meta without nullable, rule: %v", r.String())
}
}
}
return tableColumns, nil
}
func (r *Rule) GenTableColumnComment() (columnComments []string, err error) {
// O2M Skip
return
}
func (r *Rule) GenSchemaName() string {
if r.TargetSchemaName == "" {
return r.SourceSchemaName
}
if r.TargetSchemaName != "" {
return r.TargetSchemaName
}
return r.SourceSchemaName
}
func (r *Rule) GenTableName() string {
if r.TargetTableName == "" {
return r.SourceTableName
}
if r.TargetTableName != "" {
return r.TargetTableName
}
return r.SourceTableName
}
func (r *Rule) String() string {
jsonStr, _ := json.Marshal(r)
return string(jsonStr)
}
func LoadColumnDefaultValueRule(columnName, defaultValue string, defaultValueColumnMapSlice []meta.BuildinColumnDefaultval, defaultValueGlobalMapSlice []meta.BuildinGlobalDefaultval) string {
// 额外处理 Oracle 默认值 ('6') 或者 (5) 或者 ('xsddd') 等包含小括号的默认值,而非 '(xxxx)' 之类的默认值
// Oracle 对于同类型 ('xxx') 或者 (xxx) 内部会自动处理,所以 O2M/O2T 需要处理成 'xxx' 或者 xxx
if strings.HasPrefix(defaultValue, "(") && strings.HasSuffix(defaultValue, ")") {
defaultValue = strings.TrimLeft(defaultValue, "(")
defaultValue = strings.TrimRight(defaultValue, ")")
}
if len(defaultValueColumnMapSlice) == 0 && len(defaultValueGlobalMapSlice) == 0 {
return defaultValue
}
// 默认值优先级: 字段级别默认值 > 全局级别默认值
if len(defaultValueColumnMapSlice) > 0 {
for _, dv := range defaultValueColumnMapSlice {
if strings.EqualFold(columnName, dv.ColumnNameS) && strings.EqualFold(strings.TrimSpace(dv.DefaultValueS), strings.TrimSpace(defaultValue)) {
return dv.DefaultValueT
}
}
}
for _, dv := range defaultValueGlobalMapSlice {
if strings.EqualFold(strings.TrimSpace(dv.DefaultValueS), strings.TrimSpace(defaultValue)) && dv.DefaultValueT != "" {
return dv.DefaultValueT
}
}
return defaultValue
}
func LoadDataTypeRuleUsingTableOrSchema(originColumnType string, buildInColumnType string, tableDataTypeMapSlice []meta.TableDatatypeRule,
schemaDataTypeMapSlice []meta.SchemaDatatypeRule) string {
switch {
case len(tableDataTypeMapSlice) != 0 && len(schemaDataTypeMapSlice) == 0:
return loadColumnTypeRuleOnlyUsingTable(originColumnType, buildInColumnType, tableDataTypeMapSlice)
case len(tableDataTypeMapSlice) != 0 && len(schemaDataTypeMapSlice) != 0:
return loadDataTypeRuleUsingTableAndSchema(originColumnType, buildInColumnType, tableDataTypeMapSlice, schemaDataTypeMapSlice)
case len(tableDataTypeMapSlice) == 0 && len(schemaDataTypeMapSlice) != 0:
return loadColumnTypeRuleOnlyUsingSchema(originColumnType, buildInColumnType, schemaDataTypeMapSlice)
case len(tableDataTypeMapSlice) == 0 && len(schemaDataTypeMapSlice) == 0:
return strings.ToUpper(buildInColumnType)
default:
panic(fmt.Errorf("oracle data type mapping failed, tableDataTypeMapSlice [%v],schemaDataTypeMapSlice [%v]", len(tableDataTypeMapSlice), len(schemaDataTypeMapSlice)))
}
}
func loadDataTypeRuleUsingTableAndSchema(originColumnType string, buildInColumnType string, tableDataTypeMapSlice []meta.TableDatatypeRule, schemaDataTypeMapSlice []meta.SchemaDatatypeRule) string {
// 规则判断
customTableDataType := loadColumnTypeRuleOnlyUsingTable(originColumnType, buildInColumnType, tableDataTypeMapSlice)
customSchemaDataType := loadColumnTypeRuleOnlyUsingSchema(originColumnType, buildInColumnType, schemaDataTypeMapSlice)
switch {
case customTableDataType == buildInColumnType && customSchemaDataType != buildInColumnType:
return customSchemaDataType
case customTableDataType != buildInColumnType && customSchemaDataType == buildInColumnType:
return customTableDataType
case customTableDataType != buildInColumnType && customSchemaDataType != buildInColumnType:
return customTableDataType
default:
return strings.ToUpper(buildInColumnType)
}
}
/*
库、表、字段自定义映射规则
*/
// 表级别自定义映射规则
func loadColumnTypeRuleOnlyUsingTable(originColumnType string, buildInColumnType string, tableDataTypeMapSlice []meta.TableDatatypeRule) string {
if len(tableDataTypeMapSlice) == 0 {
return buildInColumnType
}
for _, tbl := range tableDataTypeMapSlice {
/*
number 类型处理:函数匹配 -> GetOracleTableColumn
- number(*,10) -> number(38,10)
- number(*,0) -> number(38,0)
- number(*) -> number(38,127)
- number -> number(38,127)
- number(5) -> number(5)
- number(8,9) -> number(8,9)
*/
if strings.Contains(strings.ToUpper(tbl.ColumnTypeS), "NUMBER") {
switch {
case strings.Contains(strings.ToUpper(tbl.ColumnTypeS), "*") && strings.Contains(strings.ToUpper(tbl.ColumnTypeS), ","):
if strings.EqualFold(strings.Replace(tbl.ColumnTypeS, "*", "38", -1), originColumnType) &&
tbl.ColumnTypeT != "" {
return strings.ToUpper(tbl.ColumnTypeT)
}
case strings.Contains(strings.ToUpper(tbl.ColumnTypeS), "*") && !strings.Contains(strings.ToUpper(tbl.ColumnTypeS), ","):
if strings.EqualFold("NUMBER(38,127)", originColumnType) &&
tbl.ColumnTypeT != "" {
return strings.ToUpper(tbl.ColumnTypeT)
}
case !strings.Contains(strings.ToUpper(tbl.ColumnTypeS), "(") && !strings.Contains(strings.ToUpper(tbl.ColumnTypeS), ")"):
if strings.EqualFold("NUMBER(38,127)", originColumnType) &&
tbl.ColumnTypeT != "" {
return strings.ToUpper(tbl.ColumnTypeT)
}
default:
if strings.EqualFold(tbl.ColumnTypeS, originColumnType) && tbl.ColumnTypeT != "" {
return strings.ToUpper(tbl.ColumnTypeT)
}
}
} else {
if strings.EqualFold(tbl.ColumnTypeS, originColumnType) && tbl.ColumnTypeT != "" {
return strings.ToUpper(tbl.ColumnTypeT)
}
}
}
return strings.ToUpper(buildInColumnType)
}
// 库级别自定义映射规则
func loadColumnTypeRuleOnlyUsingSchema(originColumnType, buildInColumnType string, schemaDataTypeMapSlice []meta.SchemaDatatypeRule) string {
if len(schemaDataTypeMapSlice) == 0 {
return buildInColumnType
}
for _, tbl := range schemaDataTypeMapSlice {
/*
number 类型处理:函数匹配 -> GetOracleTableColumn
- number(*,10) -> number(38,10)
- number(*,0) -> number(38,0)
- number(*) -> number(38,127)
- number -> number(38,127)
- number(5) -> number(5)
- number(8,9) -> number(8,9)
*/
if strings.Contains(strings.ToUpper(tbl.ColumnTypeS), "NUMBER") {
switch {
case strings.Contains(strings.ToUpper(tbl.ColumnTypeS), "*") && strings.Contains(strings.ToUpper(tbl.ColumnTypeS), ","):
if strings.EqualFold(strings.Replace(tbl.ColumnTypeS, "*", "38", -1), originColumnType) &&
tbl.ColumnTypeT != "" {
return strings.ToUpper(tbl.ColumnTypeT)
}
case strings.Contains(strings.ToUpper(tbl.ColumnTypeS), "*") && !strings.Contains(strings.ToUpper(tbl.ColumnTypeS), ","):
if strings.EqualFold("NUMBER(38,127)", originColumnType) &&
tbl.ColumnTypeT != "" {
return strings.ToUpper(tbl.ColumnTypeT)
}
case !strings.Contains(strings.ToUpper(tbl.ColumnTypeS), "(") && !strings.Contains(strings.ToUpper(tbl.ColumnTypeS), ")"):
if strings.EqualFold("NUMBER(38,127)", originColumnType) &&
tbl.ColumnTypeT != "" {
return strings.ToUpper(tbl.ColumnTypeT)
}
default:
if strings.EqualFold(tbl.ColumnTypeS, originColumnType) && tbl.ColumnTypeT != "" {
return strings.ToUpper(tbl.ColumnTypeT)
}
}
} else {
if strings.EqualFold(tbl.ColumnTypeS, originColumnType) && tbl.ColumnTypeT != "" {
return strings.ToUpper(tbl.ColumnTypeT)
}
}
}
return strings.ToUpper(buildInColumnType)
}
// 字段级别自定义映射规则
func LoadColumnTypeRuleOnlyUsingColumn(columnName string, originColumnType string, buildInColumnType string, columnDataTypeMapSlice []meta.ColumnDatatypeRule) string {
if len(columnDataTypeMapSlice) == 0 {
return buildInColumnType
}
for _, tbl := range columnDataTypeMapSlice {
if strings.EqualFold(tbl.ColumnNameS, columnName) {
/*