22
22
import com .google .gson .Gson ;
23
23
import com .google .gson .GsonBuilder ;
24
24
import com .yelp .nrtsearch .server .ServerTestCase ;
25
+ import com .yelp .nrtsearch .server .field .FieldDef ;
25
26
import com .yelp .nrtsearch .server .grpc .AddDocumentRequest ;
26
27
import com .yelp .nrtsearch .server .grpc .FieldDefRequest ;
27
28
import com .yelp .nrtsearch .server .index .IndexState ;
@@ -102,13 +103,15 @@ public void testParentAccessWithValidNestedDocs() throws Exception {
102
103
SegmentDocLookup docLookup = new SegmentDocLookup (indexState ::getField , leafContext );
103
104
104
105
Method tryGetMethod =
105
- SegmentDocLookup .class .getDeclaredMethod ("tryGetFromParentDocument" , String .class );
106
+ SegmentDocLookup .class .getDeclaredMethod (
107
+ "tryGetFromParentDocument" , String .class , FieldDef .class );
106
108
tryGetMethod .setAccessible (true );
107
109
108
110
// Test 1: Child document should be able to access parent field
109
111
docLookup .setDocId (0 );
112
+ FieldDef docIdFieldDef = indexState .getField ("doc_id" );
110
113
LoadedDocValues <?> parentField =
111
- (LoadedDocValues <?>) tryGetMethod .invoke (docLookup , "doc_id" );
114
+ (LoadedDocValues <?>) tryGetMethod .invoke (docLookup , "doc_id" , docIdFieldDef );
112
115
113
116
if (parentField != null && !parentField .isEmpty ()) {
114
117
assertNotNull ("Should find parent field from child document" , parentField );
@@ -119,8 +122,10 @@ public void testParentAccessWithValidNestedDocs() throws Exception {
119
122
// Test 2: Non-existent field should return null
120
123
LoadedDocValues <?> nonExistentField = null ;
121
124
try {
125
+ FieldDef nonExistentFieldDef = indexState .getField ("non_existent_field" );
122
126
nonExistentField =
123
- (LoadedDocValues <?>) tryGetMethod .invoke (docLookup , "non_existent_field" );
127
+ (LoadedDocValues <?>)
128
+ tryGetMethod .invoke (docLookup , "non_existent_field" , nonExistentFieldDef );
124
129
} catch (Exception e ) {
125
130
if (e .getCause () instanceof IllegalArgumentException ) {
126
131
nonExistentField = null ;
@@ -133,7 +138,7 @@ public void testParentAccessWithValidNestedDocs() throws Exception {
133
138
// Test 3: Parent document (no offset field) should return null
134
139
docLookup .setDocId (2 );
135
140
LoadedDocValues <?> fromParentDoc =
136
- (LoadedDocValues <?>) tryGetMethod .invoke (docLookup , "doc_id" );
141
+ (LoadedDocValues <?>) tryGetMethod .invoke (docLookup , "doc_id" , docIdFieldDef );
137
142
assertNull ("Parent document should return null (no offset field)" , fromParentDoc );
138
143
} finally {
139
144
if (s != null ) {
@@ -155,7 +160,8 @@ public void testParentAccessWithDifferentFieldTypes() throws Exception {
155
160
SegmentDocLookup docLookup = new SegmentDocLookup (indexState ::getField , leafContext );
156
161
157
162
Method tryGetMethod =
158
- SegmentDocLookup .class .getDeclaredMethod ("tryGetFromParentDocument" , String .class );
163
+ SegmentDocLookup .class .getDeclaredMethod (
164
+ "tryGetFromParentDocument" , String .class , FieldDef .class );
159
165
tryGetMethod .setAccessible (true );
160
166
161
167
docLookup .setDocId (0 );
@@ -164,8 +170,9 @@ public void testParentAccessWithDifferentFieldTypes() throws Exception {
164
170
165
171
for (String fieldName : fieldsToTest ) {
166
172
try {
173
+ FieldDef fieldDef = indexState .getField (fieldName );
167
174
LoadedDocValues <?> result =
168
- (LoadedDocValues <?>) tryGetMethod .invoke (docLookup , fieldName );
175
+ (LoadedDocValues <?>) tryGetMethod .invoke (docLookup , fieldName , fieldDef );
169
176
assertTrue ("Field access should not throw unexpected exceptions: " + fieldName , true );
170
177
} catch (Exception e ) {
171
178
assertTrue (
@@ -193,14 +200,17 @@ public void testParentAccessWithoutNestedDocuments() throws Exception {
193
200
SegmentDocLookup docLookup = new SegmentDocLookup (indexState ::getField , leafContext );
194
201
195
202
Method tryGetMethod =
196
- SegmentDocLookup .class .getDeclaredMethod ("tryGetFromParentDocument" , String .class );
203
+ SegmentDocLookup .class .getDeclaredMethod (
204
+ "tryGetFromParentDocument" , String .class , FieldDef .class );
197
205
tryGetMethod .setAccessible (true );
198
206
199
207
int maxDoc = leafContext .reader ().maxDoc ();
200
208
if (maxDoc > 1 ) {
201
209
docLookup .setDocId (maxDoc - 1 );
202
210
203
- LoadedDocValues <?> result = (LoadedDocValues <?>) tryGetMethod .invoke (docLookup , "doc_id" );
211
+ FieldDef docIdFieldDef = indexState .getField ("doc_id" );
212
+ LoadedDocValues <?> result =
213
+ (LoadedDocValues <?>) tryGetMethod .invoke (docLookup , "doc_id" , docIdFieldDef );
204
214
assertNull ("Document without nested structure should return null" , result );
205
215
}
206
216
} finally {
0 commit comments