Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Carry over hash value for all literal types in remote caching #378

Merged
merged 1 commit into from
Jul 18, 2023
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
15 changes: 8 additions & 7 deletions go/tasks/pluginmachinery/catalog/hashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ var emptyLiteralMap = core.LiteralMap{Literals: map[string]*core.Literal{}}
// Hashify a literal, in other words, produce a new literal where the corresponding value is removed in case
// the literal hash is set.
func hashify(literal *core.Literal) *core.Literal {
// If the hash is set, return an empty literal with the same hash,
// regardless of type (scalar/collection/map).
if literal.GetHash() != "" {
return &core.Literal{
Hash: literal.GetHash(),
}
}

// Two recursive cases:
// 1. A collection of literals or
// 2. A map of literals

if literal.GetCollection() != nil {
literals := literal.GetCollection().Literals
literalsHash := make([]*core.Literal, 0)
Expand Down Expand Up @@ -45,12 +52,6 @@ func hashify(literal *core.Literal) *core.Literal {
}
}

// And a base case that consists of a scalar, where the hash might be set
if literal.GetHash() != "" {
return &core.Literal{
Hash: literal.GetHash(),
}
}
return literal
}

Expand Down
58 changes: 58 additions & 0 deletions go/tasks/pluginmachinery/catalog/hashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,64 @@ func TestHashLiteralMap_LiteralsWithHashSet(t *testing.T) {
},
},
},
{
name: "literal map containing hash",
literal: &core.Literal{
Value: &core.Literal_Map{
Map: &core.LiteralMap{
Literals: map[string]*core.Literal{
"hello": {
Value: &core.Literal_Scalar{
Scalar: &core.Scalar{
Value: &core.Scalar_Primitive{
Primitive: &core.Primitive{
Value: &core.Primitive_StringValue{
StringValue: "world",
},
},
},
},
},
},
},
},
},
Hash: "0xffff",
},
expectedLiteral: &core.Literal{
Value: nil,
Hash: "0xffff",
},
},
{
name: "literal collection containing hash",
literal: &core.Literal{
Value: &core.Literal_Collection{
Collection: &core.LiteralCollection{
Literals: []*core.Literal{
{
Value: &core.Literal_Scalar{
Scalar: &core.Scalar{
Value: &core.Scalar_Primitive{
Primitive: &core.Primitive{
Value: &core.Primitive_Integer{
Integer: 42,
},
},
},
},
},
},
},
},
},
Hash: "0xabcdef",
},
expectedLiteral: &core.Literal{
Value: nil,
Hash: "0xabcdef",
},
},
}

for _, tt := range tests {
Expand Down