Skip to content

Commit

Permalink
ensure unique ReferenceDataType instances
Browse files Browse the repository at this point in the history
  • Loading branch information
arnej27959 committed Mar 11, 2022
1 parent 759f0f2 commit 69bb8e9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import com.yahoo.document.DataType;
import com.yahoo.document.Document;
import com.yahoo.document.Field;
import com.yahoo.document.ReferenceDataType;
import com.yahoo.document.StructDataType;
import com.yahoo.document.StructuredDataType;
import com.yahoo.document.TemporaryStructuredDataType;
import com.yahoo.document.annotation.AnnotationType;
import com.yahoo.document.annotation.AnnotationTypeRegistry;
import com.yahoo.document.datatypes.FieldValue;
Expand Down Expand Up @@ -383,4 +385,18 @@ public boolean equals(Object other) {

}

private ReferenceDataType refToThis = null;

@SuppressWarnings("deprecation")
public ReferenceDataType getReferenceDataType() {
if (refToThis == null) {
// super ugly, the APIs for this are horribly inconsistent
var tmptmp = TemporaryStructuredDataType.create(getName());
var tmp = ReferenceDataType.createWithInferredId(tmptmp);
tmp.setTargetType((StructuredDataType) this);
refToThis = tmp;
}
return refToThis;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -292,17 +292,8 @@ else if (type instanceof WeightedSetDataType) {
else if (type instanceof ReferenceDataType) {
ReferenceDataType t = (ReferenceDataType) type;
var tt = t.getTargetType();
if (tt instanceof TemporaryStructuredDataType) {
DataType targetType = resolveTemporariesRecurse(tt, repo, docs, replacements);
t.setTargetType((StructuredDataType) targetType);
} else if (tt instanceof DocumentType) {
DataType targetType = resolveTemporariesRecurse(tt, repo, docs, replacements);
// super ugly, the APIs for this are horribly inconsistent
var tmptmp = TemporaryStructuredDataType.create(tt.getName());
var tmp = new ReferenceDataType(tmptmp, t.getId());
tmp.setTargetType((StructuredDataType) targetType);
type = tmp;
}
var doc = getDocumentType(docs, tt.getId());
type = doc.getReferenceDataType();
}
if (type != original) {
replacements.add(new TypeReplacement(original, type));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,17 @@ doctype[1].fieldsets{[document]}.fields[0] "campaign_ref"
doctype[1].fieldsets{[document]}.fields[1] "other_campaign_ref"
doctype[1].documentref[0].idx 10017
doctype[1].documentref[0].targettype 10018
doctype[1].documentref[1].idx 10019
doctype[1].documentref[1].targettype 10018
doctype[1].structtype[0].idx 10016
doctype[1].structtype[0].name "ad.header"
doctype[1].structtype[0].field[0].name "campaign_ref"
doctype[1].structtype[0].field[0].internalid 23963250
doctype[1].structtype[0].field[0].type 10017
doctype[1].structtype[0].field[1].name "other_campaign_ref"
doctype[1].structtype[0].field[1].internalid 874751172
doctype[1].structtype[0].field[1].type 10019
doctype[1].structtype[0].field[1].type 10017
doctype[2].name "campaign"
doctype[2].idx 10018
doctype[2].inherits[0].idx 10000
doctype[2].contentstruct 10020
doctype[2].structtype[0].idx 10020
doctype[2].contentstruct 10019
doctype[2].structtype[0].idx 10019
doctype[2].structtype[0].name "campaign.header"

0 comments on commit 69bb8e9

Please sign in to comment.