diff --git a/java/adapter/jdbc/pom.xml b/java/adapter/jdbc/pom.xml index 5a879247746..d8dd422ec68 100644 --- a/java/adapter/jdbc/pom.xml +++ b/java/adapter/jdbc/pom.xml @@ -29,6 +29,7 @@ arrow-memory ${project.version} + org.apache.arrow @@ -41,7 +42,6 @@ ${dep.guava.version} - junit @@ -49,6 +49,7 @@ ${dep.junit.version} test + com.h2database @@ -83,18 +84,55 @@ - - - - org.apache.maven.plugins - maven-surefire-plugin - - - UTC - - + + + + org.jacoco + jacoco-maven-plugin + 0.8.1 + + + + default-prepare-agent + + prepare-agent + + + + ${project.build.directory}/coverage-reports/jacoco-ut.exec + + surefireArgLine + + + + + post-unit-test + test + + report + + + + ${project.build.directory}/coverage-reports/jacoco-ut.exec + + true + ${project.build.directory}/jacoco-ut + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + UTC + + + ${surefireArgLine} + + + + - - - diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/AbstractJdbcToArrowTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/AbstractJdbcToArrowTest.java index eeea07ec477..2c76c178ea0 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/AbstractJdbcToArrowTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/AbstractJdbcToArrowTest.java @@ -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; @@ -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 @@ -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); + } diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowTestHelper.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowTestHelper.java index 6abfdff35fd..37580f0f2ea 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowTestHelper.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowTestHelper.java @@ -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; @@ -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; @@ -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; diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowCharSetTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowCharSetTest.java index 2184d127f70..db3620f38c7 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowCharSetTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowCharSetTest.java @@ -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; @@ -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"; @@ -94,60 +99,27 @@ public void setUp() throws SQLException, ClassNotFoundException { public static Collection 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)); diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowDataTypesTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowDataTypesTest.java index 303a772a1a2..c615d0b77d3 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowDataTypesTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowDataTypesTest.java @@ -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; @@ -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) @@ -128,47 +128,17 @@ public static Collection 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())); } /** diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowNullTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowNullTest.java index 883f8192558..4be27d9b46d 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowNullTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowNullTest.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.sql.SQLException; -import java.sql.Statement; import java.util.Arrays; import java.util.Calendar; import java.util.Collection; @@ -51,7 +50,7 @@ /** * - * JUnit Test class to test null values stored into Arrow vector for various datatypes for H2 database + * JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with null values for H2 database * */ @RunWith(Parameterized.class) @@ -86,48 +85,20 @@ public static Collection getTestData() throws SQLException, ClassNotFo } /** - * This method tests null values stored into Arrow vector for various datatypes for H2 database - * @throws SQLException - * @throws IOException - */ - @Test - public void testNullValues() throws SQLException, IOException { - try (VectorSchemaRoot root = JdbcToArrow.sqlToArrow(conn, table.getQuery(), - new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance())) { - - testDataSets(root); - } - } - - /** - * This method tests null values stored into Arrow vector for various datatypes for H2 database using ResultSet - * @throws SQLException - * @throws IOException + * Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes with null values */ @Test - public void testNullValuesUsingResultSet() throws SQLException, IOException { - try (Statement stmt = conn.createStatement(); - VectorSchemaRoot root = JdbcToArrow.sqlToArrow(stmt.executeQuery(table.getQuery()), - Calendar.getInstance())) { - testDataSets(root); - } - } - - /** - * This method tests null values stored into Arrow vector for various datatypes for H2 database using ResultSet And Allocator - * @throws SQLException - * @throws IOException - */ - @Test - public void testNullValuesUsingResultSetAndAllocator() 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())); } + /** * This method calls the assert methods for various DataSets * @param root diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTest.java index a854145746f..8e0606985ac 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTest.java @@ -43,7 +43,6 @@ import java.io.IOException; import java.sql.SQLException; -import java.sql.Statement; import java.util.Arrays; import java.util.Calendar; import java.util.Collection; @@ -72,6 +71,9 @@ import static org.apache.arrow.adapter.jdbc.JdbcToArrowTestHelper.getBinaryValues; /** + * + * JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with various data types for H2 database + * using single test data file * */ @RunWith(Parameterized.class) @@ -116,47 +118,20 @@ public JdbcToArrowTest(Table table) { public static Collection getTestData() throws SQLException, ClassNotFoundException, IOException { return Arrays.asList(prepareTestData(testFiles, JdbcToArrowTest.class)); } - - /** - * This method tests various datatypes converted into Arrow vector for H2 database - * @throws SQLException - * @throws IOException - */ - @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 Method to test JdbcToArrow Functionality for various H2 DB based datatypes with only one test data file + * */ @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())); } /** @@ -215,5 +190,5 @@ public void testDataSets(VectorSchemaRoot root) { assertFloat4VectorValues((Float4Vector) root.getVector(REAL), table.getRowCount(), getFloatValues(table.getValues(), REAL)); } - + } diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTimeZoneTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTimeZoneTest.java index 59700e30ab2..438a0228e7d 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTimeZoneTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTimeZoneTest.java @@ -23,7 +23,6 @@ import java.io.IOException; import java.sql.SQLException; -import java.sql.Statement; import java.util.Arrays; import java.util.Calendar; import java.util.Collection; @@ -43,9 +42,11 @@ /** * - * JUnit Test class to test TimeZone based Date, Time and Timestamp datatypes for H2 database + * JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with TimeZone based Date, + * Time and Timestamp datatypes for H2 database * */ + @RunWith(Parameterized.class) public class JdbcToArrowTimeZoneTest extends AbstractJdbcToArrowTest { @@ -92,47 +93,17 @@ public static Collection getTestData() throws SQLException, ClassNotFo } /** - * This method tests TimeZone based Date, Time and Timestamp datatypes for H2 database - * @throws SQLException - * @throws IOException - */ - @Test - public void testTimeZoneBasedValues() throws SQLException, IOException { - try (VectorSchemaRoot root = JdbcToArrow.sqlToArrow(conn, table.getQuery(), - new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone())))) { - - testDataSets(root); - } - } - - /** - * This method tests TimeZone based Date, Time and Timestamp datatypes for H2 database using ResultSet - * @throws SQLException - * @throws IOException - */ - @Test - public void testTimeZoneBasedValuesUsingResultSet() throws SQLException, IOException { - try (Statement stmt = conn.createStatement(); - VectorSchemaRoot root = JdbcToArrow.sqlToArrow(stmt.executeQuery(table.getQuery()), - Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone())))) { - - testDataSets(root); - } - } - - /** - * This method tests TimeZone based Date, Time and Timestamp datatypes for H2 database using ResultSet and Allocator - * @throws SQLException - * @throws IOException - */ + * Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes with TimeZone based Date, + * Time and Timestamp datatype + */ @Test - public void testTimeZoneBasedValuesUsingResultSetAndAllocator() throws SQLException, IOException { - try (Statement stmt = conn.createStatement(); - VectorSchemaRoot root = JdbcToArrow.sqlToArrow(stmt.executeQuery(table.getQuery()), new RootAllocator(Integer.MAX_VALUE), - Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone())))) { - - testDataSets(root); - } + public void testJdbcToArroValues() throws SQLException, IOException { + testDataSets(JdbcToArrow.sqlToArrow(conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE), + Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone())))); + testDataSets(JdbcToArrow.sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), new RootAllocator(Integer.MAX_VALUE), + Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone())))); + testDataSets(JdbcToArrow.sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), + Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone())))); } /**