Skip to content

Commit 02dfa8c

Browse files
committed
WIP
1 parent 6612c32 commit 02dfa8c

File tree

1 file changed

+50
-38
lines changed

1 file changed

+50
-38
lines changed

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

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -81,48 +81,61 @@ public void allowDuplicateKeys(boolean allowDuplicateKeys) {
8181
@Override
8282
public Token nextToken() throws IOException {
8383
if (currentToken == Token.FIELD_NAME) {
84-
currentToken = nextToken;
85-
nextToken = null;
86-
return currentToken;
84+
return returnFieldValue();
8785
} else if (currentToken != null && containerStack.isEmpty() == false) {
88-
int stackValue = containerStack.currentStackValue();
89-
int remainingFields = IntStack.fieldsRemaining(stackValue);
90-
if (remainingFields > 0) {
91-
currentEntry = keyArray.get(currentIndex);
92-
currentValue = null;
93-
containerStack.updateRemainingFields(stackValue - 1);
94-
++currentIndex;
95-
96-
byte type = currentEntry.type();
97-
final Token token = switch (type) {
98-
case ESONEntry.STRING -> Token.VALUE_STRING;
99-
case ESONEntry.TYPE_INT, ESONEntry.TYPE_LONG, ESONEntry.TYPE_FLOAT, ESONEntry.TYPE_DOUBLE, ESONEntry.BIG_INTEGER,
100-
ESONEntry.BIG_DECIMAL -> Token.VALUE_NUMBER;
101-
case ESONEntry.TYPE_NULL -> Token.VALUE_NULL;
102-
case ESONEntry.TYPE_TRUE, ESONEntry.TYPE_FALSE -> Token.VALUE_BOOLEAN;
103-
case ESONEntry.TYPE_OBJECT -> Token.START_OBJECT;
104-
case ESONEntry.TYPE_ARRAY -> Token.START_ARRAY;
105-
case ESONEntry.BINARY -> Token.VALUE_EMBEDDED_OBJECT;
106-
default -> throw new IllegalArgumentException("Unknown type: " + type);
107-
};
108-
if (token == Token.START_OBJECT || token == Token.START_ARRAY) {
109-
newContainer(type);
110-
}
111-
// token = TOKEN_LOOKUP[type];
112-
113-
if (IntStack.isObject(stackValue)) {
114-
nextToken = token;
115-
return currentToken = Token.FIELD_NAME;
116-
} else {
117-
return currentToken = token;
118-
}
86+
return advanceInContainer();
87+
} else {
88+
return handleInitial();
89+
}
90+
91+
}
92+
93+
private Token returnFieldValue() {
94+
currentToken = nextToken;
95+
nextToken = null;
96+
return currentToken;
97+
}
98+
99+
private Token advanceInContainer() {
100+
int stackValue = containerStack.currentStackValue();
101+
int remainingFields = IntStack.fieldsRemaining(stackValue);
102+
if (remainingFields > 0) {
103+
currentEntry = keyArray.get(currentIndex);
104+
currentValue = null;
105+
containerStack.updateRemainingFields(stackValue - 1);
106+
++currentIndex;
107+
108+
byte type = currentEntry.type();
109+
final Token token = switch (type) {
110+
case ESONEntry.STRING -> Token.VALUE_STRING;
111+
case ESONEntry.TYPE_INT, ESONEntry.TYPE_LONG, ESONEntry.TYPE_FLOAT, ESONEntry.TYPE_DOUBLE, ESONEntry.BIG_INTEGER,
112+
ESONEntry.BIG_DECIMAL -> Token.VALUE_NUMBER;
113+
case ESONEntry.TYPE_NULL -> Token.VALUE_NULL;
114+
case ESONEntry.TYPE_TRUE, ESONEntry.TYPE_FALSE -> Token.VALUE_BOOLEAN;
115+
case ESONEntry.TYPE_OBJECT -> Token.START_OBJECT;
116+
case ESONEntry.TYPE_ARRAY -> Token.START_ARRAY;
117+
case ESONEntry.BINARY -> Token.VALUE_EMBEDDED_OBJECT;
118+
default -> throw new IllegalArgumentException("Unknown type: " + type);
119+
};
120+
if (token == Token.START_OBJECT || token == Token.START_ARRAY) {
121+
newContainer(type);
122+
}
123+
// token = TOKEN_LOOKUP[type];
124+
125+
if (IntStack.isObject(stackValue)) {
126+
nextToken = token;
127+
return currentToken = Token.FIELD_NAME;
119128
} else {
120-
// End of container
121-
containerStack.popContainer();
122-
return currentToken = IntStack.isObject(stackValue) ? Token.END_OBJECT : Token.END_ARRAY;
129+
return currentToken = token;
123130
}
131+
} else {
132+
// End of container
133+
containerStack.popContainer();
134+
return currentToken = IntStack.isObject(stackValue) ? Token.END_OBJECT : Token.END_ARRAY;
124135
}
136+
}
125137

138+
private Token handleInitial() {
126139
if (closed) {
127140
return null;
128141
}
@@ -135,7 +148,6 @@ public Token nextToken() throws IOException {
135148
currentIndex++;
136149
return currentToken = Token.START_OBJECT;
137150
}
138-
139151
return null;
140152
}
141153

0 commit comments

Comments
 (0)