How is it possible to modify query to pull out data from 2 arrays with different sizes from ClickHouse table? At the moment I have following query which works properly:
SELECT
concat(toString(ApplicationID),': ',dictGetString('Application','Name',CAST(ApplicationID as
UInt64))) as site,
concat(toString(SpotID),': ',dictGetString('Spot','Name',CAST(SpotID as UInt64))) as `Spot`,
dictGetString('Domain', 'Value', DomainMap.ID) AS sourceDomain,
toFloat64(sum(DomainMap.Impressions)) as cnt,
SUM(DomainMap.Price/1000000000) as p,
SUM(DomainMap.Revenue/1000000000) as r,
p - r as res
FROM distributed.publishers_map array Join DomainMap
WHERE ActionDate = '2021-05-16' and ApplicationID in (4749)
GROUP BY
DomainMap.ID,
ApplicationID,SpotID
ORDER BY cnt DESC
Then I need to add data from similar array which name is ExternalSpotMap. From this array I need to get as well
SUM(ExternalSpotMap.Price/1000000000) as p,
SUM(ExternalSpotMap.Revenue/1000000000) as r,
p - r as res
And to add to the data from above mentioned existing query. The problem is that these 2 arrays - DomainMap and ExternalSpotMap are of different sizes and I cannot make just following:
FROM distributed.publishers_map array Join DomainMap, ExternalSpotMap
Option 2. If I make following:
SELECT *
from
(
Select *
from
(
SELECT
concat(toString(ApplicationID),': ',dictGetString('Application','Name',CAST(ApplicationID as
UInt64))) as site,
concat(toString(SpotID),': ',dictGetString('Spot','Name',CAST(SpotID as UInt64))) as `Spot`,
dictGetString('Domain', 'Value', DomainMap.ID) AS sourceDomain,
toFloat64(sum(DomainMap.Impressions)) as cnt,
SUM(DomainMap.Price/1000000000) as p,
SUM(DomainMap.Revenue/1000000000) as r,
p - r as res,
SUM(ExternalSpotMap.Price/1000000000) as esmp,
SUM(ExternalSpotMap.Revenue/1000000000) as esmr,
esmp - esmr as res2
FROM distributed.publishers_map
WHERE ActionDate = '2021-05-16' and ApplicationID in (4749)
GROUP BY DomainMap.ID, ApplicationID,SpotID
ORDER BY cnt DESC
)
array join DomainMap
)
ARRAY JOIN ExternalSpotMap
Then I get an error:
SQL Error [43]: ClickHouse exception, Code: 43, e.displayText() =
DB::Exception: Illegal type Array(Int64) of argument for aggregate function
sum
What could be the reason of issue?
SELECT *
FROM
(
SELECT *
FROM
(
SELECT
1,
[1, 2, 3] AS a,
['a', 'b'] AS b
)
ARRAY JOIN a
)
ARRAY JOIN b
┌─1─┬─a─┬─b─┐
│ 1 │ 1 │ a │
│ 1 │ 1 │ b │
│ 1 │ 2 │ a │
│ 1 │ 2 │ b │
│ 1 │ 3 │ a │
│ 1 │ 3 │ b │
└───┴───┴───┘
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.