Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved dgraph-converter binary to dgraph subcommand. #2635

Merged
merged 2 commits into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions dgraph/cmd/cert/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ func init() {
},
}

Cert.Cmd.AddCommand()

flag := Cert.Cmd.Flags()
flag.StringP("dir", "d", defaultDir, "directory containing TLS certs and keys")
flag.StringP("ca-key", "k", defaultCAKey, "path to the CA private key")
Expand Down
21 changes: 2 additions & 19 deletions dgraph/cmd/dgraph-converter/main.go → dgraph/cmd/conv/conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
* with the Commons Clause restriction.
*/

package main
package conv

import (
"bufio"
"compress/gzip"
"encoding/json"
"flag"
"fmt"
"io"
"io/ioutil"
Expand All @@ -23,13 +22,6 @@ import (
"github.com/paulmach/go.geojson"
)

var (
// TODO - Take a directory here and convert all the files in the directory.
geoFile = flag.String("geo", "", "Location of geo file to convert")
outputFile = flag.String("out", "output.rdf.gz", "Location of output rdf.gz file")
geoPred = flag.String("geopred", "loc", "Predicate to use to store geometries")
)

// TODO: Reconsider if we need this binary.
func writeToFile(fpath string, ch chan []byte) error {
f, err := os.Create(fpath)
Expand Down Expand Up @@ -106,7 +98,7 @@ func convertGeoFile(input string, output string) error {

geometry := strings.Replace(string(b), `"`, "'", -1)
bn := fmt.Sprintf("_:%s-%d", name, count)
rdf := fmt.Sprintf("%s <%s> \"%s\"^^<geo:geojson> .\n", bn, *geoPred, geometry)
rdf := fmt.Sprintf("%s <%s> \"%s\"^^<geo:geojson> .\n", bn, opt.geopred, geometry)
chb <- []byte(rdf)

for k, _ := range f.Properties {
Expand All @@ -127,12 +119,3 @@ func convertGeoFile(input string, output string) error {
fmt.Printf("%d features converted. %d rdf's generated\n", count, rdfCount)
return <-che
}

func main() {
flag.Parse()
if len(*geoFile) == 0 {
fmt.Printf("The file to be loaded must be specified using the --geo flag.\n")
os.Exit(1)
}
x.Check(convertGeoFile(*geoFile, *outputFile))
}
48 changes: 48 additions & 0 deletions dgraph/cmd/conv/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2018 Dgraph Labs, Inc.
*
* This file is available under the Apache License, Version 2.0,
* with the Commons Clause restriction.
*/

package conv

import (
"os"

"github.com/dgraph-io/dgraph/x"
"github.com/spf13/cobra"
)

var Conv x.SubCommand

var opt struct {
geo string
out string
geopred string
}

func init() {
Conv.Cmd = &cobra.Command{
Use: "conv",
Short: "Dgraph Geo file converter",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
defer x.StartProfile(Conv.Conf).Stop()
if err := run(); err != nil {
x.Println(err)
os.Exit(1)
}
},
}

flag := Conv.Cmd.Flags()
flag.StringVar(&opt.geo, "geo", "", "Location of geo file to convert")
flag.StringVar(&opt.out, "out", "output.rdf.gz", "Location of output rdf.gz file")
flag.StringVar(&opt.geopred, "geopred", "loc", "Predicate to use to store geometries")
Conv.Cmd.MarkFlagRequired("geo")
}

func run() error {
return convertGeoFile(opt.geo, opt.out)
}
1 change: 0 additions & 1 deletion dgraph/cmd/dgraph-converter/.gitignore

This file was deleted.

3 changes: 2 additions & 1 deletion dgraph/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/dgraph-io/dgraph/dgraph/cmd/bulk"
"github.com/dgraph-io/dgraph/dgraph/cmd/cert"
"github.com/dgraph-io/dgraph/dgraph/cmd/conv"
"github.com/dgraph-io/dgraph/dgraph/cmd/debug"
"github.com/dgraph-io/dgraph/dgraph/cmd/live"
"github.com/dgraph-io/dgraph/dgraph/cmd/server"
Expand Down Expand Up @@ -68,7 +69,7 @@ func init() {
flag.CommandLine.AddGoFlagSet(goflag.CommandLine)

var subcommands = []*x.SubCommand{
&bulk.Bulk, &cert.Cert, &live.Live, &server.Server, &zero.Zero,
&bulk.Bulk, &cert.Cert, &conv.Conv, &live.Live, &server.Server, &zero.Zero,
&version.Version, &debug.Debug,
}
for _, sc := range subcommands {
Expand Down