Skip to content

Commit 675c4dd

Browse files
mtopolnikclaude
andcommitted
Use little-endian for QWP decimal wire format
QWP transmitted DECIMAL64/128/256 values in big-endian while all other numeric types used little-endian. This was inherited from Parquet's convention but served no purpose in QWP, which is its own protocol. Switch decimal columns to little-endian on the wire, matching Cairo's in-memory layout. This replaces putLongBE() with putLong() in QwpColumnWriter and deletes the now-unused putLongBE() method from the buffer writer interface and its implementations. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6a9235d commit 675c4dd

6 files changed

Lines changed: 8 additions & 58 deletions

File tree

core/src/main/java/io/questdb/client/cutlass/http/client/WebSocketSendBuffer.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,6 @@ public void putLong(long value) {
310310
writePos += 8;
311311
}
312312

313-
/**
314-
* Writes a long value in big-endian format.
315-
*/
316-
public void putLongBE(long value) {
317-
ensureCapacity(8);
318-
Unsafe.getUnsafe().putLong(bufPtr + writePos, Long.reverseBytes(value));
319-
writePos += 8;
320-
}
321-
322313
/**
323314
* Writes a short value in little-endian format.
324315
*/

core/src/main/java/io/questdb/client/cutlass/qwp/client/NativeBufferWriter.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,6 @@ public void putLong(long value) {
211211
position += 8;
212212
}
213213

214-
/**
215-
* Writes a long in big-endian order.
216-
*/
217-
@Override
218-
public void putLongBE(long value) {
219-
ensureCapacity(8);
220-
Unsafe.getUnsafe().putLong(bufferPtr + position, Long.reverseBytes(value));
221-
position += 8;
222-
}
223-
224214
/**
225215
* Writes a short (2 bytes, little-endian).
226216
*/

core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpBufferWriter.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
* <li>{@link io.questdb.client.cutlass.http.client.WebSocketSendBuffer} - WebSocket frame buffer</li>
4040
* </ul>
4141
* <p>
42-
* All multi-byte values are written in little-endian format unless the method
43-
* name explicitly indicates big-endian (e.g., {@link #putLongBE}).
42+
* All multi-byte values are written in little-endian format.
4443
*/
4544
public interface QwpBufferWriter extends ArrayBufferAppender {
4645

@@ -85,11 +84,6 @@ public interface QwpBufferWriter extends ArrayBufferAppender {
8584
*/
8685
void putFloat(float value);
8786

88-
/**
89-
* Writes a long in big-endian byte order.
90-
*/
91-
void putLongBE(long value);
92-
9387
/**
9488
* Writes a short (2 bytes, little-endian).
9589
*/

core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpColumnWriter.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,26 +194,26 @@ private void writeDecimal128Column(byte scale, long addr, int count) {
194194
long offset = (long) i * 16;
195195
long hi = Unsafe.getUnsafe().getLong(addr + offset);
196196
long lo = Unsafe.getUnsafe().getLong(addr + offset + 8);
197-
buffer.putLongBE(hi);
198-
buffer.putLongBE(lo);
197+
buffer.putLong(hi);
198+
buffer.putLong(lo);
199199
}
200200
}
201201

202202
private void writeDecimal256Column(byte scale, long addr, int count) {
203203
buffer.putByte(scale);
204204
for (int i = 0; i < count; i++) {
205205
long offset = (long) i * 32;
206-
buffer.putLongBE(Unsafe.getUnsafe().getLong(addr + offset));
207-
buffer.putLongBE(Unsafe.getUnsafe().getLong(addr + offset + 8));
208-
buffer.putLongBE(Unsafe.getUnsafe().getLong(addr + offset + 16));
209-
buffer.putLongBE(Unsafe.getUnsafe().getLong(addr + offset + 24));
206+
buffer.putLong(Unsafe.getUnsafe().getLong(addr + offset));
207+
buffer.putLong(Unsafe.getUnsafe().getLong(addr + offset + 8));
208+
buffer.putLong(Unsafe.getUnsafe().getLong(addr + offset + 16));
209+
buffer.putLong(Unsafe.getUnsafe().getLong(addr + offset + 24));
210210
}
211211
}
212212

213213
private void writeDecimal64Column(byte scale, long addr, int count) {
214214
buffer.putByte(scale);
215215
for (int i = 0; i < count; i++) {
216-
buffer.putLongBE(Unsafe.getUnsafe().getLong(addr + (long) i * 8));
216+
buffer.putLong(Unsafe.getUnsafe().getLong(addr + (long) i * 8));
217217
}
218218
}
219219

core/src/main/java/io/questdb/client/cutlass/qwp/client/SegmentedNativeBufferWriter.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,6 @@ public void putLong(long value) {
116116
currentChunk.putLong(value);
117117
}
118118

119-
@Override
120-
public void putLongBE(long value) {
121-
currentChunk.putLongBE(value);
122-
}
123-
124119
@Override
125120
public void putShort(short value) {
126121
currentChunk.putShort(value);

core/src/test/java/io/questdb/client/test/cutlass/qwp/client/NativeBufferWriterTest.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -379,26 +379,6 @@ public void testWriteLong() throws Exception {
379379
});
380380
}
381381

382-
@Test
383-
public void testWriteLongBigEndian() throws Exception {
384-
assertMemoryLeak(() -> {
385-
try (NativeBufferWriter writer = new NativeBufferWriter()) {
386-
writer.putLongBE(0x0102030405060708L);
387-
Assert.assertEquals(8, writer.getPosition());
388-
// Check big-endian byte order
389-
long ptr = writer.getBufferPtr();
390-
Assert.assertEquals((byte) 0x01, Unsafe.getUnsafe().getByte(ptr));
391-
Assert.assertEquals((byte) 0x02, Unsafe.getUnsafe().getByte(ptr + 1));
392-
Assert.assertEquals((byte) 0x03, Unsafe.getUnsafe().getByte(ptr + 2));
393-
Assert.assertEquals((byte) 0x04, Unsafe.getUnsafe().getByte(ptr + 3));
394-
Assert.assertEquals((byte) 0x05, Unsafe.getUnsafe().getByte(ptr + 4));
395-
Assert.assertEquals((byte) 0x06, Unsafe.getUnsafe().getByte(ptr + 5));
396-
Assert.assertEquals((byte) 0x07, Unsafe.getUnsafe().getByte(ptr + 6));
397-
Assert.assertEquals((byte) 0x08, Unsafe.getUnsafe().getByte(ptr + 7));
398-
}
399-
});
400-
}
401-
402382
@Test
403383
public void testWriteNullString() throws Exception {
404384
assertMemoryLeak(() -> {

0 commit comments

Comments
 (0)