Skip to content

Commit 872e0c7

Browse files
committed
optimizations
1 parent cdd00e6 commit 872e0c7

5 files changed

Lines changed: 805 additions & 468 deletions

File tree

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

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ class QwpColumnWriter {
4646
private final QwpGorillaEncoder gorillaEncoder = new QwpGorillaEncoder();
4747
private QwpBufferWriter buffer;
4848

49-
private void encodeColumn(QwpTableBuffer.ColumnBuffer col, QwpColumnDef colDef, int rowCount, boolean useGorilla, boolean useGlobalSymbols) {
50-
int valueCount = col.getValueCount();
49+
private void encodeColumn(
50+
QwpTableBuffer.ColumnBuffer col,
51+
QwpColumnDef colDef,
52+
int rowCount,
53+
int valueCount,
54+
long stringDataSize,
55+
int symbolDictionarySize,
56+
boolean useGorilla,
57+
boolean useGlobalSymbols
58+
) {
5159
long dataAddr = col.getDataAddress();
5260

5361
if (colDef.isNullable()) {
@@ -80,13 +88,13 @@ private void encodeColumn(QwpTableBuffer.ColumnBuffer col, QwpColumnDef colDef,
8088
break;
8189
case TYPE_STRING:
8290
case TYPE_VARCHAR:
83-
writeStringColumn(col, valueCount);
91+
writeStringColumn(col, valueCount, stringDataSize);
8492
break;
8593
case TYPE_SYMBOL:
8694
if (useGlobalSymbols) {
8795
writeSymbolColumnWithGlobalIds(col, valueCount);
8896
} else {
89-
writeSymbolColumn(col, valueCount);
97+
writeSymbolColumn(col, valueCount, symbolDictionarySize);
9098
}
9199
break;
92100
case TYPE_UUID:
@@ -118,8 +126,20 @@ private void encodeColumn(QwpTableBuffer.ColumnBuffer col, QwpColumnDef colDef,
118126
}
119127

120128
void encodeTable(QwpTableBuffer tableBuffer, boolean useSchemaRef, boolean useGlobalSymbols, boolean useGorilla) {
129+
encodeTable(tableBuffer, tableBuffer.getRowCount(), null, null, null, useSchemaRef, useGlobalSymbols, useGorilla);
130+
}
131+
132+
void encodeTable(
133+
QwpTableBuffer tableBuffer,
134+
int rowCount,
135+
int[] limitedValueCounts,
136+
long[] limitedStringDataSizes,
137+
int[] limitedSymbolDictionarySizes,
138+
boolean useSchemaRef,
139+
boolean useGlobalSymbols,
140+
boolean useGorilla
141+
) {
121142
QwpColumnDef[] columnDefs = tableBuffer.getColumnDefs();
122-
int rowCount = tableBuffer.getRowCount();
123143

124144
if (useSchemaRef) {
125145
writeTableHeaderWithSchemaRef(
@@ -135,7 +155,17 @@ void encodeTable(QwpTableBuffer tableBuffer, boolean useSchemaRef, boolean useGl
135155
for (int i = 0; i < tableBuffer.getColumnCount(); i++) {
136156
QwpTableBuffer.ColumnBuffer col = tableBuffer.getColumn(i);
137157
QwpColumnDef colDef = columnDefs[i];
138-
encodeColumn(col, colDef, rowCount, useGorilla, useGlobalSymbols);
158+
int valueCount = col.getValueCount();
159+
long stringDataSize = col.getStringDataSize();
160+
int symbolDictionarySize = col.getSymbolDictionarySize();
161+
162+
if (limitedValueCounts != null && limitedValueCounts[i] > -1) {
163+
valueCount = limitedValueCounts[i];
164+
stringDataSize = limitedStringDataSizes[i];
165+
symbolDictionarySize = limitedSymbolDictionarySizes[i];
166+
}
167+
168+
encodeColumn(col, colDef, rowCount, valueCount, stringDataSize, symbolDictionarySize, useGorilla, useGlobalSymbols);
139169
}
140170
}
141171

@@ -261,18 +291,16 @@ private void writeNullBitmap(QwpTableBuffer.ColumnBuffer col, int rowCount) {
261291
}
262292
}
263293

264-
private void writeStringColumn(QwpTableBuffer.ColumnBuffer col, int valueCount) {
294+
private void writeStringColumn(QwpTableBuffer.ColumnBuffer col, int valueCount, long stringDataSize) {
265295
buffer.putBlockOfBytes(col.getStringOffsetsAddress(), (long) (valueCount + 1) * 4);
266-
buffer.putBlockOfBytes(col.getStringDataAddress(), col.getStringDataSize());
296+
buffer.putBlockOfBytes(col.getStringDataAddress(), stringDataSize);
267297
}
268298

269-
private void writeSymbolColumn(QwpTableBuffer.ColumnBuffer col, int count) {
299+
private void writeSymbolColumn(QwpTableBuffer.ColumnBuffer col, int count, int dictionarySize) {
270300
long dataAddr = col.getDataAddress();
271-
String[] dictionary = col.getSymbolDictionary();
272-
273-
buffer.putVarint(dictionary.length);
274-
for (String symbol : dictionary) {
275-
buffer.putString(symbol);
301+
buffer.putVarint(dictionarySize);
302+
for (int i = 0; i < dictionarySize; i++) {
303+
buffer.putString((String) col.getSymbolValue(i));
276304
}
277305

278306
for (int i = 0; i < count; i++) {

0 commit comments

Comments
 (0)