use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class TestVoltTable method testJSONRoundTrip.
@SuppressWarnings("deprecation")
public void testJSONRoundTrip() throws JSONException, IOException {
VoltTable t1 = new VoltTable(new ColumnInfo("tinyint", VoltType.TINYINT), new ColumnInfo("smallint", VoltType.SMALLINT), new ColumnInfo("integer", VoltType.INTEGER), new ColumnInfo("bigint", VoltType.BIGINT), new ColumnInfo("float", VoltType.FLOAT), new ColumnInfo("string", VoltType.STRING), new ColumnInfo("varbinary", VoltType.VARBINARY), new ColumnInfo("timestamp", VoltType.TIMESTAMP), new ColumnInfo("decimal", VoltType.DECIMAL));
// add a row of nulls the hard way
t1.addRow(VoltType.NULL_TINYINT, VoltType.NULL_SMALLINT, VoltType.NULL_INTEGER, VoltType.NULL_BIGINT, VoltType.NULL_FLOAT, VoltType.NULL_STRING_OR_VARBINARY, VoltType.NULL_STRING_OR_VARBINARY, VoltType.NULL_TIMESTAMP, VoltType.NULL_DECIMAL);
// add a row of nulls the easy way
t1.addRow(null, null, null, null, null, null, null, null, null);
// add a row with NaN
t1.addRow(null, null, null, null, Double.NaN, null, null, null, null);
// add a row with +inf
t1.addRow(null, null, null, null, Double.POSITIVE_INFINITY, null, null, null, null);
// add a row with all defaults
t1.addRow(VoltType.NULL_TINYINT, VoltType.NULL_SMALLINT, VoltType.NULL_INTEGER, VoltType.NULL_BIGINT, VoltType.NULL_FLOAT, VoltType.NULL_STRING_OR_VARBINARY, VoltType.NULL_STRING_OR_VARBINARY, VoltType.NULL_TIMESTAMP, VoltType.NULL_DECIMAL);
// add a row of actual data
t1.addRow(123, 12345, 1234567, 12345678901L, 1.234567, "aabbcc", new byte[] { 10, 26, 10 }, new TimestampType(System.currentTimeMillis()), new BigDecimal("123.45"));
String json = t1.toJSONString();
VoltTable t2 = VoltTable.fromJSONString(json);
assertTrue(t1.equals(t2));
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class TestVoltType method testTimestampStringRoundTrip.
public void testTimestampStringRoundTrip() {
String[] date_str = { "1900-01-01", "2000-02-03", "2100-04-05", "2012-12-31", "2001-10-25" };
for (int ii = 0; ii < date_str.length; ++ii) {
try {
String str = new TimestampType(date_str[ii]).toString();
assertEquals(date_str[ii] + " 00:00:00.000000", str);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class TestVoltTable method testRowGet.
public void testRowGet() {
byte b1 = (byte) 1;
short s1 = (short) 2;
int i1 = 3;
long l1 = Long.MIN_VALUE + 1;
double f1 = 3.5;
String S1 = "A";
TimestampType d1 = new TimestampType(0);
BigDecimal B1 = new BigDecimal(7654321).setScale(VoltDecimalHelper.kDefaultScale);
// create a table with one column per supported type with NULLS on the
// left to right diagonal.
// tinyint is intentionally first AND last to test that wasNull is
// correctly cleared by the
// the next-to-last instance and re-initialized by tinyint.
Object[] content = { b1, S1, i1, l1, f1, s1, d1, B1, b1 };
Object[] nulls = { VoltType.NULL_TINYINT, VoltType.NULL_STRING_OR_VARBINARY, VoltType.NULL_INTEGER, VoltType.NULL_BIGINT, VoltType.NULL_FLOAT, VoltType.NULL_SMALLINT, VoltType.NULL_TIMESTAMP, VoltType.NULL_DECIMAL, VoltType.NULL_TINYINT };
VoltType[] types = { VoltType.TINYINT, VoltType.STRING, VoltType.INTEGER, VoltType.BIGINT, VoltType.FLOAT, VoltType.SMALLINT, VoltType.TIMESTAMP, VoltType.DECIMAL, VoltType.TINYINT };
VoltTable tt = new VoltTable(new ColumnInfo("tinyint", types[0]), new ColumnInfo("string", types[1]), new ColumnInfo("integer", types[2]), new ColumnInfo("bigint", types[3]), new ColumnInfo("float", types[4]), new ColumnInfo("smallint", types[5]), new ColumnInfo("timestamp", types[6]), new ColumnInfo("decimal", types[7]), new ColumnInfo("tinyint", types[0]));
for (int i = 0; i < content.length; ++i) {
Object[] vals = new Object[content.length];
;
for (int k = 0; k < content.length; k++) {
if (i == k)
vals[k] = nulls[k];
else
vals[k] = content[k];
}
System.out.println("Adding row: " + i);
tt.addRow(vals);
}
// now iterate all the fields in the table and verify that row.get(idx,
// type)
// works and that the wasNull state is correctly set and cleared.
System.out.println(tt);
int rowcounter = 0;
while (tt.advanceRow()) {
for (int k = 0; k < content.length; k++) {
System.out.println("verifying row:" + rowcounter + " col:" + k);
if (rowcounter == k) {
boolean result = comparisonHelper(nulls[k], tt.get(k, types[k]), types[k]);
assertTrue(result);
assertTrue(tt.wasNull());
} else {
Object got = tt.get(k, types[k]);
System.out.println("Type: " + types[k]);
System.out.println("Expecting: " + content[k]);
System.out.println("Got: " + got);
assertTrue(comparisonHelper(content[k], got, types[k]));
assertFalse(tt.wasNull());
}
}
rowcounter++;
}
assertEquals(rowcounter, content.length);
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class TestVoltType method testTimestampToStringBeforeEpoch.
public void testTimestampToStringBeforeEpoch() {
long micros = -48932323284323L;
TimeZone tz = TimeZone.getTimeZone("America/New_York");
TimestampType beforeEpoch = new TimestampType(micros);
String answer = beforeEpoch.toString(tz);
assertEquals("1968-06-13 11:41:16.715677", answer);
assertEquals(micros, beforeEpoch.getTime());
// test Long.MIN as NULL_TimestampType
// NULL_TimestampType is translated to VoltType.NULL_BIGINT in
// @see org.voltdb.ParameterSet#flattenToBuffer()
beforeEpoch = new TimestampType(VoltType.NULL_BIGINT);
answer = beforeEpoch.toString(tz);
assertEquals("290303-12-10 14:59:05.224192", answer);
assertEquals(VoltType.NULL_BIGINT, beforeEpoch.getTime());
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class TestVoltType method testTimestampEquality.
/* Compare some values that differ by microseconds and by full millis */
public void testTimestampEquality() {
TimestampType ts1 = new TimestampType(150000);
TimestampType ts2 = new TimestampType(150000);
TimestampType ts3 = new TimestampType(150001);
TimestampType ts4 = new TimestampType(160000);
assertTrue(ts1.equals(ts2));
assertTrue(ts2.equals(ts1));
assertFalse(ts1.equals(ts3));
assertFalse(ts3.equals(ts1));
assertFalse(ts1.equals(ts4));
assertFalse(ts4.equals(ts1));
assertTrue(ts1.compareTo(ts2) == 0);
assertTrue(ts2.compareTo(ts1) == 0);
assertTrue(ts1.compareTo(ts3) < 0);
assertTrue(ts3.compareTo(ts1) > 0);
assertTrue(ts1.compareTo(ts4) < 0);
assertTrue(ts4.compareTo(ts1) > 0);
String micro = "2011-06-24 10:30:26.123012";
String milli = "2011-06-24 10:30:26.123";
TimestampType microTs = new TimestampType(micro);
TimestampType milliTs = new TimestampType(milli);
Date fromString = new Date(TimestampType.millisFromJDBCformat(milli.toString()));
Date fromMillis = new Date(milliTs.getTime() / 1000);
assertEquals(fromString, fromMillis);
java.sql.Date sqlFromString = new java.sql.Date(TimestampType.millisFromJDBCformat(milliTs.toString()));
java.sql.Date sqlFromMillis = new java.sql.Date(milliTs.getTime() / 1000);
assertEquals(sqlFromString, sqlFromMillis);
boolean caught = false;
caught = false;
try {
// Date string inputs converted from TimestampType should not have sub-millisecond granularity.
new Date(TimestampType.millisFromJDBCformat(microTs.toString()));
} catch (IllegalArgumentException ex) {
caught = true;
}
assertTrue(caught);
caught = false;
try {
// Date string inputs converted from TimestampType should not have sub-millisecond granularity.
new java.sql.Date(TimestampType.millisFromJDBCformat(microTs.toString()));
} catch (IllegalArgumentException ex) {
caught = true;
}
assertTrue(caught);
}
Aggregations