This message was deleted.
# troubleshooting
s
This message was deleted.
j
In MSQ it would be an INSERT/SELECT statement such as:
Copy code
insert into ds2
 select floor(__time to HOUR) as __time,
        emailid, 
        count(distinct tmp_hash) as num_hashes
   from ds1
  group by 1, 2
partitioned by HOUR
The ingestion shouldn't care about the segment granularity of ds1, it is only source data. Let me know if that doesn't do what you want.
k
i am on druid .22 Should the datasource already exist?
Copy code
Object 'ds2' not found
till now i have only used ingestion tasks to create datasources. so not aware of this. sorry if its too basic. learning.
v
What you have is the correct result. If you query ds2 with approx count ds hll you will get the result you want. Creating a hll sketch in the ingestion will replace the column with the sketch
j
With INSERT INTO the datasource does not need to exist already. Druid 22 doesn't have MSQ ... to my knowledge MSQ was added in Druid 24. So you may need to upgrade, then add the "druid-multi-stage-query" extension to enable it. One easy way to tell that you have MSQ enabled is to look at the SQL engine options in the Query tab (see screenshot) ...
k
Hi Vijay, pls find the query here
Copy code
{
  "queryType": "topN",
  "dataSource": {
    "type": "join",
    "left": "myDataSource",
    "right": {
      "type": "query",
      "query": {
        "queryType": "topN",
        "dataSource": "myDataSource",
        "dimension": "emailid",
        "threshold": 50000,
        "granularity": "all",
        "filter": {},
        "aggregations": [
          {
            "type": "HLLSketchBuild",
            "name": "dev_hash_chg_freq",
            "fieldName": "dev_hash",
            "lgK": 12,
            "tgtHllType": "HLL_4",
            "round": true
          }
        ],
        "metric": {
          "type": "numeric",
          "metric": "dev_hash_chg_freq"
        },
        "intervals": []
      }
    },
    "rightPrefix": "b.",
    "condition": "emailid == \"b.emailid\"",
    "joinType": "INNER"
  },
  "virtualColumns": [],
  "dimension": {
    "type": "default",
    "dimension": "host",
    "outputName": "host",
    "outputType": "STRING"
  },
  "metric": {
    "type": "numeric",
    "metric": "totalcount"
  },
  "intervals": {
    "type": "intervals",
    "intervals": []
  },
  "filter": {},
  "granularity": "all",
  "aggregations": [
    {
      "type": "filtered",
      "aggregator": {
        "type": "count",
        "name": "totalcount"
      },
      "filter": {},
      "name": "totalcount"
    }
  ],
  "context": {},
  "descending": false,
  "threshold": 10
}
----- yes, i think i need to o an approx count on ds2. But since i am performing a kind of a background task with the 2nd ds, i was hoping to get aggregated count value there. something like
Copy code
email1   32
email1 has 32 unique dev_hashes in the last hour
instead of the following as that would again need an aggregate. email1. AHeee email1 AHfff
v
Please get me the sql query
k
Sql version
Copy code
select count(*), a.host from myDatasource a inner join (
 select emailid, APPROX_COUNT_DISTINCT_DS_HLL(dev_hash, 12, 'HLL_4') from myDatasource
 where "__time" BETWEEN TIMESTAMP '2023-03-06 07:10:00' AND TIMESTAMP '2023-03-06 11:11:00' 
   group by emailid
   order by 2 desc
   limit 50000
    ) b
    on a.emailid=b.emailid
  where   
	"__time" BETWEEN TIMESTAMP '2023-03-06 07:10:00' AND TIMESTAMP '2023-03-06 11:11:00' 
   GROUP BY a.host
People are not happy with the inner join here. so i am trying to come up with 2 other DS with hourly and daily granularity. which can be used as a lookup source. that would contain email vs distinct dev_hash count I dont have a query yet for that
v
I assume the query is
Copy code
select count(*), a.host,a.emailid from myDatasource a inner join (
 select emailid, APPROX_COUNT_DISTINCT_DS_HLL(dev_hash, 12, 'HLL_4') from myDatasource
 where "__time" BETWEEN TIMESTAMP '2023-03-06 07:10:00' AND TIMESTAMP '2023-03-06 11:11:00' 
   group by emailid
   order by 2 desc
   limit 50000
    ) b
    on a.emailid=b.emailid
  where   
	"__time" BETWEEN TIMESTAMP '2023-03-06 07:10:00' AND TIMESTAMP '2023-03-06 11:11:00' 
   GROUP BY a.host
left also need emailid
k
not really since the use of the emailid is only for joining as it represents a unique user. after that i need the host count irrespective of the emailid.
v
ok...got it
how much time does
Copy code
select emailid, APPROX_COUNT_DISTINCT_DS_HLL(dev_hash, 12, 'HLL_4') from myDatasource
 where "__time" BETWEEN TIMESTAMP '2023-03-06 07:10:00' AND TIMESTAMP '2023-03-06 11:11:00' 
   group by emailid
   order by 2 desc
   limit 50000
take?
k
8s on a dataset of 21M records with 500k unique emailid
v
one thing is that your native query does not have any time filter.
k
oh i removed that for the sake of a smaller query/simplicity here. i can post the complete query if you need that
v
what is the requirement....I see that you are doing a hll in the right query but not using it in the final output. This is wasteful.
you need to get top 50k emailids by the dev_hash count?
k
actually i am working with native query only. i just converted this into sql and missed that condition. pasting it again.
Copy code
select count(*), a.host from myDatasource a inner join (
 select emailid, APPROX_COUNT_DISTINCT_DS_HLL(dev_hash, 12, 'HLL_4') dev_hash_count from myDatasource
 where "__time" BETWEEN TIMESTAMP '2023-03-06 07:10:00' AND TIMESTAMP '2023-03-06 11:11:00' 
   group by emailid
   order by 2 desc
   limit 50000
    ) b
    on a.emailid=b.emailid
  where   
	"__time" BETWEEN TIMESTAMP '2023-03-06 07:10:00' AND TIMESTAMP '2023-03-06 11:11:00' AND b.dev_hash_count > 20
   GROUP BY a.host
I am looking for - “number of times host has been accessed if the unique hash count for any user is greater than a threshold”
v
try
Copy code
select a.host,sum(total) from (select count(*) total, host,emailid from myDatasource group by emailid,host) a inner join (
 select emailid, APPROX_COUNT_DISTINCT_DS_HLL(dev_hash, 12, 'HLL_4') dev_hash_count from myDatasource from myDatasource
 where "__time" BETWEEN TIMESTAMP '2023-03-06 07:10:00' AND TIMESTAMP '2023-03-06 11:11:00' 
   group by emailid
   order by 2 desc
   limit 50000
    ) b
    on a.emailid=b.emailid
  where   
  "__time" BETWEEN TIMESTAMP '2023-03-06 07:10:00' AND TIMESTAMP '2023-03-06 11:11:00' 
  AND b.dev_hash_count > 20
   GROUP BY a.host
I have re-written to aggregtae the left table first before the join
this will help if the aggregation reduces the left table significantly.
in your query the entire datasource will scanned for the left part of the join. Joins in druid execute on the broker and hence you will see impact on the broker.
forgot to add time filter into left query
Copy code
select a.host,sum(total) from (select count(*) total, host,emailid from myDatasource 
   where "__time" BETWEEN TIMESTAMP '2023-03-06 07:10:00' AND TIMESTAMP '2023-03-06 11:11:00'  group by emailid,host) a inner join (
 select emailid, APPROX_COUNT_DISTINCT_DS_HLL(dev_hash, 12, 'HLL_4') dev_hash_count from myDatasource from myDatasource
 where "__time" BETWEEN TIMESTAMP '2023-03-06 07:10:00' AND TIMESTAMP '2023-03-06 11:11:00' 
   group by emailid
   order by 2 desc
   limit 50000
    ) b
    on a.emailid=b.emailid
  where   
  "__time" BETWEEN TIMESTAMP '2023-03-06 07:10:00' AND TIMESTAMP '2023-03-06 11:11:00' 
  AND b.dev_hash_count > 20
   GROUP BY a.host
moved the dev_hash condition into having....this way the number of rows coming out of right query is reduced
Copy code
select a.host,sum(total) from (select count(*) total, host,emailid from myDatasource 
   where "__time" BETWEEN TIMESTAMP '2023-03-06 07:10:00' AND TIMESTAMP '2023-03-06 11:11:00'  group by emailid,host) a inner join (
 select emailid, APPROX_COUNT_DISTINCT_DS_HLL(dev_hash, 12, 'HLL_4') dev_hash_count from myDatasource from myDatasource
 where "__time" BETWEEN TIMESTAMP '2023-03-06 07:10:00' AND TIMESTAMP '2023-03-06 11:11:00' 
   group by emailid
   order by 2 desc
   limit 50000 having dev_hash>20
    ) b
    on a.emailid=b.emailid
  where   
  "__time" BETWEEN TIMESTAMP '2023-03-06 07:10:00' AND TIMESTAMP '2023-03-06 11:11:00' 
  
   GROUP BY a.host
k
Thanks Vijay. I will try that and let you know.