Search in sources :

Example 61 with Timestamp

use of java.sql.Timestamp in project hazelcast by hazelcast.

the class QueryNullIndexingTest method queryIndexedDateFieldAsNullValue.

private List<Long> queryIndexedDateFieldAsNullValue(boolean ordered, Predicate pred) {
    HazelcastInstance instance = createHazelcastInstance();
    IMap<Integer, SampleObjects.Employee> map = instance.getMap("default");
    map.addIndex("date", ordered);
    for (int i = 10; i >= 1; i--) {
        Employee employee = new Employee(i, "name-" + i, i, true, i * 100);
        if (i % 2 == 0) {
            employee.setDate(new Timestamp(i * 1000000));
        } else {
            employee.setDate(null);
        }
        map.put(i, employee);
    }
    List<Long> dates = new ArrayList<Long>();
    for (SampleObjects.Employee employee : map.values(pred)) {
        Timestamp date = employee.getDate();
        dates.add(date == null ? null : date.getTime());
    }
    return dates;
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) SampleObjects(com.hazelcast.query.SampleObjects) Employee(com.hazelcast.query.SampleObjects.Employee) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp)

Example 62 with Timestamp

use of java.sql.Timestamp in project presto by prestodb.

the class TestRow method testRowFromString.

@Test
public void testRowFromString() throws Exception {
    Row expected = new Row();
    expected.addField(new Field(AccumuloRowSerializer.getBlockFromArray(VARCHAR, ImmutableList.of("a", "b", "c")), new ArrayType(VARCHAR)));
    expected.addField(true, BOOLEAN);
    expected.addField(new Field(new Date(TimeUnit.MILLISECONDS.toDays(new GregorianCalendar(1999, 0, 1).getTime().getTime())), DATE));
    expected.addField(123.45678, DOUBLE);
    expected.addField(new Field(123.45678f, REAL));
    expected.addField(12345678, INTEGER);
    expected.addField(new Field(12345678L, BIGINT));
    expected.addField(new Field((short) 12345, SMALLINT));
    expected.addField(new GregorianCalendar(1999, 0, 1, 12, 30, 0).getTime().getTime(), TIME);
    expected.addField(new Field(new Timestamp(new GregorianCalendar(1999, 0, 1, 12, 30, 0).getTime().getTime()), TIMESTAMP));
    expected.addField((byte) 123, TINYINT);
    expected.addField(new Field("O'Leary".getBytes(UTF_8), VARBINARY));
    expected.addField("O'Leary", VARCHAR);
    expected.addField(null, VARCHAR);
    RowSchema schema = new RowSchema();
    schema.addRowId("a", new ArrayType(VARCHAR));
    schema.addColumn("b", Optional.of("b"), Optional.of("b"), BOOLEAN);
    schema.addColumn("c", Optional.of("c"), Optional.of("c"), DATE);
    schema.addColumn("d", Optional.of("d"), Optional.of("d"), DOUBLE);
    schema.addColumn("e", Optional.of("e"), Optional.of("e"), REAL);
    schema.addColumn("f", Optional.of("f"), Optional.of("f"), INTEGER);
    schema.addColumn("g", Optional.of("g"), Optional.of("g"), BIGINT);
    schema.addColumn("h", Optional.of("h"), Optional.of("h"), SMALLINT);
    schema.addColumn("i", Optional.of("i"), Optional.of("i"), TIME);
    schema.addColumn("j", Optional.of("j"), Optional.of("j"), TIMESTAMP);
    schema.addColumn("k", Optional.of("k"), Optional.of("k"), TINYINT);
    schema.addColumn("l", Optional.of("l"), Optional.of("l"), VARBINARY);
    schema.addColumn("m", Optional.of("m"), Optional.of("m"), VARCHAR);
    schema.addColumn("n", Optional.of("n"), Optional.of("n"), VARCHAR);
    Row actual = Row.fromString(schema, "a,b,c|true|1999-01-01|123.45678|123.45678|12345678|12345678|12345|12:30:00|1999-01-01 12:30:00.0|123|O'Leary|O'Leary|", '|');
    assertEquals(actual, expected);
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) GregorianCalendar(java.util.GregorianCalendar) Timestamp(java.sql.Timestamp) Date(java.sql.Date) Test(org.testng.annotations.Test)

Example 63 with Timestamp

use of java.sql.Timestamp in project presto by prestodb.

the class TestRow method testRow.

@Test
public void testRow() throws Exception {
    Row r1 = new Row();
    r1.addField(new Field(AccumuloRowSerializer.getBlockFromArray(VARCHAR, ImmutableList.of("a", "b", "c")), new ArrayType(VARCHAR)));
    r1.addField(true, BOOLEAN);
    r1.addField(new Field(new Date(new GregorianCalendar(1999, 0, 1).getTime().getTime()), DATE));
    r1.addField(123.45678, DOUBLE);
    r1.addField(new Field(123.45678f, REAL));
    r1.addField(12345678, INTEGER);
    r1.addField(new Field(12345678L, BIGINT));
    r1.addField(new Field((short) 12345, SMALLINT));
    r1.addField(new GregorianCalendar(1999, 0, 1, 12, 30, 0).getTime().getTime(), TIME);
    r1.addField(new Field(new Timestamp(new GregorianCalendar(1999, 0, 1, 12, 30, 0).getTime().getTime()), TIMESTAMP));
    r1.addField((byte) 123, TINYINT);
    r1.addField(new Field("O'Leary".getBytes(UTF_8), VARBINARY));
    r1.addField("O'Leary", VARCHAR);
    r1.addField(null, VARCHAR);
    assertEquals(r1.length(), 14);
    assertEquals(r1.toString(), "(ARRAY ['a','b','c'],true,DATE '1999-01-01',123.45678,123.45678,12345678,12345678,12345,TIME '12:30:00',TIMESTAMP '1999-01-01 12:30:00.0',123,CAST('O''Leary' AS VARBINARY),'O''Leary',null)");
    Row r2 = new Row(r1);
    assertEquals(r2, r1);
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) GregorianCalendar(java.util.GregorianCalendar) Timestamp(java.sql.Timestamp) Date(java.sql.Date) Test(org.testng.annotations.Test)

Example 64 with Timestamp

use of java.sql.Timestamp in project presto by prestodb.

the class GenericHiveRecordCursor method getLongExpressedValue.

private static long getLongExpressedValue(Object value, DateTimeZone hiveTimeZone) {
    if (value instanceof Date) {
        long storageTime = ((Date) value).getTime();
        // convert date from VM current time zone to UTC
        long utcMillis = storageTime + DateTimeZone.getDefault().getOffset(storageTime);
        return TimeUnit.MILLISECONDS.toDays(utcMillis);
    }
    if (value instanceof Timestamp) {
        // The Hive SerDe parses timestamps using the default time zone of
        // this JVM, but the data might have been written using a different
        // time zone. We need to convert it to the configured time zone.
        // the timestamp that Hive parsed using the JVM time zone
        long parsedJvmMillis = ((Timestamp) value).getTime();
        // remove the JVM time zone correction from the timestamp
        DateTimeZone jvmTimeZone = DateTimeZone.getDefault();
        long hiveMillis = jvmTimeZone.convertUTCToLocal(parsedJvmMillis);
        // convert to UTC using the real time zone for the underlying data
        long utcMillis = hiveTimeZone.convertLocalToUTC(hiveMillis, false);
        return utcMillis;
    }
    if (value instanceof Float) {
        return floatToRawIntBits(((Float) value));
    }
    return ((Number) value).longValue();
}
Also used : Timestamp(java.sql.Timestamp) Date(java.sql.Date) DateTimeZone(org.joda.time.DateTimeZone)

Example 65 with Timestamp

use of java.sql.Timestamp in project flink by apache.

the class SqlTimestampSerializer method deserialize.

@Override
public Timestamp deserialize(DataInputView source) throws IOException {
    final long v = source.readLong();
    if (v == Long.MIN_VALUE) {
        return null;
    } else {
        final Timestamp t = new Timestamp(v);
        t.setNanos(source.readInt());
        return t;
    }
}
Also used : Timestamp(java.sql.Timestamp)

Aggregations

Timestamp (java.sql.Timestamp)1539 PreparedStatement (java.sql.PreparedStatement)265 Test (org.junit.Test)245 SQLException (java.sql.SQLException)236 ResultSet (java.sql.ResultSet)209 BigDecimal (java.math.BigDecimal)204 Date (java.util.Date)165 Date (java.sql.Date)122 Connection (java.sql.Connection)117 ArrayList (java.util.ArrayList)109 Calendar (java.util.Calendar)76 Test (org.testng.annotations.Test)71 GregorianCalendar (java.util.GregorianCalendar)68 Time (java.sql.Time)65 SimpleDateFormat (java.text.SimpleDateFormat)62 Change (com.google.gerrit.reviewdb.client.Change)59 IOException (java.io.IOException)51 BaseTest (util.BaseTest)49 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)45 Properties (java.util.Properties)41