Skip to content

Commit

Permalink
feat(columnar): support build_config filtering of columnar decorations (
Browse files Browse the repository at this point in the history
  • Loading branch information
schroederc committed Feb 6, 2019
1 parent 2480a93 commit 810c921
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 100 deletions.
6 changes: 6 additions & 0 deletions kythe/go/serving/pipeline/beam_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ func TestServingSimpleDecorations(t *testing.T) {
}, {
Name: &scpb.Fact_KytheName{scpb.FactName_LOC_END},
Value: []byte("9"),
}, {
Name: &scpb.Fact_KytheName{scpb.FactName_BUILD_CONFIG},
Value: []byte("test-build-config"),
}},
Edge: []*scpb.Edge{{
Kind: &scpb.Edge_KytheKind{scpb.EdgeKind_REF},
Expand Down Expand Up @@ -202,6 +205,7 @@ func TestServingSimpleDecorations(t *testing.T) {
LineNumber: 1,
},
},
BuildConfig: "test-build-config",
Kind: "/kythe/edge/ref",
TargetTicket: "kythe:#decorWithDef",
// TargetDefinition: explicitly not requested
Expand Down Expand Up @@ -242,6 +246,7 @@ func TestServingSimpleDecorations(t *testing.T) {
LineNumber: 1,
},
},
BuildConfig: "test-build-config",
Kind: "/kythe/edge/ref",
TargetTicket: "kythe:#decorWithDef",
// TargetDefinition: explicitly not requested
Expand Down Expand Up @@ -288,6 +293,7 @@ func TestServingSimpleDecorations(t *testing.T) {
LineNumber: 1,
},
},
BuildConfig: "test-build-config",
Kind: "/kythe/edge/ref",
TargetTicket: "kythe:#decorWithDef",
TargetDefinition: "kythe:#def1", // expected definition
Expand Down
1 change: 1 addition & 0 deletions kythe/go/serving/pipeline/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func encodeDecorRef(file *spb.VName, ref *ppb.Reference, emit func([]byte, []byt
target := &xspb.FileDecorations_Target{
StartOffset: ref.Anchor.Span.Start.ByteOffset,
EndOffset: ref.Anchor.Span.End.ByteOffset,
BuildConfig: ref.Anchor.BuildConfiguration,
Target: ref.Source,
}
if k := ref.GetGenericKind(); k != "" {
Expand Down
6 changes: 6 additions & 0 deletions kythe/go/serving/xrefs/columnar.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (c *ColumnarTable) Decorations(ctx context.Context, req *xpb.DecorationsReq
var norm *span.Normalizer // span normalizer for references
refsByTarget := make(map[string][]*xpb.DecorationsReply_Reference) // target -> set<Reference>
defs := stringset.New() // set<needed definition tickets>
buildConfigs := stringset.New(req.BuildConfig...)
patterns := xrefs.ConvertFilters(req.Filter)
emitSnippets := req.Snippets != xpb.SnippetsKind_NONE

Expand Down Expand Up @@ -168,12 +169,17 @@ func (c *ColumnarTable) Decorations(ctx context.Context, req *xpb.DecorationsReq
continue
}
t := e.Target
// Filter decorations by requested build configs.
if len(buildConfigs) != 0 && !buildConfigs.Contains(t.BuildConfig) {
continue
}
kind := t.GetGenericKind()
if kind == "" {
kind = schema.EdgeKindString(t.GetKytheKind())
}
ref := &xpb.DecorationsReply_Reference{
TargetTicket: kytheuri.ToString(t.Target),
BuildConfig: t.BuildConfig,
Kind: kind,
Span: norm.SpanOffsets(t.StartOffset, t.EndOffset),
}
Expand Down
6 changes: 4 additions & 2 deletions kythe/go/serving/xrefs/columnar/columnar_encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func encodeDecorText(prefix []byte, file *spb.VName, t *xspb.FileDecorations_Tex

func encodeDecorTarget(prefix []byte, file *spb.VName, t *xspb.FileDecorations_Target) (*KV, error) {
key, err := keys.Append(prefix, file,
columnarDecorationsTargetGroup, t.StartOffset, t.EndOffset,
columnarDecorationsTargetGroup, t.BuildConfig, t.StartOffset, t.EndOffset,
t.GetGenericKind(), int32(t.GetKytheKind()), t.Target)
if err != nil {
return nil, err
Expand Down Expand Up @@ -268,7 +268,9 @@ func decodeDecorTarget(file *spb.VName, key string, val []byte) (*xspb.FileDecor
kytheKindNum int32
genericKind string
)
key, err := keys.Parse(key, &target.StartOffset, &target.EndOffset, &genericKind, &kytheKindNum, target.Target)
key, err := keys.Parse(key,
&target.BuildConfig, &target.StartOffset, &target.EndOffset,
&genericKind, &kytheKindNum, target.Target)
if err != nil {
return nil, err
}
Expand Down
5 changes: 4 additions & 1 deletion kythe/proto/xref_serving.proto
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ message FileDecorations {

// File decoration target
//
// Columnar key: 10-start-end-kind-target
// Columnar key: 10-build_config-start-end-kind-target
message Target {
// Starting offset of this file decoration.
int32 start_offset = 1;
Expand All @@ -79,6 +79,8 @@ message FileDecorations {
}

kythe.proto.VName target = 5;

string build_config = 6;
}

// Override per file decoration target node.
Expand Down Expand Up @@ -131,6 +133,7 @@ message FileDecorations {
// Diagnostic per file span
//
// Columnar key: 70-start-end-hash
// TODO(schroederc): add build_config to spanning Diagnostics and key
message Diagnostic {
kythe.proto.common.Diagnostic diagnostic = 1;
}
Expand Down
Loading

0 comments on commit 810c921

Please sign in to comment.