You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by yu...@apache.org on 2016/03/22 21:52:51 UTC

[04/13] cassandra git commit: cqlsh: COPY FROM should check that explicit column names are valid

cqlsh: COPY FROM should check that explicit column names are valid

patch by Stefania Alborghetti; reviewed by Paulo Motta for CASSANDRA-11333


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

Branch: refs/heads/cassandra-3.5
Commit: c74df401768fe25eb80f9d328cad974c8ab220ad
Parents: b06bcf7
Author: Stefania Alborghetti <st...@datastax.com>
Authored: Wed Mar 16 17:42:54 2016 +0800
Committer: Yuki Morishita <yu...@apache.org>
Committed: Tue Mar 22 15:49:20 2016 -0500

----------------------------------------------------------------------
 CHANGES.txt                |  1 +
 pylib/cqlshlib/copyutil.py | 43 +++++++++++++++++++++++++++++++----------
 2 files changed, 34 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/c74df401/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index bcdf189..e4db50e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.2.6
+ * cqlsh: COPY FROM should check that explicit column names are valid (CASSANDRA-11333)
  * Add -Dcassandra.start_gossip startup option (CASSANDRA-10809)
  * Fix UTF8Validator.validate() for modified UTF-8 (CASSANDRA-10748)
  * Clarify that now() function is calculated on the coordinator node in CQL documentation (CASSANDRA-10900)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c74df401/pylib/cqlshlib/copyutil.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/copyutil.py b/pylib/cqlshlib/copyutil.py
index 2755dd5..d08a4fd 100644
--- a/pylib/cqlshlib/copyutil.py
+++ b/pylib/cqlshlib/copyutil.py
@@ -152,6 +152,7 @@ class CopyTask(object):
         self.shell = shell
         self.ks = ks
         self.table = table
+        self.table_meta = self.shell.get_table_meta(self.ks, self.table)
         self.local_dc = shell.conn.metadata.get_host(shell.hostname).datacenter
         self.fname = safe_normpath(fname)
         self.protocol_version = protocol_version
@@ -386,6 +387,20 @@ class CopyTask(object):
                     debug=shell.debug
                     )
 
+    def validate_columns(self):
+        shell = self.shell
+
+        if not self.columns:
+            shell.printerr("No column specified")
+            return False
+
+        for c in self.columns:
+            if c not in self.table_meta.columns:
+                shell.printerr('Invalid column name %s' % (c,))
+                return False
+
+        return True
+
     def update_params(self, params, i):
         """
         Add the communication channels to the parameters to be passed to the worker process:
@@ -515,8 +530,7 @@ class ExportTask(CopyTask):
             shell.printerr('Unrecognized COPY TO options: %s' % ', '.join(self.options.unrecognized.keys()))
             return
 
-        if not self.columns:
-            shell.printerr("No column specified")
+        if not self.validate_columns():
             return 0
 
         ranges = self.get_ranges()
@@ -987,7 +1001,6 @@ class ImportTask(CopyTask):
         options = self.options
         self.skip_columns = [c.strip() for c in self.options.copy['skipcols'].split(',')]
         self.valid_columns = [c for c in self.columns if c not in self.skip_columns]
-        self.table_meta = self.shell.get_table_meta(self.ks, self.table)
         self.receive_meter = RateMeter(log_fcn=self.printmsg,
                                        update_interval=options.copy['reportfrequency'],
                                        log_file=options.copy['ratefile'])
@@ -1001,6 +1014,22 @@ class ImportTask(CopyTask):
         ret['valid_columns'] = self.valid_columns
         return ret
 
+    def validate_columns(self):
+        if not CopyTask.validate_columns(self):
+            return False
+
+        shell = self.shell
+        if not self.valid_columns:
+            shell.printerr("No valid column specified")
+            return False
+
+        for c in self.table_meta.primary_key:
+            if c.name not in self.valid_columns:
+                shell.printerr("Primary key column '%s' missing or skipped" % (c.name,))
+                return False
+
+        return True
+
     def run(self):
         shell = self.shell
 
@@ -1008,15 +1037,9 @@ class ImportTask(CopyTask):
             shell.printerr('Unrecognized COPY FROM options: %s' % ', '.join(self.options.unrecognized.keys()))
             return
 
-        if not self.valid_columns:
-            shell.printerr("No column specified")
+        if not self.validate_columns():
             return 0
 
-        for c in self.table_meta.primary_key:
-            if c.name not in self.valid_columns:
-                shell.printerr("Primary key column '%s' missing or skipped" % (c.name,))
-                return 0
-
         self.printmsg("\nStarting copy of %s.%s with columns %s." % (self.ks, self.table, self.valid_columns))
 
         try: