Skip to content

Commit

Permalink
update parameterized test (step 1) for jdbc
Browse files Browse the repository at this point in the history
  • Loading branch information
llama90 committed Jun 8, 2024
1 parent 1512c4f commit b9edf08
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
import org.apache.arrow.vector.types.pojo.ArrowType;
import org.apache.arrow.vector.util.ValueVectorUtility;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
Expand Down Expand Up @@ -98,7 +96,6 @@ protected static Table getTable(String ymlFilePath, @SuppressWarnings("rawtypes"
* @throws SQLException on error
* @throws ClassNotFoundException on error
*/
@BeforeEach
public void setUp() throws SQLException, ClassNotFoundException {
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
String url = "jdbc:h2:mem:JdbcToArrowTest";
Expand Down Expand Up @@ -149,11 +146,11 @@ public static Object[][] prepareTestData(String[] testFiles, @SuppressWarnings("
/**
* Abstract method to implement test Functionality to test JdbcToArrow methods.
*
* @param table Table object
* @throws SQLException on error
* @throws IOException on error
*/
@Test
public abstract void testJdbcToArrowValues() throws SQLException, IOException;
public abstract void testJdbcToArrowValues(Table table) throws SQLException, IOException, ClassNotFoundException;

/**
* Abstract method to implement logic to assert test various datatype values.
Expand Down Expand Up @@ -377,5 +374,4 @@ protected Function<JdbcFieldInfo, ArrowType> jdbcToArrowTypeConverter(
protected ResultSetMetaData getQueryMetaData(String query) throws SQLException {
return conn.createStatement().executeQuery(query).getMetaData();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.sql.Statement;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.stream.Stream;

import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest;
import org.apache.arrow.adapter.jdbc.JdbcToArrowConfig;
Expand All @@ -40,17 +40,15 @@
import org.apache.arrow.vector.VarCharVector;
import org.apache.arrow.vector.VectorSchemaRoot;
import org.apache.arrow.vector.types.pojo.Schema;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

/**
* 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[] testFiles = {
Expand All @@ -60,28 +58,12 @@ public class JdbcToArrowCharSetTest extends AbstractJdbcToArrowTest {
"h2/test1_charset_kr_h2.yml"
};

/**
* Constructor which populates the table object for each test iteration.
*
* @param table Table oject
*/
public JdbcToArrowCharSetTest(Table table) {
this.table = table;
}

/**
* This method creates Connection object and DB table and also populate data into table for test.
*
* @throws SQLException on error
* @throws ClassNotFoundException on error
*/
@BeforeEach
@Override
public void setUp() throws SQLException, ClassNotFoundException {
private void initializeDatabase(Table table) throws SQLException, ClassNotFoundException {
String url = "jdbc:h2:mem:JdbcToArrowTest?characterEncoding=UTF-8";
String driver = "org.h2.Driver";
Class.forName(driver);
conn = DriverManager.getConnection(url);
this.table = table;
try (Statement stmt = conn.createStatement();) {
stmt.executeUpdate(table.getCreate());
for (String insert : table.getData()) {
Expand All @@ -98,18 +80,18 @@ public void setUp() throws SQLException, ClassNotFoundException {
* @throws ClassNotFoundException on error
* @throws IOException on error
*/
@Parameters
public static Collection<Object[]> getTestData() throws SQLException, ClassNotFoundException, IOException {
return Arrays.asList(prepareTestData(testFiles, JdbcToArrowCharSetTest.class));
public static Stream<Arguments> getTestData() throws SQLException, ClassNotFoundException, IOException {
return Arrays.stream(prepareTestData(testFiles, JdbcToArrowCharSetTest.class)).map(Arguments::of);
}

/**
* Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes with UTF-8 Charset, including
* the multi-byte CJK characters.
*/
@Test
@Override
public void testJdbcToArrowValues() throws SQLException, IOException {
@ParameterizedTest
@MethodSource("getTestData")
public void testJdbcToArrowValues(Table table) throws SQLException, IOException, ClassNotFoundException {
initializeDatabase(table);
testDataSets(sqlToArrow(conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE),
Calendar.getInstance()), false);
testDataSets(sqlToArrow(conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE)), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.stream.Stream;

import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest;
import org.apache.arrow.adapter.jdbc.JdbcToArrowConfig;
Expand All @@ -66,15 +66,14 @@
import org.apache.arrow.vector.complex.ListVector;
import org.apache.arrow.vector.types.pojo.Schema;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

/**
* 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)
public class JdbcToArrowDataTypesTest extends AbstractJdbcToArrowTest {

private static final String BIGINT = "big_int";
Expand Down Expand Up @@ -119,15 +118,6 @@ public class JdbcToArrowDataTypesTest extends AbstractJdbcToArrowTest {
"h2/test1_null_h2.yml"
};

/**
* Constructor which populates the table object for each test iteration.
*
* @param table Table object
*/
public JdbcToArrowDataTypesTest(Table table) {
this.table = table;
}

/**
* Get the test data as a collection of Table objects for each test iteration.
*
Expand All @@ -136,17 +126,16 @@ public JdbcToArrowDataTypesTest(Table table) {
* @throws ClassNotFoundException on error
* @throws IOException on error
*/
@Parameters
public static Collection<Object[]> getTestData() throws SQLException, ClassNotFoundException, IOException {
return Arrays.asList(prepareTestData(testFiles, JdbcToArrowDataTypesTest.class));
public static Stream<Arguments> getTestData() throws SQLException, ClassNotFoundException, IOException {
return Arrays.stream(prepareTestData(testFiles, JdbcToArrowMapDataTypeTest.class)).map(Arguments::of);
}

/**
* Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes.
*/
@Test
@Override
public void testJdbcToArrowValues() throws SQLException, IOException {
@ParameterizedTest
@MethodSource("getTestData")
public void testJdbcToArrowValues(Table table) throws SQLException, IOException {
testDataSets(sqlToArrow(conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE),
Calendar.getInstance()), false);
testDataSets(sqlToArrow(conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE)), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,34 @@
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.stream.Stream;

import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest;
import org.apache.arrow.adapter.jdbc.JdbcToArrowConfigBuilder;
import org.apache.arrow.adapter.jdbc.Table;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.VectorSchemaRoot;
import org.apache.arrow.vector.complex.MapVector;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

/**
* Test MapConsumer with OTHER jdbc type.
*/
public class JdbcToArrowMapDataTypeTest extends AbstractJdbcToArrowTest {

public JdbcToArrowMapDataTypeTest() throws IOException {
this.table = getTable("h2/test1_map_h2.yml", JdbcToArrowMapDataTypeTest.class);
public static Stream<Arguments> getTestData() throws IOException {
return Stream.of(Arguments.of(getTable("h2/test1_map_h2.yml", JdbcToArrowMapDataTypeTest.class)));
}

/**
* Test Method to test JdbcToArrow Functionality for Map form Types.OTHER column
*/
@Test
@Override
public void testJdbcToArrowValues() throws SQLException, IOException {
@ParameterizedTest
@MethodSource("getTestData")
public void testJdbcToArrowValues(Table table) throws SQLException, IOException {
this.table = getTable("h2/test1_map_h2.yml", JdbcToArrowMapDataTypeTest.class);
Calendar calendar = Calendar.getInstance();
ResultSetMetaData rsmd = getQueryMetaData(table.getQuery());
testDataSets(sqlToArrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.stream.Stream;

import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest;
import org.apache.arrow.adapter.jdbc.JdbcToArrowConfig;
Expand All @@ -77,15 +77,14 @@
import org.apache.arrow.vector.complex.MapVector;
import org.apache.arrow.vector.types.pojo.Schema;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

/**
* JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with null values for
* H2 database.
*/
@RunWith(Parameterized.class)
public class JdbcToArrowNullTest extends AbstractJdbcToArrowTest {

private static final String NULL = "null";
Expand All @@ -98,15 +97,6 @@ public class JdbcToArrowNullTest extends AbstractJdbcToArrowTest {
"h2/test1_all_datatypes_selected_null_rows_h2.yml"
};

/**
* Constructor which populates the table object for each test iteration.
*
* @param table Table object
*/
public JdbcToArrowNullTest(Table table) {
this.table = table;
}

/**
* Get the test data as a collection of Table objects for each test iteration.
*
Expand All @@ -115,17 +105,16 @@ public JdbcToArrowNullTest(Table table) {
* @throws ClassNotFoundException on error
* @throws IOException on error
*/
@Parameters
public static Collection<Object[]> getTestData() throws SQLException, ClassNotFoundException, IOException {
return Arrays.asList(prepareTestData(testFiles, JdbcToArrowNullTest.class));
public static Stream<Arguments> getTestData() throws SQLException, ClassNotFoundException, IOException {
return Arrays.stream(prepareTestData(testFiles, JdbcToArrowNullTest.class)).map(Arguments::of);
}

/**
* Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes with null values.
*/
@Test
@Override
public void testJdbcToArrowValues() throws SQLException, IOException {
@ParameterizedTest
@MethodSource("getTestData")
public void testJdbcToArrowValues(Table table) throws SQLException, IOException {
testDataSets(sqlToArrow(conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE),
Calendar.getInstance()), false);
testDataSets(sqlToArrow(conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE)), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,26 @@
import java.io.IOException;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Stream;

import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest;
import org.apache.arrow.adapter.jdbc.JdbcToArrowTestHelper;
import org.apache.arrow.adapter.jdbc.Table;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.VectorSchemaRoot;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

/**
* JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality for
* (non-)optional columns, in particular with regard to the ensuing VectorSchemaRoot's schema.
*/
@RunWith(Parameterized.class)
public class JdbcToArrowOptionalColumnsTest extends AbstractJdbcToArrowTest {
private static final String[] testFiles = {
"h2/test1_null_and_notnull.yml"
};

/**
* Constructor which populates the table object for each test iteration.
*
* @param table Table object
*/
public JdbcToArrowOptionalColumnsTest(Table table) {
this.table = table;
}

/**
* Get the test data as a collection of Table objects for each test iteration.
*
Expand All @@ -61,17 +51,16 @@ public JdbcToArrowOptionalColumnsTest(Table table) {
* @throws ClassNotFoundException on error
* @throws IOException on error
*/
@Parameterized.Parameters
public static Collection<Object[]> getTestData() throws SQLException, ClassNotFoundException, IOException {
return Arrays.asList(prepareTestData(testFiles, JdbcToArrowOptionalColumnsTest.class));
public static Stream<Arguments> getTestData() throws SQLException, ClassNotFoundException, IOException {
return Arrays.stream(prepareTestData(testFiles, JdbcToArrowOptionalColumnsTest.class)).map(Arguments::of);
}

/**
* Test Method to test JdbcToArrow Functionality for dealing with nullable and non-nullable columns.
*/
@Test
@Override
public void testJdbcToArrowValues() throws SQLException, IOException {
@ParameterizedTest
@MethodSource("getTestData")
public void testJdbcToArrowValues(Table table) throws SQLException, IOException {
testDataSets(sqlToArrow(conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE)), false);
}

Expand Down
Loading

0 comments on commit b9edf08

Please sign in to comment.