Skip to content

Commit 7b10bcc

Browse files
committed
WL10772: Cleanup Drop APIs
This worklog is about normalizing the drop API's for consistency. This patch removed the need of calling execute() method in the Collection.drop_index(), therefore DropCollectionIndexStatement was also removed. Tests were added for regression.
1 parent 6b82c4b commit 7b10bcc

File tree

4 files changed

+50
-69
lines changed

4 files changed

+50
-69
lines changed

lib/mysqlx/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
FindStatement, AddStatement, RemoveStatement,
4040
ModifyStatement, SelectStatement, InsertStatement,
4141
DeleteStatement, UpdateStatement,
42-
CreateCollectionIndexStatement,
43-
DropCollectionIndexStatement, CreateTableStatement,
42+
CreateCollectionIndexStatement, CreateTableStatement,
4443
CreateViewStatement, AlterViewStatement, ColumnDef,
4544
GeneratedColumnDef, ForeignKeyDef, Expr)
4645

@@ -216,7 +215,7 @@ def get_session(*args, **kwargs):
216215
"DbDoc", "Statement", "FilterableStatement", "SqlStatement",
217216
"FindStatement", "AddStatement", "RemoveStatement", "ModifyStatement",
218217
"SelectStatement", "InsertStatement", "DeleteStatement", "UpdateStatement",
219-
"CreateCollectionIndexStatement", "DropCollectionIndexStatement",
220-
"CreateTableStatement", "CreateViewStatement", "AlterViewStatement",
221-
"ColumnDef", "GeneratedColumnDef", "ForeignKeyDef", "Expr",
218+
"CreateCollectionIndexStatement", "CreateTableStatement",
219+
"CreateViewStatement", "AlterViewStatement","ColumnDef",
220+
"GeneratedColumnDef", "ForeignKeyDef", "Expr",
222221
]

lib/mysqlx/crud.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# MySQL Connector/Python - MySQL driver written in Python.
2-
# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
33

44
# MySQL Connector/Python is licensed under the terms of the GPLv2
55
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -27,8 +27,7 @@
2727
from .statement import (FindStatement, AddStatement, RemoveStatement,
2828
ModifyStatement, SelectStatement, InsertStatement,
2929
DeleteStatement, UpdateStatement,
30-
CreateCollectionIndexStatement,
31-
DropCollectionIndexStatement, CreateViewStatement,
30+
CreateCollectionIndexStatement, CreateViewStatement,
3231
AlterViewStatement, CreateTableStatement)
3332

3433

@@ -407,7 +406,8 @@ def drop_index(self, index_name):
407406
Args:
408407
index_name (str): Index name.
409408
"""
410-
return DropCollectionIndexStatement(self, index_name)
409+
self._connection.execute_nonquery("xplugin", "drop_collection_index",
410+
True, self._schema.name, self._name, index_name)
411411

412412

413413
class Table(DatabaseObject):

lib/mysqlx/statement.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -760,28 +760,6 @@ def execute(self):
760760
self._is_unique, *fields)
761761

762762

763-
class DropCollectionIndexStatement(Statement):
764-
"""A statement that drops an index on a collection.
765-
766-
Args:
767-
collection (mysqlx.Collection): The Collection object.
768-
index_name (string): The index name.
769-
"""
770-
def __init__(self, collection, index_name):
771-
super(DropCollectionIndexStatement, self).__init__(target=collection)
772-
self._index_name = index_name
773-
774-
def execute(self):
775-
"""Execute the statement.
776-
777-
Returns:
778-
mysqlx.Result: Result object.
779-
"""
780-
return self._connection.execute_nonquery(
781-
"xplugin", "drop_collection_index", True,
782-
self._target.schema.name, self._target.name, self._index_name)
783-
784-
785763
class TableIndex(object):
786764
UNIQUE_INDEX = 1
787765
INDEX = 2

tests/test_mysqlx_crud.py

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -957,44 +957,48 @@ def test_results(self):
957957

958958
self.schema.drop_collection(collection_name)
959959

960-
# def test_create_index(self):
961-
# collection_name = "collection_test"
962-
# collection = self.schema.create_collection(collection_name)
963-
#
964-
# index_name = "age_idx"
965-
# collection.create_index(index_name, True) \
966-
# .field("$.age", "INT", False).execute()
967-
#
968-
# show_indexes_sql = (
969-
# "SHOW INDEXES FROM `{0}`.`{1}` WHERE Key_name='{2}'"
970-
# "".format(self.schema_name, collection_name, index_name)
971-
# )
972-
#
973-
# result = self.session.sql(show_indexes_sql).execute()
974-
# rows = result.fetch_all()
975-
# self.assertEqual(1, len(rows))
976-
977-
# def test_drop_index(self):
978-
# collection_name = "collection_test"
979-
# collection = self.schema.create_collection(collection_name)
980-
#
981-
# index_name = "age_idx"
982-
# collection.create_index(index_name, True) \
983-
# .field("$.age", "INT", False).execute()
984-
#
985-
# show_indexes_sql = (
986-
# "SHOW INDEXES FROM `{0}`.`{1}` WHERE Key_name='{2}'"
987-
# "".format(self.schema_name, collection_name, index_name)
988-
# )
989-
#
990-
# result = self.session.sql(show_indexes_sql).execute()
991-
# rows = result.fetch_all()
992-
# self.assertEqual(1, len(rows))
993-
#
994-
# collection.drop_index(index_name).execute()
995-
# result = self.session.sql(show_indexes_sql).execute()
996-
# rows = result.fetch_all()
997-
# self.assertEqual(0, len(rows))
960+
def test_create_index(self):
961+
collection_name = "collection_test"
962+
collection = self.schema.create_collection(collection_name)
963+
964+
index_name = "age_idx"
965+
collection.create_index(index_name, True) \
966+
.field("$.age", "INT", False).execute()
967+
968+
show_indexes_sql = (
969+
"SHOW INDEXES FROM `{0}`.`{1}` WHERE Key_name='{2}'"
970+
"".format(self.schema_name, collection_name, index_name)
971+
)
972+
973+
result = self.session.sql(show_indexes_sql).execute()
974+
rows = result.fetch_all()
975+
self.assertEqual(1, len(rows))
976+
977+
self.schema.drop_collection(collection_name)
978+
979+
def test_drop_index(self):
980+
collection_name = "collection_test"
981+
collection = self.schema.create_collection(collection_name)
982+
983+
index_name = "age_idx"
984+
collection.create_index(index_name, True) \
985+
.field("$.age", "INT", False).execute()
986+
987+
show_indexes_sql = (
988+
"SHOW INDEXES FROM `{0}`.`{1}` WHERE Key_name='{2}'"
989+
"".format(self.schema_name, collection_name, index_name)
990+
)
991+
992+
result = self.session.sql(show_indexes_sql).execute()
993+
rows = result.fetch_all()
994+
self.assertEqual(1, len(rows))
995+
996+
collection.drop_index(index_name)
997+
result = self.session.sql(show_indexes_sql).execute()
998+
rows = result.fetch_all()
999+
self.assertEqual(0, len(rows))
1000+
1001+
self.schema.drop_collection(collection_name)
9981002

9991003
def test_parameter_binding(self):
10001004
collection_name = "collection_test"

0 commit comments

Comments
 (0)