-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #315 from bmeg/feature/BulkDelete
Feature/bulk delete
- Loading branch information
Showing
25 changed files
with
878 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package delete | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/bmeg/grip/gripql" | ||
"github.com/bmeg/grip/log" | ||
"github.com/bmeg/grip/util/rpc" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var host = "localhost:8202" | ||
var file string | ||
var edges []string | ||
var vertices []string | ||
var graph string | ||
var data Data | ||
|
||
type Data struct { | ||
Graph string `json:"graph"` | ||
Edges []string `json:"edges"` | ||
Vertices []string `json:"vertices"` | ||
} | ||
|
||
// Cmd command line declaration | ||
var Cmd = &cobra.Command{ | ||
Use: "delete <graph>", | ||
Short: "Delete data from a graph", | ||
Long: `JSON File Format: { | ||
"graph": 'graph_name', | ||
"edges":['list of edge ids'], | ||
"vertices":['list of vertice ids'] | ||
} | ||
comma delimited --edges or --vertices arguments are also supported ex: | ||
--edges="edge1,edge2"`, | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if file == "" && edges == nil && vertices == nil { | ||
return fmt.Errorf("no input file path or --edges or --vertices arg was provided") | ||
} | ||
|
||
conn, err := gripql.Connect(rpc.ConfigWithDefaults(host), true) | ||
if err != nil { | ||
return err | ||
} | ||
graph = args[0] | ||
|
||
if file != "" { | ||
jsonFile, err := os.Open(file) | ||
if err != nil { | ||
log.Errorf("Failed to open file: %s", err) | ||
} | ||
defer jsonFile.Close() | ||
|
||
// Read the JSON file | ||
byteValue, err := ioutil.ReadAll(jsonFile) | ||
if err != nil { | ||
log.Errorf("Failed to read file: %s", err) | ||
} | ||
|
||
// Unmarshal the JSON into the Data struct | ||
err = json.Unmarshal(byteValue, &data) | ||
if err != nil { | ||
log.Errorf("Failed to unmarshal JSON: %s", err) | ||
} | ||
} else if edges != nil || vertices != nil { | ||
data.Edges = edges | ||
data.Vertices = vertices | ||
} | ||
|
||
log.WithFields(log.Fields{"graph": graph}).Info("deleting data") | ||
log.Info("VALUE OF DATA: ", data.Edges, data.Vertices) | ||
conn.BulkDelete(&gripql.DeleteData{Graph: graph, Vertices: data.Vertices, Edges: data.Edges}) | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
flags := Cmd.Flags() | ||
flags.StringVar(&host, "host", host, "grip server url") | ||
flags.StringSliceVar(&edges, "edges", edges, "grip edges list") | ||
flags.StringSliceVar(&vertices, "vertices", vertices, "grip vertices list") | ||
flags.StringVar(&file, "file", file, "file name") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import json | ||
|
||
|
||
def extract_ids_from_ndjson(input_file, output_file): | ||
ids = [] | ||
|
||
# Read the NDJSON file | ||
with open(input_file, 'r') as f: | ||
for line in f: | ||
data = json.loads(line.strip()) | ||
ids.append(data['gid']) | ||
|
||
with open(input_file_edge, 'r') as f: | ||
for line in f: | ||
data = json.loads(line.strip()) | ||
ids.append(data['gid']) | ||
|
||
|
||
# Write the IDs to the output file in the specified format | ||
with open(output_file, 'w') as f: | ||
f.write('[' + ','.join([f'"{gid}"' for gid in ids]) + ']') | ||
|
||
# Specify the input and output file paths | ||
input_file = 'OUT/Observation.vertex.json' | ||
input_file_edge= 'OUT/Observation.in.edge.json' | ||
output_file = 'output.json' | ||
|
||
# Extract the IDs and write them to the output file | ||
extract_ids_from_ndjson(input_file, output_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.