use of org.apache.phoenix.schema.TypeMismatchException in project phoenix by apache.
the class ToDateFunctionIT method testTimestampCast.
@Test
public void testTimestampCast() throws SQLException {
Properties props = new Properties();
props.setProperty(QueryServices.DATE_FORMAT_TIMEZONE_ATTRIB, "GMT+1");
Connection customTimeZoneConn = DriverManager.getConnection(getUrl(), props);
assertEquals(1426188807198L, callToDateFunction(customTimeZoneConn, "CAST(1426188807198 AS TIMESTAMP)").getTime());
try {
callToDateFunction(customTimeZoneConn, "CAST(22005 AS TIMESTAMP)");
fail();
} catch (TypeMismatchException e) {
}
}
use of org.apache.phoenix.schema.TypeMismatchException in project phoenix by apache.
the class ToDateFunctionIT method testUnsignedLongToTimestampCast.
@Test
public void testUnsignedLongToTimestampCast() throws SQLException {
Properties props = new Properties();
props.setProperty(QueryServices.DATE_FORMAT_TIMEZONE_ATTRIB, "GMT+1");
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
try {
conn.prepareStatement("create table TT(" + "a unsigned_int not null, " + "b unsigned_int not null, " + "ts unsigned_long not null " + "constraint PK primary key (a, b, ts))").execute();
conn.commit();
conn.prepareStatement("upsert into TT values (0, 22120, 1426188807198)").execute();
conn.commit();
ResultSet rs = conn.prepareStatement("select a, b, ts, CAST(ts AS TIMESTAMP) from TT").executeQuery();
assertTrue(rs.next());
assertEquals(new Date(1426188807198L), rs.getObject(4));
rs.close();
try {
rs = conn.prepareStatement("select a, b, ts, CAST(b AS TIMESTAMP) from TT").executeQuery();
fail();
} catch (TypeMismatchException e) {
}
} finally {
conn.close();
}
}
Aggregations