}
}
@Test
public void testAllDatatypes() throws Exception {
CSVParser parser = null;
PhoenixConnection conn = null;
try {
// 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);";
conn = DriverManager.getConnection(getUrl())
.unwrap(PhoenixConnection.class);
PhoenixRuntime.executeStatements(conn,
new StringReader(statements), null);
// Upsert CSV file
CSVCommonsLoader csvUtil = new CSVCommonsLoader(conn,
DATATYPE_TABLE, Collections.<String> emptyList(), true);
csvUtil.upsert(new StringReader(DATATYPES_CSV_VALUES));
// 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();
parser = new CSVParser(new StringReader(DATATYPES_CSV_VALUES),
csvUtil.getFormat());
for (CSVRecord record : parser) {
assertTrue(phoenixResultSet.next());
int i = 0;
int size = record.size();
for (String value : record) {
assertEquals(value, phoenixResultSet.getObject(i + 1)
.toString().toUpperCase());
if (i < size - 2)
break;
i++;
}
// special case for matching date, time values
assertEquals(DateUtil.parseTime(record.get(8)),
phoenixResultSet.getTime("CTIME"));
assertEquals(DateUtil.parseDate(record.get(9)),
phoenixResultSet.getDate("CDATE"));
}
assertFalse(phoenixResultSet.next());
} finally {
if (parser != null)
parser.close();
if (conn != null)
conn.close();
}
}