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

update api proto and fields #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions lib/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,18 @@ message Request {
bool commit_now = 13;
}

message Uids {
repeated string uids = 1;
}

message Response {
bytes json = 1;
TxnContext txn = 2;
Latency latency = 3;
// Metrics contains all metrics related to the query.
Metrics metrics = 4;
// uids contains a mapping of blank_node => uid for the node. It only returns uids
// that were created as part of a mutation.
map<string, string> uids = 12;
}

Expand Down Expand Up @@ -119,6 +127,12 @@ message Latency {
uint64 processing_ns = 2;
uint64 encoding_ns = 3;
uint64 assign_timestamp_ns = 4;
uint64 total_ns = 5;
}

message Metrics {
// num_uids is the map of number of uids processed by each attribute.
map<string, uint64> num_uids = 1;
}

message NQuad {
Expand Down
60 changes: 51 additions & 9 deletions lib/dlex/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,32 @@ defmodule Api.Request.VarsEntry do
field :value, 2, type: :string
end

defmodule Api.Metrics.NumUidsEntry do
@moduledoc false
use Protobuf, map: true, syntax: :proto3

@type t :: %__MODULE__{
key: String.t(),
value: non_neg_integer
}
defstruct [:key, :value]

field :key, 1, type: :string
field :value, 2, type: :uint64
end

defmodule Api.Metrics do
@moduledoc false
use Protobuf, syntax: :proto3

@type t :: %__MODULE__{
num_uids: %{String.t() => non_neg_integer}
}
defstruct [:num_uids]

field :num_uids, 1, repeated: true, type: Api.Metrics.NumUidsEntry, map: true
end

defmodule Api.Request do
@moduledoc false
use Protobuf, syntax: :proto3
Expand Down Expand Up @@ -74,6 +100,18 @@ defmodule Api.Response.UidsEntry do
field :value, 2, type: :string
end

defmodule Api.Uids do
@moduledoc false
use Protobuf, syntax: :proto3

@type t :: %__MODULE__{
uids: [String.t()]
}
defstruct [:uids]

field :uids, 1, repeated: true, type: :string
end

defmodule Api.Response do
@moduledoc false
use Protobuf, syntax: :proto3
Expand All @@ -82,13 +120,15 @@ defmodule Api.Response do
json: binary,
txn: Api.TxnContext.t() | nil,
latency: Api.Latency.t() | nil,
metrics: Api.Metrics.t() | nil,
uids: %{String.t() => String.t()}
}
defstruct [:json, :txn, :latency, :uids]
defstruct [:json, :txn, :latency, :metrics, :uids]

field :json, 1, type: :bytes
field :txn, 2, type: Api.TxnContext
field :latency, 3, type: Api.Latency
field :metrics, 4, type: Api.Metrics
field :uids, 12, repeated: true, type: Api.Response.UidsEntry, map: true
end

Expand Down Expand Up @@ -198,14 +238,16 @@ defmodule Api.Latency do
parsing_ns: non_neg_integer,
processing_ns: non_neg_integer,
encoding_ns: non_neg_integer,
assign_timestamp_ns: non_neg_integer
assign_timestamp_ns: non_neg_integer,
total_ns: non_neg_integer
}
defstruct [:parsing_ns, :processing_ns, :encoding_ns, :assign_timestamp_ns]
defstruct [:parsing_ns, :processing_ns, :encoding_ns, :assign_timestamp_ns, :total_ns]

field :parsing_ns, 1, type: :uint64
field :processing_ns, 2, type: :uint64
field :encoding_ns, 3, type: :uint64
field :assign_timestamp_ns, 4, type: :uint64
field :total_ns, 5, type: :uint64
end

defmodule Api.NQuad do
Expand Down Expand Up @@ -241,7 +283,7 @@ defmodule Api.Value do
}
defstruct [:val]

oneof(:val, 0)
oneof :val, 0
field :default_val, 1, type: :string, oneof: 0
field :bytes_val, 2, type: :bytes, oneof: 0
field :int_val, 3, type: :int64, oneof: 0
Expand Down Expand Up @@ -309,11 +351,11 @@ defmodule Api.Dgraph.Service do
@moduledoc false
use GRPC.Service, name: "api.Dgraph"

rpc(:Login, Api.LoginRequest, Api.Response)
rpc(:Query, Api.Request, Api.Response)
rpc(:Alter, Api.Operation, Api.Payload)
rpc(:CommitOrAbort, Api.TxnContext, Api.TxnContext)
rpc(:CheckVersion, Api.Check, Api.Version)
rpc :Login, Api.LoginRequest, Api.Response
rpc :Query, Api.Request, Api.Response
rpc :Alter, Api.Operation, Api.Payload
rpc :CommitOrAbort, Api.TxnContext, Api.TxnContext
rpc :CheckVersion, Api.Check, Api.Version
end

defmodule Api.Dgraph.Stub do
Expand Down
2 changes: 1 addition & 1 deletion lib/dlex/field.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Dlex.Field do
@type type :: :integer | :float | :string | :geo | :datetime | :uid | :auto
@type type :: :integer | :float | :string | :geo | :datetime | :uid | :boolean | :password | :auto

@type t :: %__MODULE__{
name: atom(),
Expand Down
6 changes: 5 additions & 1 deletion lib/dlex/node.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ defmodule Dlex.Node do
* `:geo`
* `:datetime`
* `:uid`
* `:boolean`
* `:password`
* `:auto` - special type, which can be used for `depends_on`

## Reflection
Expand Down Expand Up @@ -237,7 +239,9 @@ defmodule Dlex.Node do
string: "string",
geo: "geo",
datetime: "datetime",
uid: "uid"
uid: "uid",
boolean: "bool",
password: "password"
]

for {type, dgraph_type} <- @types_mapping do
Expand Down