Skip to content

Commit

Permalink
update parquet-tool
Browse files Browse the repository at this point in the history
  • Loading branch information
xitongsys committed Mar 21, 2018
1 parent 381f931 commit 12272b2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
10 changes: 9 additions & 1 deletion tool/parquet-tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ More functions will be added.
## Build
cd parquet-tools && go build parquet-tools

## Description
### -cmd
schema: show schema of the parquet file;
### -file
parquet file name;
### -tag
print the go struct tags; default is false;

## Example

### Output Schema

```bash
bash$ ./parquet-tools -cmd=schema -file=a.parquet
bash$ ./parquet-tools -cmd=schema -file=a.parquet -tag=false
bash$
----- Go struct -----
parquet_go_root struct{
Expand Down
18 changes: 11 additions & 7 deletions tool/parquet-tools/SchemaTool/SchemaTool.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (self *Node) OutputJsonSchema() string {
return res
}

func(cNode *Node) getStructTags() string {
func (cNode *Node) getStructTags() string {
rTStr := "REQUIRED"
if cNode.SE.GetRepetitionType() == parquet.FieldRepetitionType_OPTIONAL {
rTStr = "OPTIONAL"
Expand Down Expand Up @@ -227,7 +227,7 @@ func(cNode *Node) getStructTags() string {
return tags
}

func (self *Node) OutputStruct(withName bool) string {
func (self *Node) OutputStruct(withName bool, withTags bool) string {
name := self.SE.GetName()

res := ""
Expand All @@ -249,7 +249,11 @@ func (self *Node) OutputStruct(withName bool) string {
if pT == nil && cT == nil {
res += rTStr + "struct{\n"
for _, cNode := range self.Children {
res += cNode.OutputStruct(true) + " " + cNode.getStructTags() + "\n"
if withTags {
res += cNode.OutputStruct(true, withTags) + " " + cNode.getStructTags() + "\n"
} else {
res += cNode.OutputStruct(true, withTags) + "\n"
}
}
res += "}"

Expand All @@ -258,11 +262,11 @@ func (self *Node) OutputStruct(withName bool) string {
keyPT, keyCT := keyNode.SE.Type, keyNode.SE.ConvertedType
keyGoTypeStr := ParquetTypeToGoTypeStr(keyPT, keyCT)
valNode := self.Children[0].Children[1]
res += rTStr + "map[" + keyGoTypeStr + "]" + valNode.OutputStruct(false)
res += rTStr + "map[" + keyGoTypeStr + "]" + valNode.OutputStruct(false, withTags)

} else if cT != nil && *cT == parquet.ConvertedType_LIST {
cNode := self.Children[0].Children[0]
res += rTStr + "[]" + cNode.OutputStruct(false)
res += rTStr + "[]" + cNode.OutputStruct(false, withTags)

} else {
goTypeStr := ParquetTypeToGoTypeStr(pT, cT)
Expand Down Expand Up @@ -320,6 +324,6 @@ func (self *SchemaTree) OutputJsonSchema() string {

}

func (self *SchemaTree) OutputStruct() string {
return self.Root.OutputStruct(true)
func (self *SchemaTree) OutputStruct(withTags bool) string {
return self.Root.OutputStruct(true, withTags)
}
3 changes: 2 additions & 1 deletion tool/parquet-tools/parquet-tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
func main() {
cmd := flag.String("cmd", "schema", "command")
fileName := flag.String("file", "", "file name")
withTags := flag.Bool("tag", false, "show struct tags")

flag.Parse()

Expand All @@ -30,7 +31,7 @@ func main() {
if *cmd == "schema" {
tree := SchemaTool.CreateSchemaTree(pr.SchemaHandler.SchemaElements)
fmt.Println("----- Go struct -----")
fmt.Printf("%s\n", tree.OutputStruct())
fmt.Printf("%s\n", tree.OutputStruct(*withTags))
fmt.Println("----- Json schema -----")
fmt.Printf("%s\n", tree.OutputJsonSchema())
} else {
Expand Down

0 comments on commit 12272b2

Please sign in to comment.