Search in sources :

Example 1 with Type

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);
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) ArrayType(com.facebook.presto.type.ArrayType) MapType(com.facebook.presto.type.MapType) Type(com.facebook.presto.spi.type.Type) Test(org.testng.annotations.Test)

Example 2 with Type

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());
                }
            }
        }
    }
}
Also used : Type(com.facebook.presto.spi.type.Type) ColumnUpdate(org.apache.accumulo.core.data.ColumnUpdate) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) ByteBuffer(java.nio.ByteBuffer)

Example 3 with Type

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);
}
Also used : Type(com.facebook.presto.spi.type.Type) VarbinaryType(com.facebook.presto.spi.type.VarbinaryType) VarcharType(com.facebook.presto.spi.type.VarcharType)

Example 4 with 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);
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) MapType(com.facebook.presto.type.MapType) Type(com.facebook.presto.spi.type.Type) Test(org.testng.annotations.Test)

Example 5 with Type

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);
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) MapType(com.facebook.presto.type.MapType) Type(com.facebook.presto.spi.type.Type) GregorianCalendar(java.util.GregorianCalendar) Time(java.sql.Time) Test(org.testng.annotations.Test)

Aggregations

Type (com.facebook.presto.spi.type.Type)392 Test (org.testng.annotations.Test)103 Block (com.facebook.presto.spi.block.Block)83 ImmutableList (com.google.common.collect.ImmutableList)79 ArrayType (com.facebook.presto.type.ArrayType)78 MapType (com.facebook.presto.type.MapType)72 Page (com.facebook.presto.spi.Page)68 PrestoException (com.facebook.presto.spi.PrestoException)51 List (java.util.List)50 VarcharType (com.facebook.presto.spi.type.VarcharType)48 DecimalType (com.facebook.presto.spi.type.DecimalType)44 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)40 MaterializedResult (com.facebook.presto.testing.MaterializedResult)40 ArrayList (java.util.ArrayList)40 MethodHandle (java.lang.invoke.MethodHandle)39 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)37 ImmutableMap (com.google.common.collect.ImmutableMap)36 Map (java.util.Map)36 Slice (io.airlift.slice.Slice)35 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)30