Fix FalkorDB index deletion implementation (#998)
* Update node_db_queries.py * Update node_db_queries.py * fix-delete-idx * improve-delete * fix uint tests --------- Co-authored-by: Naseem Ali <34807727+Naseem77@users.noreply.github.com> Co-authored-by: Gal Shubeli <galshubeli93@gmail.com>
This commit is contained in:
parent
e72f81092e
commit
a5f26b6764
4 changed files with 41 additions and 20 deletions
|
|
@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
|
|
@ -191,9 +192,38 @@ class FalkorDriver(GraphDriver):
|
|||
await self.client.connection.close()
|
||||
|
||||
async def delete_all_indexes(self) -> None:
|
||||
await self.execute_query(
|
||||
'CALL db.indexes() YIELD name DROP INDEX name',
|
||||
)
|
||||
result = await self.execute_query("CALL db.indexes()")
|
||||
if not result:
|
||||
return
|
||||
|
||||
records, _, _ = result
|
||||
drop_tasks = []
|
||||
|
||||
for record in records:
|
||||
label = record["label"]
|
||||
entity_type = record["entitytype"]
|
||||
|
||||
for field_name, index_type in record["types"].items():
|
||||
if "RANGE" in index_type:
|
||||
drop_tasks.append(
|
||||
self.execute_query(f"DROP INDEX ON :{label}({field_name})")
|
||||
)
|
||||
elif "FULLTEXT" in index_type:
|
||||
if entity_type == "NODE":
|
||||
drop_tasks.append(
|
||||
self.execute_query(
|
||||
f"DROP FULLTEXT INDEX FOR (n:{label}) ON (n.{field_name})"
|
||||
)
|
||||
)
|
||||
elif entity_type == "RELATIONSHIP":
|
||||
drop_tasks.append(
|
||||
self.execute_query(
|
||||
f"DROP FULLTEXT INDEX FOR ()-[e:{label}]-() ON (e.{field_name})"
|
||||
)
|
||||
)
|
||||
|
||||
if drop_tasks:
|
||||
await asyncio.gather(*drop_tasks)
|
||||
|
||||
def clone(self, database: str) -> 'GraphDriver':
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -327,4 +327,6 @@ COMMUNITY_NODE_RETURN_NEPTUNE = """
|
|||
n.group_id AS group_id,
|
||||
n.summary AS summary,
|
||||
n.created_at AS created_at
|
||||
"""
|
||||
"""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -35,21 +35,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
async def build_indices_and_constraints(driver: GraphDriver, delete_existing: bool = False):
|
||||
if delete_existing:
|
||||
records, _, _ = await driver.execute_query(
|
||||
"""
|
||||
SHOW INDEXES YIELD name
|
||||
""",
|
||||
)
|
||||
index_names = [record['name'] for record in records]
|
||||
await semaphore_gather(
|
||||
*[
|
||||
driver.execute_query(
|
||||
"""DROP INDEX $name""",
|
||||
name=name,
|
||||
)
|
||||
for name in index_names
|
||||
]
|
||||
)
|
||||
await driver.delete_all_indexes()
|
||||
|
||||
range_indices: list[LiteralString] = get_range_indices(driver.provider)
|
||||
|
||||
|
|
|
|||
|
|
@ -209,9 +209,12 @@ class TestFalkorDriver:
|
|||
async def test_delete_all_indexes(self):
|
||||
"""Test delete_all_indexes method."""
|
||||
with patch.object(self.driver, 'execute_query', new_callable=AsyncMock) as mock_execute:
|
||||
# Return None to simulate no indexes found
|
||||
mock_execute.return_value = None
|
||||
|
||||
await self.driver.delete_all_indexes()
|
||||
|
||||
mock_execute.assert_called_once_with('CALL db.indexes() YIELD name DROP INDEX name')
|
||||
mock_execute.assert_called_once_with('CALL db.indexes()')
|
||||
|
||||
|
||||
class TestFalkorDriverSession:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue