Skip to content

Commit d2c857c

Browse files
committed
Merge branch 'structured_source' into structured_source_benchmark
2 parents d44ba76 + 92a0ed3 commit d2c857c

File tree

3 files changed

+20
-54
lines changed

3 files changed

+20
-54
lines changed

modules/data-streams/src/yamlRestTest/resources/rest-api-spec/test/data_stream/260_logs_failure_store.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,5 @@ teardown:
7676
match_all: {}
7777
- length: { hits.hits: 1 }
7878
- match: { hits.hits.0._source.document.source.message.struct.value: 42 }
79+
# TODO: For some reason changed to illegal argument exception sometimes?
7980
- match: { hits.hits.0._source.error.type: "document_parsing_exception" }

server/src/main/java/org/elasticsearch/ingest/ESONSource.java

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.apache.lucene.util.BytesRef;
1313
import org.elasticsearch.common.bytes.BytesReference;
1414
import org.elasticsearch.common.io.stream.BytesStreamOutput;
15-
import org.elasticsearch.common.io.stream.StreamOutput;
1615
import org.elasticsearch.common.recycler.Recycler;
1716
import org.elasticsearch.transport.BytesRefRecycler;
1817
import org.elasticsearch.xcontent.ToXContent;
@@ -184,29 +183,26 @@ public enum ValueType {
184183
BINARY
185184
}
186185

187-
public interface KeyEntry {
186+
public abstract static class KeyEntry {
188187

189-
String key();
190-
191-
default void writeTo(StreamOutput out) throws IOException {
188+
private final String key;
192189

190+
KeyEntry(String key) {
191+
this.key = key;
193192
}
194193

194+
public String key() {
195+
return key;
196+
}
195197
}
196198

197-
public static class ObjectEntry implements KeyEntry {
199+
public static class ObjectEntry extends KeyEntry {
198200

199-
private final String key;
200201
public int fieldCount = 0;
201202
private Map<String, Type> mutationMap = null;
202203

203204
public ObjectEntry(String key) {
204-
this.key = key;
205-
}
206-
207-
@Override
208-
public String key() {
209-
return key;
205+
super(key);
210206
}
211207

212208
public boolean hasMutations() {
@@ -215,23 +211,17 @@ public boolean hasMutations() {
215211

216212
@Override
217213
public String toString() {
218-
return "ObjectEntry{" + "key='" + key + '\'' + ", fieldCount=" + fieldCount + ", hasMutations=" + hasMutations() + '}';
214+
return "ObjectEntry{" + "key='" + key() + '\'' + ", fieldCount=" + fieldCount + ", hasMutations=" + hasMutations() + '}';
219215
}
220216
}
221217

222-
public static class ArrayEntry implements KeyEntry {
218+
public static class ArrayEntry extends KeyEntry {
223219

224-
private final String key;
225220
public int elementCount = 0;
226221
private List<Type> mutationArray = null;
227222

228223
public ArrayEntry(String key) {
229-
this.key = key;
230-
}
231-
232-
@Override
233-
public String key() {
234-
return key;
224+
super(key);
235225
}
236226

237227
public boolean hasMutations() {
@@ -240,27 +230,21 @@ public boolean hasMutations() {
240230

241231
@Override
242232
public String toString() {
243-
return "ArrayEntry{" + "key='" + key + '\'' + ", elementCount=" + elementCount + ", hasMutations=" + hasMutations() + '}';
233+
return "ArrayEntry{" + "key='" + key() + '\'' + ", elementCount=" + elementCount + ", hasMutations=" + hasMutations() + '}';
244234
}
245235
}
246236

247-
public static class FieldEntry implements KeyEntry {
248-
public final String key;
237+
public static class FieldEntry extends KeyEntry {
249238
public final Type type;
250239

251240
public FieldEntry(String key, Type type) {
252-
this.key = key;
241+
super(key);
253242
this.type = type;
254243
}
255244

256-
@Override
257-
public String key() {
258-
return key;
259-
}
260-
261245
@Override
262246
public String toString() {
263-
return "FieldEntry{" + "key='" + key + '\'' + ", type=" + type + '}';
247+
return "FieldEntry{" + "key='" + key() + '\'' + ", type=" + type + '}';
264248
}
265249
}
266250

@@ -397,7 +381,7 @@ private void ensureMaterializedMap() {
397381
for (int i = 0; i < objEntry.fieldCount; i++) {
398382
KeyEntry entry = keyArray.get(currentIndex);
399383
if (entry instanceof FieldEntry fieldEntry) {
400-
materializedMap.put(fieldEntry.key, fieldEntry.type);
384+
materializedMap.put(fieldEntry.key(), fieldEntry.type);
401385
currentIndex++;
402386
} else {
403387
if (entry instanceof ObjectEntry) {
@@ -1056,23 +1040,4 @@ private static void flattenArray(ESONArray arr, String arrayFieldName, List<KeyE
10561040
newArrEntry.elementCount = elementCount;
10571041
}
10581042
}
1059-
1060-
public void writeToStream(ESONObject object, StreamOutput out) throws IOException {
1061-
out.writeByte((byte) 'E');
1062-
out.writeByte((byte) 'S');
1063-
out.writeByte((byte) 'O');
1064-
out.writeByte((byte) 'N');
1065-
// TODO: How to write size
1066-
// TODO: Assert flattened or support transition to flattened
1067-
for (KeyEntry entry : object.getKeyArray()) {
1068-
if (entry instanceof ObjectEntry) {
1069-
1070-
} else if (entry instanceof ArrayEntry) {
1071-
1072-
} else {
1073-
1074-
}
1075-
entry.writeTo(out);
1076-
}
1077-
}
10781043
}

server/src/main/java/org/elasticsearch/ingest/ESONXContentSerializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ public static XContentBuilder flattenToXContent(ESONSource.ESONObject rootObject
8686
// Process the current entry
8787
if (entry instanceof ESONSource.FieldEntry fieldEntry) {
8888
// Simple field with a value
89-
if (currentContainer.isArray == false && fieldEntry.key != null) {
90-
builder.field(fieldEntry.key);
89+
if (currentContainer.isArray == false && fieldEntry.key() != null) {
90+
builder.field(fieldEntry.key());
9191
}
9292

9393
writeValue(values, builder, fieldEntry.type, params);

0 commit comments

Comments
 (0)