You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemml.apache.org by mb...@apache.org on 2017/08/19 21:46:18 UTC

systemml git commit: [SYSTEMML-1854] Fix NPE on transformapply w/ empty recode map

Repository: systemml
Updated Branches:
  refs/heads/master 8e06ff3cc -> 129710a01


[SYSTEMML-1854] Fix NPE on transformapply w/ empty recode map

Project: http://git-wip-us.apache.org/repos/asf/systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/129710a0
Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/129710a0
Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/129710a0

Branch: refs/heads/master
Commit: 129710a01458a9e6bae8806b8d982e580ebb225e
Parents: 8e06ff3
Author: Matthias Boehm <mb...@gmail.com>
Authored: Fri Aug 18 21:13:56 2017 -0700
Committer: Matthias Boehm <mb...@gmail.com>
Committed: Sat Aug 19 14:47:24 2017 -0700

----------------------------------------------------------------------
 .../runtime/transform/encode/EncoderRecode.java |  4 +-
 .../TransformApplyEmptyRecodeMapTest.java       | 68 ++++++++++++++++++++
 .../functions/transform/ZPackageSuite.java      |  1 +
 3 files changed, 72 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/129710a0/src/main/java/org/apache/sysml/runtime/transform/encode/EncoderRecode.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/transform/encode/EncoderRecode.java b/src/main/java/org/apache/sysml/runtime/transform/encode/EncoderRecode.java
index 3acf640..2a7e405 100644
--- a/src/main/java/org/apache/sysml/runtime/transform/encode/EncoderRecode.java
+++ b/src/main/java/org/apache/sysml/runtime/transform/encode/EncoderRecode.java
@@ -59,6 +59,8 @@ public class EncoderRecode extends Encoder
 	}
 	
 	private long lookupRCDMap(int colID, String key) {
+		if( !_rcdMaps.containsKey(colID) )
+			return -1; //empty recode map
 		Long tmp = _rcdMaps.get(colID).get(key);
 		return (tmp!=null) ? tmp : -1;
 	}
@@ -130,7 +132,7 @@ public class EncoderRecode extends Encoder
 			for( int i=0; i<in.getNumRows(); i++ ) {
 				Object okey = in.get(i, colID-1);
 				String key = (okey!=null) ? okey.toString() : null;
-				long code = lookupRCDMap(colID, key);			
+				long code = lookupRCDMap(colID, key);
 				out.quickSetValue(i, colID-1,
 					(code >= 0) ? code : Double.NaN);
 			}

http://git-wip-us.apache.org/repos/asf/systemml/blob/129710a0/src/test/java/org/apache/sysml/test/integration/functions/transform/TransformApplyEmptyRecodeMapTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/sysml/test/integration/functions/transform/TransformApplyEmptyRecodeMapTest.java b/src/test/java/org/apache/sysml/test/integration/functions/transform/TransformApplyEmptyRecodeMapTest.java
new file mode 100644
index 0000000..c694fe4
--- /dev/null
+++ b/src/test/java/org/apache/sysml/test/integration/functions/transform/TransformApplyEmptyRecodeMapTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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 org.apache.sysml.test.integration.functions.transform;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.sysml.parser.Expression.ValueType;
+import org.apache.sysml.runtime.DMLRuntimeException;
+import org.apache.sysml.runtime.matrix.data.FrameBlock;
+import org.apache.sysml.runtime.matrix.data.MatrixBlock;
+import org.apache.sysml.runtime.transform.encode.Encoder;
+import org.apache.sysml.runtime.transform.encode.EncoderFactory;
+import org.apache.sysml.runtime.util.DataConverter;
+import org.apache.sysml.test.integration.AutomatedTestBase;
+import org.apache.sysml.test.utils.TestUtils;
+
+public class TransformApplyEmptyRecodeMapTest extends AutomatedTestBase 
+{
+	private static final int rows = 7;
+	private static final int cols = 1;
+	
+	@Override
+	public void setUp()  {
+		TestUtils.clearAssertionInformation();
+	}
+	
+	@Test
+	public void testTransformApplyEmptyRecodeMap() {
+		try {
+			//generate input data
+			FrameBlock data = DataConverter.convertToFrameBlock(
+				DataConverter.convertToMatrixBlock(getRandomMatrix(rows, cols, 1, 1, 1, 7)));
+			FrameBlock meta = new FrameBlock(new ValueType[]{ValueType.STRING}, new String[]{"C1"});
+			
+			//execute transform apply
+			Encoder encoder = EncoderFactory.createEncoder(
+				"{ids:true, recode:[1]}", data.getColumnNames(), meta.getSchema(), meta);
+			MatrixBlock out = encoder.apply(data, new MatrixBlock(rows, cols, true));
+			
+			//check outputs
+			Assert.assertEquals(rows, out.getNumRows());
+			Assert.assertEquals(cols, out.getNumColumns());
+			for(int i=0; i<rows; i++)
+				for(int j=0; j<cols; j++)
+					Assert.assertTrue(Double.isNaN(out.quickGetValue(i, j)));
+		} 
+		catch (DMLRuntimeException e) {
+			throw new RuntimeException(e);
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/systemml/blob/129710a0/src/test_suites/java/org/apache/sysml/test/integration/functions/transform/ZPackageSuite.java
----------------------------------------------------------------------
diff --git a/src/test_suites/java/org/apache/sysml/test/integration/functions/transform/ZPackageSuite.java b/src/test_suites/java/org/apache/sysml/test/integration/functions/transform/ZPackageSuite.java
index 736cfc7..2571031 100644
--- a/src/test_suites/java/org/apache/sysml/test/integration/functions/transform/ZPackageSuite.java
+++ b/src/test_suites/java/org/apache/sysml/test/integration/functions/transform/ZPackageSuite.java
@@ -27,6 +27,7 @@ import org.junit.runners.Suite;
 @RunWith(Suite.class)
 @Suite.SuiteClasses({
 	FrameCSVReadWriteTest.class,
+	TransformApplyEmptyRecodeMapTest.class,
 	TransformCSVFrameEncodeDecodeTest.class,
 	TransformCSVFrameEncodeReadTest.class,
 	TransformEncodeDecodeTest.class,