Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 52 additions & 14 deletions java/adapter/jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<artifactId>arrow-memory</artifactId>
<version>${project.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.arrow/arrow-vector -->
<dependency>
<groupId>org.apache.arrow</groupId>
Expand All @@ -41,14 +42,14 @@
<version>${dep.guava.version}</version>
</dependency>


<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${dep.junit.version}</version>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
<dependency>
<groupId>com.h2database</groupId>
Expand Down Expand Up @@ -83,18 +84,55 @@

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<user.timezone>UTC</user.timezone>
</systemPropertyVariables>
</configuration>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<executions>
<!-- Prepares property pointing to JaCoCo runtime agent which is passed as VM argument when Surefire is executed. -->
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
<!--Sets the name of the property containing the settings for JaCoCo runtime agent. -->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!--Ensures that the code coverage report for unit tests is created after unit tests have been run. -->
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<includeTests>true</includeTests>
<outputDirectory>${project.build.directory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<user.timezone>UTC</user.timezone>
</systemPropertyVariables>
<!-- Sets the VM argument line used when unit tests are run. -->
<argLine>${surefireArgLine}</argLine>
</configuration>
</plugin>
</plugins>
</build>

</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.arrow.vector.VectorSchemaRoot;
import org.junit.After;
import org.junit.Before;

import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

Expand All @@ -36,41 +36,6 @@
public abstract class AbstractJdbcToArrowTest {
protected Connection conn = null;
protected Table table;
protected void createTestData(Connection conn, Table table) throws Exception {
Statement stmt = null;
try {
//create the table and insert the data and once done drop the table
stmt = conn.createStatement();
stmt.executeUpdate(table.getCreate());

for (String insert: table.getData()) {
stmt.executeUpdate(insert);
}

} catch (Exception e) {
e.printStackTrace();
} finally {
if (stmt != null) {
stmt.close();
}
}

}

protected void deleteTestData(Connection conn, Table table) throws Exception {
Statement stmt = null;
try {
stmt = conn.createStatement();
stmt.executeUpdate(table.getDrop());

} catch (Exception e) {
e.printStackTrace();
} finally {
if (stmt != null) {
stmt.close();
}
}
}

/**
* This method creates Table object after reading YAML file
Expand Down Expand Up @@ -130,4 +95,19 @@ public static Object[][] prepareTestData(String[] testFiles, Class clss) throws
}
return tableArr;
}

/**
* Abstract method to implement test Functionality to test JdbcToArrow methods
* @throws SQLException
* @throws IOException
*/
@Test
public abstract void testJdbcToArroValues() throws SQLException, IOException;

/**
* Abstract method to implement logic to assert test various datatype values
* @param root
*/
public abstract void testDataSets(VectorSchemaRoot root);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package org.apache.arrow.adapter.jdbc;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.util.Arrays;
Expand All @@ -38,7 +37,6 @@
import org.apache.arrow.vector.VarBinaryVector;
import org.apache.arrow.vector.VarCharVector;

import static org.apache.arrow.adapter.jdbc.JdbcToArrowTestHelper.hexStringToByteArray;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -249,7 +247,7 @@ public static byte[] hexStringToByteArray(String s) {
return valueArr;
}

public static byte [][] getCharArrayWithCharSet(String[] values, String dataType, Charset charSet) throws UnsupportedEncodingException {
public static byte [][] getCharArrayWithCharSet(String[] values, String dataType, Charset charSet) {
String[] dataArr= getValues(values, dataType);
byte [][] valueArr = new byte [dataArr.length][];
int i =0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.apache.arrow.adapter.jdbc.JdbcToArrowTestHelper.assertVarcharVectorValues;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.sql.DriverManager;
import java.sql.SQLException;
Expand All @@ -43,6 +42,12 @@

import static org.apache.arrow.adapter.jdbc.JdbcToArrowTestHelper.getCharArrayWithCharSet;

/**
*
* JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with UTF-8 Charset, including
* the multi-byte CJK characters for H2 database
*
*/
@RunWith(Parameterized.class)
public class JdbcToArrowCharSetTest extends AbstractJdbcToArrowTest {
private static final String VARCHAR = "VARCHAR_FIELD13";
Expand Down Expand Up @@ -94,60 +99,27 @@ public void setUp() throws SQLException, ClassNotFoundException {
public static Collection<Object[]> getTestData() throws SQLException, ClassNotFoundException, IOException {
return Arrays.asList(prepareTestData(testFiles, JdbcToArrowCharSetTest.class));
}

/**
* This method tests Chars, Varchars and Clob data with UTF-8 charset
* @throws SQLException
* @throws IOException
* @throws ClassNotFoundException
*/
@Test
public void testCharSetBasedData() throws SQLException, IOException, ClassNotFoundException {
try (VectorSchemaRoot root = JdbcToArrow.sqlToArrow(conn, table.getQuery(),
new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance())) {

testDataSets(root);
}
}

/**
* This method tests Chars, Varchars and Clob data with UTF-8 charset using ResultSet
* @throws SQLException
* @throws IOException
* @throws ClassNotFoundException
*/

@Test
public void testCharSetDataUsingResultSet() throws SQLException, IOException, ClassNotFoundException {
try (Statement stmt = conn.createStatement();
VectorSchemaRoot root = JdbcToArrow.sqlToArrow(stmt.executeQuery(table.getQuery()),
Calendar.getInstance())) {
testDataSets(root);
}
}

/**
* This method tests Chars, Varchars and Clob data with UTF-8 charset using ResultSet and Allocator
* @throws SQLException
* @throws IOException
* @throws ClassNotFoundException
* Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes with UTF-8 Charset, including
* the multi-byte CJK characters
*/

@Test
public void testCharSetDataUsingResultSetAndAllocator() throws SQLException, IOException, ClassNotFoundException {
try (Statement stmt = conn.createStatement();
VectorSchemaRoot root = JdbcToArrow.sqlToArrow(stmt.executeQuery(table.getQuery()),
new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance())) {

testDataSets(root);
}
public void testJdbcToArroValues() throws SQLException, IOException {
testDataSets(JdbcToArrow.sqlToArrow(conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()));
testDataSets(JdbcToArrow.sqlToArrow(conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE)));
testDataSets(JdbcToArrow.sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), new RootAllocator(Integer.MAX_VALUE),
Calendar.getInstance()));
testDataSets(JdbcToArrow.sqlToArrow(conn.createStatement().executeQuery(table.getQuery())));
testDataSets(JdbcToArrow.sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), new RootAllocator(Integer.MAX_VALUE)));
testDataSets(JdbcToArrow.sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), Calendar.getInstance()));
}

/**
* This method calls the assert methods for various DataSets
* @param root
*/
public void testDataSets(VectorSchemaRoot root) throws UnsupportedEncodingException{
public void testDataSets(VectorSchemaRoot root) {
assertVarcharVectorValues((VarCharVector) root.getVector(CLOB), table.getRowCount(),
getCharArrayWithCharSet(table.getValues(), CLOB, StandardCharsets.UTF_8));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.junit.runners.Parameterized.Parameters;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
Expand All @@ -63,7 +62,8 @@

/**
*
* JUnit Test class to test various datatypes converted into Arrow vector for H2 database
* JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with various data types for H2 database
* using multiple test data files
*
*/
@RunWith(Parameterized.class)
Expand Down Expand Up @@ -128,47 +128,17 @@ public static Collection<Object[]> getTestData() throws SQLException, ClassNotFo
}

/**
* This method tests various datatypes converted into Arrow vector for H2 database
* @throws SQLException
* @throws IOException
* Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes
*/
@Test
public void testDBValues() throws SQLException, IOException {
try (VectorSchemaRoot root = JdbcToArrow.sqlToArrow(conn, table.getQuery(),
new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance())) {
testDataSets(root);

}
}

/**
* This method tests various datatypes converted into Arrow vector for H2 database using ResultSet
* @throws SQLException
* @throws IOException
*/
@Test
public void testDBValuesUsingResultSet() throws SQLException, IOException {
try (Statement stmt = conn.createStatement();
VectorSchemaRoot root = JdbcToArrow.sqlToArrow(stmt.executeQuery(table.getQuery()),
Calendar.getInstance())) {

testDataSets(root);
}
}

/**
* This method tests various datatypes converted into Arrow vector for H2 database using ResultSet And Allocator
* @throws SQLException
* @throws IOException
*/
@Test
public void testDBValuesUsingResultSetAndAllocator() throws SQLException, IOException {
try (Statement stmt = conn.createStatement();
VectorSchemaRoot root = JdbcToArrow.sqlToArrow(stmt.executeQuery(table.getQuery()),
new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance())) {

testDataSets(root);
}
public void testJdbcToArroValues() throws SQLException, IOException {
testDataSets(JdbcToArrow.sqlToArrow(conn, table.getQuery(),new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()));
testDataSets(JdbcToArrow.sqlToArrow(conn, table.getQuery(),new RootAllocator(Integer.MAX_VALUE)));
testDataSets(JdbcToArrow.sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), new RootAllocator(Integer.MAX_VALUE),
Calendar.getInstance()));
testDataSets(JdbcToArrow.sqlToArrow(conn.createStatement().executeQuery(table.getQuery())));
testDataSets(JdbcToArrow.sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), new RootAllocator(Integer.MAX_VALUE)));
testDataSets(JdbcToArrow.sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), Calendar.getInstance()));
}

/**
Expand Down
Loading