use of org.apache.phoenix.execute.TupleProjector.ProjectedValueTuple in project phoenix by apache.
the class HashJoinRegionScanner method processResults.
private void processResults(List<Cell> result, boolean hasBatchLimit) throws IOException {
if (result.isEmpty())
return;
Tuple tuple = useQualifierAsListIndex ? new PositionBasedResultTuple(result) : new ResultTuple(Result.create(result));
// always returns true.
if (joinInfo.forceProjection()) {
tuple = projector.projectResults(tuple, useNewValueColumnQualifier);
}
// TODO: fix below Scanner.next() and Scanner.nextRaw() methods as well.
if (hasBatchLimit)
throw new UnsupportedOperationException("Cannot support join operations in scans with limit");
int count = joinInfo.getJoinIds().length;
boolean cont = true;
for (int i = 0; i < count; i++) {
if (!(joinInfo.earlyEvaluation()[i]) || hashCaches[i] == null)
continue;
ImmutableBytesPtr key = TupleUtil.getConcatenatedValue(tuple, joinInfo.getJoinExpressions()[i]);
tempTuples[i] = hashCaches[i].get(key);
JoinType type = joinInfo.getJoinTypes()[i];
if (((type == JoinType.Inner || type == JoinType.Semi) && tempTuples[i] == null) || (type == JoinType.Anti && tempTuples[i] != null)) {
cont = false;
break;
}
}
if (cont) {
if (projector == null) {
int dup = 1;
for (int i = 0; i < count; i++) {
dup *= (tempTuples[i] == null ? 1 : tempTuples[i].size());
}
for (int i = 0; i < dup; i++) {
resultQueue.offer(tuple);
}
} else {
KeyValueSchema schema = joinInfo.getJoinedSchema();
if (!joinInfo.forceProjection()) {
// backward compatibility
tuple = projector.projectResults(tuple, useNewValueColumnQualifier);
}
resultQueue.offer(tuple);
for (int i = 0; i < count; i++) {
boolean earlyEvaluation = joinInfo.earlyEvaluation()[i];
JoinType type = joinInfo.getJoinTypes()[i];
if (earlyEvaluation && (type == JoinType.Semi || type == JoinType.Anti))
continue;
int j = resultQueue.size();
while (j-- > 0) {
Tuple lhs = resultQueue.poll();
if (!earlyEvaluation) {
ImmutableBytesPtr key = TupleUtil.getConcatenatedValue(lhs, joinInfo.getJoinExpressions()[i]);
tempTuples[i] = hashCaches[i].get(key);
if (tempTuples[i] == null) {
if (type == JoinType.Inner || type == JoinType.Semi) {
continue;
} else if (type == JoinType.Anti) {
resultQueue.offer(lhs);
continue;
}
}
}
if (tempTuples[i] == null) {
Tuple joined = tempSrcBitSet[i] == ValueBitSet.EMPTY_VALUE_BITSET ? lhs : TupleProjector.mergeProjectedValue((ProjectedValueTuple) lhs, schema, tempDestBitSet, null, joinInfo.getSchemas()[i], tempSrcBitSet[i], joinInfo.getFieldPositions()[i], useNewValueColumnQualifier);
resultQueue.offer(joined);
continue;
}
for (Tuple t : tempTuples[i]) {
Tuple joined = tempSrcBitSet[i] == ValueBitSet.EMPTY_VALUE_BITSET ? lhs : TupleProjector.mergeProjectedValue((ProjectedValueTuple) lhs, schema, tempDestBitSet, t, joinInfo.getSchemas()[i], tempSrcBitSet[i], joinInfo.getFieldPositions()[i], useNewValueColumnQualifier);
resultQueue.offer(joined);
}
}
}
}
// apply post-join filter
Expression postFilter = joinInfo.getPostJoinFilterExpression();
if (postFilter != null) {
for (Iterator<Tuple> iter = resultQueue.iterator(); iter.hasNext(); ) {
Tuple t = iter.next();
postFilter.reset();
ImmutableBytesPtr tempPtr = new ImmutableBytesPtr();
try {
if (!postFilter.evaluate(t, tempPtr) || tempPtr.getLength() == 0) {
iter.remove();
continue;
}
} catch (IllegalDataException e) {
iter.remove();
continue;
}
Boolean b = (Boolean) postFilter.getDataType().toObject(tempPtr);
if (!Boolean.TRUE.equals(b)) {
iter.remove();
}
}
}
}
}
use of org.apache.phoenix.execute.TupleProjector.ProjectedValueTuple in project phoenix by apache.
the class CorrelatePlan method iterator.
@Override
public ResultIterator iterator(final ParallelScanGrouper scanGrouper, final Scan scan) throws SQLException {
return new ResultIterator() {
private final ValueBitSet destBitSet = ValueBitSet.newInstance(joinedSchema);
private final ValueBitSet lhsBitSet = ValueBitSet.newInstance(lhsSchema);
private final ValueBitSet rhsBitSet = (joinType == JoinType.Semi || joinType == JoinType.Anti) ? ValueBitSet.EMPTY_VALUE_BITSET : ValueBitSet.newInstance(rhsSchema);
private final ResultIterator iter = delegate.iterator(scanGrouper, scan);
private ResultIterator rhsIter = null;
private Tuple current = null;
private boolean closed = false;
@Override
public void close() throws SQLException {
if (!closed) {
closed = true;
iter.close();
if (rhsIter != null) {
rhsIter.close();
}
}
}
@Override
public Tuple next() throws SQLException {
if (closed)
return null;
Tuple rhsCurrent = null;
if (rhsIter != null) {
rhsCurrent = rhsIter.next();
if (rhsCurrent == null) {
rhsIter.close();
rhsIter = null;
} else if (isSingleValueOnly) {
throw new SQLExceptionInfo.Builder(SQLExceptionCode.SINGLE_ROW_SUBQUERY_RETURNS_MULTIPLE_ROWS).build().buildException();
}
}
while (rhsIter == null) {
current = iter.next();
if (current == null) {
close();
return null;
}
runtimeContext.setCorrelateVariableValue(variableId, current);
rhsIter = rhs.iterator();
rhsCurrent = rhsIter.next();
if ((rhsCurrent == null && (joinType == JoinType.Inner || joinType == JoinType.Semi)) || (rhsCurrent != null && joinType == JoinType.Anti)) {
rhsIter.close();
rhsIter = null;
}
}
Tuple joined;
try {
joined = rhsBitSet == ValueBitSet.EMPTY_VALUE_BITSET ? current : TupleProjector.mergeProjectedValue(convertLhs(current), joinedSchema, destBitSet, rhsCurrent, rhsSchema, rhsBitSet, rhsFieldPosition, true);
} catch (IOException e) {
throw new SQLException(e);
}
if ((joinType == JoinType.Semi || rhsCurrent == null) && rhsIter != null) {
rhsIter.close();
rhsIter = null;
}
return joined;
}
@Override
public void explain(List<String> planSteps) {
}
private ProjectedValueTuple convertLhs(Tuple lhs) throws IOException {
ProjectedValueTuple t;
if (lhs instanceof ProjectedValueTuple) {
t = (ProjectedValueTuple) lhs;
} else {
ImmutableBytesWritable ptr = getContext().getTempPtr();
TupleProjector.decodeProjectedValue(lhs, ptr);
lhsBitSet.clear();
lhsBitSet.or(ptr);
int bitSetLen = lhsBitSet.getEstimatedLength();
t = new ProjectedValueTuple(lhs, lhs.getValue(0).getTimestamp(), ptr.get(), ptr.getOffset(), ptr.getLength(), bitSetLen);
}
return t;
}
};
}
Aggregations