-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove the schema prefix when we do joins
Summary On the columns that are part of the clause for a join, remove the schema prefix by creating an alias based on the table and setting the `table` attribute of the columns in the join clause to be alias and not the table. The name of the alias is picked to be the name of the table as well as it works in plain SQL. We only do that if: 1. there is a schema prefix on the table (ie. `commons` or `production`) 2. the "table" is not actually already an alias 3. the "table" is not actually a subquery Testing I created unit tests for the visit_join function they are all passing. I also created a wheel package and uploaded it in `superset`, I used to have issues with queries when superset wanted to do a self join to limit the number of series returned in a query. It was complaining: ``` Relation name `commons` not found. If you are trying to access a nested field within an object ``` With the fix the query is working fine.
- Loading branch information
Showing
3 changed files
with
103 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
setup( | ||
name="rockset-sqlalchemy", | ||
version="1.0.0", | ||
version="1.0.1", | ||
author="Rockset", | ||
author_email="[email protected]", | ||
keywords=["Rockset", "rockset-client"], | ||
|
@@ -15,16 +15,13 @@ | |
entry_points={ | ||
"sqlalchemy.dialects": [ | ||
"rockset_sqlalchemy = rockset_sqlalchemy.sqlalchemy:RocksetDialect", | ||
"rockset = rockset_sqlalchemy.sqlalchemy:RocksetDialect" | ||
"rockset = rockset_sqlalchemy.sqlalchemy:RocksetDialect", | ||
] | ||
}, | ||
install_requires=[ | ||
"rockset>=1.0.0", | ||
"sqlalchemy>=1.4.0" | ||
], | ||
install_requires=["rockset>=1.0.0", "sqlalchemy>=1.4.0"], | ||
classifiers=[ | ||
'Programming Language :: Python :: 3', | ||
'License :: OSI Approved :: Apache Software License', | ||
'Operating System :: OS Independent', | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: Apache Software License", | ||
"Operating System :: OS Independent", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import sys | ||
|
||
from sqlalchemy.dialects import registry | ||
from sqlalchemy.sql import and_, column, table | ||
from sqlalchemy.testing import AssertsCompiledSQL | ||
|
||
|
||
class TestSQL(AssertsCompiledSQL): | ||
__dialect__ = "rockset" | ||
|
||
def setup_method(self): | ||
|
||
sys.path.insert(0, "./src") | ||
|
||
registry.register("rockset", "rockset_sqlalchemy.sqlalchemy", "RocksetDialect") | ||
pass | ||
|
||
def test_inner_join_table_on_clause_w_schema(self): | ||
t1 = table("t1", column("x"), schema="s1") | ||
t2 = table("t2", column("y"), schema="s2") | ||
nd = and_(*[column("x") == t2.c.y]) | ||
# the column in the join condition is not part of a table so it shouldn't be prefixed | ||
self.assert_compile( | ||
t1.join(t2, nd), | ||
'"s1"."t1" JOIN "s2"."t2" ON "x" = "t2"."y"', | ||
) | ||
nd = and_(*[column("x") == t2.c.y]) | ||
self.assert_compile( | ||
t1.join(t2, nd), | ||
'"s1"."t1" JOIN "s2"."t2" ON "x" = "t2"."y"', | ||
) | ||
t3 = t2.alias("t3") | ||
col = column("y") | ||
col.table = t3 | ||
nd = and_(*[t1.c.x == col]) | ||
# the column in the join condition is not part of a table so it shouldn't be prefixed | ||
self.assert_compile( | ||
t1.join(t2, nd), | ||
'"s1"."t1" JOIN "s2"."t2" ON "t1"."x" = "t3"."y"', | ||
) | ||
|
||
def test_inner_join_table_on_clause(self): | ||
t1 = table("t1", column("x")) | ||
t2 = table("t2", column("y")) | ||
nd = and_(*[column("x") == t2.c.y]) | ||
self.assert_compile( | ||
t1.join(t2.alias("t3"), nd), | ||
'"t1" JOIN "t2" AS "t3" ON "x" = "t2"."y"', | ||
) | ||
|
||
def test_inner_join_no_table_on_clause(self): | ||
t1 = table("t1", column("x")) | ||
t2 = table("t2", column("y")) | ||
nd = and_(*[column("x") == column("y")]) | ||
self.assert_compile( | ||
t1.join(t2.alias("t3"), nd), | ||
'"t1" JOIN "t2" AS "t3" ON "x" = "y"', | ||
) |