Rows aggregation by string concatenation? - sap

I am working on a SAP webi 4 report where I have a table that looks like
student
discipline
exam session
josé
geo
june session
josé
geo
september session
josé
math
june session
from which I would like to obtain another table that looks like:
student
discipline
CONCAT_exam session
NBR_exam session
josé
geo
june session; september session
2
josé
math
june session
1
however I am stucked with the column "CONCAT_exam session":
I have read dozen of posts like this one https://answers.sap.com/questions/12...ed-on-da.html; and tried the creation of tens of variables, but nothing works and I am not able to obtain the desired output !
could anyone help ?? after tons of trials, I am really running out of ideas....
side question: if anyone has a clear explanation/guidance whether I should create new "measure(s)" or "dimension(s)" for this purpose, I would be very grateful !

it's my first reply so I have no idea how to format the answer correctly.
I think I have done similar exerice some time ago. Let's try my idea:
create such 5 variables:
[v_full_name] -> =[student]+" "+[discipline]
[Object 1] -> =Previous(Self;([v_full_name])) +","+ [exam session]
[maximum] -> =Max([exam session]) In ([v_full name])
[Object 2] -> =[Object 1] Where ([exam session]=[maximum])
[CONCAT_exam session] -> =Substr([Object 2];2;(Length([Object 2])))
please let me know if it helps

Related

How to simulate a loop in Hive Sql?

I want to simulate a loop in Hive. The problem is that of link traversal.
Raw Data:
phone,name
1234,Sam
2345,John
3456,Max
7899,Sam
7899,Tim
8899,Tim
8898,Dan
8899,John
I am only interested in getting phone numbers.
If I take 1234,Sam and go to 7899,Sam that would be 1-hop because Sam used 7899 number too. Then if I go from 7899,Sam to 8899,Tim that would be 1-hop because 7899 was used by Tim and Tim also used 8899. Now where we started from, 1234, to where we are now, 8899, we are 2-hops away. I can do this with a shell script with loops but I am interested to find if this is possible to do purely in Hive. I want the loop to stop if any one criteria is met:
10 hops reached OR no new numbers detected
(If the conditions above are hard to implement, I can just have one condition - 10hops reached)
Visual representation:
1 hop:
1234 -> Sam
Sam linked to 7899
2 hops:
7899 -> Tim
Tim linked to 8899
so 1234 and 8899 are 2 hops away.
Any tips are welcome!

Matching an element in a column, to others in the same column

I have columns taken from excel as a dataframe, the columns are as follows:
HolidayTourProvider|Packages|Meals|Accommodation|LocalTravelVehicle|Cancellationfee
Holiday Tour Provider has a couple of company names
Packages, the features provided in each package are mostly the same like
Meals,Accommodation etc... even though one company may call it "Saver", others may call it "Budget". (each of column mostly follow Yes/No, except Local travel vehicle are again car names like Ford Taurus,jeep cherokee etc..
Cancellation amount is integers)
I need to write a function like
match(HolidayTP,Package)
where the user can give input like
match(AdventureLife, Luxury)
then I need to return all the packages that have similar features with Luxury by other Holiday Tour Providers, no matter what name they give the package like 'Semi Lux', 'Comfort' etc...
I want to give a counter for every match and display all the packages that exceed the counter by 3 or 4.
This is my first python code. I am stuck here.
fb is the total df I exported to
def mapHol(HTP, PACKAGE):
mfb = (fb['HTP']== HTP)&(fb['package']== package)
B = fb[mfb]
for i in fb[i]:
for j in B[j]:
if fb[i]==B[j]:
count+=1
I dont know how to proceed, please help me this is my first major project, I started on my own.

NYT article search API not returning results for certain queries

I have a set of queries and I am trying to get web_urls using the NYT article search API. But I am seeing that it works for q2 below but not for q1.
q1: Seattle+Jacob Vigdor+the University of Washington
q2: Seattle+Jacob Vigdor+University of Washington
If you paste the url below with your API key in the web browser, you get an empty result.
Search request for q1
api.nytimes.com/svc/search/v2/articlesearch.json?q=Seattle+Jacob%20Vigdor+the%20University%20of%20Washington&begin_date=20170626&api-key=XXXX
Empty results for q1
{"response":{"meta":{"hits":0,"time":27,"offset":0},"docs":[]},"status":"OK","copyright":"Copyright (c) 2013 The New York Times Company. All Rights Reserved."}
Instead if you paste the following in your web browser (without the article 'the' in the query) you get non-empty results
Search request for q2
api.nytimes.com/svc/search/v2/articlesearch.json?q=Seattle+Jacob%20Vigdor+University%20of%20Washington&begin_date=20170626&api-key=XXXX
Non-empty results for q2
{"response":{"meta":{"hits":1,"time":22,"offset":0},"docs":[{"web_url":"https://www.nytimes.com/aponline/2017/06/26/us/ap-us-seattle-minimum-wage.html","snippet":"Seattle's $15-an-hour minimum wage law has cost the city jobs, according to a study released Monday that contradicted another new study published last week....","lead_paragraph":"Seattle's $15-an-hour minimum wage law has cost the city jobs, according to a study released Monday that contradicted another new study published last week.","abstract":null,"print_page":null,"blog":[],"source":"AP","multimedia":[],"headline":{"main":"New Study of Seattle's $15 Minimum Wage Says It Costs Jobs","print_headline":"New Study of Seattle's $15 Minimum Wage Says It Costs Jobs"},"keywords":[],"pub_date":"2017-06-26T15:16:28+0000","document_type":"article","news_desk":"None","section_name":"U.S.","subsection_name":null,"byline":{"person":[],"original":"By THE ASSOCIATED PRESS","organization":"THE ASSOCIATED PRESS"},"type_of_material":"News","_id":"5951255195d0e02550996fb3","word_count":643,"slideshow_credits":null}]},"status":"OK","copyright":"Copyright (c) 2013 The New York Times Company. All Rights Reserved."}
Interestingly, both queries work fine on the api test page
http://developer.nytimes.com/article_search_v2.json#/Console/
Also, if you look at the article below returned by q2, you see that the query term in q1, 'the University of Washington' does occur in it and it should have returned this article.
https://www.nytimes.com//aponline//2017//06//26//us//ap-us-seattle-minimum-wage.html
I am confused about this behaviour of the API. Any ideas what's going on? Am I missing something?
Thank you for all the answers. Below I am pasting the answer I received from NYT developers.
NYT's Article Search API uses Elasticsearch. There are lots of docs online about the query syntax of Elasticsearch (it is based on Lucene).
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-syntax
If you want articles that contain "Seattle", "Jacob Vigdor" and "University of Washington", do
"Seattle" AND "Jacob Vigdor" AND "University of Washington"
or
+"Seattle" +"Jacob Vigdor" +"University of Washington"
I think you need to change encoding of spaces (%20) to + (%2B):
In your example,
q=Seattle+Jacob%20Vigdor+the%20University%20of%20Washington
When I submit from the page on the site, it uses %2B:
q=Seattle%2BJacob+Vigdor%2Bthe+University+of+Washington
How are you URL encoding? One way to fix it would be to replace your spaces with + before URL encoding.
Also, you may need to replace %20 with +. There are various schemes for URL encoding, so the best way would depend on how you are doing it.

SQL and relational algebra

I've got some problems which I can't work out. Here is the scheme:
sch(branch)=(branch_Nr,town) (Key: branch_Nr)
sch(account)=(account_Nr,ballance) (Key: account_Nr)
sch(manages)=(account_Nr,branch_Nr) (Key: account_Nr, branch_Nr)
sch(customer)=(customer_Nr,Name,street,place) (Key: customer_Nr)
sch(mentors)=(branch_Nr,customer_Nr) (Key: customer_Nr)
sch(opens)=(customer_Nr,account_Nr) (Key: account_Nr)
the task is to get with relational algebra: get all customers with 2 different accounts. I tried the solution:
πname(Customer) |X| σ k1!=k2 (πk1 <- account_Nr (account) X πk2 <- account_Nr (account))
But this doesnt work does it? I feel like im missing sth here.
Second task is: to get 2 customers with two different accounts, which are managed by different branches in SQL:
I tried it with:
CREATE VIEW N AS
SELECT account_Nr
FROM account
GROUP BY accountNr
HAVING TOTAL = 2
With this I wanted to make it more structured so I used a view before I actually use the real selection task. But im kinda stuck here already. The problem is that I want everybody who got 2 accounts which are at different branches. This means that he can still have more than 2 accounts. But with this I ignore that. And i am not so sure how to proceed after that as well. These are one of the problems I try to prepare myself for an upcoming test. I would really appreciate help! kinda stuck here.

Related jobs in JSprit

Is it possible to handle relations between jobs (in this case services) in jsprit?
For instance one job has to start at the same time with one or more other jobs.
Or one job must not start before the end of another job (normal sequence).
If not, do you know other java libraries that can handle such kind of restrictions?
Thank you!
Yes you can handle such relations with jsprit.
It is a bit of coding, but - I think - easy to implement. To illustrate it, I prepared you five examples that are based on the Vehicle Routing Problems (VRP) developed by Christofides-Mingozzi-Toth's* (first benchmarking instance). Follow the links behind the individual headlines and you get to the code. Note that the first activity in a route is marked with a triangle. The labels denote jobIds.
noConstraints
capacityConstraints
job 13 and 21 in same route
job 13 and 21 in same route AND 21 before 13
job 13 and 21 in same route AND 13 right after 21
Visit http://jsprit.github.io/ and you get to a number of code examples and docs.
*N. Christofides, A. Mingozzi, and P. Toth. The vehicle routing problem. In N. Christofides, A. Mingozzi, P. Toth, and C. Sandi, editors, Combinatorial Optimization. John Wiley, Chichester, 1979.