You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apex.apache.org by yogidevendra <gi...@git.apache.org> on 2016/04/06 12:29:16 UTC

[GitHub] incubator-apex-malhar pull request: Added concrete implementation ...

GitHub user yogidevendra opened a pull request:

    https://github.com/apache/incubator-apex-malhar/pull/233

    Added concrete implementation for HDFS output operator with unit tests.

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/yogidevendra/incubator-apex-malhar APEXMALHAR-2009-hdfs-output-concrete-tuple-PR

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-apex-malhar/pull/233.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #233
    
----
commit 2ebb72626cd7798a46592486e39f05922374ca8e
Author: yogidevendra <de...@datatorrent.com>
Date:   2016-04-06T10:17:31Z

    Added concrete implementation for HDFS output operator with unit tests.

----


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

[GitHub] incubator-apex-malhar pull request: Added concrete implementation ...

Posted by DT-Priyanka <gi...@git.apache.org>.
Github user DT-Priyanka commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/233#discussion_r58693168
  
    --- Diff: library/src/main/java/com/datatorrent/lib/io/fs/HDFSOutputOperator.java ---
    @@ -0,0 +1,393 @@
    +/**
    + * 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.ByteArrayOutputStream;
    +import java.io.IOException;
    +import java.util.concurrent.ExecutionException;
    +
    +import javax.validation.constraints.NotNull;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import com.datatorrent.api.AutoMetric;
    +import com.datatorrent.api.Context.OperatorContext;
    +import com.datatorrent.api.DefaultInputPort;
    +import com.datatorrent.api.StreamCodec;
    +import com.datatorrent.netlet.util.DTThrowable;
    +
    +/**
    + * This class is responsible for writing tuples to HDFS. All tuples are written
    + * to the same file. Rolling file based on size, no. of tuples, idle windows,
    + * elapsed windows is supported.
    + * 
    + * @param <T>
    + */
    +
    +class HDFSOutputOperator extends AbstractFileOutputOperator<byte[]>
    +{
    +
    +  /**
    +   * Name of the file to write the output. Directory for the output file should
    +   * be specified in the filePath
    +   */
    +  @NotNull
    +  private String fileName;
    +
    +  /**
    +   * currentPartName is of the form fileName_physicalPartionId.partNumber
    --- End diff --
    
    I guess it can be of form "fileName_physicalPartionId.partNumber" (or it's a default), user can give any other format right?


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

[GitHub] incubator-apex-malhar pull request: Added concrete implementation ...

Posted by DT-Priyanka <gi...@git.apache.org>.
Github user DT-Priyanka commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/233#discussion_r58693785
  
    --- Diff: library/src/main/java/com/datatorrent/lib/io/fs/HDFSOutputOperator.java ---
    @@ -0,0 +1,393 @@
    +/**
    + * 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.ByteArrayOutputStream;
    +import java.io.IOException;
    +import java.util.concurrent.ExecutionException;
    +
    +import javax.validation.constraints.NotNull;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import com.datatorrent.api.AutoMetric;
    +import com.datatorrent.api.Context.OperatorContext;
    +import com.datatorrent.api.DefaultInputPort;
    +import com.datatorrent.api.StreamCodec;
    +import com.datatorrent.netlet.util.DTThrowable;
    +
    +/**
    + * This class is responsible for writing tuples to HDFS. All tuples are written
    + * to the same file. Rolling file based on size, no. of tuples, idle windows,
    + * elapsed windows is supported.
    + * 
    + * @param <T>
    + */
    +
    +class HDFSOutputOperator extends AbstractFileOutputOperator<byte[]>
    +{
    +
    +  /**
    +   * Name of the file to write the output. Directory for the output file should
    +   * be specified in the filePath
    +   */
    +  @NotNull
    +  private String fileName;
    +
    +  /**
    +   * currentPartName is of the form fileName_physicalPartionId.partNumber
    +   */
    +  private String currentPartNameformat = "%s_%d";
    +
    +  /**
    +   * currentPartName is of the form fileName_physicalPartionId.partNumber
    +   */
    +  private transient String currentPartName;
    +
    +  /**
    +   * Physical partition id for the current partition.
    +   */
    +  protected transient int physicalPartitionId;
    +
    +  /**
    +   * Flag to mark if new data in current application window
    +   */
    +  private transient boolean isNewDataInCurrentWindow;
    +
    +  /**
    +   * Separator between the tuples
    +   */
    +  private String tupleSeparator;
    +
    +  /**
    +   * byte[] representation of tupleSeparator
    +   */
    +  private transient byte[] tupleSeparatorBytes;
    +
    +  /**
    +   * No. of bytes received in current application window
    +   */
    +  @AutoMetric
    +  private long byteCount;
    +
    +  /**
    +   * No. of tuples present in current output file
    +   */
    +  private long currentPartTupleCount;
    +
    +  /**
    +   * Max. number of tuples allowed per part. Part file will be finalized after
    +   * these many tuples
    +   */
    +  private long maxTupleCount = Long.MAX_VALUE;
    +
    +  /**
    +   * No. of windows since last new data received
    +   */
    +  private long currentPartIdleWindows;
    +
    +  /**
    +   * Max number of idle windows for which no new data is added to current part
    +   * file. Part file will be finalized after these many idle windows after last
    +   * new data.
    +   */
    +  private long maxIdleWindows = Long.MAX_VALUE;
    +
    +  /**
    +   * Stream codec for string input port
    +   */
    +  protected StreamCodec<String> stringStreamCodec;
    +
    +  /**
    +   * Default value for stream expiry
    +   */
    +  private static final long DEFAULT_STREAM_EXPIRY_ACCESS_MILL = 60 * 60 * 1000L; //1 hour
    +
    +  /**
    +   * Default value for rotation windows
    +   */
    +  private static final int DEFAULT_ROTATION_WINDOWS = 2 * 60 * 10; //10 min  
    +
    +  /**
    +   * Initializing default values for tuple separator, stream expiry, rotation
    +   * windows
    +   */
    +  public HDFSOutputOperator()
    +  {
    +    setTupleSeparator(System.getProperty("line.separator"));
    +    setExpireStreamAfterAccessMillis(DEFAULT_STREAM_EXPIRY_ACCESS_MILL);
    +    setRotationWindows(DEFAULT_ROTATION_WINDOWS);
    +  }
    +
    +  /**
    +   * Initializing current partition id, part name etc. {@inheritDoc}
    +   */
    +  @Override
    +  public void setup(OperatorContext context)
    +  {
    +    super.setup(context);
    +    physicalPartitionId = context.getId();
    +    currentPartName = String.format(currentPartNameformat, fileName, physicalPartitionId);
    +  }
    +
    +  /**
    +   * {@inheritDoc}
    +   */
    +  @Override
    +  protected String getFileName(byte[] tuple)
    +  {
    +    return currentPartName;
    +  }
    +
    +  /**
    +   * Input port for receiving string tuples.
    +   */
    +  public final transient DefaultInputPort<String> stringInput = new DefaultInputPort<String>()
    +  {
    +    @Override
    +    public void process(String tuple)
    +    {
    +      processTuple(tuple.getBytes());
    +    }
    +
    +    @Override
    +    public StreamCodec<String> getStreamCodec()
    +    {
    +      if (HDFSOutputOperator.this.stringStreamCodec == null) {
    +        return super.getStreamCodec();
    +      } else {
    +        return stringStreamCodec;
    +      }
    +    }
    +  };
    +
    +  /**
    +   * {@inheritDoc}
    +   * 
    +   * @return byte[] representation of the given tuple. if input tuple is of type
    +   *         byte[] then it is returned as it is. for any other type toString()
    +   *         representation is used to generate byte[].
    +   */
    +  @Override
    +  protected byte[] getBytesForTuple(byte[] tuple)
    +  {
    +    ByteArrayOutputStream bytesOutStream = new ByteArrayOutputStream();
    +
    +    try {
    +      bytesOutStream.write(tuple);
    +      bytesOutStream.write(tupleSeparatorBytes);
    +      byteCount += bytesOutStream.size();
    +      return bytesOutStream.toByteArray();
    +    } catch (IOException e) {
    +      throw new RuntimeException(e);
    +    } finally {
    +      try {
    +        bytesOutStream.close();
    +      } catch (IOException e) {
    +        throw new RuntimeException(e);
    +      }
    +    }
    +  }
    +
    +  /**
    +   * Initializing per window level fields {@inheritDoc}
    +   */
    +  @Override
    +  public void beginWindow(long windowId)
    +  {
    +    super.beginWindow(windowId);
    +    byteCount = 0;
    +    isNewDataInCurrentWindow = false;
    +  }
    +
    +  /**
    +   * {@inheritDoc} Does additional state maintenance for rollover
    +   */
    +  @Override
    +  protected void processTuple(byte[] tuple)
    +  {
    +    super.processTuple(tuple);
    +    isNewDataInCurrentWindow = true;
    +
    +    if (++currentPartTupleCount == maxTupleCount) {
    +      rotateCall(currentPartName);
    +    }
    +  }
    +
    +  /**
    +   * {@inheritDoc} Does additional checks if file should be rolled over for this
    +   * window.
    +   */
    +  @Override
    +  public void endWindow()
    +  {
    +    super.endWindow();
    +
    +    if (!isNewDataInCurrentWindow) {
    +      ++currentPartIdleWindows;
    +    } else {
    +      currentPartIdleWindows = 0;
    +    }
    +
    +    if (checkEndWindowFinalization()) {
    +      rotateCall(currentPartName);
    +    }
    +  }
    +
    +  /**
    +   * Rollover check at the endWindow
    +   */
    +  private boolean checkEndWindowFinalization()
    +  {
    +    if ((currentPartIdleWindows == maxIdleWindows) && !endOffsets.isEmpty()) {
    --- End diff --
    
    what is this condition about endOffsets?


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

[GitHub] incubator-apex-malhar pull request: Added concrete implementation ...

Posted by DT-Priyanka <gi...@git.apache.org>.
Github user DT-Priyanka commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/233#discussion_r58694240
  
    --- Diff: library/src/test/java/com/datatorrent/lib/io/fs/HDFSOutputOperatorTest.java ---
    @@ -0,0 +1,113 @@
    +/**
    + * 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.junit.Test;
    +
    +public class HDFSOutputOperatorTest extends AbstractFileOutputOperatorTest
    +{
    +
    +  /**
    +   * Test file rollover in case of idle windows
    +   * 
    +   * @throws IOException
    +   */
    +  @Test
    +  public void testIdleWindowsFinalize() throws IOException
    +  {
    +    HDFSOutputOperator writer = new HDFSOutputOperator();
    +    writer.setFileName("output.txt");
    +    writer.setFilePath(testMeta.getDir());
    +    writer.setAlwaysWriteToTmp(false);
    +    writer.setMaxIdleWindows(5);
    +    writer.setup(testMeta.testOperatorContext);
    +
    +    String[][] tuples = {{"0a", "0b" }, {"1a", "1b" }, {}, {}, {}, {}, {"6a", "6b" }, {"7a", "7b" }, {}, {}, {},
    --- End diff --
    
    You can reduce test input here.
    Good test cases though :+1: 


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

[GitHub] incubator-apex-malhar pull request: Added concrete implementation ...

Posted by devtagare <gi...@git.apache.org>.
Github user devtagare commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/233#discussion_r60866383
  
    --- Diff: library/src/main/java/com/datatorrent/lib/io/fs/HDFSOutputOperator.java ---
    @@ -0,0 +1,393 @@
    +/**
    + * 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.ByteArrayOutputStream;
    +import java.io.IOException;
    +import java.util.concurrent.ExecutionException;
    +
    +import javax.validation.constraints.NotNull;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import com.datatorrent.api.AutoMetric;
    +import com.datatorrent.api.Context.OperatorContext;
    +import com.datatorrent.api.DefaultInputPort;
    +import com.datatorrent.api.StreamCodec;
    +import com.datatorrent.netlet.util.DTThrowable;
    +
    +/**
    + * This class is responsible for writing tuples to HDFS. All tuples are written
    + * to the same file. Rolling file based on size, no. of tuples, idle windows,
    + * elapsed windows is supported.
    + * 
    + * @param <T>
    + */
    +
    +class HDFSOutputOperator extends AbstractFileOutputOperator<byte[]>
    +{
    +
    +  /**
    +   * Name of the file to write the output. Directory for the output file should
    +   * be specified in the filePath
    +   */
    +  @NotNull
    +  private String fileName;
    +
    +  /**
    +   * currentPartName can be of the form fileName_physicalPartionId.partNumber
    +   */
    +  private String currentPartNameformat = "%s_%d";
    +
    +  /**
    +   * currentPartName is of the form fileName_physicalPartionId.partNumber
    +   */
    +  private transient String currentPartName;
    +
    +  /**
    +   * Physical partition id for the current partition.
    +   */
    +  private transient int physicalPartitionId;
    +
    +  /**
    +   * Flag to mark if new data in current application window
    +   */
    +  private transient boolean isNewDataInCurrentWindow;
    +
    +  /**
    +   * Separator between the tuples
    +   */
    +  private String tupleSeparator;
    +
    +  /**
    +   * byte[] representation of tupleSeparator
    +   */
    +  private transient byte[] tupleSeparatorBytes;
    +
    +  /**
    +   * No. of bytes received in current application window
    +   */
    +  @AutoMetric
    +  private long byteCount;
    +
    +  /**
    +   * No. of tuples present in current part for file
    +   */
    +  private long currentPartTupleCount;
    +
    +  /**
    +   * Max. number of tuples allowed per part. Part file will be finalized after
    +   * these many tuples
    +   */
    +  private long maxTupleCount = Long.MAX_VALUE;
    +
    +  /**
    +   * No. of windows since last new data received
    +   */
    +  private long currentPartIdleWindows;
    +
    +  /**
    +   * Max number of idle windows for which no new data is added to current part
    +   * file. Part file will be finalized after these many idle windows after last
    +   * new data.
    +   */
    +  private long maxIdleWindows = Long.MAX_VALUE;
    +
    +  /**
    +   * Stream codec for string input port
    +   */
    +  protected StreamCodec<String> stringStreamCodec;
    +
    +  /**
    +   * Default value for stream expiry
    +   */
    +  private static final long DEFAULT_STREAM_EXPIRY_ACCESS_MILL = 60 * 60 * 1000L; //1 hour
    +
    +  /**
    +   * Default value for rotation windows
    +   */
    +  private static final int DEFAULT_ROTATION_WINDOWS = 2 * 60 * 10; //10 min  
    +
    +  /**
    +   * Initializing default values for tuple separator, stream expiry, rotation
    +   * windows
    +   */
    +  public HDFSOutputOperator()
    +  {
    +    setTupleSeparator(System.getProperty("line.separator"));
    +    setExpireStreamAfterAccessMillis(DEFAULT_STREAM_EXPIRY_ACCESS_MILL);
    +    setRotationWindows(DEFAULT_ROTATION_WINDOWS);
    +  }
    +
    +  /**
    +   * Initializing current partition id, part name etc. {@inheritDoc}
    +   */
    +  @Override
    +  public void setup(OperatorContext context)
    +  {
    +    super.setup(context);
    +    physicalPartitionId = context.getId();
    +    currentPartName = String.format(currentPartNameformat, fileName, physicalPartitionId);
    +  }
    +
    +  /**
    +   * {@inheritDoc}
    +   */
    +  @Override
    +  protected String getFileName(byte[] tuple)
    +  {
    +    return currentPartName;
    +  }
    +
    +  /**
    +   * Input port for receiving string tuples.
    +   */
    +  public final transient DefaultInputPort<String> stringInput = new DefaultInputPort<String>()
    +  {
    +    @Override
    +    public void process(String tuple)
    +    {
    +      processTuple(tuple.getBytes());
    +    }
    +
    +    @Override
    +    public StreamCodec<String> getStreamCodec()
    +    {
    +      if (HDFSOutputOperator.this.stringStreamCodec == null) {
    +        return super.getStreamCodec();
    +      } else {
    +        return stringStreamCodec;
    +      }
    +    }
    +  };
    +
    +  /**
    +   * {@inheritDoc}
    +   * 
    +   * @return byte[] representation of the given tuple. if input tuple is of type
    +   *         byte[] then it is returned as it is. for any other type toString()
    +   *         representation is used to generate byte[].
    +   */
    +  @Override
    +  protected byte[] getBytesForTuple(byte[] tuple)
    +  {
    +    ByteArrayOutputStream bytesOutStream = new ByteArrayOutputStream();
    +
    +    try {
    +      bytesOutStream.write(tuple);
    +      bytesOutStream.write(tupleSeparatorBytes);
    +      byteCount += bytesOutStream.size();
    +      return bytesOutStream.toByteArray();
    +    } catch (IOException e) {
    +      throw new RuntimeException(e);
    +    } finally {
    +      try {
    +        bytesOutStream.close();
    +      } catch (IOException e) {
    +        throw new RuntimeException(e);
    +      }
    +    }
    +  }
    +
    +  /**
    +   * Initializing per window level fields {@inheritDoc}
    +   */
    +  @Override
    +  public void beginWindow(long windowId)
    +  {
    +    super.beginWindow(windowId);
    +    byteCount = 0;
    +    isNewDataInCurrentWindow = false;
    +  }
    +
    +  /**
    +   * {@inheritDoc} Does additional state maintenance for rollover
    +   */
    +  @Override
    +  protected void processTuple(byte[] tuple)
    +  {
    +    super.processTuple(tuple);
    +    isNewDataInCurrentWindow = true;
    +
    +    if (++currentPartTupleCount == maxTupleCount) {
    +      rotateCall(currentPartName);
    +    }
    +  }
    +
    +  /**
    +   * {@inheritDoc} Does additional checks if file should be rolled over for this
    +   * window.
    +   */
    +  @Override
    +  public void endWindow()
    +  {
    +    super.endWindow();
    +
    +    if (!isNewDataInCurrentWindow) {
    +      ++currentPartIdleWindows;
    +    } else {
    +      currentPartIdleWindows = 0;
    +    }
    +
    +    if (checkEndWindowFinalization()) {
    +      rotateCall(currentPartName);
    +    }
    +  }
    +
    +  /**
    +   * Rollover check at the endWindow
    +   */
    +  private boolean checkEndWindowFinalization()
    +  {
    +    if ((currentPartIdleWindows == maxIdleWindows)) {
    +      return true;
    +    }
    +    return false;
    +  }
    +
    +  /**
    +   * {@inheritDoc} Handles file rotation along with exception handling
    +   * 
    +   * @param lastFile
    +   */
    +  protected void rotateCall(String lastFile)
    +  {
    +    try {
    +      this.rotate(lastFile);
    +      currentPartName = String.format(currentPartNameformat, fileName, physicalPartitionId);
    +      currentPartIdleWindows = 0;
    +      currentPartTupleCount = 0;
    +    } catch (IOException ex) {
    +      LOG.debug(ex.getMessage());
    +      DTThrowable.rethrow(ex);
    +    } catch (ExecutionException ex) {
    +      LOG.debug(ex.getMessage());
    --- End diff --
    
    Full exception log and at ERROR level


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

[GitHub] incubator-apex-malhar pull request: Added concrete implementation ...

Posted by devtagare <gi...@git.apache.org>.
Github user devtagare commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/233#discussion_r60866562
  
    --- Diff: library/src/test/java/com/datatorrent/lib/io/fs/HDFSOutputOperatorTest.java ---
    @@ -0,0 +1,113 @@
    +/**
    + * 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.junit.Test;
    +
    +public class HDFSOutputOperatorTest extends AbstractFileOutputOperatorTest
    +{
    +
    +  /**
    +   * Test file rollover in case of idle windows
    +   * 
    +   * @throws IOException
    +   */
    +  @Test
    +  public void testIdleWindowsFinalize() throws IOException
    +  {
    +    HDFSOutputOperator writer = new HDFSOutputOperator();
    +    writer.setFileName("output.txt");
    +    writer.setFilePath(testMeta.getDir());
    +    writer.setAlwaysWriteToTmp(false);
    --- End diff --
    
    This would not trigger a file rolling since setAlwaysWriteToTmp is false.Could you please add a test case with it set to true and check the file rolling ? You can repeat both the test cases with it set to true and split the input across files and then check the results.
     + 1 for the test cases though, well thought of.


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

[GitHub] incubator-apex-malhar pull request: Added concrete implementation ...

Posted by DT-Priyanka <gi...@git.apache.org>.
Github user DT-Priyanka commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/233#discussion_r58693831
  
    --- Diff: library/src/main/java/com/datatorrent/lib/io/fs/HDFSOutputOperator.java ---
    @@ -0,0 +1,393 @@
    +/**
    + * 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.ByteArrayOutputStream;
    +import java.io.IOException;
    +import java.util.concurrent.ExecutionException;
    +
    +import javax.validation.constraints.NotNull;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import com.datatorrent.api.AutoMetric;
    +import com.datatorrent.api.Context.OperatorContext;
    +import com.datatorrent.api.DefaultInputPort;
    +import com.datatorrent.api.StreamCodec;
    +import com.datatorrent.netlet.util.DTThrowable;
    +
    +/**
    + * This class is responsible for writing tuples to HDFS. All tuples are written
    + * to the same file. Rolling file based on size, no. of tuples, idle windows,
    + * elapsed windows is supported.
    + * 
    + * @param <T>
    + */
    +
    +class HDFSOutputOperator extends AbstractFileOutputOperator<byte[]>
    +{
    +
    +  /**
    +   * Name of the file to write the output. Directory for the output file should
    +   * be specified in the filePath
    +   */
    +  @NotNull
    +  private String fileName;
    +
    +  /**
    +   * currentPartName is of the form fileName_physicalPartionId.partNumber
    +   */
    +  private String currentPartNameformat = "%s_%d";
    +
    +  /**
    +   * currentPartName is of the form fileName_physicalPartionId.partNumber
    +   */
    +  private transient String currentPartName;
    +
    +  /**
    +   * Physical partition id for the current partition.
    +   */
    +  protected transient int physicalPartitionId;
    +
    +  /**
    +   * Flag to mark if new data in current application window
    +   */
    +  private transient boolean isNewDataInCurrentWindow;
    +
    +  /**
    +   * Separator between the tuples
    +   */
    +  private String tupleSeparator;
    +
    +  /**
    +   * byte[] representation of tupleSeparator
    +   */
    +  private transient byte[] tupleSeparatorBytes;
    +
    +  /**
    +   * No. of bytes received in current application window
    +   */
    +  @AutoMetric
    +  private long byteCount;
    +
    +  /**
    +   * No. of tuples present in current output file
    +   */
    +  private long currentPartTupleCount;
    +
    +  /**
    +   * Max. number of tuples allowed per part. Part file will be finalized after
    +   * these many tuples
    +   */
    +  private long maxTupleCount = Long.MAX_VALUE;
    +
    +  /**
    +   * No. of windows since last new data received
    +   */
    +  private long currentPartIdleWindows;
    +
    +  /**
    +   * Max number of idle windows for which no new data is added to current part
    +   * file. Part file will be finalized after these many idle windows after last
    +   * new data.
    +   */
    +  private long maxIdleWindows = Long.MAX_VALUE;
    +
    +  /**
    +   * Stream codec for string input port
    +   */
    +  protected StreamCodec<String> stringStreamCodec;
    +
    +  /**
    +   * Default value for stream expiry
    +   */
    +  private static final long DEFAULT_STREAM_EXPIRY_ACCESS_MILL = 60 * 60 * 1000L; //1 hour
    +
    +  /**
    +   * Default value for rotation windows
    +   */
    +  private static final int DEFAULT_ROTATION_WINDOWS = 2 * 60 * 10; //10 min  
    +
    +  /**
    +   * Initializing default values for tuple separator, stream expiry, rotation
    +   * windows
    +   */
    +  public HDFSOutputOperator()
    +  {
    +    setTupleSeparator(System.getProperty("line.separator"));
    +    setExpireStreamAfterAccessMillis(DEFAULT_STREAM_EXPIRY_ACCESS_MILL);
    +    setRotationWindows(DEFAULT_ROTATION_WINDOWS);
    +  }
    +
    +  /**
    +   * Initializing current partition id, part name etc. {@inheritDoc}
    +   */
    +  @Override
    +  public void setup(OperatorContext context)
    +  {
    +    super.setup(context);
    +    physicalPartitionId = context.getId();
    +    currentPartName = String.format(currentPartNameformat, fileName, physicalPartitionId);
    +  }
    +
    +  /**
    +   * {@inheritDoc}
    +   */
    +  @Override
    +  protected String getFileName(byte[] tuple)
    +  {
    +    return currentPartName;
    +  }
    +
    +  /**
    +   * Input port for receiving string tuples.
    +   */
    +  public final transient DefaultInputPort<String> stringInput = new DefaultInputPort<String>()
    +  {
    +    @Override
    +    public void process(String tuple)
    +    {
    +      processTuple(tuple.getBytes());
    +    }
    +
    +    @Override
    +    public StreamCodec<String> getStreamCodec()
    +    {
    +      if (HDFSOutputOperator.this.stringStreamCodec == null) {
    +        return super.getStreamCodec();
    +      } else {
    +        return stringStreamCodec;
    +      }
    +    }
    +  };
    +
    +  /**
    +   * {@inheritDoc}
    +   * 
    +   * @return byte[] representation of the given tuple. if input tuple is of type
    +   *         byte[] then it is returned as it is. for any other type toString()
    +   *         representation is used to generate byte[].
    +   */
    +  @Override
    +  protected byte[] getBytesForTuple(byte[] tuple)
    +  {
    +    ByteArrayOutputStream bytesOutStream = new ByteArrayOutputStream();
    +
    +    try {
    +      bytesOutStream.write(tuple);
    +      bytesOutStream.write(tupleSeparatorBytes);
    +      byteCount += bytesOutStream.size();
    +      return bytesOutStream.toByteArray();
    +    } catch (IOException e) {
    +      throw new RuntimeException(e);
    +    } finally {
    +      try {
    +        bytesOutStream.close();
    +      } catch (IOException e) {
    +        throw new RuntimeException(e);
    +      }
    +    }
    +  }
    +
    +  /**
    +   * Initializing per window level fields {@inheritDoc}
    +   */
    +  @Override
    +  public void beginWindow(long windowId)
    +  {
    +    super.beginWindow(windowId);
    +    byteCount = 0;
    +    isNewDataInCurrentWindow = false;
    +  }
    +
    +  /**
    +   * {@inheritDoc} Does additional state maintenance for rollover
    +   */
    +  @Override
    +  protected void processTuple(byte[] tuple)
    +  {
    +    super.processTuple(tuple);
    +    isNewDataInCurrentWindow = true;
    +
    +    if (++currentPartTupleCount == maxTupleCount) {
    +      rotateCall(currentPartName);
    +    }
    +  }
    +
    +  /**
    +   * {@inheritDoc} Does additional checks if file should be rolled over for this
    +   * window.
    +   */
    +  @Override
    +  public void endWindow()
    +  {
    +    super.endWindow();
    +
    +    if (!isNewDataInCurrentWindow) {
    +      ++currentPartIdleWindows;
    +    } else {
    +      currentPartIdleWindows = 0;
    +    }
    +
    +    if (checkEndWindowFinalization()) {
    +      rotateCall(currentPartName);
    +    }
    +  }
    +
    +  /**
    +   * Rollover check at the endWindow
    +   */
    +  private boolean checkEndWindowFinalization()
    +  {
    +    if ((currentPartIdleWindows == maxIdleWindows) && !endOffsets.isEmpty()) {
    +      return true;
    +    }
    +    return false;
    +  }
    +
    +  /**
    +   * {@inheritDoc} Handles file rotation along with exception handling
    +   * 
    +   * @param lastFile
    +   */
    +  protected void rotateCall(String lastFile)
    +  {
    +    try {
    +      this.rotate(lastFile);
    +      currentPartName = String.format(currentPartNameformat, fileName, physicalPartitionId);
    +      currentPartIdleWindows = 0;
    +      currentPartTupleCount = 0;
    +    } catch (IOException ex) {
    +      LOG.debug(ex.getMessage());
    --- End diff --
    
    log it at INFO or ERROR level?


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

[GitHub] incubator-apex-malhar pull request: Added concrete implementation ...

Posted by devtagare <gi...@git.apache.org>.
Github user devtagare commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/233#discussion_r60866308
  
    --- Diff: library/src/main/java/com/datatorrent/lib/io/fs/HDFSOutputOperator.java ---
    @@ -0,0 +1,393 @@
    +/**
    + * 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.ByteArrayOutputStream;
    +import java.io.IOException;
    +import java.util.concurrent.ExecutionException;
    +
    +import javax.validation.constraints.NotNull;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import com.datatorrent.api.AutoMetric;
    +import com.datatorrent.api.Context.OperatorContext;
    +import com.datatorrent.api.DefaultInputPort;
    +import com.datatorrent.api.StreamCodec;
    +import com.datatorrent.netlet.util.DTThrowable;
    +
    +/**
    + * This class is responsible for writing tuples to HDFS. All tuples are written
    + * to the same file. Rolling file based on size, no. of tuples, idle windows,
    + * elapsed windows is supported.
    + * 
    + * @param <T>
    + */
    +
    +class HDFSOutputOperator extends AbstractFileOutputOperator<byte[]>
    +{
    +
    +  /**
    +   * Name of the file to write the output. Directory for the output file should
    +   * be specified in the filePath
    +   */
    +  @NotNull
    +  private String fileName;
    +
    +  /**
    +   * currentPartName is of the form fileName_physicalPartionId.partNumber
    +   */
    +  private String currentPartNameformat = "%s_%d";
    +
    +  /**
    +   * currentPartName is of the form fileName_physicalPartionId.partNumber
    +   */
    +  private transient String currentPartName;
    +
    +  /**
    +   * Physical partition id for the current partition.
    +   */
    +  protected transient int physicalPartitionId;
    +
    +  /**
    +   * Flag to mark if new data in current application window
    +   */
    +  private transient boolean isNewDataInCurrentWindow;
    +
    +  /**
    +   * Separator between the tuples
    +   */
    +  private String tupleSeparator;
    +
    +  /**
    +   * byte[] representation of tupleSeparator
    +   */
    +  private transient byte[] tupleSeparatorBytes;
    +
    +  /**
    +   * No. of bytes received in current application window
    +   */
    +  @AutoMetric
    +  private long byteCount;
    +
    +  /**
    +   * No. of tuples present in current output file
    +   */
    +  private long currentPartTupleCount;
    +
    +  /**
    +   * Max. number of tuples allowed per part. Part file will be finalized after
    +   * these many tuples
    +   */
    +  private long maxTupleCount = Long.MAX_VALUE;
    +
    +  /**
    +   * No. of windows since last new data received
    +   */
    +  private long currentPartIdleWindows;
    +
    +  /**
    +   * Max number of idle windows for which no new data is added to current part
    +   * file. Part file will be finalized after these many idle windows after last
    +   * new data.
    +   */
    +  private long maxIdleWindows = Long.MAX_VALUE;
    +
    +  /**
    +   * Stream codec for string input port
    +   */
    +  protected StreamCodec<String> stringStreamCodec;
    +
    +  /**
    +   * Default value for stream expiry
    +   */
    +  private static final long DEFAULT_STREAM_EXPIRY_ACCESS_MILL = 60 * 60 * 1000L; //1 hour
    +
    +  /**
    +   * Default value for rotation windows
    +   */
    +  private static final int DEFAULT_ROTATION_WINDOWS = 2 * 60 * 10; //10 min  
    +
    +  /**
    +   * Initializing default values for tuple separator, stream expiry, rotation
    +   * windows
    +   */
    +  public HDFSOutputOperator()
    +  {
    +    setTupleSeparator(System.getProperty("line.separator"));
    +    setExpireStreamAfterAccessMillis(DEFAULT_STREAM_EXPIRY_ACCESS_MILL);
    +    setRotationWindows(DEFAULT_ROTATION_WINDOWS);
    +  }
    +
    +  /**
    +   * Initializing current partition id, part name etc. {@inheritDoc}
    +   */
    +  @Override
    +  public void setup(OperatorContext context)
    +  {
    +    super.setup(context);
    +    physicalPartitionId = context.getId();
    +    currentPartName = String.format(currentPartNameformat, fileName, physicalPartitionId);
    +  }
    +
    +  /**
    +   * {@inheritDoc}
    +   */
    +  @Override
    +  protected String getFileName(byte[] tuple)
    +  {
    +    return currentPartName;
    +  }
    +
    +  /**
    +   * Input port for receiving string tuples.
    +   */
    +  public final transient DefaultInputPort<String> stringInput = new DefaultInputPort<String>()
    +  {
    +    @Override
    +    public void process(String tuple)
    +    {
    +      processTuple(tuple.getBytes());
    +    }
    +
    +    @Override
    +    public StreamCodec<String> getStreamCodec()
    +    {
    +      if (HDFSOutputOperator.this.stringStreamCodec == null) {
    +        return super.getStreamCodec();
    +      } else {
    +        return stringStreamCodec;
    +      }
    +    }
    +  };
    +
    +  /**
    +   * {@inheritDoc}
    +   * 
    +   * @return byte[] representation of the given tuple. if input tuple is of type
    +   *         byte[] then it is returned as it is. for any other type toString()
    +   *         representation is used to generate byte[].
    +   */
    +  @Override
    +  protected byte[] getBytesForTuple(byte[] tuple)
    +  {
    +    ByteArrayOutputStream bytesOutStream = new ByteArrayOutputStream();
    +
    +    try {
    +      bytesOutStream.write(tuple);
    +      bytesOutStream.write(tupleSeparatorBytes);
    +      byteCount += bytesOutStream.size();
    +      return bytesOutStream.toByteArray();
    +    } catch (IOException e) {
    +      throw new RuntimeException(e);
    +    } finally {
    +      try {
    +        bytesOutStream.close();
    +      } catch (IOException e) {
    +        throw new RuntimeException(e);
    +      }
    +    }
    +  }
    +
    +  /**
    +   * Initializing per window level fields {@inheritDoc}
    +   */
    +  @Override
    +  public void beginWindow(long windowId)
    +  {
    +    super.beginWindow(windowId);
    +    byteCount = 0;
    +    isNewDataInCurrentWindow = false;
    +  }
    +
    +  /**
    +   * {@inheritDoc} Does additional state maintenance for rollover
    +   */
    +  @Override
    +  protected void processTuple(byte[] tuple)
    +  {
    +    super.processTuple(tuple);
    +    isNewDataInCurrentWindow = true;
    +
    +    if (++currentPartTupleCount == maxTupleCount) {
    +      rotateCall(currentPartName);
    +    }
    +  }
    +
    +  /**
    +   * {@inheritDoc} Does additional checks if file should be rolled over for this
    +   * window.
    +   */
    +  @Override
    +  public void endWindow()
    +  {
    +    super.endWindow();
    +
    +    if (!isNewDataInCurrentWindow) {
    +      ++currentPartIdleWindows;
    +    } else {
    +      currentPartIdleWindows = 0;
    +    }
    +
    +    if (checkEndWindowFinalization()) {
    +      rotateCall(currentPartName);
    +    }
    +  }
    +
    +  /**
    +   * Rollover check at the endWindow
    +   */
    +  private boolean checkEndWindowFinalization()
    +  {
    +    if ((currentPartIdleWindows == maxIdleWindows) && !endOffsets.isEmpty()) {
    +      return true;
    +    }
    +    return false;
    +  }
    +
    +  /**
    +   * {@inheritDoc} Handles file rotation along with exception handling
    +   * 
    +   * @param lastFile
    +   */
    +  protected void rotateCall(String lastFile)
    +  {
    +    try {
    +      this.rotate(lastFile);
    +      currentPartName = String.format(currentPartNameformat, fileName, physicalPartitionId);
    +      currentPartIdleWindows = 0;
    +      currentPartTupleCount = 0;
    +    } catch (IOException ex) {
    +      LOG.debug(ex.getMessage());
    --- End diff --
    
    why not log the entire exception ? LOG.debug("Exception in file rotation",ex);.
    Also, error level log seems more appropriate.


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

[GitHub] incubator-apex-malhar pull request: Added concrete implementation ...

Posted by yogidevendra <gi...@git.apache.org>.
Github user yogidevendra commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/233#discussion_r60865659
  
    --- Diff: library/src/test/java/com/datatorrent/lib/io/fs/HDFSOutputOperatorTest.java ---
    @@ -0,0 +1,113 @@
    +/**
    + * 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.junit.Test;
    +
    +public class HDFSOutputOperatorTest extends AbstractFileOutputOperatorTest
    +{
    +
    +  /**
    +   * Test file rollover in case of idle windows
    +   * 
    +   * @throws IOException
    +   */
    +  @Test
    +  public void testIdleWindowsFinalize() throws IOException
    +  {
    +    HDFSOutputOperator writer = new HDFSOutputOperator();
    +    writer.setFileName("output.txt");
    +    writer.setFilePath(testMeta.getDir());
    +    writer.setAlwaysWriteToTmp(false);
    +    writer.setMaxIdleWindows(5);
    +    writer.setup(testMeta.testOperatorContext);
    +
    +    String[][] tuples = {{"0a", "0b" }, {"1a", "1b" }, {}, {}, {}, {}, {"6a", "6b" }, {"7a", "7b" }, {}, {}, {},
    --- End diff --
    
    I tried to cover different scenarios with long input. Hence, would like to keep it unchanged.


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

[GitHub] incubator-apex-malhar pull request: Added concrete implementation ...

Posted by DT-Priyanka <gi...@git.apache.org>.
Github user DT-Priyanka commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/233#discussion_r58693233
  
    --- Diff: library/src/main/java/com/datatorrent/lib/io/fs/HDFSOutputOperator.java ---
    @@ -0,0 +1,393 @@
    +/**
    + * 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.ByteArrayOutputStream;
    +import java.io.IOException;
    +import java.util.concurrent.ExecutionException;
    +
    +import javax.validation.constraints.NotNull;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import com.datatorrent.api.AutoMetric;
    +import com.datatorrent.api.Context.OperatorContext;
    +import com.datatorrent.api.DefaultInputPort;
    +import com.datatorrent.api.StreamCodec;
    +import com.datatorrent.netlet.util.DTThrowable;
    +
    +/**
    + * This class is responsible for writing tuples to HDFS. All tuples are written
    + * to the same file. Rolling file based on size, no. of tuples, idle windows,
    + * elapsed windows is supported.
    + * 
    + * @param <T>
    + */
    +
    +class HDFSOutputOperator extends AbstractFileOutputOperator<byte[]>
    +{
    +
    +  /**
    +   * Name of the file to write the output. Directory for the output file should
    +   * be specified in the filePath
    +   */
    +  @NotNull
    +  private String fileName;
    +
    +  /**
    +   * currentPartName is of the form fileName_physicalPartionId.partNumber
    +   */
    +  private String currentPartNameformat = "%s_%d";
    +
    +  /**
    +   * currentPartName is of the form fileName_physicalPartionId.partNumber
    +   */
    +  private transient String currentPartName;
    +
    +  /**
    +   * Physical partition id for the current partition.
    +   */
    +  protected transient int physicalPartitionId;
    --- End diff --
    
    why protected?


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

[GitHub] incubator-apex-malhar pull request: Added concrete implementation ...

Posted by DT-Priyanka <gi...@git.apache.org>.
Github user DT-Priyanka commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/233#discussion_r58693332
  
    --- Diff: library/src/main/java/com/datatorrent/lib/io/fs/HDFSOutputOperator.java ---
    @@ -0,0 +1,393 @@
    +/**
    + * 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.ByteArrayOutputStream;
    +import java.io.IOException;
    +import java.util.concurrent.ExecutionException;
    +
    +import javax.validation.constraints.NotNull;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import com.datatorrent.api.AutoMetric;
    +import com.datatorrent.api.Context.OperatorContext;
    +import com.datatorrent.api.DefaultInputPort;
    +import com.datatorrent.api.StreamCodec;
    +import com.datatorrent.netlet.util.DTThrowable;
    +
    +/**
    + * This class is responsible for writing tuples to HDFS. All tuples are written
    + * to the same file. Rolling file based on size, no. of tuples, idle windows,
    + * elapsed windows is supported.
    + * 
    + * @param <T>
    + */
    +
    +class HDFSOutputOperator extends AbstractFileOutputOperator<byte[]>
    +{
    +
    +  /**
    +   * Name of the file to write the output. Directory for the output file should
    +   * be specified in the filePath
    +   */
    +  @NotNull
    +  private String fileName;
    +
    +  /**
    +   * currentPartName is of the form fileName_physicalPartionId.partNumber
    +   */
    +  private String currentPartNameformat = "%s_%d";
    +
    +  /**
    +   * currentPartName is of the form fileName_physicalPartionId.partNumber
    +   */
    +  private transient String currentPartName;
    +
    +  /**
    +   * Physical partition id for the current partition.
    +   */
    +  protected transient int physicalPartitionId;
    +
    +  /**
    +   * Flag to mark if new data in current application window
    +   */
    +  private transient boolean isNewDataInCurrentWindow;
    +
    +  /**
    +   * Separator between the tuples
    +   */
    +  private String tupleSeparator;
    +
    +  /**
    +   * byte[] representation of tupleSeparator
    +   */
    +  private transient byte[] tupleSeparatorBytes;
    +
    +  /**
    +   * No. of bytes received in current application window
    +   */
    +  @AutoMetric
    +  private long byteCount;
    +
    +  /**
    +   * No. of tuples present in current output file
    +   */
    +  private long currentPartTupleCount;
    --- End diff --
    
    may be rename to currentFileTupleCount?



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

[GitHub] incubator-apex-malhar pull request: Added concrete implementation ...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-apex-malhar/pull/233


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