Comments (10)
@AcLr I'm using your patch for join. The expected text should be a ANY LEFT JOIN b on a.col = b.col
, but the actually-rendered text is a ANY LEFT JOIN b on col = col
. Then I realized it is due to this line
@xzkostyan Is it still the case that "# Columns prefixed with table name are not supported" ?
from clickhouse-sqlalchemy.
Hi.
Can you provide minimal example of query that should work?
Now joins work only if you use session than provides following query attribute (session.query()
): clickhouse_sqlalchemy.orm.query.Query
.
from clickhouse-sqlalchemy.
Example:
from sqlalchemy import select, MetaData, create_engine, join
url = 'clickhouse+native://default:@localhost/default'
engine = create_engine(url)
metadata = MetaData(bind=engine)
metadata.reflect()
t0 = metadata.sorted_tables[0]
t1 = metadata.sorted_tables[1]
q0 = select([t0]).join(t1, onclause=(t0.c['_id'] == t1.c['_id']))
print(q0)
from clickhouse-sqlalchemy.
Well, the thing is join
should be custom (dialect-specific), not generic. This is required in order to support all the dialect features (GLOBAL
, ARRAY
, etc.).
You can try to use join
from following snippet (I haven't tested it, but I think it's valid):
from sqlalchemy import join as generic_join
def join(left, right, onclause=None, isouter=False, full=False, *kwargs):
global_ = kwargs.pop('global_', False)
any_ = kwargs.pop('any', None)
all_ = kwargs.pop('all', None)
j = generic_join(left, right, onclause=onclause, isouter=isouter, full=full)
j.any = any_
j.all = all_
j.global_ = global_
return j
from clickhouse-sqlalchemy.
After running your new join, the old code gives the same Error:
>>> q0 = select([t0]).join(t1, onclause=(t0.c['_id'] == t1.c['_id']))
>>> print(q0)
131 join_type = " "
132
--> 133 if join.global_:
134 join_type += "GLOBAL "
135
AttributeError: 'Join' object has no attribute 'global_'
So I changed it a bit, without using classs method 'join', but now another Error shows up:
>>>q1 = join(sqlalchemy.select([t0]), t1,onclause=(t0.c['_id'] == t1.c['_id']))
>>>print(q1)
<ipython-input-13-69e47fd8b005> in <module>
----> 1 q1 = join(sqlalchemy.select([c0]), t1, onclause=(c0==c1))
<ipython-input-2-8895d0db2cd6> in join(left, right, onclause, isouter, full, *kwargs)
2
3 def join(left, right, onclause=None, isouter=False, full=False, *kwargs):
----> 4 global_ = kwargs.pop('global_', False)
5
6 any_ = kwargs.pop('any', None)
AttributeError: 'tuple' object has no attribute 'pop'
from clickhouse-sqlalchemy.
Oh, I see. Join here is method of the query constructed by select, not imported from sqlalchemy package. As dirty-dirty hack you can patch select result before join.
query= select(...)
query.join = join
query = query.join(...)
May be there is more elegant way to use patched version of join.
from clickhouse-sqlalchemy.
I've done that feature and ready to make PR but got a question.
I found that declarative join parameners much more convenient than standard sqlalchemy joins. Examples are here.
Is it ok? Or do you want to save standard mechanism with several join arguments? In that case it will be several parameters for joins: isouter (bool), isfull (bool), isright (bool), any (bool), all (bool), global (bool), iscross (bool).
Several of them will be conflicted (any and all, isfull and cross and so on).
There is another way: provide the both mechanisms: sqla-standard and declarative (like in my examples).
from clickhouse-sqlalchemy.
I think that the second way is better (with both mechanisms: sqla-standard and declarative). There are many tools that use SA to generate SQL. If we want make these tools ClickHouse compatible sqlalchemy standard is required. But declarative way is more elegant.
from clickhouse-sqlalchemy.
@ccaapton see #87. It is fixed in latest master.
from clickhouse-sqlalchemy.
Awesome! Thanks a lot!
from clickhouse-sqlalchemy.
Related Issues (20)
- Does `clickhouse-sqlalchemy` 3.0.0 support `sqlalchemy` of the version 1.4.*? HOT 5
- Create a cluster table orm class with engines.Distributed which has a logs attribute, how to use variable to indicate it?
- alembic does not autogenerate engine for clickhouse table HOT 4
- Patreon does not work HOT 1
- Add support for Date32 HOT 2
- Handling Clickhouse Alembic Migrations for Clickhouse cluster HOT 2
- Support/example for creating views HOT 2
- `create_all` for all the `MaterializedView`
- With chdb this clickhouse downsized memory database, can clickhouse-sqlalchemy support it or not?
- Support VariantType
- Table reflection for DateTime64 timezone will be extra quoted
- Alembic_Version Records disappered after clickhouse alembic migration HOT 5
- using http mode, connecting database failed when account password ends with @ HOT 2
- Support nested Map column
- Cannot seem to run ALTER command on replicas of the same shard HOT 2
- Sqlalchemy can't catch asynch's error
- query_id cannot be set with the native TCP connection
- Feature Request: Support clickhouse-connect's NEW AsyncClient wrapper HOT 5
- Nested maps, tuples, enums don't work HOT 2
- Support Lightweight DELETE Statement HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clickhouse-sqlalchemy.