-
Notifications
You must be signed in to change notification settings - Fork 303
/
schema-repository.go
52 lines (45 loc) · 1.58 KB
/
schema-repository.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
package schemarepository
import (
"fmt"
"github.com/rudderlabs/rudder-server/utils/logger"
"github.com/rudderlabs/rudder-server/utils/misc"
warehouseutils "github.com/rudderlabs/rudder-server/warehouse/utils"
)
func init() {
pkgLogger = logger.NewLogger().Child("warehouse").Child("datalake").Child("schema-repository")
}
const MAX_CHARACTER_LIMIT = 65535
var (
pkgLogger logger.Logger
VARCHAR_TYPE = fmt.Sprintf("varchar(%d)", MAX_CHARACTER_LIMIT)
dataTypesMap = map[string]string{
"boolean": "boolean",
"int": "bigint",
"bigint": "bigint",
"float": "double",
"string": VARCHAR_TYPE,
"datetime": "timestamp",
}
dataTypesMapToRudder = map[string]string{
"boolean": "boolean",
"bigint": "int",
"double": "float",
"varchar(512)": "string",
VARCHAR_TYPE: "string",
"timestamp": "datetime",
"string": "string",
}
)
type SchemaRepository interface {
FetchSchema(warehouse warehouseutils.Warehouse) (warehouseutils.SchemaT, warehouseutils.SchemaT, error)
CreateSchema() (err error)
CreateTable(tableName string, columnMap map[string]string) (err error)
AddColumns(tableName string, columnsInfo []warehouseutils.ColumnInfo) (err error)
AlterColumn(tableName, columnName, columnType string) (err error)
}
func NewSchemaRepository(wh warehouseutils.Warehouse, uploader warehouseutils.UploaderI) (SchemaRepository, error) {
if warehouseutils.GetConfigValueBoolString(UseGlueConfig, wh) == "true" && misc.HasAWSRegionInConfig(wh.Destination.Config) {
return NewGlueSchemaRepository(wh)
}
return NewLocalSchemaRepository(wh, uploader)
}