ydb-platform / ydb

YDB is an open source Distributed SQL Database that combines high availability and scalability with strong consistency and ACID transactions
https://ydb.tech
Apache License 2.0
3.99k stars 562 forks source link

VIEW: COUNT and other aggregate functions do not work inside a view #6394

Open jepett0 opened 3 months ago

jepett0 commented 3 months ago

To reproduce:

  1. Create the necessary table to read from:

    CREATE TABLE user_group_members (
    group_id uint32,
    user_id uint32,
    PRIMARY KEY (group_id, user_id)
    );
  2. Create a view:

    CREATE VIEW user_group_view WITH (security_invoker = TRUE) AS
    SELECT COUNT(user_id) AS members_count
    FROM `/Root/user_group_members`; -- write your own path to the `user_group_members` table
  3. Select from the view:

    SELECT * FROM user_group_view;
  4. Observe an error:

    Status: GENERIC_ERROR
    Issues: 
    <main>: Error: Type annotation, code: 1030
    <main>:1:1: Error: At function: RemovePrefixMembers, At function: RemoveSystemMembers, At function: PersistableRepr, At function: SqlProject, At function: PersistableRepr, At function: SqlProject
        <main>:1:48: Error: At function: AssumeColumnOrderPartial
            <main>:1:8: Error: At function: Aggregate, At function: Apply
                <main>:1:8: Error: Expected callable type, but got: Unit
jepett0 commented 2 months ago

PRs in stable: https://github.com/ydb-platform/ydb/pull/7501 https://github.com/ydb-platform/ydb/pull/7523