Skip to content

Commit

Permalink
fixed column name modification issue (#826)
Browse files Browse the repository at this point in the history
* fixed column name modification issue

* column length fix

* updated unit test
  • Loading branch information
shreyakhajanchi committed May 27, 2024
1 parent 5874ce1 commit 49368ac
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 25 deletions.
8 changes: 4 additions & 4 deletions ui/dist/ui/index.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ui/dist/ui/main.9f319bf9ec26d72b.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion ui/dist/ui/main.e121cee446134240.js

This file was deleted.

1 change: 1 addition & 0 deletions ui/dist/ui/polyfills.0ace4ea3e0ea1aea.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion ui/dist/ui/polyfills.c2c201edf5092294.js

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion ui/dist/ui/styles.9b18c896a09ee20d.css

This file was deleted.

1 change: 1 addition & 0 deletions ui/dist/ui/styles.bf77748ba70110fe.css

Large diffs are not rendered by default.

19 changes: 17 additions & 2 deletions ui/src/app/components/object-detail/object-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,21 @@ export class ObjectDetailComponent implements OnInit {
})
)
} else {
// If the default type map doesn't have the source datatype as key then fallback to STRING with max length
let droppedColumnSpDataType = ''
let droppedColumnSpMaxLength = col.srcColMaxLength
if (this.defaultTypeMap[col.srcDataType] === undefined) {
droppedColumnSpDataType = 'STRING'
droppedColumnSpMaxLength = 'MAX'
} else {
droppedColumnSpDataType = this.defaultTypeMap[col.srcDataType].Name
}

// If the source max column length is empty but spanner datatype is STRING or BYTES, set column length to MAX
if (droppedColumnSpMaxLength == '' && (droppedColumnSpDataType == 'STRING' || droppedColumnSpDataType == 'BYTES')) {
droppedColumnSpMaxLength = 'MAX'
}

this.srcRowArray.push(
new FormGroup({
srcOrder: new FormControl(col.srcOrder),
Expand All @@ -288,11 +303,11 @@ export class ObjectDetailComponent implements OnInit {
spOrder: new FormControl(col.srcOrder),
spColName: new FormControl(col.srcColName),
spDataType: new FormControl(
this.defaultTypeMap[col.srcDataType].Name
droppedColumnSpDataType
),
spIsPk: new FormControl(col.srcIsPk),
spIsNotNull: new FormControl(col.srcIsNotNull),
spColMaxLength: new FormControl(col.srcColMaxLength),
spColMaxLength: new FormControl(droppedColumnSpMaxLength),
spAutoGen: new FormControl(col.spAutoGen)
})
)
Expand Down
9 changes: 6 additions & 3 deletions webv2/api/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/stretchr/testify/assert"
)


func TestApplyRule(t *testing.T) {
tcAddIndex := []struct {
name string
Expand Down Expand Up @@ -243,7 +242,7 @@ func TestApplyRule(t *testing.T) {
expectedSchema: ddl.CreateTable{
Name: "table1",
Id: "t1",
ColIds: []string{"c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11", "c12", "c13", "c14", "c15", "c16"},
ColIds: []string{"c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11", "c12", "c13", "c14", "c15", "c16", "c17"},
ColDefs: map[string]ddl.ColumnDef{
"c1": {Name: "a", Id: "c1", T: ddl.Type{Name: ddl.String, Len: ddl.MaxLength}},
"c2": {Name: "b", Id: "c2", T: ddl.Type{Name: ddl.String, Len: ddl.MaxLength}},
Expand All @@ -261,6 +260,7 @@ func TestApplyRule(t *testing.T) {
"c14": {Name: "n", Id: "c14", T: ddl.Type{Name: ddl.Bytes, Len: ddl.MaxLength}},
"c15": {Name: "o", Id: "c15", T: ddl.Type{Name: ddl.String, Len: ddl.MaxLength}},
"c16": {Name: "p", Id: "c16", T: ddl.Type{Name: ddl.String, Len: ddl.MaxLength}},
"c17": {Name: "q", Id: "c17", T: ddl.Type{Name: ddl.String, Len: ddl.MaxLength}},
},
PrimaryKeys: []ddl.IndexKey{{ColId: "c1"}},
},
Expand All @@ -278,6 +278,7 @@ func TestApplyRule(t *testing.T) {
"c13": {internal.Widened, internal.Serial},
"c15": {internal.Widened},
"c16": {internal.Widened},
"c17": {internal.NoGoodType},
},
},
},
Expand All @@ -300,7 +301,7 @@ func TestApplyRule(t *testing.T) {
expectedSchema: ddl.CreateTable{
Name: "table1",
Id: "t1",
ColIds: []string{"c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11", "c12", "c13", "c14", "c15", "c16"},
ColIds: []string{"c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11", "c12", "c13", "c14", "c15", "c16", "c17"},
ColDefs: map[string]ddl.ColumnDef{
"c1": {Name: "a", Id: "c1", T: ddl.Type{Name: ddl.String, Len: ddl.MaxLength}},
"c2": {Name: "b", Id: "c2", T: ddl.Type{Name: ddl.String, Len: ddl.MaxLength}},
Expand All @@ -318,6 +319,7 @@ func TestApplyRule(t *testing.T) {
"c14": {Name: "n", Id: "c14", T: ddl.Type{Name: ddl.String, Len: ddl.MaxLength}},
"c15": {Name: "o", Id: "c15", T: ddl.Type{Name: ddl.Timestamp}},
"c16": {Name: "p", Id: "c16", T: ddl.Type{Name: ddl.Int64}},
"c17": {Name: "q", Id: "c17", T: ddl.Type{Name: ddl.String, Len: ddl.MaxLength}},
},
PrimaryKeys: []ddl.IndexKey{{ColId: "c1"}},
},
Expand All @@ -331,6 +333,7 @@ func TestApplyRule(t *testing.T) {
"c13": {internal.Serial},
"c15": {internal.Timestamp},
"c16": {internal.Widened},
"c17": {internal.NoGoodType},
},
},
},
Expand Down
10 changes: 5 additions & 5 deletions webv2/api/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ func initializeTypeMap() {
}
// Initialize postgresTypeMap.
toddl = postgres.InfoSchemaImpl{}.GetToDdl()
for _, srcTypeName := range []string{"bool", "boolean", "bigserial", "bpchar", "character", "bytea", "date", "float8", "double precision", "float4", "real", "int8", "bigint", "int4", "integer", "int2", "smallint", "numeric", "serial", "text", "timestamptz", "timestamp with time zone", "timestamp", "timestamp without time zone", "varchar", "character varying"} {
for _, srcTypeName := range []string{"bool", "boolean", "bigserial", "bpchar", "character", "bytea", "date", "float8", "double precision", "float4", "real", "int8", "bigint", "int4", "integer", "int2", "smallint", "numeric", "serial", "text", "timestamptz", "timestamp with time zone", "timestamp", "timestamp without time zone", "varchar", "character varying", "path"} {
var l []types.TypeIssue
srcType := schema.MakeType()
srcType.Name = srcTypeName
Expand Down Expand Up @@ -1571,14 +1571,14 @@ func makePostgresDialectAutoGenMap() {
for _, srcTypeName := range []string{ddl.Bool, ddl.Date, ddl.Float64, ddl.Int64, ddl.PGBytea, ddl.PGFloat8, ddl.PGInt8, ddl.PGJSONB, ddl.PGTimestamptz, ddl.PGVarchar, ddl.Numeric} {
autoGenMap[srcTypeName] = []types.AutoGen{
{
Name: "",
Name: "",
GenerationType: "",
},
}
}
autoGenMap[ddl.PGVarchar] = append(autoGenMap[ddl.PGVarchar],
types.AutoGen{
Name: "UUID",
Name: "UUID",
GenerationType: "Pre-defined",
})
}
Expand All @@ -1587,14 +1587,14 @@ func makeGoogleSqlDialectAutoGenMap() {
for _, srcTypeName := range []string{ddl.Bool, ddl.Bytes, ddl.Date, ddl.Float64, ddl.Int64, ddl.String, ddl.Timestamp, ddl.Numeric, ddl.JSON} {
autoGenMap[srcTypeName] = []types.AutoGen{
{
Name: "",
Name: "",
GenerationType: "",
},
}
}
autoGenMap[ddl.String] = append(autoGenMap[ddl.String],
types.AutoGen{
Name: "UUID",
Name: "UUID",
GenerationType: "Pre-defined",
})
}
19 changes: 12 additions & 7 deletions webv2/api/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ func TestGetTypeMapPostgres(t *testing.T) {
"varchar": {
{T: ddl.Bytes, DisplayT: ddl.Bytes},
{T: ddl.String, DisplayT: ddl.String}},
"path": {
{T: ddl.String, Brief: reports.IssueDB[internal.NoGoodType].Brief, DisplayT: ddl.String}},
}
assert.Equal(t, expectedTypemap, typemap)

Expand Down Expand Up @@ -2230,7 +2232,7 @@ func buildConvPostgres(conv *internal.Conv) {
"t1": {
Name: "table1",
Id: "t1",
ColIds: []string{"c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11", "c12", "c13", "c14", "c15", "c16"},
ColIds: []string{"c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11", "c12", "c13", "c14", "c15", "c16", "c17"},
ColDefs: map[string]schema.Column{
"c1": {Name: "a", Id: "c1", Type: schema.Type{Name: "int8"}},
"c2": {Name: "b", Id: "c2", Type: schema.Type{Name: "float4"}},
Expand All @@ -2248,6 +2250,7 @@ func buildConvPostgres(conv *internal.Conv) {
"c14": {Name: "n", Id: "c14", Type: schema.Type{Name: "text"}},
"c15": {Name: "o", Id: "c15", Type: schema.Type{Name: "timestamp"}},
"c16": {Name: "p", Id: "c16", Type: schema.Type{Name: "bool"}},
"c17": {Name: "q", Id: "c17", Type: schema.Type{Name: "path"}},
},
PrimaryKeys: []schema.Key{{ColId: "c1"}}},
"t2": {
Expand All @@ -2264,7 +2267,7 @@ func buildConvPostgres(conv *internal.Conv) {
"t1": {
Name: "table1",
Id: "t1",
ColIds: []string{"c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11", "c12", "c13", "c14", "c15", "c16"},
ColIds: []string{"c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11", "c12", "c13", "c14", "c15", "c16", "c17"},
ColDefs: map[string]ddl.ColumnDef{
"c1": {Name: "a", Id: "c1", T: ddl.Type{Name: ddl.Int64}},
"c2": {Name: "b", Id: "c2", T: ddl.Type{Name: ddl.Float64}},
Expand All @@ -2282,6 +2285,7 @@ func buildConvPostgres(conv *internal.Conv) {
"c14": {Name: "n", Id: "c14", T: ddl.Type{Name: ddl.String, Len: ddl.MaxLength}},
"c15": {Name: "o", Id: "c15", T: ddl.Type{Name: ddl.Timestamp}},
"c16": {Name: "p", Id: "c16", T: ddl.Type{Name: ddl.Int64}},
"c17": {Name: "q", Id: "c17", T: ddl.Type{Name: ddl.String, Len: ddl.MaxLength}},
},
PrimaryKeys: []ddl.IndexKey{{ColId: "c1"}},
},
Expand All @@ -2302,11 +2306,12 @@ func buildConvPostgres(conv *internal.Conv) {
conv.SchemaIssues = map[string]internal.TableIssues{
"t1": {
ColumnLevelIssues: map[string][]internal.SchemaIssue{
"c2": {internal.Widened}, //b
"c7": {internal.Serial}, //g
"c12": {internal.Widened}, //l
"c13": {internal.Serial}, //m
"c15": {internal.Timestamp}, //o
"c2": {internal.Widened}, //b
"c7": {internal.Serial}, //g
"c12": {internal.Widened}, //l
"c13": {internal.Serial}, //m
"c15": {internal.Timestamp}, //o
"c17": {internal.NoGoodType}, //q
},
},
"t2": {
Expand Down

0 comments on commit 49368ac

Please sign in to comment.