Solved

JQL - Join and map

  • 20 July 2019
  • 2 replies
  • 713 views

Userlevel 3
Badge

join() Operation Details

You cannot apply any transformations to the collections inside join(). For example, this is not legal: join(Events(...).map(...), People(...).filter())

How can I write JQL for join() and map()? please give me sample.

My JQL to join Event() and People, too much fields displayed, I want to select some of fields what I need like using map() function.

function main() {

return join(

Events({

from_date: "2019-05-20",

to_date: "2019-05-26",

}),

People(),

{

type:"inner",

}

);

}

thank you.


icon

Best answer by willyv 24 July 2019, 23:33

Hey @cuongnd, Jaycee00 shared a JQL query that uses 'map' to determine how the events are displayed. I played around with it and came up with this.

function main() { 

return join( 

  Events({ 

  from_date: "2018-04-18", 

  to_date: "2019-07-24", 

  event_selectors: [{event:'Account Created'}] 

  }), 

  People(), 

  {type:'inner'} 



//just return a single object per user in case any user has fired the event more than once 

.groupByUser(mixpanel.reducer.any()) 

.map(function(tuple){  

    return { 

    "distinct_id": tuple.value.distinct_id, 

    "email": tuple.value.user.properties.$email

    }; 

  }); 

}


The first thing I did is join() we perform is an inner join. This means that we only return profiles of users that have fired this specific event.

From there, I've applied a .groupByUser() function to the query to make sure that we only return a single object per user.

Then, from the final object returned I use the .map() function to just attain the properties I'm looking for. You can add key/value pairs to the object you return in the .map() function based on the return of the preceding .groupByUser() function.


Hopefully this example helps get you what you need when combining join with people!



View original

2 replies

Userlevel 3
Badge

Hey @cuongnd, Jaycee00 shared a JQL query that uses 'map' to determine how the events are displayed. I played around with it and came up with this.

function main() { 
return join( 
  Events({ 
  from_date: "2018-04-18", 
  to_date: "2019-07-24", 
  event_selectors: [{event:'Account Created'}] 
  }), 
  People(), 
  {type:'inner'} 

//just return a single object per user in case any user has fired the event more than once 
.groupByUser(mixpanel.reducer.any()) 
.map(function(tuple){  
    return { 
    "distinct_id": tuple.value.distinct_id, 
    "email": tuple.value.user.properties.$email
    }; 
  }); 
}


The first thing I did is join() we perform is an inner join. This means that we only return profiles of users that have fired this specific event.

From there, I've applied a .groupByUser() function to the query to make sure that we only return a single object per user.

Then, from the final object returned I use the .map() function to just attain the properties I'm looking for. You can add key/value pairs to the object you return in the .map() function based on the return of the preceding .groupByUser() function.


Hopefully this example helps get you what you need when combining join with people!


Userlevel 3
Badge

Thanks @willyv, your code works for me.


Reply


Mixpanel