use of com.facebook.presto.spi.type.Type in project presto by prestodb.
the class AbstractTestAccumuloRowSerializer method testArray.
@Test
public void testArray() throws Exception {
AccumuloRowSerializer serializer = serializerClass.getConstructor().newInstance();
Type type = new ArrayType(VARCHAR);
List<Object> expected = ImmutableList.of("a", "b", "c");
byte[] data = serializer.encode(type, AccumuloRowSerializer.getBlockFromArray(VARCHAR, expected));
List<Object> actual = serializer.decode(type, data);
assertEquals(actual, expected);
deserializeData(serializer, data);
actual = AccumuloRowSerializer.getArrayFromBlock(VARCHAR, serializer.getArray(COLUMN_NAME, type));
assertEquals(actual, expected);
}
use of com.facebook.presto.spi.type.Type in project presto by prestodb.
the class Indexer method index.
/**
* Index the given mutation, adding mutations to the index and metrics table
* <p>
* Like typical use of a BatchWriter, this method does not flush mutations to the underlying index table.
* For higher throughput the modifications to the metrics table are tracked in memory and added to the metrics table when the indexer is flushed or closed.
*
* @param mutation Mutation to index
*/
public void index(Mutation mutation) {
// Increment the cardinality for the number of rows in the table
metrics.get(METRICS_TABLE_ROW_COUNT).incrementAndGet();
// Set the first and last row values of the table based on existing row IDs
if (firstRow == null || byteArrayComparator.compare(mutation.getRow(), firstRow) < 0) {
firstRow = mutation.getRow();
}
if (lastRow == null || byteArrayComparator.compare(mutation.getRow(), lastRow) > 0) {
lastRow = mutation.getRow();
}
// For each column update in this mutation
for (ColumnUpdate columnUpdate : mutation.getUpdates()) {
// Get the column qualifiers we want to index for this column family (if any)
ByteBuffer family = wrap(columnUpdate.getColumnFamily());
Collection<ByteBuffer> indexQualifiers = indexColumns.get(family);
// If we have column qualifiers we want to index for this column family
if (indexQualifiers != null) {
// Check if we want to index this particular qualifier
ByteBuffer qualifier = wrap(columnUpdate.getColumnQualifier());
if (indexQualifiers.contains(qualifier)) {
// If so, create a mutation using the following mapping:
// Row ID = column value
// Column Family = columnqualifier_columnfamily
// Column Qualifier = row ID
// Value = empty
ByteBuffer indexFamily = getIndexColumnFamily(columnUpdate.getColumnFamily(), columnUpdate.getColumnQualifier());
Type type = indexColumnTypes.get(family).get(qualifier);
ColumnVisibility visibility = new ColumnVisibility(columnUpdate.getColumnVisibility());
// If this is an array type, then index each individual element in the array
if (Types.isArrayType(type)) {
Type elementType = Types.getElementType(type);
List<?> elements = serializer.decode(type, columnUpdate.getValue());
for (Object element : elements) {
addIndexMutation(wrap(serializer.encode(elementType, element)), indexFamily, visibility, mutation.getRow());
}
} else {
addIndexMutation(wrap(columnUpdate.getValue()), indexFamily, visibility, mutation.getRow());
}
}
}
}
}
use of com.facebook.presto.spi.type.Type in project presto by prestodb.
the class AccumuloRecordCursor method getObject.
@Override
public Object getObject(int field) {
Type type = getType(field);
checkArgument(Types.isArrayType(type) || Types.isMapType(type), "Expected field %s to be a type of array or map but is %s", field, type);
if (Types.isArrayType(type)) {
return serializer.getArray(fieldToColumnName[field], type);
}
return serializer.getMap(fieldToColumnName[field], type);
}
use of com.facebook.presto.spi.type.Type in project presto by prestodb.
the class TestField method testDouble.
@Test
public void testDouble() throws Exception {
Type type = DOUBLE;
Double expected = 123.45678;
Field f1 = new Field(expected, type);
assertEquals(f1.getDouble(), expected);
assertEquals(f1.getObject(), expected);
assertEquals(f1.getType(), type);
assertEquals(f1.toString(), "123.45678");
Field f2 = new Field(f1);
assertEquals(f2, f1);
}
use of com.facebook.presto.spi.type.Type in project presto by prestodb.
the class TestField method testTime.
@Test
public void testTime() throws Exception {
Type type = TIME;
Time expected = new Time(new GregorianCalendar(1999, 0, 1, 12, 30, 0).getTime().getTime());
Field f1 = new Field(expected, type);
assertEquals(f1.getTime(), expected);
assertEquals(f1.getObject(), expected);
assertEquals(f1.getType(), type);
assertEquals(f1.toString(), "TIME '12:30:00'");
Field f2 = new Field(f1);
assertEquals(f2, f1);
}
Aggregations