Java Code Examples for com.datastax.driver.core.SimpleStatement#setFetchSize()
The following examples show how to use
com.datastax.driver.core.SimpleStatement#setFetchSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestBaselineApproach.java From bboxdb with Apache License 2.0 | 5 votes |
/** * Execute a range query * @param destTable * @param range */ public void executeRangeQuery(final String destTable, final String format, final Hyperrectangle range) { System.out.println("# Execute range query in range " + range); final Stopwatch stopwatch = Stopwatch.createStarted(); final TupleBuilder tupleBuilder = TupleBuilderFactory.getBuilderForFormat(format); long readRecords = 0; long resultRecords = 0; final SimpleStatement statement = new SimpleStatement("SELECT * FROM " + destTable); statement.setFetchSize(2000); // Use 2000 tuples per page final ResultSet rs = session.execute(statement); for (final Row row : rs) { // Request next page if (rs.getAvailableWithoutFetching() == 100 && !rs.isFullyFetched()) { rs.fetchMoreResults(); // this is asynchronous } readRecords++; final long id = row.getLong(0); final String text = row.getString(1); final Tuple tuple = tupleBuilder.buildTuple(text, Long.toString(id)); if(tuple.getBoundingBox().intersects(range)) { resultRecords++; } } System.out.println("# Read records " + readRecords + " result records " + resultRecords); System.out.println("# Execution time in sec " + stopwatch.elapsed(TimeUnit.SECONDS)); }
Example 2
Source File: AbstractCassandraInputOperator.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
/** * This executes the query to retrieve result from database. * It then converts each row into tuple and emit that into output port. */ @Override public void emitTuples() { String query = queryToRetrieveData(); logger.debug("select statement: {}", query); SimpleStatement stmt = new SimpleStatement(query); stmt.setFetchSize(fetchSize); try { if (nextPageState != null) { stmt.setPagingState(nextPageState); } ResultSet result = store.getSession().execute(stmt); nextPageState = result.getExecutionInfo().getPagingState(); if (!result.isExhausted()) { for (Row row : result) { T tuple = getTuple(row); emit(tuple); } } else { // No rows available wait for some time before retrying so as to not continuously slam the database Thread.sleep(waitForDataTimeout); } } catch (Exception ex) { store.disconnect(); DTThrowable.rethrow(ex); } }
Example 3
Source File: TestBaselineApproach.java From bboxdb with Apache License 2.0 | 4 votes |
/** * Execute a join (nested loop join) * @param table1 * @param table2 * @param range */ public void executeJoin(final String table1, final String table2, final String format1, final String format2, final Hyperrectangle range, final double padding) { System.out.println("# Execute join query in range " + range); final Stopwatch stopwatch = Stopwatch.createStarted(); final TupleBuilder tupleBuilder1 = TupleBuilderFactory.getBuilderForFormat(format1); final TupleBuilder tupleBuilder2 = TupleBuilderFactory.getBuilderForFormat(format2); long readRecords = 0; long resultRecords = 0; final SimpleStatement statementTable1 = new SimpleStatement("SELECT * FROM " + table1); statementTable1.setFetchSize(2000); // Use 2000 tuples per page final ResultSet rs1 = session.execute(statementTable1); for (final Row row1 : rs1) { // Request next page if (rs1.getAvailableWithoutFetching() == 100 && !rs1.isFullyFetched()) { rs1.fetchMoreResults(); // this is asynchronous } readRecords++; final long id1 = row1.getLong(0); final String text1 = row1.getString(1); final Tuple tuple1 = tupleBuilder1.buildTuple(text1, Long.toString(id1)); // Tuple is outside of our query range if(! tuple1.getBoundingBox().intersects(range)) { continue; } // Perform the nested loop join final SimpleStatement statementTable2 = new SimpleStatement("SELECT * FROM " + table2); statementTable2.setFetchSize(2000); // Use 2000 tuples per page final ResultSet rs2 = session.execute(statementTable2); for (final Row row2 : rs2) { // Request next page if (rs1.getAvailableWithoutFetching() == 100 && !rs1.isFullyFetched()) { rs1.fetchMoreResults(); // this is asynchronous } readRecords++; final long id2 = row2.getLong(0); final String text2 = row2.getString(1); final Tuple tuple2 = tupleBuilder2.buildTuple(text2, Long.toString(id2)); if(tuple1.getBoundingBox().intersects(tuple2.getBoundingBox().enlargeByAmount(padding))) { resultRecords++; } } } System.out.println("# Read records " + readRecords + " result records " + resultRecords); System.out.println("# Execution time in sec " + stopwatch.elapsed(TimeUnit.SECONDS)); }