Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
optimize memory allocation of validity buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisStaratzis committed Jan 9, 2023
1 parent 4539473 commit d1f9dbb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@
<artifactId>joda-time</artifactId>
</dependency>

<!-- <dependency>-->
<!-- <groupId>org.slf4j</groupId>-->
<!-- <artifactId>slf4j-api</artifactId>-->
<!-- <version>2.0.5</version>-->
<!-- </dependency>-->

<!-- Trino SPI -->
<dependency>
<groupId>io.trino</groupId>
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/trino/plugin/tiledb/TileDBMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
import static io.trino.plugin.tiledb.TileDBColumnProperties.getExtent;
import static io.trino.plugin.tiledb.TileDBColumnProperties.getFilterList;
import static io.trino.plugin.tiledb.TileDBColumnProperties.getLowerBound;
import static io.trino.plugin.tiledb.TileDBColumnProperties.getNullable;
import static io.trino.plugin.tiledb.TileDBColumnProperties.getUpperBound;
import static io.trino.plugin.tiledb.TileDBErrorCode.TILEDB_CREATE_TABLE_ERROR;
import static io.trino.plugin.tiledb.TileDBModule.tileDBTypeFromTrinoType;
Expand Down Expand Up @@ -438,7 +437,7 @@ public TileDBOutputTableHandle beginCreateArray(ConnectorSession session, Connec
if (filterPairs.isPresent()) {
attribute.setFilterList(Util.createTileDBFilterList(localCtx, filterPairs.get()));
}
attribute.setNullable(getNullable(columnProperties));
attribute.setNullable(column.isNullable());
arraySchema.addAttribute(attribute);
}

Expand Down
13 changes: 10 additions & 3 deletions src/main/java/io/trino/plugin/tiledb/TileDBPageSink.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private void resetBuffers(Map<String, Pair<NativeArray, NativeArray>> buffers) t
buffers.clear();
query.resetBuffers();

validityMaps = new short[columnHandles.size()][maxBufferSize];
validityMaps = new short[columnHandles.size()][];
// Loop through each column
for (int channel = 0; channel < columnHandles.size(); channel++) {
// Datatype
Expand All @@ -195,9 +195,16 @@ private void resetBuffers(Map<String, Pair<NativeArray, NativeArray>> buffers) t
if (isVariableLength) {
offsets = new NativeArray(ctx, maxBufferSize, Datatype.TILEDB_UINT64);
}
if (!columnHandle.getIsDimension()) {
Arrays.fill(validityMaps[channel], (short) 1); // all valid

// allocate validity buffers for nullable attributes only.
if (array.getSchema().hasAttribute(columnName)) {
Attribute attribute = array.getSchema().getAttribute(columnHandle.getColumnName());
if (attribute.getNullable()) {
validityMaps[channel] = new short[maxBufferSize / type.getNativeSize()]; //allocate for the max amount of values
Arrays.fill(validityMaps[channel], (short) 1); // all valid
}
}

buffers.put(columnName, new Pair<>(offsets, values));
}
}
Expand Down

0 comments on commit d1f9dbb

Please sign in to comment.