Skip to content

Commit

Permalink
Merge pull request #18 from DIMO-Network/cloudevent-db2
Browse files Browse the repository at this point in the history
update split value to handle partial indexing
  • Loading branch information
KevinJoiner authored Jan 6, 2025
2 parents d0798e8 + ed30b2f commit 68717ce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
27 changes: 15 additions & 12 deletions internal/processors/splitvalues/splitvalues.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,29 @@ func createLegacyMessage(msg *service.Message, rawValues []byte) ([]*service.Mes
if err != nil {
return nil, fmt.Errorf("failed to unmarshal old index values: %w", err)
}
decodedSubject, err := nameindexer.DecodeNFTDIDIndex(vals[0].(string))
if err != nil {
return nil, fmt.Errorf("failed to decode subject: %w", err)
subject := vals[0].(string)
decodedSubject, err := nameindexer.DecodeNFTDIDIndex(subject)
if err == nil {
subject = decodedSubject.String()
}
decodedSource, err := nameindexer.DecodeAddress(vals[3].(string))
if err != nil {
return nil, fmt.Errorf("failed to decode source: %w", err)
source := vals[3].(string)
decodedSource, err := nameindexer.DecodeAddress(source)
if err == nil {
source = decodedSource.String()
}
decodedProducer, err := nameindexer.DecodeNFTDIDIndex(vals[6].(string))
if err != nil {
return nil, fmt.Errorf("failed to decode subject: %w", err)
producer := vals[6].(string)
decodedProducer, err := nameindexer.DecodeNFTDIDIndex(producer)
if err == nil {
producer = decodedProducer.String()
}
oldIndex := nameindexer.Index{
Subject: decodedSubject.String(),
Subject: subject,
Timestamp: vals[1].(time.Time),
PrimaryFiller: nameindexer.DecodePrimaryFiller(vals[2].(string)),
Source: decodedSource.String(),
Source: source,
DataType: nameindexer.DecodeDataType(vals[4].(string)),
SecondaryFiller: nameindexer.DecodeSecondaryFiller(vals[5].(string)),
Producer: decodedProducer.String(),
Producer: producer,
Optional: vals[7].(string),
}
key := vals[8].(string)
Expand Down
6 changes: 6 additions & 0 deletions internal/processors/splitvalues/splitvalues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ func TestProcessBatch(t *testing.T) {
indexKey: "test_index",
expectedCount: 1,
},
{
name: "valid partial legacy format",
indexValue: `[["", "2024-12-12T16:00:33Z", "MA", "F26421509Efe92861a587482100c6d728aBf1CD0", "!!!!!!!!!!!!!!r/v0/s","00", "0000000000013882325b45949C833986bC98e98a49F3CA5C5c4643B50000000e", "", "000000000001388245fbCD3ef7361d156e8b16F5538AE36DEdf61Da8000001af758787160033MAF26421509Efe92861a587482100c6d728aBf1CD0!!!!!!!!!!!!!!r/v0/s000000000000013882325b45949C833986bC98e98a49F3CA5C5c4643B50000000e"]]`,
indexKey: "test_index",
expectedCount: 1,
},
{
name: "missing index values",
indexValue: "",
Expand Down

0 comments on commit 68717ce

Please sign in to comment.