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.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
|
|
@ -191,9 +192,38 @@ class FalkorDriver(GraphDriver):
|
||||||
await self.client.connection.close()
|
await self.client.connection.close()
|
||||||
|
|
||||||
async def delete_all_indexes(self) -> None:
|
async def delete_all_indexes(self) -> None:
|
||||||
await self.execute_query(
|
result = await self.execute_query("CALL db.indexes()")
|
||||||
'CALL db.indexes() YIELD name DROP INDEX name',
|
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':
|
def clone(self, database: str) -> 'GraphDriver':
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -327,4 +327,6 @@ COMMUNITY_NODE_RETURN_NEPTUNE = """
|
||||||
n.group_id AS group_id,
|
n.group_id AS group_id,
|
||||||
n.summary AS summary,
|
n.summary AS summary,
|
||||||
n.created_at AS created_at
|
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):
|
async def build_indices_and_constraints(driver: GraphDriver, delete_existing: bool = False):
|
||||||
if delete_existing:
|
if delete_existing:
|
||||||
records, _, _ = await driver.execute_query(
|
await driver.delete_all_indexes()
|
||||||
"""
|
|
||||||
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
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
range_indices: list[LiteralString] = get_range_indices(driver.provider)
|
range_indices: list[LiteralString] = get_range_indices(driver.provider)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -209,9 +209,12 @@ class TestFalkorDriver:
|
||||||
async def test_delete_all_indexes(self):
|
async def test_delete_all_indexes(self):
|
||||||
"""Test delete_all_indexes method."""
|
"""Test delete_all_indexes method."""
|
||||||
with patch.object(self.driver, 'execute_query', new_callable=AsyncMock) as mock_execute:
|
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()
|
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:
|
class TestFalkorDriverSession:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue