is there anyway i can pass an array to getAll()? - rethinkdb

I am looking for a good way to do the following.
Get a list of uids from tableA like..
r.Table('tableA').get(1)('somelistofuid')
Then I want to use the list go get all the data I need from tableB
r.Table('tableB').getAll(listfromQueryAbove)
I know that i can do getAll(a,b,c) to get a,b,c but could there be a simpler way?

You want something to unpack an array into an argument list, that's args.
So change your query to
r.Table('tableB').getAll(r.args(listfromQueryAbove))
and it should work.

You can use r.args for this:
r.table('table').getAll(r.args(ARRAY))

Related

How to map an element from the list to a single element in Tibco?

I obtain a list of elements from the JDBC. And then I have to map an element from the returned list to another single element of a different system. Could someone help, please ? I tried for-each, but couldn't handle it. Any hints would be helpful. Thanks.
Assuming the output of your JDBC query is something like this records.A and records is repeating.
You can use the following syntax records[1].A to map the first value of the list to a non repeating elements, or if you have another fields B returned by your query and want to select the data depending on B value you can do something like this : records[B=123].A, in that second example the first record found with B=123 will be mapped to your target element.

Combining multiple tables with r.union in RethinkDB

I will be dynamically combining a range of tables with the exact same structure in RethinkDB.
I have my dynamically-generated list of tables in an array as follows:
tables = [r.table('table1'), r.table('table2'), ...]
And I am trying to do this:
r.union(r.args(tables))
But that just gives me an error: ReqlLogicError: Expected type DATUM but found TABLE
Overall, I have not been able to find a way to generate a list of tables in JavaScript and to add use r.union to combine them into a stream. Would appreciate help on this.
Thanks!
You can use reduce to do what you want, we merge one by one, like r.table(t1).union(r.table(t2)).union(r.table(t3)).
Like this:
[r.table('t1'), r.table('t2'), r.table('t3')].reduce(function(p, c) {
return p.union(c)
})
Try it from data explorer.
The answer provided by kureikain works. I still wish the functionality existed in RethinkDB with r.args() (it seems to me that this would be consistent with the documentation of that function).
Moreover, one important tip tangentially related to this question: if you want to combine multiple tables into a stream through r.union() but be able to tell which table it is in the results, use merge(). So my query would look something like this:
[r.db('database').table('table1').merge({source: 'table1'}), r.db('database').table('table2').merge({source: 'table2'})].reduce(function(p, c) { return p.union(c) }).filter( ...)
This allows you to not only combine multiple tables into one stream, but to always distinguish between the source tables in your results (by looking up the value of the key 'source').

Distinct count a field that has been sorted by territory from another source

I am trying to find a way to get a distinct count on a field that is being filtered by a territory without using grouping because of the fact that I need to then pass this value over to another report. The easiest way would be something like this:
distinctcount({Comm_Link.CmLi_Comm_CompanyId}) if {Company.Comp_Territory}='Atlanta'
But for obvious reasons that won't work. Any thoughts?
what you have to do is a running total. Right click on {Comm_Link.CmLi_Comm_CompanyId} insert running total, type of summary will be distinct count and on evaluate where says Use a formula type your condition {Company.Comp_Territory}="Atlanta"
your formula and approach is wrong.. I doubt whether your formula compiled with out any errors...
first create the value and then find the distinct count
if {Company.Comp_Territory}='Atlanta'
Then {Comm_Link.CmLi_Comm_CompanyId}
Now in footer write or you can get it by right click on the filed.
distinctcount({Comm_Link.CmLi_Comm_CompanyId})

Using pluck with maximum

Is it possible to chain options when using maximum?
I have a PhoneStats class and I want to pull the name from a few columns who have the maximum value in the table. For example if I run
PhoneStat.maximum('calls')
I get the value I expect but I would like to get maximum value as well as the id of the user in that record. Is it possible to use pluck or collect for something like this?
Thanks spickermann
Thanks. Below got me exactly what I needed.
PhoneStat.order('calls DESC').pluck(:name).first
You have to write this a bit more detailed:
PhoneStat.order('calls DESC').first

Does hsqldb provide a function similar to listagg?

I am looking for a function (or a group of functions) in HSQLDB that does something similar to Oracle's LISTAGG.
I have this as part of a larger select and would like to keep the syntax as similar as possible in HSQLDB:
SELECT LISTAGG(owner_nm, ', ') WITHIN GROUP (ORDER BY owner_nm)
FROM OWNERSHIP WHERE FK_BIZ_ID = BIZ.BIZ_DATA_ID) AS CURRENT_OWNER
The point of this is that we're trying to use HSQLDB for remote work and Oracle for working on site, prod, etc so I want to change the DDLs as little as possible to achieve that.
Looking at ARRAY_AGG, it doesn't seem like it does anything similar (as far as being able to pull from a separate table like we're doing above with OWNERSHIP). Any suggestions for how I may accomplish this?
group_concat is probably what you are looking for:
http://www.hsqldb.org/doc/2.0/guide/dataaccess-chapt.html#dac_aggregate_funcs
Quote from the manual:
GROUP_CONCAT is a specialised function derived from ARRAY_AGG. This function computes the array in the same way as ARRAY_AGG, removes all the NULL elements, then returns a string that is a concatenation of the elements of the array

Resources