Skip to content

Commit

Permalink
Merge pull request apache#35 from rafael-telles/to-string-array-jdbc-…
Browse files Browse the repository at this point in the history
…review

Implement toString method for JdbcArray class
  • Loading branch information
jcralmeida authored Apr 22, 2022
2 parents f24ef45 + c1e0cc3 commit e2fee64
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Arrays;
import java.util.Map;

import org.apache.arrow.driver.jdbc.accessor.impl.complex.AbstractArrowFlightJdbcListVectorAccessor;
Expand All @@ -30,6 +31,7 @@
import org.apache.arrow.vector.ValueVector;
import org.apache.arrow.vector.VectorSchemaRoot;
import org.apache.arrow.vector.types.pojo.ArrowType;
import org.apache.arrow.vector.util.JsonStringArrayList;
import org.apache.arrow.vector.util.TransferPair;

/**
Expand Down Expand Up @@ -160,4 +162,17 @@ public ResultSet getResultSet(long index, int count, Map<String, Class<?>> map)
public void free() {

}

@Override
public String toString() {
JsonStringArrayList<Object> array = new JsonStringArrayList<>((int) this.valuesCount);

try {
array.addAll(Arrays.asList((Object[]) getArray()));
} catch (SQLException e) {
throw new RuntimeException(e);
}

return array.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Types;
import java.util.Arrays;
import java.util.HashMap;

import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestRule;
import org.apache.arrow.vector.IntVector;
import org.apache.arrow.vector.util.JsonStringArrayList;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -142,6 +144,17 @@ public void testShouldGetResultSetReturnValidResultSetWithOffsets() throws SQLEx
}
}

@Test
public void testToString() throws SQLException {
ArrowFlightJdbcArray arrowFlightJdbcArray =
new ArrowFlightJdbcArray(dataVector, 0, dataVector.getValueCount());

JsonStringArrayList<Object> array = new JsonStringArrayList<>();
array.addAll(Arrays.asList((Object[]) arrowFlightJdbcArray.getArray()));

Assert.assertEquals(array.toString(), arrowFlightJdbcArray.toString());
}

@Test(expected = SQLFeatureNotSupportedException.class)
public void testShouldGetResultSetWithMapNotBeSupported() throws SQLException {
ArrowFlightJdbcArray arrowFlightJdbcArray =
Expand Down

0 comments on commit e2fee64

Please sign in to comment.