public InMemoryQueryResult toQueryResult() throws LensException { List<ResultRow> rows = new ArrayList<>(); while (hasNext()) { rows.add(next()); } this.setFullyAccessed(true); return new InMemoryQueryResult(rows); } public boolean isHttpResultAvailable() throws LensException {
@Override public boolean canBePurged() { //If the result is completely pre-fetched, defer the purging until preFetchedRows have been consumed. //In Case not consumed, it should be cleared based on lens.server.inmemory.resultset.ttl.secs if (isComplteleyFetched && !preFetchedRowsConsumed) { return false; } else { return inMemoryRS.canBePurged(); } }
@Override public void setFetchSize(int size) throws LensException { inMemoryRS.setFetchSize(size); }
private void preFetchRows(int reqPreFetchSize) throws LensException { //rows fetched = reqPreFetchSize+1. One extra row is read to check if underlying inMemoryRS result is completely //or partially read. preFetchedRows = new ArrayList<ResultRow>(reqPreFetchSize + 1); boolean hasNext = inMemoryRS.hasNext(); while (hasNext) { if (numOfPreFetchedRows >= reqPreFetchSize) { break; } preFetchedRows.add(inMemoryRS.next()); numOfPreFetchedRows++; hasNext = inMemoryRS.hasNext(); } if (!hasNext) { isComplteleyFetched = true; // No more rows to be read form inMemory result. } else { isComplteleyFetched = false; //we have accessed ( hasNext() for ) one extra row. Lets cache it too. preFetchedRows.add(inMemoryRS.next()); numOfPreFetchedRows++; } }
if (resultSet instanceof InMemoryResultSet) { InMemoryResultSet rs = (InMemoryResultSet) resultSet; LensResultSetMetadata rsMeta = rs.getMetadata(); assertEquals(rsMeta.getColumns().size(), 1); assertEquals(col1.getName(), "ID"); while (rs.hasNext()) { ResultRow row = rs.next(); List<Object> rowObjects = row.getValues();
@Override public boolean hasNext() throws LensException { cursor++; if (cursor <= numOfPreFetchedRows) { return true; } else if (isComplteleyFetched) { return false; } else { return inMemoryRS.hasNext(); } }
@Override public ResultRow next() throws LensException { if (cursor <= numOfPreFetchedRows) { return preFetchedRows.get(cursor-1); } else { return inMemoryRS.next(); } }
/** * Checks the TTL for ResultSet. TTL is applicable to In Memory ResultSets only. * * @param resultSet * @return */ private boolean hasResultSetExceededTTL(LensResultSet resultSet) { if (resultSet instanceof InMemoryResultSet && System.currentTimeMillis() > ((InMemoryResultSet) resultSet).getCreationTime() + inMemoryResultsetTTLMillis) { log.info("InMemoryResultSet for query {} has exceeded its TTL and is eligible for purging now", getQueryHandle()); return true; } return false; }
@Override public void setFullyAccessed(boolean fullyAccessed) { inMemoryRS.setFullyAccessed(fullyAccessed); }
/** * Constructor * @param inMemoryRS : Underlying in-memory result set * @param reqPreFetchSize : requested number of rows to be pre-fetched and cached. * @throws LensException */ public PartiallyFetchedInMemoryResultSet(InMemoryResultSet inMemoryRS, int reqPreFetchSize) throws LensException { this.inMemoryRS = inMemoryRS; if (reqPreFetchSize <= 0) { throw new IllegalArgumentException("Invalid pre fetch size " + reqPreFetchSize); } cachedResultSetMetadata = inMemoryRS.getMetadata(); preFetchRows(reqPreFetchSize); log.info("Pre-Fetched {} rows of result and isComplteleyFetched = {} and doNotPurgeUntilTimeMillis ={}", numOfPreFetchedRows, isComplteleyFetched); }
if (resultSet instanceof InMemoryResultSet) { InMemoryResultSet rs = (InMemoryResultSet) resultSet; LensResultSetMetadata rsMeta = rs.getMetadata(); assertEquals(rsMeta.getColumns().size(), 1); assertEquals(col1.getName(), "ID"); while (rs.hasNext()) { ResultRow row = rs.next(); List<Object> rowObjects = row.getValues();
private void preFetchRows(int reqPreFetchSize) throws LensException { //rows fetched = reqPreFetchSize+1. One extra row is read to check if underlying inMemoryRS result is completely //or partially read. preFetchedRows = new ArrayList<ResultRow>(reqPreFetchSize + 1); boolean hasNext = inMemoryRS.hasNext(); while (hasNext) { if (numOfPreFetchedRows >= reqPreFetchSize) { break; } preFetchedRows.add(inMemoryRS.next()); numOfPreFetchedRows++; hasNext = inMemoryRS.hasNext(); } if (!hasNext) { isComplteleyFetched = true; // No more rows to be read form inMemory result. } else { isComplteleyFetched = false; //we have accessed ( hasNext() for ) one extra row. Lets cache it too. preFetchedRows.add(inMemoryRS.next()); numOfPreFetchedRows++; } }
@Override public boolean hasNext() throws LensException { cursor++; if (cursor <= numOfPreFetchedRows) { return true; } else if (isComplteleyFetched) { return false; } else { return inMemoryRS.hasNext(); } }
@Override public ResultRow next() throws LensException { if (cursor <= numOfPreFetchedRows) { return preFetchedRows.get(cursor-1); } else { return inMemoryRS.next(); } }
private String getResultMessage(QueryContext queryContext) { try { LensResultSet result = queryService.getResultset(queryContext.getQueryHandle()); if (result instanceof InMemoryResultSet) { // Do not include the result rows for InMemory results. long availableUntilTime = ((InMemoryResultSet)result).getCreationTime() + inMemoryResultsetTTLSecs; return RESULT_AVAILABLE_UNTIL_MSG + MESSAGE_DATE_FORMATTER.print(availableUntilTime); } else { return result.toQueryResult().toPrettyString(); } } catch (LensException e) { log.error("Error retrieving result of query handle {} for sending e-mail", queryContext.getQueryHandle(), e); return "Error retrieving result."; } }
@Override public void setFullyAccessed(boolean fullyAccessed) { inMemoryRS.setFullyAccessed(fullyAccessed); }
/** * Constructor * @param inMemoryRS : Underlying in-memory result set * @param reqPreFetchSize : requested number of rows to be pre-fetched and cached. * @throws LensException */ public PartiallyFetchedInMemoryResultSet(InMemoryResultSet inMemoryRS, int reqPreFetchSize) throws LensException { this.inMemoryRS = inMemoryRS; if (reqPreFetchSize <= 0) { throw new IllegalArgumentException("Invalid pre fetch size " + reqPreFetchSize); } cachedResultSetMetadata = inMemoryRS.getMetadata(); preFetchRows(reqPreFetchSize); log.info("Pre-Fetched {} rows of result and isComplteleyFetched = {} and doNotPurgeUntilTimeMillis ={}", numOfPreFetchedRows, isComplteleyFetched); }
LensResultSetMetadata rsMeta = rs.getMetadata(); assertEquals(rsMeta.getColumns().size(), 4); assertEquals(col4.getName(), "c4".toUpperCase()); while (rs.hasNext()) { ResultRow row = rs.next(); List<Object> rowObjects = row.getValues(); System.out.println(rowObjects);
public InMemoryQueryResult toQueryResult() throws LensException { List<ResultRow> rows = new ArrayList<>(); while (hasNext()) { rows.add(next()); } this.setFullyAccessed(true); return new InMemoryQueryResult(rows); } public boolean isHttpResultAvailable() throws LensException {