[
https://issues.apache.org/jira/browse/APEXMALHAR-2015?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15201394#comment-15201394
]
ASF GitHub Bot commented on APEXMALHAR-2015:
--------------------------------------------
Github user yogidevendra commented on a diff in the pull request:
https://github.com/apache/incubator-apex-malhar/pull/217#discussion_r56648250
--- Diff:
library/src/test/java/com/datatorrent/lib/projection/ActivateTest.java ---
@@ -0,0 +1,147 @@
+/**
+ * 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.projection;
+
+import java.util.Date;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests for Projection related Activate method
+ */
+
+public class ActivateTest
+{
+ private static final Logger logger =
LoggerFactory.getLogger(ActivateTest.class);
+
+ public static class DummyPOJO
+ {
+ private long l;
+ private String str;
+ private Date date;
+
+ public long getL()
+ {
+ return l;
+ }
+
+ public void setL(long l)
+ {
+ this.l = l;
+ }
+
+ public String getStr()
+ {
+ return str;
+ }
+
+ public void setStr(String str)
+ {
+ this.str = str;
+ }
+
+ public Date getDate()
+ {
+ return date;
+ }
+
+ public void setDate(Date date)
+ {
+ this.date = date;
+ }
+ }
+
+ private static DummyProjection projection;
+ private static DummyPOJO data;
+
+ @Test
+ public void testSelectDropFieldsNull()
+ {
+ logger.debug("start round 0");
+ projection.selectFields = null;
+ projection.dropFields = null;
+ projection.activate(null);
+ Assert.assertEquals("projected fields", 3,
projection.getProjectedFieldsSize());
+ Assert.assertEquals("remainder fields", 0,
projection.getRemainderFieldsSize());
+ projection.deactivate();
+ logger.debug("start round 0");
+ }
+
+ @Test
+ public void testSelectDropFieldsEmpty()
+ {
+ logger.debug("start round 0");
+ projection.selectFields = "";
+ projection.dropFields = "";
+ projection.activate(null);
+ Assert.assertEquals("projected fields", 3,
projection.getProjectedFieldsSize());
+ Assert.assertEquals("remainder fields", 0,
projection.getRemainderFieldsSize());
+ projection.deactivate();
+ logger.debug("start round 0");
+ }
+
+ @Test
+ public void testSelectFields()
+ {
+ logger.debug("start round 0");
+ projection.selectFields = "l,str";
+ projection.dropFields = "";
+ projection.activate(null);
+ Assert.assertEquals("projected fields", 2,
projection.getProjectedFieldsSize());
+ Assert.assertEquals("remainder fields", 1,
projection.getRemainderFieldsSize());
+ projection.deactivate();
+ logger.debug("start round 0");
+ }
+
+ @Test
+ public void testDropFields()
+ {
+ logger.debug("start round 0");
+ projection.selectFields = "";
+ projection.dropFields = "str,date";
+ projection.activate(null);
+ Assert.assertEquals("projected fields", 1,
projection.getProjectedFieldsSize());
+ Assert.assertEquals("remainder fields", 2,
projection.getRemainderFieldsSize());
+ projection.deactivate();
+ logger.debug("start round 0");
+ }
+
--- End diff --
Should we add test case for where both selectFields, dropFields are
specified.
> Projection Operator
> -------------------
>
> Key: APEXMALHAR-2015
> URL: https://issues.apache.org/jira/browse/APEXMALHAR-2015
> Project: Apache Apex Malhar
> Issue Type: New Feature
> Reporter: Pradeep A Dalvi
>
> Projection Operator will allow apex users to project (select/drop) certain
> fields from the incoming tuples. This operation might be done unconditionally
> or based on certain condition.
> Use case:
> -------------
> Not all fields of tuples are of interest for the downstream operators. In
> such cases, one may want project selective fields to downstream. Also one may
> want to drop few fields, instead of selecting many.
> In certain scenarios, one may want to project certain fields based on given
> condition or expression.
> Functionality:
> -----------------
> 1. Projection operator shall receive POJO as input tuple and emit 2 POJOs on
> separate output ports i.e. selected and dropped. Selected output port shall
> emit POJO with selected fields and dropped output shall emit POJO of dropped
> fields.
> 2. Operator needs select or drop fields as input params. This shall be
> specified using comma separated list of fields.
> 3. Operator shall emit POJO only on connected output ports. In another words,
> if dropped output port is not connected, it shall not even try to generate
> POJOs with dropped fields.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)