-
Notifications
You must be signed in to change notification settings - Fork 295
/
Copy pathcsv.go
46 lines (40 loc) · 1.37 KB
/
csv.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
package schema
import (
"fmt"
"github.com/xitongsys/parquet-go/common"
"github.com/xitongsys/parquet-go/parquet"
)
//Create a schema handler from CSV metadata
func NewSchemaHandlerFromMetadata(mds []string) (*SchemaHandler, error) {
schemaList := make([]*parquet.SchemaElement, 0)
infos := make([]*common.Tag, 0)
rootSchema := parquet.NewSchemaElement()
rootSchema.Name = "Parquet_go_root"
rootNumChildren := int32(len(mds))
rootSchema.NumChildren = &rootNumChildren
rt := parquet.FieldRepetitionType_REQUIRED
rootSchema.RepetitionType = &rt
schemaList = append(schemaList, rootSchema)
rootInfo := common.NewTag()
rootInfo.InName = "Parquet_go_root"
rootInfo.ExName = "parquet_go_root"
rootInfo.RepetitionType = parquet.FieldRepetitionType_REQUIRED
infos = append(infos, rootInfo)
for _, md := range mds {
info, err := common.StringToTag(md)
if err != nil {
return nil, fmt.Errorf("failed to parse metadata: %s", err.Error())
}
infos = append(infos, info)
schema, err := common.NewSchemaElementFromTagMap(info)
if err != nil {
return nil, fmt.Errorf("failed to create schema from tag map: %s", err.Error())
}
//schema.RepetitionType = parquet.FieldRepetitionTypePtr(parquet.FieldRepetitionType_OPTIONAL)
schemaList = append(schemaList, schema)
}
res := NewSchemaHandlerFromSchemaList(schemaList)
res.Infos = infos
res.CreateInExMap()
return res, nil
}