# Help Debugging Join in tick sctript

**URL:** https://community.influxdata.com/t/help-debugging-join-in-tick-sctript/8934
**Category:** Kapacitor
**Created:** [March 8, 2019, 8:30am UTC](https://community.influxdata.com/t/help-debugging-join-in-tick-sctript/8934 "2019-03-08T08:30:33Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Robert\_George](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/robert_george/32/3480_2.png) [@Robert\_George](https://community.influxdata.com/u/Robert_George)
#### Post date: [March 8, 2019, 8:30am UTC](https://community.influxdata.com/t/help-debugging-join-in-tick-sctript/8934/1 "2019-03-08T08:30:33Z")

</div>

I’m trying to join two batch queries. However, after join the series is empties. Please help be debug this.

> TICK script:  
> ID: join  
> Error:  
> Template:  
> Type: batch  
> Status: enabled  
> Executing: true  
> Created: 08 Mar 19 06:45 UTC  
> Modified: 08 Mar 19 08:13 UTC  
> LastEnabled: 08 Mar 19 08:13 UTC  
> Databases Retention Policies: [“telegraf”.“two\_months”]  
> TICKscript:  
> dbrp “telegraf”.“two\_months”
> 
> // The measurement to analyze  
> var measurement = ‘responsetimes’
> 
> // The amount of data to window at once  
> var window = 15m
> 
> var series = batch  
> |query(‘’’  
> SELECT count(timetaken) as count  
> FROM “telegraf”.two\_months.responsetimes  
> WHERE “responsecode” != ‘10018’ AND “responsecode” != ‘10097’ AND “responsecode” != ‘10181’ AND “responsecode” != ‘10256’ AND “responsecode” != ‘10285’ AND “merchant” != ‘Sevasys’  
> ‘’‘)  
> .period(window)  
> .groupBy(time(1m), ‘qcinstance’)  
> .cron(’\*/1 \* \* \* \*')  
> .align()  
> .fill(0)  
> |log()  
> .prefix(‘series’)
> 
> var counts = batch  
> |query(‘’’  
> SELECT count(timetaken) as sum  
> FROM “telegraf”.two\_months.responsetimes  
> WHERE “responsecode” != ‘10018’ AND “responsecode” != ‘10097’ AND “responsecode” != ‘10181’ AND “responsecode” != ‘10256’ AND “responsecode” != ‘10285’ AND “merchant” != ‘Sevasys’  
> ‘’‘)  
> .period(window)  
> .groupBy(‘qcinstance’)  
> .cron(’\*/1 \* \* \* \*')  
> .align()  
> .fill(0)  
> |log()  
> .prefix(‘counts’)
> 
> series  
> |join(counts)  
> .on(‘qcinstance’)  
> .fill(‘null’)  
> .tolerance(14m)  
> .as(‘counts’, ‘series’)  
> |log()  
> .prefix(‘join’)
> 
> DOT:  
> digraph join {  
> graph [throughput=“0.00 batches/s”];
> 
> query3 [avg\_exec\_time\_ns=“2.683689867s” batches\_queried=“52” errors=“0” points\_queried=“52” working\_cardinality=“0”];  
> query3 → log4 [processed=“52”];
> 
> log4 [avg\_exec\_time\_ns=“46.864µs” errors=“0” working\_cardinality=“0”];  
> log4 → join6 [processed=“52”];
> 
> query1 [avg\_exec\_time\_ns=“0s” batches\_queried=“52” errors=“0” points\_queried=“780” working\_cardinality=“0”];  
> query1 → log2 [processed=“52”];
> 
> log2 [avg\_exec\_time\_ns=“234.01µs” errors=“0” working\_cardinality=“0”];  
> log2 → join6 [processed=“52”];
> 
> join6 [avg\_exec\_time\_ns=“6.863µs” errors=“0” working\_cardinality=“0”];  
> join6 → log7 [processed=“0”];
> 
> log7 [avg\_exec\_time\_ns=“0s” errors=“0” working\_cardinality=“0”];  
> }

The logs:

```
ts=2019-03-08T08:14:00.674Z lvl=info msg="batch point" service=kapacitor task_master=main task=join node=log4 prefix=counts name=responsetimes group=qcinstan
ce=SCLP-FC tag_qcinstance=SCLP-FC field_sum=11 time=2019-03-08T07:59:00Z

ts=2019-03-08T08:14:01.174Z lvl=info msg="batch point" service=kapacitor task_master=main task=join node=log2 prefix=series name=responsetimes 
group=qcinstance=SCLP-FC tag_qcinstance=SCLP-FC field_count=0 time=2019-03-08T07:59:00Z
ts=2019-03-08T08:14:01.174Z lvl=info msg="batch point" service=kapacitor task_master=main task=join node=log2 prefix=series name=responsetimes group=qcinstan
ce=SCLP-FC tag_qcinstance=SCLP-FC field_count=4 time=2019-03-08T08:00:00Z
ts=2019-03-08T08:14:01.174Z lvl=info msg="batch point" service=kapacitor task_master=main task=join node=log2 prefix=series name=responsetimes group=qcinstan
ce=SCLP-FC tag_qcinstance=SCLP-FC field_count=0 time=2019-03-08T08:01:00Z
ts=2019-03-08T08:14:01.174Z lvl=info msg="batch point" service=kapacitor task_master=main task=join node=log2 prefix=series name=responsetimes group=qcinstan
ce=SCLP-FC tag_qcinstance=SCLP-FC field_count=0 time=2019-03-08T08:02:00Z
ts=2019-03-08T08:14:01.174Z lvl=info msg="batch point" service=kapacitor task_master=main task=join node=log2 prefix=series name=responsetimes group=qcinstan
ce=SCLP-FC tag_qcinstance=SCLP-FC field_count=0 time=2019-03-08T08:03:00Z
ts=2019-03-08T08:14:01.174Z lvl=info msg="batch point" service=kapacitor task_master=main task=join node=log2 prefix=series name=responsetimes group=qcinstan
ce=SCLP-FC tag_qcinstance=SCLP-FC field_count=0 time=2019-03-08T08:04:00Z
ts=2019-03-08T08:14:01.174Z lvl=info msg="batch point" service=kapacitor task_master=main task=join node=log2 prefix=series name=responsetimes group=qcinstan
ce=SCLP-FC tag_qcinstance=SCLP-FC field_count=0 time=2019-03-08T08:05:00Z
ts=2019-03-08T08:14:01.174Z lvl=info msg="batch point" service=kapacitor task_master=main task=join node=log2 prefix=series name=responsetimes group=qcinstan
ce=SCLP-FC tag_qcinstance=SCLP-FC field_count=0 time=2019-03-08T08:06:00Z
ts=2019-03-08T08:14:01.174Z lvl=info msg="batch point" service=kapacitor task_master=main task=join node=log2 prefix=series name=responsetimes group=qcinstan
ce=SCLP-FC tag_qcinstance=SCLP-FC field_count=2 time=2019-03-08T08:07:00Z
ts=2019-03-08T08:14:01.174Z lvl=info msg="batch point" service=kapacitor task_master=main task=join node=log2 prefix=series name=responsetimes group=qcinstan
ce=SCLP-FC tag_qcinstance=SCLP-FC field_count=1 time=2019-03-08T08:08:00Z
ts=2019-03-08T08:14:01.174Z lvl=info msg="batch point" service=kapacitor task_master=main task=join node=log2 prefix=series name=responsetimes group=qcinstan
ce=SCLP-FC tag_qcinstance=SCLP-FC field_count=0 time=2019-03-08T08:09:00Z
ts=2019-03-08T08:14:01.174Z lvl=info msg="batch point" service=kapacitor task_master=main task=join node=log2 prefix=series name=responsetimes group=qcinstan
ce=SCLP-FC tag_qcinstance=SCLP-FC field_count=4 time=2019-03-08T08:10:00Z
ts=2019-03-08T08:14:01.174Z lvl=info msg="batch point" service=kapacitor task_master=main task=join node=log2 prefix=series name=responsetimes group=qcinstan
ce=SCLP-FC tag_qcinstance=SCLP-FC field_count=0 time=2019-03-08T08:11:00Z
ts=2019-03-08T08:14:01.174Z lvl=info msg="batch point" service=kapacitor task_master=main task=join node=log2 prefix=series name=responsetimes group=qcinstan
ce=SCLP-FC tag_qcinstance=SCLP-FC field_count=0 time=2019-03-08T08:12:00Z
ts=2019-03-08T08:14:01.174Z lvl=info msg="batch point" service=kapacitor task_master=main task=join node=log2 prefix=series name=responsetimes group=qcinstan
ce=SCLP-FC tag_qcinstance=SCLP-FC field_count=0 time=2019-03-08T08:13:00Z
ts=2019-03-08T08:14:01.174Z lvl=info msg="end batch" service=kapacitor task_master=main task=join node=log2 prefix=series name=responsetimes group=qcinstance
=SCLP-FC tag_qcinstance=SCLP-FC time=2019-03-08T08:13:00Z

```

Here the series are not joining, even though the tag is matching and I have set a tolerance of 14 minutes

---

<div class="post-metadata">

### Author: ![MarcV](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/marcv/32/7676_2.png) [@MarcV](https://community.influxdata.com/u/MarcV)
#### Post date: [March 11, 2019, 3:03pm UTC](https://community.influxdata.com/t/help-debugging-join-in-tick-sctript/8934/2 "2019-03-11T15:03:19Z")

</div>

Hi , after these steps the join will succeed

1. replace the 2 .cron() by .every() ( because align() in combination with cron() does not work )
2. remove the .on() from the join node (joins are based on timestamp or a subset of a group by )
3. use the same .groupBy() in the two queries

best regards ,

---

<div class="post-metadata">

### Author: ![Robert\_George](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/robert_george/32/3480_2.png) [@Robert\_George](https://community.influxdata.com/u/Robert_George)
#### Post date: [March 12, 2019, 8:32am UTC](https://community.influxdata.com/t/help-debugging-join-in-tick-sctript/8934/3 "2019-03-12T08:32:32Z")

</div>

Thanks, @MarcV. I figured out that if I use same .groupBy join works.

However, my intention of doing the join was different.

I’m doing anomaly detection on series generated by `series` batch query. In the alert I wanted to show the total number of requests I got which is available in `counts` query.

I thought if I do a join, I will get that value.

Any suggestions on how to get the total number of requests in the alert node?

---

<div class="post-metadata">

### Author: ![MarcV](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/marcv/32/7676_2.png) [@MarcV](https://community.influxdata.com/u/MarcV)
#### Post date: [March 12, 2019, 9:46am UTC](https://community.influxdata.com/t/help-debugging-join-in-tick-sctript/8934/4 "2019-03-12T09:46:47Z")

</div>

hi maybe this example can help ?

```
dbrp "telegraf"."autogen"

var window = 30s

var series = batch
|query('''SELECT usage_idle FROM "telegraf"."autogen".cpu ''')
.period(window)
.every(window)
.groupBy('cpu')
.align()
.alignGroup()
.fill(0)
|count('usage_idle')
 .as('countedvalue')
|alert()
.crit(lambda:"countedvalue" > 1 )
.message('the counted field for {{ index .Tags "cpu" }} is : {{ index .Fields "countedvalue" }}')
```
