apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhupeshchawda <...@git.apache.org>
Subject [GitHub] incubator-apex-malhar pull request: APEXMALHAR-1985: Using startRo...
Date Mon, 15 Feb 2016 09:55:36 GMT
Github user bhupeshchawda commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/182#discussion_r52878430
  
    --- Diff: contrib/src/main/java/com/datatorrent/contrib/cassandra/CassandraPOJOInputOperator.java
---
    @@ -359,24 +373,43 @@ public void emitTuples()
       {
         super.emitTuples();
         if (lastRowInBatch != null) {
    -      switch (primaryKeyColumnType.getName()) {
    -        case INT:
    -          startRow = lastRowInBatch.getInt(primaryKeyColumn);
    -          break;
    -        case COUNTER:
    -          startRow = lastRowInBatch.getLong(primaryKeyColumn);
    -          break;
    -        case FLOAT:
    -          startRow = lastRowInBatch.getFloat(primaryKeyColumn);
    -          break;
    -        case DOUBLE:
    -          startRow = lastRowInBatch.getDouble(primaryKeyColumn);
    -          break;
    -        default:
    -          throw new RuntimeException("unsupported data type " + primaryKeyColumnType.getName());
    -      }
    +      startRowToken = getPrimaryKeyToken(primaryKeyColumnType.getName());
         }
    +  }
     
    +  private Long getPrimaryKeyToken(DataType.Name primaryKeyDataType)
    +  {
    +    Object keyValue;
    +    switch (primaryKeyDataType) {
    +    case UUID:
    +      keyValue = lastRowInBatch.getUUID(primaryKeyColumn);
    +      break;
    +    case INT:
    +      keyValue = lastRowInBatch.getInt(primaryKeyColumn);
    +      break;
    +    case COUNTER:
    +      keyValue = lastRowInBatch.getLong(primaryKeyColumn);
    +      break;
    +    case FLOAT:
    +      keyValue = lastRowInBatch.getFloat(primaryKeyColumn);
    +      break;
    +    case DOUBLE:
    +      keyValue = lastRowInBatch.getDouble(primaryKeyColumn);
    +      break;
    +    default:
    +      throw new RuntimeException("unsupported data type " + primaryKeyColumnType.getName());
    +    }
    +    return fetchKeyTokenFromDB(keyValue);
    +  }
    +
    +  private Long fetchKeyTokenFromDB(Object keyValue)
    +  {
    +    PreparedStatement statement = store.getSession().prepare(TOKEN_QUERY);
    --- End diff --
    
    Can we move this to setup()? This will get called for each tuple, so better to have a
prepared statement created just once.


---
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