Skip to content

Commit

Permalink
fix: cleaning vector module v7
Browse files Browse the repository at this point in the history
  • Loading branch information
vibhatha committed Sep 13, 2024
1 parent 7c1d829 commit 003e1ab
Show file tree
Hide file tree
Showing 23 changed files with 167 additions and 135 deletions.
5 changes: 4 additions & 1 deletion java/c/src/test/java/org/apache/arrow/c/RoundtripTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.arrow.c;

import static org.apache.arrow.vector.complex.BaseRepeatedValueVector.DATA_VECTOR_NAME;
import static org.apache.arrow.vector.testing.ValueVectorDataPopulator.setVector;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -965,7 +966,9 @@ public void testImportReleasedArray() {
try (ArrowSchema arrowSchema = ArrowSchema.wrap(consumerArrowSchema.memoryAddress());
ArrowArray arrowArray = ArrowArray.wrap(consumerArrowArray.memoryAddress())) {
// Producer exports vector into the C Data Interface structures
try (final NullVector vector = new NullVector()) {
try (final NullVector vector =
new NullVector(
new Field(DATA_VECTOR_NAME, FieldType.nullable(new ArrowType.Null()), null))) {
Data.exportVector(allocator, vector, null, arrowArray, arrowSchema);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void run(String[] args) throws Exception {
System.out.println("\nExiting...");
AutoCloseables.close(server, allocator);
} catch (Exception e) {
e.printStackTrace();
LOGGER.error("Error during shutdown", e);
}
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ public Entry(StackTraceElement[] stackTrace, long size, boolean forAllocation) {

List<Entry> trail = new ArrayList<>();

@Override
public void onAllocation(long size) {
trail.add(new Entry(Thread.currentThread().getStackTrace(), size, true));
}

@Override
public void onRelease(long size) {
trail.add(new Entry(Thread.currentThread().getStackTrace(), size, false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ public void testShouldFailToPrepareStatementForBadStatement() {
*/
assertThat(
e.getMessage(),
is(format("Error while executing SQL \"%s\": Query not found", badQuery)));
is(
format(
"Error while executing SQL \"%s\": org.apache.arrow.flight.FlightRuntimeException: INVALID_ARGUMENT: Query not found",
badQuery)));
}
assertThat(count, is(1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public void testShouldGetStringMethodFromDecimalVector(Supplier<ValueVector> vec

@ParameterizedTest
@MethodSource("data")
@SuppressWarnings("BigDecimalEquals")
public void testShouldGetBooleanMethodFromDecimalVector(Supplier<ValueVector> vectorSupplier)
throws Exception {
setup(vectorSupplier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ public class Filter {

private final JniWrapper wrapper;
private final long moduleId;

@SuppressWarnings("UnusedVariable")
private final Schema schema;

private boolean closed;

private Filter(JniWrapper wrapper, long moduleId, Schema schema) {
Expand Down Expand Up @@ -98,7 +101,7 @@ public static Filter make(Schema schema, Condition condition, boolean optimize)
schema,
condition,
JniLoader.getConfiguration(
(new ConfigurationBuilder.ConfigOptions()).withOptimize(optimize)));
new ConfigurationBuilder.ConfigOptions().withOptimize(optimize)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import java.util.List;
import java.util.Locale;
import org.apache.arrow.vector.types.pojo.ArrowType;

/** POJO to define a function signature. */
Expand Down Expand Up @@ -58,11 +59,12 @@ public FunctionSignature(String name, ArrowType returnType, List<ArrowType> para
* @param signature - signature to compare
* @return true if equal and false if not.
*/
@Override
public boolean equals(Object signature) {
if (signature == null) {
return false;
}
if (getClass() != signature.getClass()) {
if (!(signature instanceof FunctionSignature)) {
return false;
}
final FunctionSignature other = (FunctionSignature) signature;
Expand All @@ -73,7 +75,8 @@ public boolean equals(Object signature) {

@Override
public int hashCode() {
return Objects.hashCode(this.name.toLowerCase(), this.returnType, this.paramTypes);
return Objects.hashCode(
this.name.toLowerCase(Locale.getDefault()), this.returnType, this.paramTypes);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ JniWrapper getWrapper() throws GandivaException {
static long getConfiguration(ConfigurationBuilder.ConfigOptions configOptions)
throws GandivaException {
if (!configurationMap.containsKey(configOptions)) {
synchronized (ConfigurationBuilder.class) {
synchronized (JniLoader.class) {
if (!configurationMap.containsKey(configOptions)) {
JniLoader.getInstance(); // setup
long configInstance = new ConfigurationBuilder().buildConfigInstance(configOptions);
Expand All @@ -150,7 +150,7 @@ static long getConfiguration(ConfigurationBuilder.ConfigOptions configOptions)
*/
static long getDefaultConfiguration() throws GandivaException {
if (defaultConfiguration == 0L) {
synchronized (ConfigurationBuilder.class) {
synchronized (JniLoader.class) {
if (defaultConfiguration == 0L) {
JniLoader.getInstance(); // setup
ConfigurationBuilder.ConfigOptions defaultConfigOptions =
Expand All @@ -167,10 +167,9 @@ static long getDefaultConfiguration() throws GandivaException {
/** Remove the configuration. */
static void removeConfiguration(ConfigurationBuilder.ConfigOptions configOptions) {
if (configurationMap.containsKey(configOptions)) {
synchronized (ConfigurationBuilder.class) {
synchronized (JniLoader.class) {
if (configurationMap.containsKey(configOptions)) {
(new ConfigurationBuilder())
.releaseConfigInstance(configurationMap.remove(configOptions));
new ConfigurationBuilder().releaseConfigInstance(configurationMap.remove(configOptions));
if (configOptions.equals(ConfigurationBuilder.ConfigOptions.getDefault())) {
defaultConfiguration = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public class Projector {

private JniWrapper wrapper;
private final long moduleId;

@SuppressWarnings("UnusedVariable")
private final Schema schema;

private final int numExprs;
private boolean closed;

Expand Down Expand Up @@ -108,7 +111,7 @@ public static Projector make(Schema schema, List<ExpressionTree> exprs, boolean
exprs,
SelectionVectorType.SV_NONE,
JniLoader.getConfiguration(
(new ConfigurationBuilder.ConfigOptions()).withOptimize(optimize)));
new ConfigurationBuilder.ConfigOptions().withOptimize(optimize)));
}

/**
Expand Down Expand Up @@ -173,7 +176,7 @@ public static Projector make(
exprs,
selectionVectorType,
JniLoader.getConfiguration(
(new ConfigurationBuilder.ConfigOptions()).withOptimize(optimize)));
new ConfigurationBuilder.ConfigOptions().withOptimize(optimize)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public final int getRecordCount() {
* Set the number of records in the selection vector.
*/
final void setRecordCount(int recordCount) {
if (recordCount * getRecordSize() > buffer.capacity()) {
if ((long) recordCount * getRecordSize() > buffer.capacity()) {
throw new IllegalArgumentException(
"recordCount "
+ recordCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public SelectionVectorType getType() {
public int getIndex(int index) {
checkReadBounds(index);

char value = getBuffer().getChar(index * getRecordSize());
return (int) value;
return getBuffer().getChar((long) index * getRecordSize());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public SelectionVectorType getType() {
public int getIndex(int index) {
checkReadBounds(index);

return getBuffer().getInt(index * getRecordSize());
return getBuffer().getInt((long) index * getRecordSize());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public GandivaException(String msg, Exception cause) {

@Override
public String toString() {
return getMessage();
return this.getMessage();
}

@Override
public String getMessage() {
return super.getMessage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
*/
package org.apache.arrow.gandiva.evaluator;

import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -51,7 +54,7 @@ interface BaseEvaluator {
long getElapsedMillis();
}

class ProjectEvaluator implements BaseEvaluator {
static class ProjectEvaluator implements BaseEvaluator {

private Projector projector;
private DataAndVectorGenerator generator;
Expand Down Expand Up @@ -97,9 +100,9 @@ public long getElapsedMillis() {
}
}

class FilterEvaluator implements BaseEvaluator {
static class FilterEvaluator implements BaseEvaluator {

private Filter filter;
private final Filter filter;
private long elapsedTime = 0;

public FilterEvaluator(Filter filter) {
Expand All @@ -109,7 +112,7 @@ public FilterEvaluator(Filter filter) {
@Override
public void evaluate(ArrowRecordBatch recordBatch, BufferAllocator allocator)
throws GandivaException {
ArrowBuf selectionBuffer = allocator.buffer(recordBatch.getLength() * 2);
ArrowBuf selectionBuffer = allocator.buffer(recordBatch.getLength() * 2L);
SelectionVectorInt16 selectionVector = new SelectionVectorInt16(selectionBuffer);

try {
Expand All @@ -135,7 +138,7 @@ interface DataAndVectorGenerator {
ValueVector generateOutputVector(int numRowsInBatch);
}

class Int32DataAndVectorGenerator implements DataAndVectorGenerator {
static class Int32DataAndVectorGenerator implements DataAndVectorGenerator {

protected final BufferAllocator allocator;
protected final Random rand;
Expand All @@ -158,7 +161,7 @@ public ValueVector generateOutputVector(int numRowsInBatch) {
}
}

class BoundedInt32DataAndVectorGenerator extends Int32DataAndVectorGenerator {
static class BoundedInt32DataAndVectorGenerator extends Int32DataAndVectorGenerator {

private final int upperBound;

Expand Down Expand Up @@ -222,7 +225,7 @@ ArrowBuf arrowBufWithAllValid(int size) {
}

ArrowBuf intBuf(int[] ints) {
ArrowBuf buffer = allocator.buffer(ints.length * 4);
ArrowBuf buffer = allocator.buffer(ints.length * 4L);
for (int i = 0; i < ints.length; i++) {
buffer.writeInt(ints[i]);
}
Expand Down Expand Up @@ -255,45 +258,45 @@ VarCharVector varcharVector(String[] values) {
VarCharVector vector = new VarCharVector("VarCharVector" + Math.random(), allocator);
vector.allocateNew();
for (int i = 0; i < values.length; i++) {
vector.setSafe(i, values[i].getBytes(), 0, values[i].length());
vector.setSafe(i, values[i].getBytes(StandardCharsets.UTF_8), 0, values[i].length());
}

vector.setValueCount(values.length);
return vector;
}

ArrowBuf longBuf(long[] longs) {
ArrowBuf buffer = allocator.buffer(longs.length * 8);
for (int i = 0; i < longs.length; i++) {
buffer.writeLong(longs[i]);
ArrowBuf buffer = allocator.buffer(longs.length * 8L);
for (long aLong : longs) {
buffer.writeLong(aLong);
}
return buffer;
}

ArrowBuf doubleBuf(double[] data) {
ArrowBuf buffer = allocator.buffer(data.length * 8);
for (int i = 0; i < data.length; i++) {
buffer.writeDouble(data[i]);
ArrowBuf buffer = allocator.buffer(data.length * 8L);
for (double datum : data) {
buffer.writeDouble(datum);
}

return buffer;
}

ArrowBuf stringToMillis(String[] dates) {
ArrowBuf buffer = allocator.buffer(dates.length * 8);
for (int i = 0; i < dates.length; i++) {
Instant instant = Instant.parse(dates[i]);
ArrowBuf buffer = allocator.buffer(dates.length * 8L);
for (String date : dates) {
Instant instant = Instant.parse(date);
buffer.writeLong(instant.toEpochMilli());
}

return buffer;
}

ArrowBuf stringToDayInterval(String[] values) {
ArrowBuf buffer = allocator.buffer(values.length * 8);
for (int i = 0; i < values.length; i++) {
buffer.writeInt(Integer.parseInt(values[i].split(" ")[0])); // days
buffer.writeInt(Integer.parseInt(values[i].split(" ")[1])); // millis
ArrowBuf buffer = allocator.buffer(values.length * 8L);
for (String value : values) {
buffer.writeInt(Integer.parseInt(Iterables.get(Splitter.on(' ').split(value), 0))); // days
buffer.writeInt(Integer.parseInt(Iterables.get(Splitter.on(' ').split(value), 1))); // millis
}
return buffer;
}
Expand Down Expand Up @@ -342,7 +345,7 @@ private void generateDataAndEvaluate(

// generate data
for (int i = 0; i < numFields; i++) {
ArrowBuf buf = allocator.buffer(numRowsInBatch * inputFieldSize);
ArrowBuf buf = allocator.buffer((long) numRowsInBatch * inputFieldSize);
ArrowBuf validity = arrowBufWithAllValid(maxRowsInBatch);
generateData(generator, numRowsInBatch, buf);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
Expand All @@ -47,12 +48,11 @@ private int[] selectionVectorToArray(SelectionVector vector) {
return actual;
}

private Charset utf8Charset = Charset.forName("UTF-8");
private Charset utf16Charset = Charset.forName("UTF-16");
private final Charset utf8Charset = StandardCharsets.UTF_8;

List<ArrowBuf> varBufs(String[] strings, Charset charset) {
ArrowBuf offsetsBuffer = allocator.buffer((strings.length + 1) * 4);
ArrowBuf dataBuffer = allocator.buffer(strings.length * 8);
ArrowBuf offsetsBuffer = allocator.buffer((strings.length + 1) * 4L);
ArrowBuf dataBuffer = allocator.buffer(strings.length * 8L);

int startOffset = 0;
for (int i = 0; i < strings.length; i++) {
Expand Down
Loading

0 comments on commit 003e1ab

Please sign in to comment.