@Override protected Tuple advance() throws SQLException { return iterator.next(); } };
@Override public Tuple next() throws SQLException { return delegate.next(); }
@Override public Tuple next() throws SQLException { if (chunkComplete || lastKey == null) { return null; } Tuple next = delegate.next(); if (next != null) { // We actually keep going past the chunk size until the row key changes. This is // necessary for (at least) hash joins, as they can return multiple rows with the // same row key. Stopping a chunk at a row key boundary is necessary in order to // be able to start the next chunk on the next row key if (rowCount == chunkSize) { next.getKey(lastKey); } else if (rowCount > chunkSize && rowKeyChanged(next)) { chunkComplete = true; return null; } rowCount++; } else { lastKey = null; } return next; }
@Override protected Tuple advance() throws SQLException { Tuple next; do { next = delegate.next(); expression.reset(); } while (next != null && (!expression.evaluate(next, ptr) || ptr.getLength() == 0 || !Boolean.TRUE.equals(expression.getDataType().toObject(ptr)))); return next; }
private HashMap<ImmutableBytesWritable, Aggregator[]> populateHash() throws SQLException { hash = new HashMap<ImmutableBytesWritable, Aggregator[]>(HASH_AGG_INIT_SIZE, 0.75f); final int aggSize = aggregators.getEstimatedByteSize(); long keySize = 0; for (Tuple result = resultIterator.next(); result != null; result = resultIterator.next()) { ImmutableBytesWritable key = new ImmutableBytesWritable(UNITIALIZED_KEY_BUFFER); key = getGroupingKey(result, key); Aggregator[] rowAggregators = hash.get(key); if (rowAggregators == null) { keySize += key.getSize(); long hashSize = SizedUtil.sizeOfMap(hash.size() + 1, SizedUtil.IMMUTABLE_BYTES_WRITABLE_SIZE, aggSize) + keySize; if (hashSize > memoryChunk.getSize() + CLIENT_HASH_AGG_MEMORY_CHUNK_SIZE) { // This will throw InsufficientMemoryException if necessary memoryChunk.resize(hashSize + CLIENT_HASH_AGG_MEMORY_CHUNK_SIZE); } rowAggregators = aggregators.newAggregators(); hash.put(key, rowAggregators); } aggregators.aggregate(rowAggregators, result); } return hash; }
private void advance(boolean lhs) throws SQLException { if (lhs) { lhsTuple = nextLhsTuple; lhsKey.set(nextLhsKey); if (lhsTuple != null) { nextLhsTuple = lhsIterator.next(); if (nextLhsTuple != null) { nextLhsKey.evaluate(nextLhsTuple); } else { nextLhsKey.clear(); } } } else { rhsTuple = nextRhsTuple; rhsKey.set(nextRhsKey); if (rhsTuple != null) { nextRhsTuple = rhsIterator.next(); if (nextRhsTuple != null) { nextRhsKey.evaluate(nextRhsTuple); } else { nextRhsKey.clear(); } } } }
@Override public Tuple next() throws SQLException { while (true) { if (!initSnapshotScanner()) return null; try { lastTuple = scanIterator.next(); if (lastTuple != null) { ImmutableBytesWritable ptr = new ImmutableBytesWritable(); lastTuple.getKey(ptr); return lastTuple; } } finally { if (lastTuple == null) { scanIterator.close(); scanIterator = UNINITIALIZED_SCANNER; } } } }
@Override public MutationState execute() throws SQLException { connection.getMutationState().commitDDLFence(dataTable); Tuple tuple = plan.iterator().next(); long rowCount = 0; if (tuple != null) { Cell kv = tuple.getValue(0); ImmutableBytesWritable tmpPtr = new ImmutableBytesWritable(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength()); // A single Cell will be returned with the count(*) - we decode that here rowCount = PLong.INSTANCE.getCodec().decodeLong(tmpPtr, SortOrder.getDefault()); } // The contract is to return a MutationState that contains the number of rows modified. In this // case, it's the number of rows in the data table which corresponds to the number of index // rows that were added. return new MutationState(0, 0, connection, rowCount); }
private void testLiteralResultIteratorPlan(Object[][] expectedResult, Integer offset, Integer limit) throws SQLException { QueryPlan plan = newLiteralResultIterationPlan(offset, limit); ResultIterator iter = plan.iterator(); ImmutableBytesWritable ptr = new ImmutableBytesWritable(); for (Object[] row : expectedResult) { Tuple next = iter.next(); assertNotNull(next); for (int i = 0; i < row.length; i++) { PColumn column = table.getColumns().get(i); boolean eval = new ProjectedColumnExpression(column, table, column.getName().getString()).evaluate(next, ptr); Object o = eval ? column.getDataType().toObject(ptr) : null; assertEquals(row[i], o); } } assertNull(iter.next()); }
parallelIteratorFactory.setProjectedTableRef(projectedTableRef); while ((tuple=iterator.next()) != null) {// Runs query Cell kv = tuple.getValue(0); totalRowCount += PLong.INSTANCE.getCodec().decodeLong(kv.getValueArray(), kv.getValueOffset(), SortOrder.getDefault());
long totalRowCount = 0; StatementContext context = queryPlan.getContext(); while ((tuple=iterator.next()) != null) {// Runs query Cell kv = tuple.getValue(0); totalRowCount += PLong.INSTANCE.getCodec().decodeLong(kv.getValueArray(), kv.getValueOffset(), SortOrder.getDefault());
Tuple row = iterator.next(); final long mutationCount = (Long) aggProjector.getColumnProjector(0).getValue(row, PLong.INSTANCE, ptr);
Tuple row = iterator.next(); final long mutationCount = (Long) projector.getColumnProjector(0).getValue(row, PLong.INSTANCE, ptr); return new MutationState(maxSize, maxSizeBytes, connection) {
private void testCorrelatePlan(Object[][] leftRelation, Object[][] rightRelation, int leftCorrelColumn, int rightCorrelColumn, JoinType type, Object[][] expectedResult, Integer offset) throws SQLException { TableRef leftTable = createProjectedTableFromLiterals(leftRelation[0]); TableRef rightTable = createProjectedTableFromLiterals(rightRelation[0]); String varName = "$cor0"; RuntimeContext runtimeContext = new RuntimeContextImpl(); runtimeContext.defineCorrelateVariable(varName, leftTable); QueryPlan leftPlan = newLiteralResultIterationPlan(leftRelation, offset); QueryPlan rightPlan = newLiteralResultIterationPlan(rightRelation, offset); Expression columnExpr = new ColumnRef(rightTable, rightCorrelColumn).newColumnExpression(); Expression fieldAccess = new CorrelateVariableFieldAccessExpression(runtimeContext, varName, new ColumnRef(leftTable, leftCorrelColumn).newColumnExpression()); Expression filter = ComparisonExpression.create(CompareOp.EQUAL, Arrays.asList(columnExpr, fieldAccess), CONTEXT.getTempPtr(), false); rightPlan = new ClientScanPlan(CONTEXT, SelectStatement.SELECT_ONE, rightTable, RowProjector.EMPTY_PROJECTOR, null, null, filter, OrderBy.EMPTY_ORDER_BY, rightPlan); PTable joinedTable = JoinCompiler.joinProjectedTables(leftTable.getTable(), rightTable.getTable(), type); CorrelatePlan correlatePlan = new CorrelatePlan(leftPlan, rightPlan, varName, type, false, runtimeContext, joinedTable, leftTable.getTable(), rightTable.getTable(), leftTable.getTable().getColumns().size()); ResultIterator iter = correlatePlan.iterator(); ImmutableBytesWritable ptr = new ImmutableBytesWritable(); for (Object[] row : expectedResult) { Tuple next = iter.next(); assertNotNull(next); for (int i = 0; i < row.length; i++) { PColumn column = joinedTable.getColumns().get(i); boolean eval = new ProjectedColumnExpression(column, joinedTable, column.getName().getString()).evaluate(next, ptr); Object o = eval ? column.getDataType().toObject(ptr) : null; assertEquals(row[i], o); } } }