Greetings.

I want to implement NestedType
<https://clickhouse.yandex/docs/en/data_types/nested_data_structures/nested/>
for the dialect <https://github.com/xzkostyan/clickhouse-sqlalchemy> of
ClickHouse database.

At the first sight it looks like copmosite type, but not not completely:
1. Each subtype considers like separate column
2. `NestedType` is just syntax sugar:
CREATE TABLE test_table1 (
    date Date,
    object Nested (
        type String,
        content String

    )

)...


CREATE TABLE test_table2 (
    date Date,
    object.type String,
    object.content String
)...
Both of DDL's create tables with the same structure.
3. Queries can be done only using full format, like that:
SELECT count(*), objects.type FROM test_table group by objects.type
or
SELECT count(*), test_table.objects.type FROM test_table group by test_table
.objects.type



My question is how can I implement that behaviour? I've tried to adjust
sqlachemy_utils.CompositeType, but it looks like there are a lot of
differences.

Looks like I need to use separated DeclarativeMeta class and register each
member of nested field (with
sqlalchemy.ext.declarative.base._add_attribute).
Another problem: append parent column name to nested column name, because I
want to make that:


class Test(Base):
    __tablename__ = 'test'
    object = Column(
        Nested(
             Column('type', String),
             Column('content', String),
        )

    )


Session.query(Test).filter(Test.object.type == 'type')...
# generates that query...
select ... from test where test.object.type = 'type'

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to