For a given user I want to get all the runs that
satisfy some conditions
get only runs from projects that the user has access to
In Users table, every user has a list of project ids while in Runs table, every run has a project id. The following is a query that works. Can it be optimized using concatMap?
r.table('users')
.inner_join(
r.table('runs').filter( lambda var_6: (<some_condns>),
lambda user, run: user['projects'].contains(run['project_id'])
)
.filter(lambda l: l['left']['id'] == '<user_id>').without('left')
I think equiJoin may not work because I am looking for item in a list as apposed to equality.
The below worked perfectly well for me -
r.table("users").get_all(user_id).map(lambda user:
{
"run_array": r.table("runs").filter(lambda var_6: (<some_condns>))
.filter(lambda run:
user['projects'].contains(run["project_id"]))
.coerce_to("array")
}).concat_map(lambda run: run['run_array'])
Related
I am trying to create an SAP data query using SQVI (or SQ01) to display all entries that meet certain criteria. I can use the 'Selection Fields' tab to have a user specify any of these parameters, but I want to be able to query the data with more complex conditions such as a nested 'AND'/'OR'. I have researched the question for a couple hours and have yet to find a solution that works. Here is an example simplified query that I would like to do, written in SQL form:
SELECT t0.name, t0.birthYear, t1.grade, t1.county
FROM t0
INNER JOIN t1 on t0.personID = t1.personID
WHERE t0.name = 'Bob'
AND t0.birthyear = 2000
AND (t1.grade = 12
OR t1.county <> 'Cook');
Now the tricky part is figuring out how to do a nested 'AND' and 'OR' in SQVI. At first, I pulled all the data without these conditions, exported it to Excel, and then performed this logic to get the correct entries that meet these criteria. However, I do not want to do this every time, as it is highly repetitive and there HAS TO be some solution within the SAP environment. Ideally, I would be able to create a query that I can share with co-workers to execute once a week, where they don't need to enter any values to test against 'name', 'birthyear', 'grade', or 'county'. They should be able to type in the code for this query and hit execute, and it should spit out all of the entries that meet all the criteria. I want to be able to hard-code the testing parameters in this instance.
Let me know if this is even possible! If it's not possible using SQVI, what would I need access to in order to do a complex conditional query like this? I do not have write-access on the data, so I am not authorized to use 'DBACOCKPIT' to write the query as SQL (which would be so much simpler).
I currently process a paginated list with the following command:
paginatedList.each { it.update() }
However this is slow and I'd like to leverage GPars to update each item concurrently.
I have used:
GParsPool.withPool {
paginatedList.eachParallel { it.update() }
}
However when I run this I get:
Message: ORA-00942: table or view does not exist
The code runs serially for any number of items in the list, but it wont work concurrently for any number even if there is only one item in paginatedList.
The update function calls in data from several tables/views and other tables/views work fine but it stops on one particular view. The query it is trying works fine when executed manually (and is the same as when called serially, which works).
Can anyone help with why this doesn't work.
Thanks
So I'm not sure if this would b econsidered an inner join or a merge in ReQL. What I want to do is watch for changes in online status of people I'm following.
So the first query works if I pass in the people I'm following via arguments:
r.table("users")
.getAll(r.args(['mike','foo']), {index: "name"})
.pluck('name', 'online')
.changes();
However, I want to just pass in my username and let it fetch the following list dynamically - I would normally use a join or a subquery in SQL, but how would I do this in ReQL? I tried using a lambda I didn't get the right syntax.
r.table("users")
.getAll(r.args(lambda following {
r.table('users').get('mike').pluck('following')
}),
{index: "name"})
.pluck('name', 'online')
.changes();
You can write .getAll(r.args(r.table('users').get('mike')('following')), {index: 'name'}), but subscribing to changes on that might not do what you think it does -- it will get the users mike is following at the time the changefeed starts, and subscribe to changes on them, but if mike starts following a new user that user won't be automatically added to the feed.
I'm trying to build a report in AX 2009 (SP1, currently rollup 6) with a primary data source of the SalesQuotationLine table. Due to how our inventory is structured, I need to apply a filter that shows only certain categories of items (in this case, non-service items as defined in the InventTable). However, it seems that there is a problem in the link between the SalesQuotationLine and InventTable such that only two specific items will ever display.
We have tested this against the Sales Quotation Details screen as well, with the same results. Executing a query such as this:
...will only show quotes that have one of the specific items mentioned earlier. If we change the Item Type to something else (for example to Item), the result is an empty set. We are also getting this issue on one of our secondary test servers, which for all intents is a fresh install.
There doesn't seem to be any issues with the data mapping from the one table to the other, and we are not experiencing this issue with any other table set. Is this a real issue, or am I just missing something?
After analyzing the results from a SQL Profile run during the execution of the query, it seems the issue was a system bug. When selecting a table to join to the SalesQuotationLines, you have two options: 'Items' and 'Items (Item Number)'. Regardless of which table you select the query executes with, it joins the InventTable with the relation "SalesQuotationLines.ProjTransCode = InventTable.ItemId".
After comparing the table to other layers in the system, I found the following block of code removed from the createLine method (in the SYP layer):
if (this.ProjTransType == QuotationProjTransType::Item)
{
this.ProjTransCode = this.ItemId;
}
Since the ProjTransCode is no longer being populated, the join does not work except on certain quote lines that do have the ProjTransCode populated.
In addition, there is no directly defined relation to the InventTable - the link is only maintained via an Extended Data Type that is used on the SalesQuotationLine.ItemId field. Adding this relation in manually solved the problem.
I'm building a poll widget. I've 2 tables, call them Polls and PollsCompleted. I need to do a linq query to get all the Polls that do not exist for a given user in PollsCompleted.
I have the following sets:
For Polls
Where Active == True
For PollsCompleted
Where UserId == ThisUserId
Where PollId = Polls.Id
Now I need to get all Polls that do not exist in PollsCompleted. I need an example for this using either a single or multiple queries. I've tried to break it down into 2 queries.
Basically, I've 2 IQueryables of type T and T1. I want to take all T's where T.ID does not exist in T1.ParentId.
T.Where(x => ! T1.Select(y => y.ParentID).Contains(x.ID))
In Linq you often work from the bottom up. Here we first get a collection of all the parentIDs in T1 -- the T1.Select(...) part. Then we create a where clause that selects all of the Ts whose IDs are not contained in that set.
Note that the result is a query. To materialize it, use ToList() or similar on the statement above.
Use Except. That will work in this case.
For your reference Enumerable.Except Method