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;
}
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);
}
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);
}
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();
}
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;
}
}
Aggregations