def get_connection(cls, table_object_name): if table_object_name not in cls._connection_dict: if cls._region_conn is None: cls._region_conn = get_dynamodb_connection() table_properties = cls._TABLE_NAME_TO_PROPERTIES[table_object_name] avro_schema = get_avro_schema(table_properties['avro_schema']) table_name = read_string(table_properties['physical_id_key']) table = Table(table_name, connection=cls._region_conn) try: results = table.describe() raw_indexes = results['Table'].get('GlobalSecondaryIndexes', []) table.global_indexes = introspect_global_indexes(raw_indexes) except Exception: log_exception("Table Connection Failed") cls._connection_dict[table_object_name] = table_properties[ 'class'](table, avro_schema) return cls._connection_dict[table_object_name]
def get_connection(cls, table_object_name): if table_object_name not in cls._connection_dict: if cls._region_conn is None: cls._region_conn = get_dynamodb_connection() table_properties = cls._TABLE_NAME_TO_PROPERTIES[table_object_name] avro_schema = get_avro_schema(table_properties['avro_schema']) table_name = read_string(table_properties['physical_id_key']) table = Table( table_name, connection=cls._region_conn ) try: results = table.describe() raw_indexes = results['Table'].get('GlobalSecondaryIndexes', []) table.global_indexes = introspect_global_indexes(raw_indexes) except Exception: log_exception("Table Connection Failed") cls._connection_dict[table_object_name] = table_properties['class']( table, avro_schema ) return cls._connection_dict[table_object_name]
def test_introspect_global_indexes(): indexes = introspect_global_indexes(safe_load(raw_indexes)) assert len(indexes) == 3 for index in indexes: assert isinstance(index, GlobalAllIndex)