Skip to content

groupArray result is not as expected #27115

Closed

Description

@peaksnail

ch version 20.8.12.2

select * from (
select *  from (
  select eventDate from (
    select 
      eventDate 
    from daily_business_report final where 1=1 and storeId = '882ff105-695b-4e6c-90be-b231bfbd7db5' and 
    eventDate>=toDate(1625090400000/1000) and eventDate<toDate(1627682400000/1000) order by eventDate
  ) order by eventDate with fill from toDate(1625090400000/1000) to toDate(1627682400000/1000)-1 
) order by  eventDate 
)

result

2021-07-01
2021-07-02
2021-07-03
2021-07-04
2021-07-05
2021-07-06
2021-07-07
2021-07-08
2021-07-09
2021-07-10
2021-07-11
2021-07-12
2021-07-13
2021-07-14
2021-07-15
2021-07-16
2021-07-17
2021-07-18
2021-07-19
2021-07-20
2021-07-21
2021-07-22
2021-07-23
2021-07-24
2021-07-25
2021-07-26
2021-07-27
2021-07-28
2021-07-29

there has 9 records is not in the ch, gived by the 'with fill'

and then execute sql

select  
  groupArray(eventDate) as keys,
  count() as c   
from (
select * from (
  select *  from (
    select eventDate from (
      select 
        eventDate 
      from daily_business_report final where 1=1 and storeId = '882ff105-695b-4e6c-90be-b231bfbd7db5' and 
      eventDate>=toDate(1625090400000/1000) and eventDate<toDate(1627682400000/1000) order by eventDate
      ) order by eventDate with fill from toDate(1625090400000/1000) to toDate(1627682400000/1000)-1 
    ) order by  eventDate 
  )
)

result

keys    c
['2021-07-06','2021-07-08','2021-07-09','2021-07-10','2021-07-11','2021-07-12','2021-07-14','2021-07-15','2021-07-16','2021-07-17','2021-07-18','2021-07-19','2021-07-20','2021-07-21','2021-07-22','2021-07-23','2021-07-24','2021-07-25','2021-07-26','2021-07-27']	20

it just has 20 record and not inlcude the data gived by the 'with fill'

there expect to get the all data include the record gived by the 'with fill'

thanks

Activity

  1. added
    unexpected behaviour
    on Aug 3, 2021
  2. den-crane commented on Aug 3, 2021

    @den-crane
    Contributor

    Do you have reproducible example?

    SELECT
        groupArray(x),
        count()
    FROM
    (
        SELECT x
        FROM
        (
            SELECT toDate('2020-01-15') AS x
        )
        ORDER BY x ASC WITH FILL FROM toDate('2020-01-10') TO toDate('2020-01-19')
    )
    
    ┌─groupArray(x)──────────────────────────────────────────────────────────────────────────────────────────────────────────┬─count()─┐
    │ ['2020-01-10','2020-01-11','2020-01-12','2020-01-13','2020-01-14','2020-01-15','2020-01-16','2020-01-17','2020-01-18'] │       9 │
    └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴─────────┘```
    
    works for me
    
  3. peaksnail commented on Aug 3, 2021

    @peaksnail
    Author

    create table

    create table fill_ex (
      eventDate Date ,
      storeId String
    ) engine = ReplacingMergeTree() partition by toYYYYMM(eventDate) order by (storeId,eventDate)
    

    insert into data

    insert into fill_ex (eventDate,storeId) values ('2021-07-16','s') ('2021-07-17','ee')
    

    query

    select
      groupArray(key) as keys,
      count() as c
    from
      (
      select
        *,
        eventDate as key
      from
        (
        select
          eventDate
        from
          (
          select
            eventDate
          from
            fill_ex final
          where
            eventDate >= toDate('2021-07-01')
            and eventDate<toDate('2021-07-30')
          order by
            eventDate )
        order by
          eventDate with fill
        from
          toDate('2021-07-01') to toDate('2021-07-30') )
      order by
        eventDate )
    

    result

    ['2021-07-16','2021-07-17']	2
    
  4. peaksnail commented on Aug 3, 2021

    @peaksnail
    Author

    I find that I use the alias eventDate as key and then groupArray(key) and I get the unexpected result

    If I don't use the alias eventDate as key, it works

    select
      groupArray(eventDate) as keys,
      count() as c
    from
      (
      select
        *
      from
        (
        select
          eventDate
        from
          (
          select
            eventDate
          from
            fill_ex final
          where
            eventDate >= toDate('2021-07-01')
            and eventDate<toDate('2021-07-30')
          order by
            eventDate )
        order by
          eventDate with fill
        from
          toDate('2021-07-01') to toDate('2021-07-30') )
      order by
        eventDate )
    

    the sql works

  5. alexey-milovidov commented on Oct 20, 2022

    @alexey-milovidov
    Member

    See #23194

  6. added a commit that references this issue on Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    unexpected behaviour

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions