Skip to content

Commit 89ac8a2

Browse files
committed
Changes
1 parent 9969f8e commit 89ac8a2

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.ingest;
11+
12+
public class ESONBytes {}

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ public void allowDuplicateKeys(boolean allowDuplicateKeys) {
112112

113113
@Override
114114
public Token nextToken() throws IOException {
115-
if (closed) return null;
115+
if (closed) {
116+
return null;
117+
}
116118

117119
// Clear value state
118120
currentValue = null;
@@ -132,7 +134,8 @@ public Token nextToken() throws IOException {
132134

133135
case OBJECT_FIELD_NAME:
134136
if (currentContainer.fieldsRemaining == 0) {
135-
Token endToken = currentContainer.type == ContainerContext.Type.OBJECT ? Token.END_OBJECT : Token.END_ARRAY;
137+
assert currentContainer.type == ContainerContext.Type.OBJECT;
138+
Token endToken = Token.END_OBJECT;
136139
containerStack.pop();
137140
currentContainer = containerStack.isEmpty() ? null : containerStack.peek();
138141
updateStateAfterEnd();
@@ -143,8 +146,18 @@ public Token nextToken() throws IOException {
143146
return currentToken = Token.FIELD_NAME;
144147
}
145148
case OBJECT_VALUE:
146-
case ARRAY_VALUE:
147149
return emitValue(keyArray.get(currentIndex++));
150+
case ARRAY_VALUE:
151+
if (currentContainer.fieldsRemaining == 0) {
152+
assert currentContainer.type == ContainerContext.Type.ARRAY;
153+
Token endToken = Token.END_ARRAY;
154+
containerStack.pop();
155+
currentContainer = containerStack.isEmpty() ? null : containerStack.peek();
156+
updateStateAfterEnd();
157+
return currentToken = endToken;
158+
} else {
159+
return emitValue(keyArray.get(currentIndex++));
160+
}
148161
case DONE:
149162
return null;
150163
}
@@ -168,19 +181,21 @@ private Token emitValue(ESONSource.KeyEntry entry) {
168181
case ESONSource.KeyEntry.TYPE_OBJECT -> {
169182
containerStack.push(new ContainerContext(ContainerContext.Type.OBJECT, ((ESONSource.ObjectEntry) entry).fieldCount));
170183
currentToken = Token.START_OBJECT;
184+
state = State.OBJECT_FIELD_NAME;
171185
}
172186
case ESONSource.KeyEntry.TYPE_ARRAY -> {
173187
containerStack.push(new ContainerContext(ContainerContext.Type.ARRAY, ((ESONSource.ArrayEntry) entry).elementCount));
174188
currentToken = Token.START_ARRAY;
189+
state = State.ARRAY_VALUE;
175190
}
176191
case ESONSource.KeyEntry.TYPE_FIELD -> {
177192
currentType = ((ESONSource.FieldEntry) entry).type;
178193
currentToken = determineValueToken(currentType);
194+
state = State.OBJECT_FIELD_NAME;
179195
}
180196
default -> throw new IllegalStateException("Unknown key entry type: " + entry.type());
181197
}
182198

183-
currentIndex++;
184199
if (currentContainer != null) {
185200
currentContainer.fieldsRemaining--;
186201
}

0 commit comments

Comments
 (0)