Search in sources :

Example 1 with TypeMismatchException

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) {
    }
}
Also used : TypeMismatchException(org.apache.phoenix.schema.TypeMismatchException) Properties(java.util.Properties) Test(org.junit.Test)

Example 2 with TypeMismatchException

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();
    }
}
Also used : TypeMismatchException(org.apache.phoenix.schema.TypeMismatchException) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

Properties (java.util.Properties)2 TypeMismatchException (org.apache.phoenix.schema.TypeMismatchException)2 Test (org.junit.Test)2