-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtypes.go
55 lines (51 loc) · 1.64 KB
/
types.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
package bigquerysql
import (
"strings"
"github.com/pingcap/tiflow/pkg/sink/cloudstorage"
"github.com/pkg/errors"
)
// TiDB2BigQueryTypeMap is a map from TiDB type to BigQuery type.
// Reference: https://cloud.google.com/data-fusion/docs/reference/replication-data-types#mysql
var TiDB2BigQueryTypeMap map[string]string = map[string]string{
"bigint": "INT64",
"bigint unsigned": "NUMERIC",
"binary": "BYTES",
"bit": "BOOL",
"blob": "BYTES",
"char": "STRING",
"date": "DATE",
"datetime": "DATETIME",
"decimal": "NUMERIC",
"double": "FLOAT64",
"float": "FLOAT64",
"int": "INT64",
"int unsigned": "INT64",
"json": "STRING",
"longblob": "BYTES",
"longtext": "STRING",
"mediumblob": "BYTES",
"mediumint": "INT64",
"mediumint unsigned": "INT64",
"mediumtext": "STRING",
"set": "STRING",
"smallint": "INT64",
"smallint unsigned": "INT64",
"text": "STRING",
"time": "TIME",
"timestamp": "TIMESTAMP",
"tinyblob": "BYTES",
"tinyint": "INT64",
"tinyint unsigned": "INT64",
"tinytext": "STRING",
"varbinary": "BYTES",
"varchar": "STRING",
"year": "INT64",
}
func GetBigQueryColumnTypeString(column cloudstorage.TableCol) (string, error) {
tp := strings.ToLower(column.Tp)
bqType, ok := TiDB2BigQueryTypeMap[tp]
if !ok {
return bqType, errors.Errorf("Unsupported TiDB type %s", tp)
}
return bqType, nil
}