Skip to content

Commit 55cb5c8

Browse files
author
ffffwh
committed
kafka: default value of empty string #939
1 parent 274be7d commit 55cb5c8

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

drivers/mysql/kafka/kafka3.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,9 +1246,6 @@ func kafkaColumnListToColDefs(colList *common.ColumnList, loc *time.Location) (v
12461246
for i, _ := range cols {
12471247
var field *Schema
12481248
defaultValue := cols[i].Default
1249-
if defaultValue == "" {
1250-
defaultValue = nil
1251-
}
12521249
optional := cols[i].Nullable
12531250
fieldName := cols[i].RawName
12541251
switch cols[i].Type {

drivers/mysql/mysql/base/utils.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ func ParseBinlogCoordinatesFromRow(row *sql.Row) (r *common.BinlogCoordinatesX,
7777
return r, nil
7878
}
7979

80-
// GetTableColumns reads column list from given table
8180
func GetTableColumns(db usql.QueryAble, databaseName, tableName string) (*common.ColumnList, error) {
8281
databaseNameEscaped := umconf.EscapeName(databaseName)
8382
tableNameEscaped := umconf.EscapeName(tableName)
@@ -88,10 +87,14 @@ func GetTableColumns(db usql.QueryAble, databaseName, tableName string) (*common
8887
aColumn := umconf.Column{
8988
RawName: rowMap.GetString("Field"),
9089
ColumnType: rowMap.GetString("Type"),
91-
Default: rowMap.GetString("Default"),
9290
Key: strings.ToUpper(rowMap.GetString("Key")),
9391
Nullable: strings.ToUpper(rowMap.GetString("Null")) == "YES",
9492
}
93+
if d, ok := rowMap["Default"]; ok {
94+
if d.Valid {
95+
aColumn.Default = d.String
96+
}
97+
}
9598
aColumn.EscapedName = umconf.EscapeName(aColumn.RawName)
9699
columns = append(columns, aColumn)
97100
return nil

drivers/mysql/mysql/base/utils_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717

1818
"github.com/actiontech/dtle/drivers/mysql/common"
1919

20-
test "github.com/outbrain/golib/tests"
2120
gomysql "github.com/go-mysql-org/go-mysql/mysql"
21+
test "github.com/outbrain/golib/tests"
2222
)
2323

2424
func TestStringContainsAll(t *testing.T) {
@@ -175,6 +175,20 @@ func TestGetTableColumns(t *testing.T) {
175175
}
176176
}
177177

178+
//func TestGetTableColumns2(t *testing.T) {
179+
// db, err := sql.CreateDB(fmt.Sprintf("%s@(%s)/?timeout=5s&tls=false&autocommit=true&charset=utf8mb4,utf8,latin1&multiStatements=true", "root:password", "10.186.62.40:3307"))
180+
// if err != nil {
181+
// t.Error(err)
182+
// }
183+
// cl, err := GetTableColumns(db, "a", "a939")
184+
// if err != nil {
185+
// t.Error(err)
186+
// }
187+
// for _, col := range cl.Columns {
188+
// fmt.Printf("%v default '%v'\n", col.RawName, col.Default)
189+
// }
190+
//}
191+
178192
func TestApplyColumnTypes(t *testing.T) {
179193
type args struct {
180194
db *gosql.Tx

helper/try-sqle-inspector/trysqleinspector.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"github.com/actiontech/dtle/drivers/mysql/mysql/base"
56
"github.com/actiontech/dtle/drivers/mysql/mysql/sqle/inspector"
67
//"github.com/actiontech/dtle/internal/client/driver/mysql/base"
@@ -28,7 +29,7 @@ func main() {
2829
//ctx.LoadTables("a", nil)
2930
//ctx.UseSchema("a")
3031

31-
case7()
32+
case8()
3233
//case6()
3334
//case5()
3435
//case4()
@@ -43,6 +44,23 @@ func panicIfErr(err interface{}, args ...interface{}) {
4344
}
4445
}
4546

47+
func case8() { // #939
48+
do("create schema a")
49+
ctx.LoadTables("a", nil)
50+
ctx.UseSchema("a")
51+
52+
do(`create table a.a939 (id int primary key auto_increment,
53+
val1 varchar(50) not null default 'aaa',
54+
val2 varchar(50) not null default '',
55+
val3 varchar(50) not null);`)
56+
57+
colList, _, err := base.GetTableColumnsSqle(ctx, "a", "a939")
58+
panicIfErr(err)
59+
for _, col := range colList.Columns {
60+
fmt.Printf("%v default '%v'\n", col.RawName, col.Default)
61+
}
62+
}
63+
4664
func case7() {
4765
do("create schema fk")
4866
ctx.LoadTables("fk", nil)

0 commit comments

Comments
 (0)