MCPcopy Index your code
hub / github.com/apache/cassandra-python-driver / _update_options

Function _update_options

cassandra/cqlengine/management.py:452–499  ·  view source on GitHub ↗

Updates the table options for the given model if necessary. :param model: The model to update. :param connection: Name of the connection to use :return: `True`, if the options were modified in Cassandra, `False` otherwise. :rtype: bool

(model, connection=None)

Source from the content-addressed store, hash-verified

450
451
452def _update_options(model, connection=None):
453 """Updates the table options for the given model if necessary.
454
455 :param model: The model to update.
456 :param connection: Name of the connection to use
457
458 :return: `True`, if the options were modified in Cassandra,
459 `False` otherwise.
460 :rtype: bool
461 """
462 ks_name = model._get_keyspace()
463 msg = format_log_context("Checking %s for option differences", keyspace=ks_name, connection=connection)
464 log.debug(msg, model)
465 model_options = model.__options__ or {}
466
467 table_meta = _get_table_metadata(model, connection=connection)
468 # go to CQL string first to normalize meta from different versions
469 existing_option_strings = set(table_meta._make_option_strings(table_meta.options))
470 existing_options = _options_map_from_strings(existing_option_strings)
471 model_option_strings = metadata.TableMetadataV3._make_option_strings(model_options)
472 model_options = _options_map_from_strings(model_option_strings)
473
474 update_options = {}
475 for name, value in model_options.items():
476 try:
477 existing_value = existing_options[name]
478 except KeyError:
479 msg = format_log_context("Invalid table option: '%s'; known options: %s", keyspace=ks_name, connection=connection)
480 raise KeyError(msg % (name, existing_options.keys()))
481 if isinstance(existing_value, str):
482 if value != existing_value:
483 update_options[name] = value
484 else:
485 try:
486 for k, v in value.items():
487 if existing_value[k] != v:
488 update_options[name] = value
489 break
490 except KeyError:
491 update_options[name] = value
492
493 if update_options:
494 options = ' AND '.join(metadata.TableMetadataV3._make_option_strings(update_options))
495 query = "ALTER TABLE {0} WITH {1}".format(model.column_family_name(), options)
496 execute(query, connection=connection)
497 return True
498
499 return False
500
501
502def drop_table(model, keyspaces=None, connections=None):

Calls 10

format_log_contextFunction · 0.90
executeFunction · 0.90
_get_table_metadataFunction · 0.85
setFunction · 0.85
_get_keyspaceMethod · 0.80
_make_option_stringsMethod · 0.45
itemsMethod · 0.45
keysMethod · 0.45
column_family_nameMethod · 0.45