Search in sources :

Example 11 with KeyValueSchema

use of org.apache.phoenix.schema.KeyValueSchema in project phoenix by apache.

the class ProjectedColumnExpression method readFields.

@Override
public void readFields(DataInput input) throws IOException {
    super.readFields(input);
    schema = new KeyValueSchema();
    schema.readFields(input);
    bitSet = ValueBitSet.newInstance(schema);
    position = input.readInt();
    displayName = input.readUTF();
}
Also used : KeyValueSchema(org.apache.phoenix.schema.KeyValueSchema)

Example 12 with KeyValueSchema

use of org.apache.phoenix.schema.KeyValueSchema in project phoenix by apache.

the class HashJoinInfo method deserializeHashJoinFromScan.

@SuppressWarnings("unchecked")
public static HashJoinInfo deserializeHashJoinFromScan(Scan scan) {
    byte[] join = scan.getAttribute(HASH_JOIN);
    if (join == null) {
        return null;
    }
    ByteArrayInputStream stream = new ByteArrayInputStream(join);
    try {
        DataInputStream input = new DataInputStream(stream);
        KeyValueSchema joinedSchema = new KeyValueSchema();
        joinedSchema.readFields(input);
        int count = WritableUtils.readVInt(input);
        ImmutableBytesPtr[] joinIds = new ImmutableBytesPtr[count];
        List<Expression>[] joinExpressions = new List[count];
        JoinType[] joinTypes = new JoinType[count];
        boolean[] earlyEvaluation = new boolean[count];
        KeyValueSchema[] schemas = new KeyValueSchema[count];
        int[] fieldPositions = new int[count];
        for (int i = 0; i < count; i++) {
            joinIds[i] = new ImmutableBytesPtr();
            joinIds[i].readFields(input);
            int nExprs = WritableUtils.readVInt(input);
            joinExpressions[i] = new ArrayList<Expression>(nExprs);
            for (int j = 0; j < nExprs; j++) {
                int expressionOrdinal = WritableUtils.readVInt(input);
                Expression expression = ExpressionType.values()[expressionOrdinal].newInstance();
                expression.readFields(input);
                joinExpressions[i].add(expression);
            }
            int type = WritableUtils.readVInt(input);
            joinTypes[i] = JoinType.values()[type];
            earlyEvaluation[i] = input.readBoolean();
            schemas[i] = new KeyValueSchema();
            schemas[i].readFields(input);
            fieldPositions[i] = WritableUtils.readVInt(input);
        }
        Expression postJoinFilterExpression = null;
        int expressionOrdinal = WritableUtils.readVInt(input);
        if (expressionOrdinal != -1) {
            postJoinFilterExpression = ExpressionType.values()[expressionOrdinal].newInstance();
            postJoinFilterExpression.readFields(input);
        }
        int limit = -1;
        boolean forceProjection = false;
        // both to be upgraded in lock step.
        try {
            limit = WritableUtils.readVInt(input);
            forceProjection = input.readBoolean();
        } catch (EOFException ignore) {
        }
        return new HashJoinInfo(joinedSchema, joinIds, joinExpressions, joinTypes, earlyEvaluation, schemas, fieldPositions, postJoinFilterExpression, limit >= 0 ? limit : null, forceProjection);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            stream.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) JoinType(org.apache.phoenix.parse.JoinTableNode.JoinType) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Expression(org.apache.phoenix.expression.Expression) EOFException(java.io.EOFException) ArrayList(java.util.ArrayList) List(java.util.List) KeyValueSchema(org.apache.phoenix.schema.KeyValueSchema)

Example 13 with KeyValueSchema

use of org.apache.phoenix.schema.KeyValueSchema in project phoenix by apache.

the class SpillManager method getAggregators.

// Instantiate Aggregators from a serialized byte array
private Aggregator[] getAggregators(byte[] data) throws IOException {
    DataInputStream input = null;
    try {
        input = new DataInputStream(new ByteArrayInputStream(data));
        // key length
        int keyLength = WritableUtils.readVInt(input);
        int vIntKeyLength = WritableUtils.getVIntSize(keyLength);
        ImmutableBytesPtr ptr = new ImmutableBytesPtr(data, vIntKeyLength, keyLength);
        // value length
        input.skip(keyLength);
        int valueLength = WritableUtils.readVInt(input);
        int vIntValLength = WritableUtils.getVIntSize(keyLength);
        KeyValue keyValue = KeyValueUtil.newKeyValue(ptr.get(), ptr.getOffset(), ptr.getLength(), QueryConstants.SINGLE_COLUMN_FAMILY, QueryConstants.SINGLE_COLUMN, QueryConstants.AGG_TIMESTAMP, data, vIntKeyLength + keyLength + vIntValLength, valueLength);
        Tuple result = new SingleKeyValueTuple(keyValue);
        TupleUtil.getAggregateValue(result, ptr);
        KeyValueSchema schema = aggregators.getValueSchema();
        ValueBitSet tempValueSet = ValueBitSet.newInstance(schema);
        tempValueSet.clear();
        tempValueSet.or(ptr);
        int i = 0, maxOffset = ptr.getOffset() + ptr.getLength();
        SingleAggregateFunction[] funcArray = aggregators.getFunctions();
        Aggregator[] sAggs = new Aggregator[funcArray.length];
        Boolean hasValue;
        schema.iterator(ptr);
        while ((hasValue = schema.next(ptr, i, maxOffset, tempValueSet)) != null) {
            SingleAggregateFunction func = funcArray[i];
            sAggs[i++] = hasValue ? func.newServerAggregator(conf, ptr) : func.newServerAggregator(conf);
        }
        return sAggs;
    } finally {
        Closeables.closeQuietly(input);
    }
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) ValueBitSet(org.apache.phoenix.schema.ValueBitSet) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) SingleKeyValueTuple(org.apache.phoenix.schema.tuple.SingleKeyValueTuple) Aggregator(org.apache.phoenix.expression.aggregator.Aggregator) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SingleAggregateFunction(org.apache.phoenix.expression.function.SingleAggregateFunction) KeyValueSchema(org.apache.phoenix.schema.KeyValueSchema) Tuple(org.apache.phoenix.schema.tuple.Tuple) SingleKeyValueTuple(org.apache.phoenix.schema.tuple.SingleKeyValueTuple)

Example 14 with KeyValueSchema

use of org.apache.phoenix.schema.KeyValueSchema in project phoenix by apache.

the class TupleProjector method deserializeProjectorFromScan.

public static TupleProjector deserializeProjectorFromScan(Scan scan) {
    byte[] proj = scan.getAttribute(SCAN_PROJECTOR);
    if (proj == null) {
        return null;
    }
    ByteArrayInputStream stream = new ByteArrayInputStream(proj);
    try {
        DataInputStream input = new DataInputStream(stream);
        KeyValueSchema schema = new KeyValueSchema();
        schema.readFields(input);
        int count = WritableUtils.readVInt(input);
        Expression[] expressions = new Expression[count];
        for (int i = 0; i < count; i++) {
            int ordinal = WritableUtils.readVInt(input);
            expressions[i] = ExpressionType.values()[ordinal].newInstance();
            expressions[i].readFields(input);
        }
        return new TupleProjector(schema, expressions);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            stream.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Expression(org.apache.phoenix.expression.Expression) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) KeyValueSchema(org.apache.phoenix.schema.KeyValueSchema)

Aggregations

KeyValueSchema (org.apache.phoenix.schema.KeyValueSchema)14 Expression (org.apache.phoenix.expression.Expression)7 ArrayList (java.util.ArrayList)6 PTable (org.apache.phoenix.schema.PTable)6 ValueBitSet (org.apache.phoenix.schema.ValueBitSet)6 IOException (java.io.IOException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 DataInputStream (java.io.DataInputStream)4 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)4 PColumn (org.apache.phoenix.schema.PColumn)4 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)3 RowKeyColumnExpression (org.apache.phoenix.expression.RowKeyColumnExpression)3 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)3 KeyValueColumnExpression (org.apache.phoenix.expression.KeyValueColumnExpression)2 OrderByExpression (org.apache.phoenix.expression.OrderByExpression)2 SingleCellColumnExpression (org.apache.phoenix.expression.SingleCellColumnExpression)2 JoinType (org.apache.phoenix.parse.JoinTableNode.JoinType)2 TableRef (org.apache.phoenix.schema.TableRef)2 EOFException (java.io.EOFException)1 HashMap (java.util.HashMap)1