SAMZA-2553: Fix NPE when one of the condition value is null (#1388)
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 @@
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);
+ }
+}