This is an automated email from the ASF dual-hosted git repository.
shanthoosh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/samza.git
The following commit(s) were added to refs/heads/master by this push:
new ef4fbef SAMZA-2553: Fix NPE when one of the condition value is null
(#1388)
ef4fbef is described below
commit ef4fbefa17a3e365870d3488dd434fd30bc78e64
Author: Slim Bouguerra <[email protected]>
AuthorDate: Tue Jun 23 12:29:09 2020 -0700
SAMZA-2553: Fix NPE when one of the condition value is null (#1388)
---
.../samza/sql/util/SampleRelTableKeyConverter.java | 6 +++-
.../sql/util/SampleRelTableKeyConverterTest.java | 41 ++++++++++++++++++++++
2 files changed, 46 insertions(+), 1 deletion(-)
diff --git
a/samza-sql/src/test/java/org/apache/samza/sql/util/SampleRelTableKeyConverter.java
b/samza-sql/src/test/java/org/apache/samza/sql/util/SampleRelTableKeyConverter.java
index 1589995..38cb21f 100644
---
a/samza-sql/src/test/java/org/apache/samza/sql/util/SampleRelTableKeyConverter.java
+++
b/samza-sql/src/test/java/org/apache/samza/sql/util/SampleRelTableKeyConverter.java
@@ -34,6 +34,10 @@ public class SampleRelTableKeyConverter implements
SamzaRelTableKeyConverter {
if (relRecord.getFieldValues().get(0) instanceof SamzaSqlRelRecord) {
relRecord = (SamzaSqlRelRecord) relRecord.getFieldValues().get(0);
}
- return
relRecord.getFieldValues().stream().map(Object::toString).collect(Collectors.toList()).get(0);
+ return relRecord.getFieldValues()
+ .stream()
+ .map(x -> x == null ? null : x.toString())
+ .collect(Collectors.toList())
+ .get(0);
}
}
diff --git
a/samza-sql/src/test/java/org/apache/samza/sql/util/SampleRelTableKeyConverterTest.java
b/samza-sql/src/test/java/org/apache/samza/sql/util/SampleRelTableKeyConverterTest.java
new file mode 100644
index 0000000..4d15e2b
--- /dev/null
+++
b/samza-sql/src/test/java/org/apache/samza/sql/util/SampleRelTableKeyConverterTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.samza.sql.util;
+
+import com.google.common.collect.ImmutableList;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.samza.sql.SamzaSqlRelRecord;
+import org.junit.Assert;
+import org.junit.Test;
+
+
+public class SampleRelTableKeyConverterTest {
+
+ @Test
+ public void testNullValue() {
+ SampleRelTableKeyConverter sampleRelTableKeyConverter = new
SampleRelTableKeyConverter();
+ List<Object> values = new ArrayList<>();
+ values.add(null);
+ SamzaSqlRelRecord samzaSqlRelRecord = new
SamzaSqlRelRecord(ImmutableList.of("c1"), values);
+ Object key =
sampleRelTableKeyConverter.convertToTableKeyFormat(samzaSqlRelRecord);
+ Assert.assertNull(key);
+ }
+}