apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yogidevendra <...@git.apache.org>
Subject [GitHub] incubator-apex-malhar pull request: APEXMALHAR-2019 S3-Input Imple...
Date Mon, 02 May 2016 06:48:02 GMT
Github user yogidevendra commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/263#discussion_r61707966
  
    --- Diff: library/src/main/java/com/datatorrent/lib/io/fs/S3BlockReader.java ---
    @@ -0,0 +1,89 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package com.datatorrent.lib.io.fs;
    +
    +import java.io.IOException;
    +import org.apache.hadoop.fs.FSDataInputStream;
    +import org.apache.hadoop.fs.Path;
    +
    +import com.google.common.annotations.VisibleForTesting;
    +import com.datatorrent.api.Context;
    +import com.datatorrent.lib.io.block.BlockMetadata;
    +import com.datatorrent.lib.io.block.BlockReader;
    +import com.datatorrent.lib.io.block.ReaderContext;
    +
    +/**
    + * S3BlockReader extends from BlockReader and serves the functionality of read objects
and
    + * parse Block metadata
    + */
    +public class S3BlockReader extends BlockReader
    +{
    +  protected transient String s3bucketUri;
    +
    +  public S3BlockReader()
    +  {
    +    this.readerContext = new S3BlockReaderContext();
    +  }
    +
    +  @Override
    +  public void setup(Context.OperatorContext context)
    +  {
    +    super.setup(context);
    +    s3bucketUri = fs.getScheme() + "://" + extractBucket(uri);
    +  }
    +
    +  @VisibleForTesting
    +  protected String extractBucket(String s3uri)
    +  {
    +    return s3uri.substring(s3uri.indexOf('@') + 1, s3uri.indexOf("/", s3uri.indexOf('@')));
    +  }
    +
    +  @Override
    +  protected FSDataInputStream setupStream(BlockMetadata.FileBlockMetadata block) throws
IOException
    +  {
    +    FSDataInputStream ins = fs.open(new Path(s3bucketUri + block.getFilePath()));
    +    ins.seek(block.getOffset());
    +    return ins;
    +  }
    +
    +  /**
    +   * BlockReadeContext for reading S3 Blocks.<br/>
    +   * This should use read API without offset.
    +   */
    +  private static class S3BlockReaderContext extends ReaderContext.FixedBytesReaderContext<FSDataInputStream>
    +  {
    +    @Override
    +    protected Entity readEntity() throws IOException
    --- End diff --
    
    mention the difference from super in javadocs.


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