def test_protect_names(self): """ Test cassandra.metadata.protect_names output """ self.assertEqual(protect_names(['tests']), ['tests']) self.assertEqual( protect_names(['tests', 'test\'s', 'tests ?!@#$%^&*()', '1']), ['tests', "\"test's\"", '"tests ?!@#$%^&*()"', '"1"'])
def test_protect_names(self): """ Test cassandra.metadata.protect_names output """ self.assertEqual(protect_names(["tests"]), ["tests"]) self.assertEqual( protect_names(["tests", "test's", "tests ?!@#$%^&*()", "1"]), ["tests", '"test\'s"', '"tests ?!@#$%^&*()"', '"1"'], )
def prepare_export_query(self, partition_key, token_range): """ Return a query where we select all the data for this token range """ pk_cols = ", ".join(protect_names(col.name for col in partition_key)) columnlist = ', '.join(protect_names(self.columns)) start_token, end_token = token_range query = 'SELECT %s FROM %s.%s' % (columnlist, protect_name(self.ks), protect_name(self.cf)) if start_token is not None or end_token is not None: query += ' WHERE' if start_token is not None: query += ' token(%s) > %s' % (pk_cols, start_token) if start_token is not None and end_token is not None: query += ' AND' if end_token is not None: query += ' token(%s) <= %s' % (pk_cols, end_token) return query
def test_protect_names(self): """ Test cassandra.metadata.protect_names output """ self.assertEqual(protect_names(['tests']), ['tests']) self.assertEqual(protect_names( [ 'tests', 'test\'s', 'tests ?!@#$%^&*()', '1' ]), [ 'tests', "\"test's\"", '"tests ?!@#$%^&*()"', '"1"' ])
def prepare_export_query(self, partition_key, token_range): """ Return a query where we select all the data for this token range """ pk_cols = ", ".join(protect_names(col.name for col in partition_key)) columnlist = ', '.join(protect_names(self.columns)) start_token, end_token = token_range query = 'SELECT %s FROM %s.%s' % (columnlist, protect_name( self.ks), protect_name(self.cf)) if start_token is not None or end_token is not None: query += ' WHERE' if start_token is not None: query += ' token(%s) > %s' % (pk_cols, start_token) if start_token is not None and end_token is not None: query += ' AND' if end_token is not None: query += ' token(%s) <= %s' % (pk_cols, end_token) return query