-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtypes.go
72 lines (68 loc) · 2.78 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package snowsql
import (
"fmt"
"strings"
"github.com/pingcap/errors"
"github.com/pingcap/tiflow/pkg/sink/cloudstorage"
)
// TiDB2SnowflakeTypeMap is a map from TiDB type to Snowflake type.
var TiDB2SnowflakeTypeMap map[string]string = map[string]string{
"text": "TEXT",
"tinytext": "TEXT",
"mediumtext": "TEXT",
"longtext": "TEXT",
"blob": "BINARY",
"tinyblob": "BINARY",
// The maximum size of Snowflake's BINARY type is 8 MB, so can not support mediumblob and longblob.
// "mediumblob": "TEXT",
// "longblob": "TEXT",
"varchar": "VARCHAR",
"char": "CHAR",
"binary": "BINARY",
"varbinary": "BINARY",
"tinyint": "NUMBER",
"smallint": "NUMBER",
"int": "NUMBER",
"mediumint": "NUMBER",
"bigint": "NUMBER",
"tinyint unsigned": "NUMBER",
"smallint unsigned": "NUMBER",
"int unsigned": "NUMBER",
"mediumint unsigned": "NUMBER",
"bigint unsigned": "NUMBER",
"float": "FLOAT",
"float unsigned": "FLOAT",
"double": "FLOAT",
"double unsigned": "FLOAT",
"decimal": "NUMBER",
"numeric": "NUMBER",
"bool": "BOOLEAN",
"boolean": "BOOLEAN",
"date": "DATE",
"datetime": "DATETIME",
"timestamp": "TIMESTAMP",
"time": "TIME",
}
func GetSnowflakeTypeString(column cloudstorage.TableCol) (string, error) {
tp := strings.ToLower(column.Tp)
switch tp {
case "text", "longtext", "mediumtext", "tinytext":
return fmt.Sprintf("%s %s", column.Name, TiDB2SnowflakeTypeMap[tp]), nil
case "tinyblob", "blob":
return fmt.Sprintf("%s %s(%s)", column.Name, TiDB2SnowflakeTypeMap[tp], column.Precision), nil
case "longblob", "mediumblob":
return "", errors.Errorf("The maximum size of Snowflake's BINARY type is 8 MB, so can not support mediumblob and longblob.")
case "int", "mediumint", "bigint", "tinyint", "smallint", "float", "double", "bool", "boolean", "date":
return fmt.Sprintf("%s %s", column.Name, TiDB2SnowflakeTypeMap[tp]), nil
case "int unsigned", "mediumint unsigned", "tinyint unsigned", "smallint unsigned", "bigint unsigned", "float unsigned", "double unsigned":
return fmt.Sprintf("%s %s", column.Name, TiDB2SnowflakeTypeMap[tp]), nil
case "varchar", "char", "binary", "varbinary":
return fmt.Sprintf("%s %s(%s)", column.Name, TiDB2SnowflakeTypeMap[tp], column.Precision), nil
case "decimal", "numeric":
return fmt.Sprintf("%s %s(%s, %s)", column.Name, TiDB2SnowflakeTypeMap[tp], column.Precision, column.Scale), nil
case "datetime", "timestamp", "time":
return fmt.Sprintf("%s %s(%s)", column.Name, TiDB2SnowflakeTypeMap[tp], column.Precision), nil
default:
return "", errors.Errorf("Unsupported data type: %s", column.Tp)
}
}