apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sandeepdeshmukh <...@git.apache.org>
Subject [GitHub] incubator-apex-malhar pull request: [Review only] MLHR 1957 hbase ...
Date Thu, 31 Dec 2015 09:03:44 GMT
Github user sandeepdeshmukh commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/155#discussion_r48650919
  
    --- Diff: contrib/src/main/java/com/datatorrent/contrib/hbase/HBasePOJOInputOperator.java
---
    @@ -81,104 +81,89 @@ public void setup(OperatorContext context)
       }
     
       @Override
    -  public void beginWindow(long windowId)
    -  {
    -  }
    -
    -  @Override
    -  public void teardown()
    -  {
    -    try {
    -      store.disconnect();
    -    } catch (IOException ex) {
    -      throw new RuntimeException(ex);
    -    }
    -  }
    -
    -  @Override
    -  public void emitTuples()
    +  protected Object getTuple(Result result)
       {
         try {
    -      Scan scan = nextScan();
    -      if (scan == null)
    -        return;
    -
    -      ResultScanner resultScanner = store.getTable().getScanner(scan);
    -
    -      while (true) {
    -        Result result = resultScanner.next();
    -        if (result == null)
    -          break;
    -
    -        String readRow = Bytes.toString(result.getRow());
    -        if( readRow.equals( lastReadRow ))
    -          continue;
    -
    -        Object instance = pojoType.newInstance();
    -        rowSetter.set(instance, readRow);
    -
    -        List<Cell> cells = result.listCells();
    +      String readRow = Bytes.toString(result.getRow());
    +      if( readRow.equals( getLastReadRow() )) {
    +        return null;
    +      }
     
    -        for (Cell cell : cells) {
    -          String columnName = Bytes.toString(CellUtil.cloneQualifier(cell));
    -          byte[] value = CellUtil.cloneValue(cell);
    -          fieldValueGenerator.setColumnValue( instance, columnName, value, valueConverter
);
    -        }
    +      Object instance = pojoType.newInstance();
    +      rowSetter.set(instance, readRow);
     
    -        outputPort.emit(instance);
    -        lastReadRow = readRow;
    +       List<Cell> cells = result.listCells();
    +       for (Cell cell : cells) {
    +         String columnName = Bytes.toString(CellUtil.cloneQualifier(cell));
    +         String columnFamily = Bytes.toString(CellUtil.cloneFamily(cell));
    +        byte[] value = CellUtil.cloneValue(cell);
    +         ((HBaseFieldValueGenerator)fieldValueGenerator).setColumnValue(instance, columnName,
columnFamily, value,
    +             valueConverter);
           }
     
    +      setLastReadRow(readRow);
    +      return instance;
         } catch (Exception e) {
    -      throw new RuntimeException(e.getMessage());
    +      throw new RuntimeException(e);
         }
    -
    -  }
    -
    -  protected Scan nextScan()
    -  {
    -    if(lastReadRow==null && startRow==null )
    -      return new Scan();
    -    else
    -      return new Scan( Bytes.toBytes( lastReadRow == null ? startRow : lastReadRow )
);
       }
     
    -  public HBaseStore getStore()
    -  {
    -    return store;
    -  }
    -  public void setStore(HBaseStore store)
    +  @Override
    +  protected Scan operationScan()
       {
    -    this.store = store;
    +    Scan scan;
    +    if(getLastReadRow()==null && getStartRow()==null ) {
    +      scan = new Scan();
    +    }
    +    else if(getEndRow() == null) {
    +      scan = new Scan(Bytes.toBytes(getLastReadRow() == null ? getStartRow() : getLastReadRow()));
    --- End diff --
    
    Get this into a variable and use it later: Bytes.toBytes(getLastReadRow() == null ? getStartRow()
    Readability will increase.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message