summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-03-23 14:52:05 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-03-24 14:25:41 -0400
commitcadfc608d63f4e0df46c0daaa28902423fd88d71 (patch)
tree63b05c466c5c0cbebae5515d7790291305e66cc6 /test/sql
parentfd74bd8eea3f3696c43ca0336ed4e437036c43c5 (diff)
downloadsqlalchemy-cadfc608d63f4e0df46c0daaa28902423fd88d71.tar.gz
Convert schema_translate to a post compile
Revised the :paramref:`.Connection.execution_options.schema_translate_map` feature such that the processing of the SQL statement to receive a specific schema name occurs within the execution phase of the statement, rather than at the compile phase. This is to support the statement being efficiently cached. Previously, the current schema being rendered into the statement for a particular run would be considered as part of the cache key itself, meaning that for a run against hundreds of schemas, there would be hundreds of cache keys, rendering the cache much less performant. The new behavior is that the rendering is done in a similar manner as the "post compile" rendering added in 1.4 as part of :ticket:`4645`, :ticket:`4808`. Fixes: #5004 Change-Id: Ia5c89eb27cc8dc2c5b8e76d6c07c46290a7901b6
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_compiler.py49
-rw-r--r--test/sql/test_ddlemit.py3
2 files changed, 47 insertions, 5 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index 033da10a3..ef3e5d26e 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -3960,21 +3960,40 @@ class DDLTest(fixtures.TestBase, AssertsCompiledSQL):
self.assert_compile(
schema.CreateTable(t1),
+ "CREATE TABLE [SCHEMA__none].t1 (q INTEGER)",
+ schema_translate_map=schema_translate_map,
+ )
+ self.assert_compile(
+ schema.CreateTable(t1),
"CREATE TABLE z.t1 (q INTEGER)",
schema_translate_map=schema_translate_map,
+ render_schema_translate=True,
)
self.assert_compile(
schema.CreateTable(t2),
+ "CREATE TABLE [SCHEMA_foo].t2 (q INTEGER)",
+ schema_translate_map=schema_translate_map,
+ )
+ self.assert_compile(
+ schema.CreateTable(t2),
"CREATE TABLE bat.t2 (q INTEGER)",
schema_translate_map=schema_translate_map,
+ render_schema_translate=True,
)
self.assert_compile(
schema.CreateTable(t3),
- "CREATE TABLE t3 (q INTEGER)",
+ "CREATE TABLE [SCHEMA_bar].t3 (q INTEGER)",
schema_translate_map=schema_translate_map,
)
+ self.assert_compile(
+ schema.CreateTable(t3),
+ "CREATE TABLE main.t3 (q INTEGER)",
+ schema_translate_map=schema_translate_map,
+ render_schema_translate=True,
+ default_schema_name="main",
+ )
def test_schema_translate_map_sequence(self):
s1 = schema.Sequence("s1")
@@ -3985,19 +4004,19 @@ class DDLTest(fixtures.TestBase, AssertsCompiledSQL):
self.assert_compile(
schema.CreateSequence(s1),
- "CREATE SEQUENCE z.s1",
+ "CREATE SEQUENCE [SCHEMA__none].s1",
schema_translate_map=schema_translate_map,
)
self.assert_compile(
schema.CreateSequence(s2),
- "CREATE SEQUENCE bat.s2",
+ "CREATE SEQUENCE [SCHEMA_foo].s2",
schema_translate_map=schema_translate_map,
)
self.assert_compile(
schema.CreateSequence(s3),
- "CREATE SEQUENCE s3",
+ "CREATE SEQUENCE [SCHEMA_bar].s3",
schema_translate_map=schema_translate_map,
)
@@ -4135,6 +4154,7 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL):
"bar.mytable.description FROM bar.mytable "
"WHERE bar.mytable.name = :name_1",
schema_translate_map=schema_translate_map,
+ render_schema_translate=True,
)
self.assert_compile(
@@ -4143,6 +4163,7 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL):
"foob.remotetable.value FROM foob.remotetable "
"WHERE foob.remotetable.value = :value_1",
schema_translate_map=schema_translate_map,
+ render_schema_translate=True,
)
schema_translate_map = {"remote_owner": "foob"}
@@ -4155,6 +4176,7 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL):
"foob.remotetable.value FROM mytable JOIN foob.remotetable "
"ON mytable.myid = foob.remotetable.rem_id",
schema_translate_map=schema_translate_map,
+ render_schema_translate=True,
)
def test_schema_translate_aliases(self):
@@ -4185,12 +4207,25 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL):
self.assert_compile(
stmt,
+ "SELECT [SCHEMA__none].myothertable.otherid, "
+ "[SCHEMA__none].myothertable.othername, "
+ "mytable_1.myid, mytable_1.name, mytable_1.description "
+ "FROM [SCHEMA__none].myothertable JOIN "
+ "[SCHEMA__none].mytable AS mytable_1 "
+ "ON [SCHEMA__none].myothertable.otherid = mytable_1.myid "
+ "WHERE mytable_1.name = :name_1",
+ schema_translate_map=schema_translate_map,
+ )
+
+ self.assert_compile(
+ stmt,
"SELECT bar.myothertable.otherid, bar.myothertable.othername, "
"mytable_1.myid, mytable_1.name, mytable_1.description "
"FROM bar.myothertable JOIN bar.mytable AS mytable_1 "
"ON bar.myothertable.otherid = mytable_1.myid "
"WHERE mytable_1.name = :name_1",
schema_translate_map=schema_translate_map,
+ render_schema_translate=True,
)
def test_schema_translate_crud(self):
@@ -4209,6 +4244,7 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL):
table1.insert().values(description="foo"),
"INSERT INTO bar.mytable (description) VALUES (:description)",
schema_translate_map=schema_translate_map,
+ render_schema_translate=True,
)
self.assert_compile(
@@ -4218,17 +4254,20 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL):
"UPDATE bar.mytable SET description=:description "
"WHERE bar.mytable.name = :name_1",
schema_translate_map=schema_translate_map,
+ render_schema_translate=True,
)
self.assert_compile(
table1.delete().where(table1.c.name == "hi"),
"DELETE FROM bar.mytable WHERE bar.mytable.name = :name_1",
schema_translate_map=schema_translate_map,
+ render_schema_translate=True,
)
self.assert_compile(
table4.insert().values(value="there"),
"INSERT INTO foob.remotetable (value) VALUES (:value)",
schema_translate_map=schema_translate_map,
+ render_schema_translate=True,
)
self.assert_compile(
@@ -4238,6 +4277,7 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL):
"UPDATE foob.remotetable SET value=:value "
"WHERE foob.remotetable.value = :value_1",
schema_translate_map=schema_translate_map,
+ render_schema_translate=True,
)
self.assert_compile(
@@ -4245,6 +4285,7 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL):
"DELETE FROM foob.remotetable WHERE "
"foob.remotetable.value = :value_1",
schema_translate_map=schema_translate_map,
+ render_schema_translate=True,
)
def test_alias(self):
diff --git a/test/sql/test_ddlemit.py b/test/sql/test_ddlemit.py
index 13300f0b5..667891236 100644
--- a/test/sql/test_ddlemit.py
+++ b/test/sql/test_ddlemit.py
@@ -28,7 +28,8 @@ class EmitDDLTest(fixtures.TestBase):
has_index=Mock(side_effect=has_index),
supports_comments=True,
inline_comments=False,
- )
+ ),
+ _schema_translate_map=None,
)
def _mock_create_fixture(