-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtables_schema_builder.go
More file actions
49 lines (41 loc) · 1.4 KB
/
tables_schema_builder.go
File metadata and controls
49 lines (41 loc) · 1.4 KB
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
package pg_stream
import (
"github.com/apache/arrow/go/arrow"
"github.com/benthosdev/benthos/v4/public/service"
"github.com/usedatabrew/pglogicalstream"
)
type DataSchema struct {
TableName string
Schema *arrow.Schema
}
func buildDataSchemas(config []*service.ParsedConfig) (schemas []pglogicalstream.DbTablesSchema) {
for _, tableConfig := range config {
name, err := tableConfig.FieldString("table")
if err != nil {
panic("Can't build schema")
}
var dbTableSchema pglogicalstream.DbTablesSchema
dbTableSchema.Table = name
var columnsConfig []*service.ParsedConfig
if columnsConfig, err = tableConfig.FieldObjectList("columns"); err != nil {
panic("Can't build schema")
}
for _, columnConfig := range columnsConfig {
columnType, _ := columnConfig.FieldString("databrewType")
nativeColumnType, _ := columnConfig.FieldString("nativeConnectorType")
columnName, _ := columnConfig.FieldString("name")
columnIsIdentity, _ := columnConfig.FieldBool("nullable")
columnNullable, _ := columnConfig.FieldBool("pk")
column := pglogicalstream.DbSchemaColumn{
Name: columnName,
DatabrewType: columnType,
NativeConnectorType: nativeColumnType,
Pk: columnIsIdentity,
Nullable: columnNullable,
}
dbTableSchema.Columns = append(dbTableSchema.Columns, column)
}
schemas = append(schemas, dbTableSchema)
}
return
}