use of com.facebook.presto.spi.type.Type in project presto by prestodb.
the class AbstractTestAccumuloRowSerializer method testSmallInt.
@Test
public void testSmallInt() throws Exception {
AccumuloRowSerializer serializer = serializerClass.getConstructor().newInstance();
Type type = SMALLINT;
Short expected = 12345;
byte[] data = serializer.encode(type, expected);
Short actual = ((Long) serializer.decode(type, data)).shortValue();
assertEquals(actual, expected);
deserializeData(serializer, data);
actual = serializer.getShort(COLUMN_NAME);
assertEquals(actual, expected);
}
use of com.facebook.presto.spi.type.Type in project presto by prestodb.
the class AbstractTestAccumuloRowSerializer method testInt.
@Test
public void testInt() throws Exception {
AccumuloRowSerializer serializer = serializerClass.getConstructor().newInstance();
Type type = INTEGER;
Integer expected = 123456;
byte[] data = serializer.encode(type, expected);
@SuppressWarnings("unchecked") Integer actual = ((Long) serializer.decode(type, data)).intValue();
assertEquals(actual, expected);
deserializeData(serializer, data);
actual = serializer.getInt(COLUMN_NAME);
assertEquals(actual, expected);
}
use of com.facebook.presto.spi.type.Type in project presto by prestodb.
the class AbstractTestAccumuloRowSerializer method testLong.
@Test
public void testLong() throws Exception {
AccumuloRowSerializer serializer = serializerClass.getConstructor().newInstance();
Type type = BIGINT;
Long expected = 123456L;
byte[] data = serializer.encode(type, expected);
Long actual = serializer.decode(type, data);
assertEquals(actual, expected);
deserializeData(serializer, data);
actual = serializer.getLong(COLUMN_NAME);
assertEquals(actual, expected);
}
use of com.facebook.presto.spi.type.Type in project presto by prestodb.
the class AbstractTestAccumuloRowSerializer method testDouble.
@Test
public void testDouble() throws Exception {
AccumuloRowSerializer serializer = serializerClass.getConstructor().newInstance();
Type type = DOUBLE;
Double expected = 123.45678;
byte[] data = serializer.encode(type, expected);
Double actual = serializer.decode(type, data);
assertEquals(actual, expected);
deserializeData(serializer, data);
actual = serializer.getDouble(COLUMN_NAME);
assertEquals(actual, expected);
}
use of com.facebook.presto.spi.type.Type in project presto by prestodb.
the class Row method fromString.
/**
* Creates a new {@link Row} from the given delimited string based on the given {@link RowSchema}
*
* @param schema Row's schema
* @param str String to parse
* @param delimiter Delimiter of the string
* @return A new Row
* @throws PrestoException If the length of the split string is not equal to the length of the schema
* @throws PrestoException If the schema contains an unsupported type
*/
public static Row fromString(RowSchema schema, String str, char delimiter) {
Row row = new Row();
ImmutableList.Builder<String> builder = ImmutableList.builder();
List<String> fields = builder.addAll(Splitter.on(delimiter).split(str)).build();
if (fields.size() != schema.getLength()) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Number of split tokens is not equal to schema length. Expected %s received %s. Schema: %s, fields {%s}, delimiter %s", schema.getLength(), fields.size(), schema, StringUtils.join(fields, ","), delimiter));
}
for (int i = 0; i < fields.size(); ++i) {
Type type = schema.getColumn(i).getType();
row.addField(valueFromString(fields.get(i), type), type);
}
return row;
}
Aggregations