apache / apache/arrow-java

[Java] Unable to update VectorSchemaRoot field vectors.

未关闭
#46 12 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
Type: usage
主要语言
Java
星标
94
派生
152
平均合并
3 天 16 小时
30 天内合并 PR
11

描述

### Describe the usage question you have. Please include as many useful details as possible.

Hi community,

I have a trying to modify data buffers of string column.
if i print the buffer readable bytes after ` buffers.set(index, compressedBuf); `, i see the right value.
```
List buffers = fieldVector.getFieldBuffers();
int index = buffers.size() - 1;
ArrowBuf compressedBuf = null;
ArrowBuf originalBuf = buffers.get(index);
ByteBuffer originalBuffer = originalBuf.nioBuffer(0, (int) originalBuf.readableBytes());

// Compress the buffer using LZ4
byte[] originalBytes = new byte[originalBuffer.remaining()];
System.out.println("This is buffer id: "+ index + " originalbytes: "+ originalBuf.readableBytes());
originalBuffer.get(originalBytes);

int maxCompressedLength = compressor.maxCompressedLength(originalBytes.length);
byte[] compressedBytes = new byte[maxCompressedLength];
int compressedLength = compressor.compress(originalBytes, 0, originalBytes.length, compressedBytes, 0, maxCompressedLength);

// Allocate a new ArrowBuf for the compressed data
compressedBuf = allocator.buffer(compressedLength);

compressedBuf.writeBytes(compressedBytes, 0, compressedLength);
compressedBuf.writerIndex(compressedLength);
System.out.println("This is buffer id: "+ index+ " compressedbytes: "+ compressedBuf.readableBytes());

buffers.set(index, compressedBuf); // Replace with compressed buffer

```

When i update my fieldvector.

```
int nullCount = fieldVector.getNullCount(); // Get the null count
ArrowFieldNode fieldNode = new ArrowFieldNode(fieldVectorValueCount, nullCount);
ArrowBuf validityBuffer = fieldVector.getValidityBuffer(); // Assuming it exists
ArrowBuf offsetBuffer = fieldVector.getOffsetBuffer(); // Assuming it exists

// Update FieldVector with the new compressed buffers
fieldVector.clear(); // Clear existing buffers (to prevent memory leaks)
fieldVector.loadFieldBuffers(fieldNode,java.util.Arrays.asList(validityBuffer, offsetBuffer, compressedBuf)); // Load the new (compressed) buffers
fieldVector.setValueCount(fieldVectorValueCount); // Reset value count after buffer replacement
Field field1 = fieldVector.getField();
```

and i check the buffers again then buffers reflect old value.

please advise .

### Component(s)

Java

贡献指南

打开贡献指南

调研方向

检查涉及 getFieldBuffers()、clear() 和 loadFieldBuffers() 的 VectorSchemaRoot 与 FieldVector API,首先确认它们的缓冲区所有权和替换契约。复现所示序列,并验证生成的向量公开的是 compressedBuf 还是原始缓冲区;完成的标准是确定一条受支持的更新路径,或通过一个针对性测试确认该行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
java
领域
data-engineering
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。