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();
}
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);
}
}
}
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);
}
}
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);
}
}
}
Aggregations