Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #17 from ongardie-ebay/rminsertfacts
Browse files Browse the repository at this point in the history
Remove deprecated InsertFact from API
  • Loading branch information
superfell authored Apr 13, 2019
2 parents 06c9745 + bd6acd9 commit 8de3bdc
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 1,739 deletions.
46 changes: 0 additions & 46 deletions proto/api/beam_api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ service BeamFactStore {
rpc queryFacts(QueryFactsRequest) returns (stream QueryFactsResult);
rpc lookup_sp(LookupSPRequest) returns (LookupSPResult);
rpc lookup_po(LookupPORequest) returns (LookupPOResult);
rpc insertFacts(InsertFactsRequest) returns (InsertFactsResult);
}

// QueryRequest is used to specify a SELECT/ASK-style query that returns a
Expand Down Expand Up @@ -301,48 +300,3 @@ message LookupPOResult {
repeated Items results = 1 [(gogoproto.nullable)=false];
int64 index = 2;
}

// InsertFactsRequest is the request for the deprecated insertFacts RPC.
message InsertFactsRequest {
option (gogoproto.stringer)=false;
// Each entry in this array will cause a new subjectID to be created, and
// assigned to the named var. You can use the named var in the
// InsertFact.subject.var field to bind it to a fact being inserted. You
// must use each subject ID created.
repeated string newSubjectVars = 1;
repeated InsertFact facts = 2 [(gogoproto.nullable)=false];
}

message InsertFact {
option (gogoproto.stringer)=false;
// Specify a var if you need to bind the created fact ID to a subsequent
// fact in the same insert request.
string factIDVar = 1;
KIDOrVar subject = 2 [(gogoproto.nullable)=false];
KIDOrVar predicate = 3 [(gogoproto.nullable)=false];
KGObjectOrVar object = 4 [(gogoproto.nullable)=false];
}

message KIDOrVar {
option (gogoproto.stringer)=false;
oneof value {
uint64 kid = 1;
string var = 2;
}
}

message KGObjectOrVar {
option (gogoproto.stringer)=false;
oneof value {
KGObject object = 1;
string var = 2;
}
}

// InsertFactsResult is the reply to the deprecated insertFacts RPC.
message InsertFactsResult {
option (gogoproto.stringer)=false;
repeated uint64 varResults = 1;
repeated uint64 factIds = 2;
int64 index = 3;
}
72 changes: 0 additions & 72 deletions src/github.com/ebay/beam/api/beam_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,65 +41,6 @@ func (m QueryFactsRequest) String() string {
return buf.String()
}

func (m InsertFactsResult) String() string {
var buf strings.Builder
fmt.Fprintf(&buf, "InsertFactsResult{")
fmt.Fprintf(&buf, "\n Index: %d", m.Index)
fmt.Fprint(&buf, "\n VarResults:")
for i, id := range m.VarResults {
if i > 0 {
fmt.Fprint(&buf, ",")
}
fmt.Fprintf(&buf, " %d", id)
}
fmt.Fprint(&buf, "\n FactIDs:")
for _, factID := range m.FactIds {
fmt.Fprintf(&buf, "\n %d", factID)
}
fmt.Fprintf(&buf, "\n}")
return buf.String()
}

func (m InsertFactsRequest) String() string {
return m.string("")
}

func (m InsertFactsRequest) string(indent string) string {
var buf strings.Builder
fmt.Fprintf(&buf, "InsertFactsRequest{\n")
fmt.Fprintf(&buf, "%s NewSubjectVars: %s\n", indent, strings.Join(m.NewSubjectVars, ", "))
fmt.Fprintf(&buf, "%s Facts:\n", indent)
for _, fact := range m.Facts {
fmt.Fprintf(&buf, "%s %s\n", indent, fact)
}
fmt.Fprintf(&buf, "%s}", indent)
return buf.String()
}

func (f InsertFact) String() string {
var buf strings.Builder
if f.FactIDVar != "" {
fmt.Fprintf(&buf, "?%s: ", f.FactIDVar)
}
fmt.Fprintf(&buf, "%s ", f.Subject)
fmt.Fprintf(&buf, "%s ", f.Predicate)
fmt.Fprintf(&buf, "%s", f.Object)
return buf.String()
}

func (m KIDOrVar) String() string {
switch m.Value.(type) {
case *KIDOrVar_Kid:
return fmt.Sprintf("#%d", m.GetKid())
case *KIDOrVar_Var:
return fmt.Sprintf("?%s", m.GetVar())
case nil:
return "(nil)"
default:
panic(fmt.Sprintf("Unknown kid/var: %T", m.Value))
}
}

// String returns a string version of the KGValue in the same format that
// the query parser expects.
func (m KGValue) String() string {
Expand Down Expand Up @@ -154,19 +95,6 @@ func (m KGObject) String() string {
}
}

func (m KGObjectOrVar) String() string {
switch m.Value.(type) {
case *KGObjectOrVar_Object:
return m.GetObject().String()
case *KGObjectOrVar_Var:
return fmt.Sprintf("?%s", m.GetVar())
case nil:
return "(nil)"
default:
panic(fmt.Sprintf("Unknown KGObjectOrVar value type: %T", m.Value))
}
}

func (m KGTimestamp) String() string {
return m.Value.Format(patterns[m.Precision])
}
Expand Down
177 changes: 0 additions & 177 deletions src/github.com/ebay/beam/api/beam_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/stretchr/testify/assert"
)

var ifb = &insertFactBuilder{}
var ts = time.Date(2018, time.Month(8), 8, 16, 44, 6, 999999999, time.UTC)

func Test_String(t *testing.T) {
Expand Down Expand Up @@ -73,61 +72,6 @@ func Test_String(t *testing.T) {
exp: `QueryFactsRequest{
Index: 12345
Query: '?s ?p ?o; #12345 <entity> rdfs:type "literal"'
}`,
}, {
obj: &InsertFactsResult{
Index: 12345,
VarResults: []uint64{678, 901, 234, 567},
FactIds: []uint64{890, 123, 456, 789, 123, 456},
},
exp: `InsertFactsResult{
Index: 12345
VarResults: 678, 901, 234, 567
FactIDs:
890
123
456
789
123
456
}`,
}, {
obj: &InsertFactsRequest{
NewSubjectVars: []string{"a", "b", "c"},
Facts: []InsertFact{
ifb.captureFactID("id1").sVar("s").pVar("p").oVar("o").build(),
ifb.sID(123).pID(456).oBool(true).build(),
ifb.sID(123).pID(456).oBool(true).oUID(12).build(),
ifb.sID(123).pID(456).oBool(false).build(),
ifb.sID(123).pID(456).oBool(false).oUID(12).build(),
ifb.sID(123).pID(456).oFloat64(1).build(),
ifb.sID(123).pID(456).oFloat64(1).oUID(12).build(),
ifb.sID(123).pID(456).oInt64(1).build(),
ifb.sID(123).pID(456).oInt64(1).oUID(12).build(),
ifb.sID(123).pID(456).oID(789).build(),
ifb.sID(123).pID(456).oString("Literal String").build(),
ifb.sID(123).pID(456).oString("Literal String").oLID(34).build(),
ifb.sID(123).pID(456).oTime(ts, Nanosecond).build(),
ifb.sID(123).pID(456).oTime(ts, Nanosecond).oUID(12).build(),
},
},
exp: `InsertFactsRequest{
NewSubjectVars: a, b, c
Facts:
?id1: ?s ?p ?o
#123 #456 true
#123 #456 true
#123 #456 false
#123 #456 false
#123 #456 1.000000
#123 #456 1.000000
#123 #456 1
#123 #456 1
#123 #456 #789
#123 #456 'Literal String'
#123 #456 'Literal String'
#123 #456 2018-08-08T16:44:06.999999999
#123 #456 2018-08-08T16:44:06.999999999
}`,
}, {
obj: Year,
Expand Down Expand Up @@ -177,124 +121,3 @@ func Test_String(t *testing.T) {
})
}
}

type insertFactBuilder struct {
fact InsertFact
}

func (b *insertFactBuilder) captureFactID(name string) *insertFactBuilder {
b.fact.FactIDVar = name
return b
}

func (b *insertFactBuilder) sVar(name string) *insertFactBuilder {
b.fact.Subject.Value = &KIDOrVar_Var{Var: name}
return b
}

func (b *insertFactBuilder) sID(kid uint64) *insertFactBuilder {
b.fact.Subject.Value = &KIDOrVar_Kid{Kid: kid}
return b
}

func (b *insertFactBuilder) pVar(name string) *insertFactBuilder {
b.fact.Predicate.Value = &KIDOrVar_Var{Var: name}
return b
}

func (b *insertFactBuilder) pID(kid uint64) *insertFactBuilder {
b.fact.Predicate.Value = &KIDOrVar_Kid{Kid: kid}
return b
}

func (b *insertFactBuilder) oVar(name string) *insertFactBuilder {
b.fact.Object.Value = &KGObjectOrVar_Var{Var: name}
return b
}

func (b *insertFactBuilder) oID(kid uint64) *insertFactBuilder {
b.fact.Object.Value = &KGObjectOrVar_Object{
Object: &KGObject{
Value: &KGObject_AKID{AKID: kid},
},
}
return b
}

func (b *insertFactBuilder) oString(value string) *insertFactBuilder {
b.fact.Object.Value = &KGObjectOrVar_Object{
Object: &KGObject{
Value: &KGObject_AString{AString: value},
},
}
return b
}

func (b *insertFactBuilder) oFloat64(value float64) *insertFactBuilder {
b.fact.Object.Value = &KGObjectOrVar_Object{
Object: &KGObject{
Value: &KGObject_AFloat64{AFloat64: value},
},
}
return b
}

func (b *insertFactBuilder) oInt64(value int64) *insertFactBuilder {
b.fact.Object.Value = &KGObjectOrVar_Object{
Object: &KGObject{
Value: &KGObject_AInt64{AInt64: value},
},
}
return b
}

func (b *insertFactBuilder) oTime(value time.Time, precision Precision) *insertFactBuilder {
b.fact.Object.Value = &KGObjectOrVar_Object{
Object: &KGObject{
Value: &KGObject_ATimestamp{ATimestamp: &KGTimestamp{Precision: precision, Value: value}},
},
}
return b
}

func (b *insertFactBuilder) oBool(value bool) *insertFactBuilder {
b.fact.Object.Value = &KGObjectOrVar_Object{
Object: &KGObject{
Value: &KGObject_ABool{ABool: value},
},
}
return b
}

func (b *insertFactBuilder) oUID(value uint64) *insertFactBuilder {
v, ok := b.fact.Object.Value.(*KGObjectOrVar_Object)
if !ok {
panic(fmt.Sprintf("OVar does not include unit id"))
}
v.Object.UnitID = value
return b
}

func (b *insertFactBuilder) oLID(value uint64) *insertFactBuilder {
v, ok := b.fact.Object.Value.(*KGObjectOrVar_Object)
if !ok {
panic(fmt.Sprintf("OVar does not include lang id"))
}
v.Object.LangID = value
return b
}

func (b *insertFactBuilder) build() InsertFact {
if b.fact.Subject.Value == nil {
panic("Attempted to build fact with nil subject")
}
if b.fact.Predicate.Value == nil {
panic("Attempted to build fact with nil predicate")
}
if b.fact.Object.Value == nil {
panic("Attempted to build fact with nil object")
}
f := b.fact
b.fact = InsertFact{}
return f
}
Loading

0 comments on commit 8de3bdc

Please sign in to comment.