{"record":{"id":"18e88a1fdee98787","repo":"apache/seatunnel","slug":"invalid-yashandb-2-byte-vector-buffer-length","errorCode":null,"errorMessage":"Invalid YashanDB 2-byte vector buffer length: ","messagePattern":"Invalid YashanDB 2-byte vector buffer length: ","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/yashandb/YashanDbJdbcRowConverter.java","lineNumber":291,"sourceCode":"    }\n\n    private static float[] toBFloat16Array(Object value) throws SQLException {\n        short[] shortArray = toPrimitiveShortArray(value);\n        float[] floatArray = new float[shortArray.length];\n        for (int i = 0; i < shortArray.length; i++) {\n            floatArray[i] = bfloat16ToFloat(shortArray[i]);\n        }\n        return floatArray;\n    }\n\n    private static short[] toPrimitiveShortArray(Object value) throws SQLException {\n        if (value instanceof ByteBuffer) {\n            ByteBuffer byteBuffer = ((ByteBuffer) value).duplicate();\n            byteBuffer.rewind();\n            // SeaTunnel FLOAT16_VECTOR and BFLOAT16_VECTOR ByteBuffers are encoded as one\n            // big-endian 2-byte short per vector element via VectorUtils.toByteBuffer(Short[]).\n            if (byteBuffer.remaining() % Short.BYTES != 0) {\n                throw new SQLException(\n                        \"Invalid YashanDB 2-byte vector buffer length: \" + byteBuffer.remaining());\n            }\n            short[] shortArray = new short[byteBuffer.remaining() / Short.BYTES];\n            for (int i = 0; i < shortArray.length; i++) {\n                shortArray[i] = byteBuffer.getShort();\n            }\n            return shortArray;\n        }\n\n        Object[] objectArray = (Object[]) value;\n        short[] shortArray = new short[objectArray.length];\n        for (int i = 0; i < objectArray.length; i++) {\n            shortArray[i] = ((Number) objectArray[i]).shortValue();\n        }\n        return shortArray;\n    }\n\n    private static float float16ToFloat(short value) {","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/yashandb/YashanDbJdbcRowConverter.java#L273-L309","documentation":"toPrimitiveShortArray() expects the FLOAT16/BFLOAT16 vector ByteBuffer to contain a whole number of 2-byte (short) elements, one per vector element. A buffer whose remaining bytes are not a multiple of Short.BYTES (2) is malformed, so an SQLException is thrown with the actual byte count.","triggerScenarios":"Writing a FLOAT16_VECTOR or BFLOAT16_VECTOR value where the underlying ByteBuffer has odd byte length — e.g. truncated buffer, wrong endianness/serialization, or a 1-byte-per-element encoding passed instead of 2-byte shorts.","commonSituations":"Upstream producer serialized fp16 vectors as 8-bit halves or dropped a byte (off-by-one/truncation); ByteBuffer slice with wrong position/limit; mixing FLOAT32 (4-byte) data into a FLOAT16 vector column config.","solutions":["Ensure the producer encodes fp16 vectors via VectorUtils.toByteBuffer(Short[]) so each element is exactly 2 bytes","Check the ByteBuffer has even remaining() and full elements (no truncation) before writing","Verify the vector column type matches the data: FLOAT32 vectors in a FLOAT16 column will mismatch element sizes","Regenerate the embedding data if buffers are corrupted upstream"],"exampleFix":"// before\nbyteBuffer.position(0); // slice accidentally excludes last byte -> odd remaining()\n// after\nif (byteBuffer.remaining() % 2 != 0) {\n    throw new IllegalArgumentException(\"fp16 buffer must be even-length, got \" + byteBuffer.remaining());\n}","handlingStrategy":"validation","validationCode":"if (buf.remaining() % 2 != 0) throw new IllegalStateException(\"fp16 vector buffer must be even length: \" + buf.remaining());","typeGuard":"static boolean isWellFormedFp16Buffer(ByteBuffer b) {\n    ByteBuffer d = b.duplicate(); d.rewind();\n    return d.remaining() % Short.BYTES == 0;\n}","tryCatchPattern":"try {\n    stmt.setObject(idx, Vector.ofFloat16Values(shortArray(value)));\n} catch (SQLException e) {\n    if (e.getMessage().contains(\"Invalid YashanDB 2-byte vector buffer length\")) {\n        throw new DataValidationException(\"corrupt fp16 vector from upstream\", e);\n    } else throw e;\n}","preventionTips":["Serialize fp16 vectors with VectorUtils.toByteBuffer(Short[]) consistently","Never slice/truncate ByteBuffers between producer and consumer","Confirm vector column width matches data type (FLOAT16 = 2 bytes/element, FLOAT32 = 4)"],"tags":["jdbc","yashandb","vector","bytebuffer"],"backgroundTag":"invalid-argument-format","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}