// Create table
String statements = "CREATE TABLE IF NOT EXISTS "
+ DATATYPE_TABLE +
" (CKEY VARCHAR NOT NULL PRIMARY KEY," +
" CVARCHAR VARCHAR, CINTEGER INTEGER, CDECIMAL DECIMAL(31,10), CUNSIGNED_INT UNSIGNED_INT, CBOOLEAN BOOLEAN, CBIGINT BIGINT, CUNSIGNED_LONG UNSIGNED_LONG, CTIME TIME, CDATE DATE);";
PhoenixConnection conn = DriverManager.getConnection(getUrl()).unwrap(PhoenixConnection.class);
PhoenixRuntime.executeStatements(conn, new StringReader(statements), null);
// Upsert CSV file
CSVLoader csvUtil = new CSVLoader(conn, DATATYPE_TABLE, Collections.<String>emptyList(), true);
CSVReader reader = new CSVReader(new StringReader(DATATYPES_CSV_VALUES));
csvUtil.upsert(reader);
// Compare Phoenix ResultSet with CSV file content
PreparedStatement statement = conn
.prepareStatement("SELECT CKEY, CVARCHAR, CINTEGER, CDECIMAL, CUNSIGNED_INT, CBOOLEAN, CBIGINT, CUNSIGNED_LONG, CTIME, CDATE FROM "
+ DATATYPE_TABLE);
ResultSet phoenixResultSet = statement.executeQuery();
reader = new CSVReader(new StringReader(DATATYPES_CSV_VALUES));
reader.readNext();
String[] csvData;
while ((csvData = reader.readNext()) != null) {
assertTrue (phoenixResultSet.next());
for (int i=0; i<csvData.length - 2; i++) {
assertEquals(csvData[i], phoenixResultSet.getObject(i+1).toString().toUpperCase());
}
// special case for matching date, time values
assertEquals(DateUtil.parseTime(csvData[8]), phoenixResultSet.getTime("CTIME"));
assertEquals(DateUtil.parseDate(csvData[9]), phoenixResultSet.getDate("CDATE"));
}
assertFalse(phoenixResultSet.next());
conn.close();
}