From 3ccffc94b8a6127f6a452a3fb93306ad3bbc8c97 Mon Sep 17 00:00:00 2001 From: Stefania Alborghetti Date: Tue, 22 Dec 2015 09:16:54 +0100 Subject: [PATCH] Fix multiple consecutive delimiters on cqlsh COPY FROM Patch by stefania; reviewed by pmotta for CASSANDRA-10854 --- pylib/cqlshlib/copyutil.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pylib/cqlshlib/copyutil.py b/pylib/cqlshlib/copyutil.py index f699e64620..65f599799a 100644 --- a/pylib/cqlshlib/copyutil.py +++ b/pylib/cqlshlib/copyutil.py @@ -1020,16 +1020,19 @@ class ImportConversion(object): ret[i] = self.converters[self.columns[i]](val) else: if i in self.primary_key_indexes: - message = "Cannot insert null value for primary key column '%s'." % (self.columns[i],) - if self.nullval == '': - message += " If you want to insert empty strings, consider using" \ - " the WITH NULL= option for COPY." - raise Exception(message=message) + raise ValueError(self.get_null_primary_key_message(i)) ret[i] = None return ret + def get_null_primary_key_message(self, idx): + message = "Cannot insert null value for primary key column '%s'." % (self.columns[idx],) + if self.nullval == '': + message += " If you want to insert empty strings, consider using" \ + " the WITH NULL= option for COPY." + return message + def get_row_partition_key_values(self, row): """ Return a string composed of the partition key values, serialized and binary packed - @@ -1037,6 +1040,8 @@ class ImportConversion(object): """ def serialize(n): c, v = self.columns[n], row[n] + if v == self.nullval: + raise ValueError(self.get_null_primary_key_message(n)) return self.cqltypes[c].serialize(self.converters[c](v), self.proto_version) partition_key_indexes = self.partition_key_indexes