|
9 | 9 |
|
10 | 10 | package org.elasticsearch.ingest; |
11 | 11 |
|
12 | | -import org.elasticsearch.common.io.stream.StreamInput; |
| 12 | +import org.apache.lucene.util.BytesRef; |
| 13 | +import org.elasticsearch.common.bytes.BytesReference; |
13 | 14 | import org.elasticsearch.xcontent.DeprecationHandler; |
14 | 15 | import org.elasticsearch.xcontent.NamedXContentRegistry; |
15 | 16 | import org.elasticsearch.xcontent.Text; |
@@ -292,23 +293,20 @@ public String text() throws IOException { |
292 | 293 | public XContentString optimizedText() throws IOException { |
293 | 294 | // For strings, try to access raw bytes directly without materializing the string |
294 | 295 | if (currentType instanceof ESONSource.VariableValue varValue && varValue.type() == ESONEntry.STRING) { |
295 | | - // Return XContentString with direct byte access (lazy string conversion) |
296 | | - byte[] rawBytes; |
297 | | - int offset; |
298 | | - int length = varValue.length(); |
299 | | - if (values.data().hasArray()) { |
300 | | - rawBytes = values.data().array(); |
301 | | - offset = values.data().arrayOffset() + varValue.position(); |
| 296 | + BytesReference slice = values.data().slice(varValue.position(), varValue.length()); |
| 297 | + |
| 298 | + final byte[] bytes; |
| 299 | + final int offset; |
| 300 | + if (slice.hasArray()) { |
| 301 | + bytes = slice.array(); |
| 302 | + offset = slice.arrayOffset(); |
302 | 303 | } else { |
303 | | - rawBytes = new byte[Math.toIntExact(length)]; |
304 | | - offset = 0; |
305 | | - StreamInput streamInput = values.data().streamInput(); |
306 | | - streamInput.skip(varValue.position()); |
307 | | - streamInput.read(rawBytes); |
| 304 | + BytesRef bytesRef = slice.toBytesRef(); |
| 305 | + bytes = bytesRef.bytes; |
| 306 | + offset = bytesRef.offset; |
308 | 307 | } |
309 | | - |
310 | 308 | // TODO: Fix Length |
311 | | - return new Text(new XContentString.UTF8Bytes(rawBytes, offset, length), length); |
| 309 | + return new Text(new XContentString.UTF8Bytes(bytes, offset, varValue.length()), varValue.length()); |
312 | 310 | } |
313 | 311 |
|
314 | 312 | // Fallback: materialize value and convert to bytes |
|
0 commit comments