use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class TestVoltBulkLoader method testBatchOptionAndGetsViolationsCommitByFlush.
//Test that gets constraint violations.
//has a batch that fully fails and 2 batches that has 50% failure.
public void testBatchOptionAndGetsViolationsCommitByFlush() throws Exception {
String mySchema = "create table BLAH (" + "clm_integer integer not null, " + // column that is partitioned on
"clm_tinyint tinyint default 0, " + "clm_smallint smallint default 0, " + "clm_bigint bigint default 0, " + "clm_string varchar(20) default null, " + "clm_decimal decimal default null, " + "clm_float float default null, " + "clm_timestamp timestamp default null, " + "clm_geo geography default null," + "clm_geopt geography_point default null, " + "PRIMARY KEY(clm_integer) " + "); ";
int myBatchSize = 200;
TimestampType currentTime = new TimestampType();
Object[][] myData = { { 1, 1, 1, 11111111, "first", 1.10, 1.11, currentTime, geo, geopt }, { 2, 1, 1, 11111111, "first", 1.10, 1.11, currentTime, geo, geopt }, { 3, 1, 1, 11111111, "first", 1.10, 1.11, currentTime, geo, geopt }, { 4, 1, 1, 11111111, "first", 1.10, 1.11, currentTime, geo, geopt }, //Whole batch fails
{ 1, 1, 1, 11111111, "first", 1.10, 1.11, currentTime, geo, geopt }, //Whole batch fails
{ 2, 1, 1, 11111111, "first", 1.10, 1.11, currentTime, geo, geopt }, { 5, 1, 1, 11111111, "first", 1.10, 1.11, currentTime, geo, geopt }, { 6, 1, 1, 11111111, "first", 1.10, 1.11, currentTime, geo, geopt }, //Whole batch fails
{ 1, 1, 1, 11111111, "first", 1.10, 1.11, currentTime, geo, geopt }, //Whole batch fails
{ 2, 1, 1, 11111111, "first", 1.10, 1.11, currentTime, geo, geopt }, { 7, 1, 1, 11111111, "first", 1.10, 1.11, currentTime, geo, geopt }, { 8, 1, 1, 11111111, "first", 1.10, 1.11, currentTime, geo, geopt }, { 11, 1, 1, 11111111, "first", 1.10, 1.11, currentTime, geo, geopt }, //Whole batch fails
{ 1, 1, 1, 11111111, "first", 1.10, 1.11, currentTime, geo, geopt }, //Whole batch fails
{ 2, 1, 1, 11111111, "first", 1.10, 1.11, currentTime, geo, geopt }, //Whole batch fails
{ 1, 1, 1, 11111111, "first", 1.10, 1.11, currentTime, geo, geopt }, { 12, 1, 1, 11111111, "first", 1.10, 1.11, currentTime, geo, geopt } };
Integer[] failures = { 5, 6, 9, 10, 14, 15, 16 };
ArrayList<Integer> expectedFailures = new ArrayList<Integer>(Arrays.asList(failures));
test_Interface(mySchema, myData, myBatchSize, expectedFailures, 3);
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class SerializationHelper method readArray.
public static Object readArray(final Class<?> type, ByteBuffer buf) throws IOException {
final int count = type == byte.class ? buf.getInt() : buf.getShort();
if (count < 0) {
throw new IOException("Array length is negative " + count);
} else if (type == byte.class) {
if (count > (VoltType.MAX_VALUE_LENGTH)) {
throw new IOException("Array length is greater then the max of 1 megabyte " + count);
}
if (count > buf.remaining()) {
throw new IOException("Array length is greater than total buffer " + count);
}
final byte[] retval = new byte[count];
buf.get(retval);
return retval;
} else if (type == byte[].class) {
final byte[][] retval = new byte[count][];
for (int i = 0; i < count; i++) {
int size = buf.getInt();
if (size == -1) {
// null length prefix
retval[i] = null;
} else {
retval[i] = new byte[size];
buf.get(retval[i]);
}
}
return retval;
} else if (type == short.class) {
final short[] retval = new short[count];
for (int i = 0; i < count; i++) {
retval[i] = buf.getShort();
}
return retval;
} else if (type == int.class) {
final int[] retval = new int[count];
for (int i = 0; i < count; i++) {
retval[i] = buf.getInt();
}
return retval;
} else if (type == long.class) {
final long[] retval = new long[count];
for (int i = 0; i < count; i++) {
retval[i] = buf.getLong();
}
return retval;
} else if (type == Long.class) {
final Long[] retval = new Long[count];
for (int i = 0; i < count; i++) {
retval[i] = buf.getLong();
}
return retval;
} else if (type == String.class) {
final String[] retval = new String[count];
for (int i = 0; i < count; i++) {
retval[i] = getString(buf);
}
return retval;
} else if (type == double.class) {
final double[] retval = new double[count];
for (int i = 0; i < count; i++) {
retval[i] = buf.getDouble();
}
return retval;
} else if (type == Double.class) {
final Double[] retval = new Double[count];
for (int i = 0; i < count; i++) {
retval[i] = buf.getDouble();
}
return retval;
} else if (type == TimestampType.class) {
final TimestampType[] retval = new TimestampType[count];
for (int i = 0; i < count; i++) {
retval[i] = new TimestampType(buf.getLong());
}
return retval;
} else if (type == BigDecimal.class) {
final BigDecimal[] retval = new BigDecimal[count];
for (int i = 0; i < count; ++i) {
retval[i] = getBigDecimal(buf);
}
return retval;
} else if (type == GeographyPointValue.class) {
final GeographyPointValue[] retval = new GeographyPointValue[count];
for (int i = 0; i < count; ++i) {
retval[i] = GeographyPointValue.unflattenFromBuffer(buf);
}
return retval;
} else if (type == GeographyValue.class) {
final GeographyValue[] retval = new GeographyValue[count];
for (int i = 0; i < count; ++i) {
// length prefix
int len = buf.getInt();
if (len == VoltType.NULL_STRING_LENGTH) {
retval[i] = null;
} else {
retval[i] = GeographyValue.unflattenFromBuffer(buf);
}
}
return retval;
} else if (type == VoltTable.class) {
final VoltTable[] retval = new VoltTable[count];
for (int i = 0; i < count; ++i) {
retval[i] = PrivateVoltTableFactory.createVoltTableFromSharedBuffer(buf.slice());
buf.position(buf.position() + retval[i].getSerializedSize());
}
return retval;
} else {
throw new RuntimeException("SerializationHelper.readArray called with unhandled type: " + type.getName());
}
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class VoltTableUtil method toCSVWriter.
public static void toCSVWriter(CSVWriter csv, VoltTable vt, List<VoltType> columnTypes) throws IOException {
final SimpleDateFormat sdf = m_sdf.get();
String[] fields = new String[vt.getColumnCount()];
while (vt.advanceRow()) {
for (int ii = 0; ii < vt.getColumnCount(); ii++) {
final VoltType type = columnTypes.get(ii);
if (type == VoltType.BIGINT || type == VoltType.INTEGER || type == VoltType.SMALLINT || type == VoltType.TINYINT) {
final long value = vt.getLong(ii);
if (vt.wasNull()) {
fields[ii] = Constants.CSV_NULL;
} else {
fields[ii] = Long.toString(value);
}
} else if (type == VoltType.FLOAT) {
final double value = vt.getDouble(ii);
if (vt.wasNull()) {
fields[ii] = Constants.CSV_NULL;
} else {
fields[ii] = Double.toString(value);
}
} else if (type == VoltType.DECIMAL) {
final BigDecimal bd = vt.getDecimalAsBigDecimal(ii);
if (vt.wasNull()) {
fields[ii] = Constants.CSV_NULL;
} else {
fields[ii] = bd.toString();
}
} else if (type == VoltType.STRING) {
final String str = vt.getString(ii);
if (vt.wasNull()) {
fields[ii] = Constants.CSV_NULL;
} else {
fields[ii] = str;
}
} else if (type == VoltType.TIMESTAMP) {
final TimestampType timestamp = vt.getTimestampAsTimestamp(ii);
if (vt.wasNull()) {
fields[ii] = Constants.CSV_NULL;
} else {
fields[ii] = sdf.format(timestamp.asApproximateJavaDate());
fields[ii] += String.format("%03d", timestamp.getUSec());
}
} else if (type == VoltType.VARBINARY) {
byte[] bytes = vt.getVarbinary(ii);
if (vt.wasNull()) {
fields[ii] = Constants.CSV_NULL;
} else {
fields[ii] = Encoder.hexEncode(bytes);
}
} else if (type == VoltType.GEOGRAPHY_POINT) {
final GeographyPointValue pt = vt.getGeographyPointValue(ii);
if (vt.wasNull()) {
fields[ii] = Constants.CSV_NULL;
} else {
fields[ii] = pt.toString();
}
} else if (type == VoltType.GEOGRAPHY) {
final GeographyValue gv = vt.getGeographyValue(ii);
if (vt.wasNull()) {
fields[ii] = Constants.CSV_NULL;
} else {
fields[ii] = gv.toString();
}
}
}
csv.writeNext(fields);
}
csv.flush();
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class VoltTypeUtil method getObjectFromString.
/**
* Returns a casted object of the input value string based on the given type
* @throws ParseException
*/
public static Object getObjectFromString(VoltType type, String value) throws ParseException {
Object ret = null;
switch(type) {
// --------------------------------
case TINYINT:
//break;
case SMALLINT:
//break;
case INTEGER:
//break;
case BIGINT:
ret = Long.valueOf(value);
break;
// --------------------------------
case FLOAT:
ret = Double.valueOf(value);
break;
// --------------------------------
case STRING:
ret = value;
break;
case DECIMAL:
case VARBINARY:
if (value != null) {
throw new RuntimeException("Only NULL default values for DECIMAL " + "and VARBINARY columns are supported right now");
}
break;
// --------------------------------
case TIMESTAMP:
{
// Support either long values (microseconds since epoch) or timestamp strings.
try {
// Try to parse it as a long first.
ret = new TimestampType(Long.parseLong(value));
} catch (NumberFormatException e) {
// It failed to parse as a long - parse it as a timestamp string.
Date date = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(value);
ret = new TimestampType(date.getTime() * 1000);
}
break;
}
// --------------------------------
default:
LOG.severe("ERROR: Unable to get object from string for invalid ValueType '" + type + "'");
}
return (ret);
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class TestVoltTable method testFormattedString.
public void testFormattedString() throws JSONException, IOException {
// Set the default timezone since we're using a timestamp type. Eliminate test flakeyness.
VoltDB.setDefaultTimezone();
VoltTable table = 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
table.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
table.addRow(null, null, null, null, null, null, null, null, null);
// add a row of actual data. Hard-code the timestamp so that we can compare deterministically
table.addRow(123, 12345, 1234567, 12345678901L, 1.234567, "aabbcc", new byte[] { 10, 26, 10 }, new TimestampType(99), new BigDecimal("123.45"));
String formattedOutput = table.toFormattedString();
String expectedOutput = "tinyint smallint integer bigint float string varbinary timestamp decimal \n" + "-------- --------- -------- ------------ --------- ------- ---------- --------------------------- -----------------\n" + " NULL NULL NULL NULL NULL NULL NULL NULL NULL\n" + " NULL NULL NULL NULL NULL NULL NULL NULL NULL\n" + " 123 12345 1234567 12345678901 1.234567 aabbcc 0A1A0A 1970-01-01 00:00:00.000099 123.450000000000\n";
assertExpectedOutput(expectedOutput, formattedOutput);
// fetch formatted output without column names
formattedOutput = table.toFormattedString(false);
expectedOutput = " NULL NULL NULL NULL NULL NULL NULL NULL NULL\n" + " NULL NULL NULL NULL NULL NULL NULL NULL NULL\n" + " 123 12345 1234567 12345678901 1.234567 aabbcc 0A1A0A 1970-01-01 00:00:00.000099 123.450000000000\n";
assertExpectedOutput(expectedOutput, formattedOutput);
table = new VoltTable(new ColumnInfo("bigint", VoltType.BIGINT), new ColumnInfo("geography", VoltType.GEOGRAPHY), new ColumnInfo("geography_point", VoltType.GEOGRAPHY_POINT), new ColumnInfo("timestamp", VoltType.TIMESTAMP));
table.addRow(VoltType.NULL_BIGINT, VoltType.NULL_GEOGRAPHY, VoltType.NULL_POINT, VoltType.NULL_TIMESTAMP);
table.addRow(null, null, null, null);
table.addRow(123456789, new GeographyValue("POLYGON (( 1.1 9.9, " + "-9.1 9.9, " + "-9.1 -9.9, " + " 9.1 -9.9, " + " 1.1 9.9))"), new GeographyPointValue(-179.0, -89.9), new TimestampType(-1));
formattedOutput = table.toFormattedString();
expectedOutput = "bigint geography geography_point timestamp \n" + "---------- ------------------------------------------------------------ --------------------- ---------------------------\n" + " NULL NULL NULL NULL \n" + " NULL NULL NULL NULL \n" + " 123456789 POLYGON ((1.1 9.9, -9.1 9.9, -9.1 -9.9, 9.1 -9.9, 1.1 9.9)) POINT (-179.0 -89.9) 1969-12-31 23:59:59.999999 \n";
assertExpectedOutput(expectedOutput, formattedOutput);
// row with a polygon that max's output column width for geopgraphy column
table.addRow(1234567890, new GeographyValue("POLYGON (( 179.1 89.9, " + "-179.1 89.9, " + "-179.1 -89.9, " + " 179.1 -89.9, " + " 179.1 89.9))"), new GeographyPointValue(-179.0, -89.9), new TimestampType(0));
formattedOutput = table.toFormattedString();
expectedOutput = "bigint geography geography_point timestamp \n" + "----------- --------------------------------------------------------------------------- --------------------- ---------------------------\n" + " NULL NULL NULL NULL \n" + " NULL NULL NULL NULL \n" + " 123456789 POLYGON ((1.1 9.9, -9.1 9.9, -9.1 -9.9, 9.1 -9.9, 1.1 9.9)) POINT (-179.0 -89.9) 1969-12-31 23:59:59.999999 \n" + " 1234567890 POLYGON ((179.1 89.9, -179.1 89.9, -179.1 -89.9, 179.1 -89.9, 179.1 89.9)) POINT (-179.0 -89.9) 1970-01-01 00:00:00.000000 \n";
assertExpectedOutput(expectedOutput, formattedOutput);
// row with a polygon that goes beyond max aligned display limit for polygon. This will result in
// other columns following to appear further away from their original column
table.addRow(12345678901L, new GeographyValue("POLYGON (( 179.12 89.9, " + "-179.12 89.9, " + "-179.1 -89.9, " + " 179.1 -89.9, " + " 0 0," + " 1.123 1.11," + " 179.12 89.9))"), new GeographyPointValue(0, 0), new TimestampType(99));
formattedOutput = table.toFormattedString();
expectedOutput = "bigint geography geography_point timestamp \n" + "------------ --------------------------------------------------------------------------- --------------------- ---------------------------\n" + " NULL NULL NULL NULL \n" + " NULL NULL NULL NULL \n" + " 123456789 POLYGON ((1.1 9.9, -9.1 9.9, -9.1 -9.9, 9.1 -9.9, 1.1 9.9)) POINT (-179.0 -89.9) 1969-12-31 23:59:59.999999 \n" + " 1234567890 POLYGON ((179.1 89.9, -179.1 89.9, -179.1 -89.9, 179.1 -89.9, 179.1 89.9)) POINT (-179.0 -89.9) 1970-01-01 00:00:00.000000 \n" + " 12345678901 POLYGON ((179.12 89.9, -179.12 89.9, -179.1 -89.9, 179.1 -89.9, 0.0 0.0, 1.123 1.11, 179.12 89.9)) POINT (0.0 0.0) 1970-01-01 00:00:00.000099 \n";
assertExpectedOutput(expectedOutput, formattedOutput);
// test the final one without column names
formattedOutput = table.toFormattedString(false);
expectedOutput = " NULL NULL NULL NULL \n" + " NULL NULL NULL NULL \n" + " 123456789 POLYGON ((1.1 9.9, -9.1 9.9, -9.1 -9.9, 9.1 -9.9, 1.1 9.9)) POINT (-179.0 -89.9) 1969-12-31 23:59:59.999999 \n" + " 1234567890 POLYGON ((179.1 89.9, -179.1 89.9, -179.1 -89.9, 179.1 -89.9, 179.1 89.9)) POINT (-179.0 -89.9) 1970-01-01 00:00:00.000000 \n" + " 12345678901 POLYGON ((179.12 89.9, -179.12 89.9, -179.1 -89.9, 179.1 -89.9, 0.0 0.0, 1.123 1.11, 179.12 89.9)) POINT (0.0 0.0) 1970-01-01 00:00:00.000099 \n";
assertExpectedOutput(expectedOutput, formattedOutput);
}
Aggregations