ArangoDB-Community / pyArango

Python Driver for ArangoDB with built-in validation
https://pyarango.readthedocs.io/en/latest/
Apache License 2.0
238 stars 90 forks source link

Add 'deduplicate' option to pyArango.collection.ensurePersistentIndex #170

Closed Supytalp closed 4 years ago

Supytalp commented 4 years ago

I noticed that collection.ensurePersistentIndex doesn't have a 'deduplicate' argument, unlike ensureHashIndex:

def ensureHashIndex(self, fields, unique = False, sparse = True, deduplicate = False, name = None):
    """Creates a hash index if it does not already exist, and returns it"""
    data = {
        "type" : "hash",
        "fields" : fields,
        "unique" : unique,
        "sparse" : sparse,
        "deduplicate": deduplicate
    }
    if name:
        data["name"] = name
    ind = Index(self, creationData = data)
    self.indexes["hash"][ind.infos["id"]] = ind
    if name:
        self.indexes_by_name[name] = ind
    return ind

def ensurePersistentIndex(self, fields, unique = False, sparse = True, name = None):
    """Creates a persistent index if it does not already exist, and returns it"""
    data = {
        "type" : "persistent",
        "fields" : fields,
        "unique" : unique,
        "sparse" : sparse,
    }
    if name:
        data["name"] = name
    ind = Index(self, creationData = data)
    self.indexes["skiplist"][ind.infos["id"]] = ind
    if name:
        self.indexes_by_name[name] = ind
    return ind

This causes all the persistent indexes to be created with a default 'true' value for 'deduplicate'.

Since the persistent indexes are supposed to replace the hash ones with RocksDB, I think it would make sense to add this argument here.

Supytalp commented 4 years ago

I created a pull request for this issue: #173

ghislain-bernard commented 4 years ago

Hi, I made the same observation today and look forward to the merge. In the meantime I'm using the depreciated hash index.

Supytalp commented 4 years ago

Since the changes have been merged, I’ll close the issue.

https://github.com/ArangoDB-Community/pyArango/pull/173