package com.architecting.ch09;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.params.ModifiableSolrParams;

import java.io.IOException;


public class ReadFromSORL {

  public static final TableName sensorsTableName = TableName.valueOf("sensors");
  public static final Log LOG = LogFactory.getLog(ReadFromSORL.class);

  public static void main(String[] args) throws SolrServerException, IOException {
    CloudSolrServer solr = new CloudSolrServer("localhost:2181/solr");
    solr.setDefaultCollection("Ch09-Collection");
    solr.connect();

    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("qt", "/select");
    params.set("q", "docType:ALERT AND partName:NE-555");

    QueryResponse response = solr.query(params);
    SolrDocumentList docs = response.getResults();

    LOG.info("Found " + docs.getNumFound() + " matching documents.");
    if (docs.getNumFound() == 0)
      return;
    LOG.info("First document rowkey is " +
            Bytes.toStringBinary((byte[])docs.get(0).getFieldValue("rowkey")));

    // Retrieve and print the first 10 columns of the first returned document
    Configuration config = HBaseConfiguration.create();
    try (Connection connection = ConnectionFactory.createConnection(config);
        Admin admin = connection.getAdmin();
        Table sensorsTable = connection.getTable(sensorsTableName)) {  // <1>
     byte[] rowKey = (byte[])(docs.get(0).getFieldValue("rowkey"));
     Get get = new Get (rowKey);

     Result result = sensorsTable.get(get);
     Event event = null;
     if (result != null && !result.isEmpty()) { // <4>
       for (int index = 0; index < 10; index++) { // Print first 10 columns
         if (!result.advance())
           break; // The is no more column.
         event = new Util().cellToEvent(result.current(),event); // <5>
         LOG.info("Retrieved AVRO content: " + event.toString());
       }
     } else {
       LOG.error("Impossible to find requested cell");
     }
   }
  
  }
}

@@ -889,17 +889,16 @@
 ption;%0A%0A
-%0A
 public c
@@ -1154,16 +1154,36 @@
 ption %7B%0A
+    // tag::SETUP%5B%5D%0A
     Clou
@@ -1244,16 +1244,23 @@
 /solr%22);
+ // %3C1%3E
 %0A    sol
@@ -1301,16 +1301,23 @@
 ction%22);
+ // %3C2%3E
 %0A    sol
@@ -1482,16 +1482,23 @@
 E-555%22);
+ // %3C3%3E
 %0A%0A    Qu
@@ -1539,16 +1539,23 @@
 params);
+ // %3C4%3E
 %0A    Sol
@@ -1597,16 +1597,17 @@
 sults();
+ 
 %0A%0A    LO
@@ -1706,21 +1706,86 @@
 = 0)
-%0A     
  return
+;%0A    byte%5B%5D firstRowKey = (byte%5B%5D) docs.get(0).getFieldValue(%22rowkey%22)
 ;%0A  
@@ -1824,28 +1824,16 @@
 y is %22 +
-%0A           
  Bytes.t
@@ -1850,51 +1850,19 @@
 ary(
-(byte%5B%5D)docs.get(0).getFieldValue(%22rowk
+firstRowK
 ey
-%22)
 ));%0A
@@ -2191,90 +2191,15 @@
 )) %7B
+%0A
   
-// %3C1%3E%0A     byte%5B%5D rowKey = (byte%5B%5D)(docs.get(0).getFieldValue(%22rowkey%22));%0A
     
- 
 Get 
@@ -2215,20 +2215,32 @@
  Get
- (rowKey);
+(firstRowKey); // %3C5%3E
 %0A%0A
+ 
     
@@ -2279,16 +2279,17 @@
 t(get);%0A
+ 
      Eve
@@ -2306,24 +2306,25 @@
  null;%0A     
+ 
 if (result !
@@ -2354,27 +2354,28 @@
 ty()) %7B // %3C
-4
+6
 %3E%0A
+ 
        for (
@@ -2438,16 +2438,17 @@
 columns%0A
+ 
         
@@ -2482,16 +2482,17 @@
         
+ 
 break; /
@@ -2518,10 +2518,38 @@
 lumn
+ and we have not reached 10
 .%0A
+ 
     
@@ -2605,23 +2605,18 @@
 t(),
+ 
 event);
- // %3C5%3E
 %0A
+ 
     
@@ -2684,18 +2684,20 @@
 %0A       
+ 
 %7D%0A
+ 
      %7D e
@@ -2705,24 +2705,25 @@
 se %7B%0A       
+ 
 LOG.error(%22I
@@ -2767,17 +2767,36 @@
     
+ 
 %7D%0A
+ 
    %7D%0A  
+  // end::SETUP%5B%5D
 %0A  %7D

Add asciidoc callous + simplify first key retrieval.