rethinkdb python eqJoin with filter not working - rethinkdb

I have two tables records
[
{
"payload": {
"uuid": "123",
"version": "1.0.0"
},
"record_id":"rec-123"
},
{
"payload": {
"uuid": "456",
"version": "1.0.1"
},
"record_id":"rec-456"
}
]
and records_master
[
{
"version": {
"mode": 1
},
"id": "rec-123",
"title": "Test-123"
},
{
"version": {
"mode": 0
},
"title": "Test-456",
"id": "rec-456"
}
]
I want to get records for matching payload.uuid and payload.version in records and version.mode should be 1 in records_master.
data = r.table("records").filter(
lambda doc:
(doc["payload"]["uuid"]== <some_value>) &
(doc["payload"]["version"]== <some_version>)
).coerce_to("array")
.run(connection)
This gives me all records for a matching payload.uuid and payload.version .
But unable to make it work for eqJoin with records-master
data = r.table('records').eq_join('record_id', r.table('records-master')).filter(
lambda doc,master:
(doc["payload"]["uuid"]== <some-value>) &
(doc["payload"]["version"]== <some-version>) &
(master["version"]["mode"] ==1)
).run(connection)

This query worked for me
data = r.table("records").filter(
lambda doc:
(doc["payload"]["uuid"]== <some_value>) &
(doc["payload"]["version"]== <some_version>)
).eq_join('record_id',
r.table('records-master')
)\
.filter(lambda master:(master["right"]["version"]["mode"]== 1))\
.coerce_to("array")\
.run(connection)

Related

FirstWhere method is not working properly in Laravel

I have $balance that is returned from another function like this:
$balance = {
"data": [
{
"name": "ABS",
"y": 1450
},
{
"name": "PBT",
"y": 1200
},
{
"name": "Краситель",
"y": 1000
},
{
"name": "PP",
"y": 750
}
]
}
And I have also collection called $statistics like this:
$statistics = [
{
"name": "ABS",
"data": []
},
{
"name": "PP",
"data": []
},
{
"name": "PBT",
"data": []
},
{
"name": "Краситель",
"data": []
}
]
What I'm trying to do is pushing all y 's of $balance to corresponding $statistics by matching their name.
Here is short description of my code:
foreach ($balance["data"] as $firm){
$statistics->firstWhere('name', $firm->name)['data']->push($firm->y);
}
However, I'm getting Call to a member function push() on null error. Can anyone help me find out the problem

Combine json response in nifi

We are calling invokehttp processes and getting response which json. Example
{
"id": "h569gcjhcm",
"doi": {
"id": "10.17632/h569gcjhcm.1",
"status": "allocated",
"prefix": "10.17632"
},
"name": "Data for: Flooding of the Caspian Sea at the intensification of Northern Hemisphere Glaciations",
"description": "Supplementary data for the Jeirankechmez section in Azerbaijan.\n\n- Appendix A contains all paleomagnetic data and interpretations of the Jeirankechmez section. This .dir file can be imported into the paleomagnetism.org webportal under \"Interpretation Portal\", \"Advanced Options\", \"Import Application Save\". For further details on the use of paleomagnetism.org please refer to the article by Koymans et al. (2016) - https://doi.org/10.1016/j.cageo.2016.05.007.\n- Appendix B contains the magnetic susceptibility data for the analysed samples, including geographic coordinates and stratigraphic levels.\n- Appendix C contains the 40Ar/39Ar data for the three analysed volcanic ash layers. ",
"version": 1,
"publish_date": "2019-01-29T12:51:38.090Z",
"data_licence": {
"id": "01d9c749-3c4d-4431-9df3-620b2dcfe144",
"short_name": "CC BY 4.0",
"full_name": "Creative Commons Attribution 4.0 International",
"description": "This dataset is licensed under a Creative Commons Attribution 4.0 International licence.\n\nWhat does this mean?\nYou can share, copy and modify this dataset so long as you give appropriate credit, provide a link to the CC BY license, and indicate if changes were made, but you may not do so in a way that suggests the rights holder has endorsed you or your use of the dataset. Note that further permission may be required for any content within the dataset that is identified as belonging to a third party.",
"url": "http://creativecommons.org/licenses/by/4.0",
"category": "Creative"
},
"contributors": [
{
"first_name": "Christiaan",
"last_name": "van Baak"
},
{
"first_name": "Marius",
"last_name": "Stoica"
},
{
"first_name": "Arjen",
"last_name": "Grothe"
},
{
"first_name": "Gareth",
"last_name": "Davies"
},
{
"profile_id": "72970719-95c8-341b-80d2-afa9e7154baf",
"first_name": "Wout",
"last_name": "Krijgsman"
},
{
"profile_id": "3a4bfe2c-4098-3859-9b88-789fa993e05a",
"first_name": "Keith",
"last_name": "Richards"
},
{
"profile_id": "f1660f3c-ebbd-3289-8240-1f4ea7913df4",
"first_name": "Klaudia",
"last_name": "Kuiper"
},
{
"first_name": "Elmira",
"last_name": "Aliyeva"
}
],
"versions": [
{
"version": 1,
"publish_date": "2019-01-29T12:51:38.090Z",
"available": true
}
],
"files": [
{
"filename": "Appendix_A_Jeirankechmez_pmag_interpretations.dir",
"id": "f2f4cba7-2411-4737-a9b2-f094db30dca1",
"content_details": {
"id": "994bc865-5300-4d76-a373-e528ccd830e8",
"sha256_hash": "2427c4b077372760973ce8224694f2a2ee5383c7f022ad818164d847a20e27cc",
"sha1_hash": "73792dc6d6eb2c1de1e04926ba5d4420dd0aaece",
"content_type": "application/x-director",
"size": 917022,
"created_date": "2019-01-03T00:00:00.000Z"
"download_expiry_time": "2019-01-29T13:52:25.729Z"
},
"metrics": {
"downloads": 0,
"previews": 0
}
},
{
"filename": "Appendix_B_Sample_locations_susceptibility.xlsx",
"id": "64241bf0-5279-49e8-a505-be9075b910e1",
"content_details": {
"id": "af8809d0-8e63-4599-abaa-e7af9ad39959",
"sha256_hash": "0588f44a0cbd477aa2798323e57ce0b2d4a118e767c0b1ffdc9eb1017e4d23c2",
"sha1_hash": "02e89f6f197ebf495e1e2c3d1aab250efc7545e7",
"content_type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"size": 24770,
"created_date": "2019-01-03T00:00:00.000Z"
,
"download_expiry_time": "2019-01-29T13:52:25.732Z"
},
"metrics": {
"downloads": 0,
"previews": 0
}
},
{
"filename": "Appendix_C_ArAr_data.xlsx",
"id": "2e912027-ff3f-48ad-98b9-b643b59ba0e3",
"content_details": {
"id": "4960377c-060d-41f6-b7af-150617d8ebeb",
"sha256_hash": "235dc32c1e99f350ee5c99908a5f5d72d1aeeab02f78c2e0181d585bd1880fa6",
"sha1_hash": "6483156e4577948cac5d2679eee862c76faed1c9",
"content_type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"size": 18510,
"created_date": "2019-01-03T00:00:00.000Z"
},
"metrics": {
"downloads": 0,
"previews": 0
}
}
],
"articles": [
{
"id": "10.1016/j.gloplacha.2019.01.007",
"title": "Flooding of the Caspian Sea at the intensification of Northern Hemisphere Glaciations",
"doi": "10.1016/j.gloplacha.2019.01.007",
"journal": {
"issn": "0921-8181",
"name": "Global and Planetary Change",
"url": "http://www.sciencedirect.com/science/journal/09218181"
}
}
],
"categories": [
{
"id": "http://com/vocabulary/OmniScience/Concept-170590667",
"label": "Geology"
},
{
"id": "http://data.elsevier.com/vocabulary/OmniScience/Concept-473860195",
"label": "Strontium Isotope"
}
],
"institutions": [ ],
"metrics": {
},
"available": true,
"related_links": [ ]
}
I am using $contributors.profile_id from above json to call new endpoint(invokeshttp) (https://api.xxx.com/profile/$.profile_id)
Json response for this
"contributors": [
{
“profile_id”:”cedferfiherhforhforf”
"first_name": “xxx”,
"last_name": "van Baak”,
“other_ids”:[] ,
“Other info”: “deeded” }
I have to call this endpoint depending upon number of object in contributor(let say we have 5 object in contributor ,so I have to call this endpoint 5 time)and combine these 5 response together
Then I have to merge the response(above response to the main response )
just an example:
EvaluateJsonPath to extract "id" into attribute, later join by this attribute
SplitJson to split your json by "contributors"
call endpoint
MergeContent merge by "id" and with count after SplitJson

Logstash 5.0 Ruby Filter Can't Update Hash in Array

I'm a newbie to both Logstash and Ruby, and I meet a subtle problem today.
My input JSON like the following:
{
"1": "1",
"2": "2",
"market": [
{
"id": "1",
"name": "m1"
},
{
"id": "2",
"name": "m2"
}
]
}
My filter is like the following code, and I want to set event["1"] to m1, event["2"] to m2, event["market"][0]["id"] to m1, event["market"][1]["id"] to m2:
filter {
......
ruby {
code => "
markets = event.get('market')
markets.each_index do |index|
event.set(markets[index]['id'], markets[index]['name'])
markets[index]['id'] = markets[index]['name']
end
"
}
......
}
And the output is following:
{
"1": "m1",
"2": "m2",
"market": [
{
"id": "1",
"name": "m1"
},
{
"id": "2",
"name": "m2"
}
]
}
The event["1"] and event["2"] get the expected values, but the event["market"][0]["id"] and event["market"][1]["id"] do not, and I want to know why? The desired output should be:
{
"1": "m1",
"2": "m2",
"market": [
{
"id": "m1",
"name": "m1"
},
{
"id": "m2",
"name": "m2"
}
]
}
PS: The logstash I'm using is version 5.0.
I think it is because of the new Event API introduced in the Logstash 5.0. After changing my filter to the following, I get the desired output:
filter {
......
ruby {
code => "
markets = event.get('market')
markets.each_index do |index|
event.set(markets[index]['id'], markets[index]['name'])
markets[index]['id'] = markets[index]['name']
end
event.set('market', markets) // comment: adding this setter in the filter
"
}
......
}
According to Logstash Git Issue, "Mutating a collections after setting it in the Event has an undefined behaviour".

Merge two hashes in order to create a json file

Hi I want to merge two hashes into a json file which should look like this:
{
"name": "MS Suite",
"version": "2017.1.0",
"components": [
{
"code": "1x.2017",
"name": "microservice1",
"version": "1.1.3-1"
},
{
"code": "3x.2017",
"name": "microservice2",
"version": "1.1.15-1"
}
]
}
Please find below hash1:
{
"name": "MS Suite",
"version": "2017.1.0"
}
Please find below hash2 which is an array:
[
{
"code": "1x.2017",
"name": "microservice1",
"version": "1.1.3-1"
},
{
"code": "3x.2017",
"name": "microservice2",
"version": "1.1.15-1"
}
]
You're looking for Hash#[]=:
hash = {
"name": "MS Suite",
"version": "2017.1.0"
}
array = [
{
"code": "1x.2017",
"name": "microservice1",
"version": "1.1.3-1"
},
{
"code": "3x.2017",
"name": "microservice2",
"version": "1.1.15-1"
}
]
hash['components'] = array
hash
#=> {:name=>"MS Suite", :version=>"2017.1.0", "components"=>[{:code=>"1x.2017", :name=>"microservice1", :version=>"1.1.3-1"}, {:code=>"3x.2017", :name=>"microservice2", :version=>"1.1.15-1"}]}
To convert it to json:
require 'json'
hash.to_json
#=> "{\"name\":\"MS Suite\",\"version\":\"2017.1.0\",\"components\":[{\"code\":\"1x.2017\",\"name\":\"microservice1\",\"version\":\"1.1.3-1\"},{\"code\":\"3x.2017\",\"name\":\"microservice2\",\"version\":\"1.1.15-1\"}]}"

error given Sending json array in ajax request? using javascript

hihi i am doing a project regarding ajax (xmlHttRequest),
how am i going to call the title in the note session, because normally if you call start year is like, detail = eval....
then for loop it
inside should be
var start year=""
startyear += ...[i].startyear
something like this, but how am i going to call the title inside the note?
i try to call detail.notes.note.title it say is null or is not a object
this is json data:
{
"infos": {
"info": [
{
"startYear": "1900",
"endYear": "1930",
"timeZoneDesc": "daweerrewereopreproewropewredfkfdufssfsfsfsfrerewrBlahhhhh..",
"timeZoneID": "1",
"note": {
"notes": [
{
"id": "1",
"title": "Mmm"
},
{
"id": "2",
"title": "Wmm"
},
{
"id": "3",
"title": "Smm"
}
]
},
"links": [
{
"id": "1",
"title": "Red House",
"url": "http://infopedia.nl.sg/articles/SIP_611_2004-12-24.html"
},
{
"id": "2",
"title": "Joo Chiat",
"url": "http://www.the-inncrowd.com/joochiat.htm"
},
{
"id": "3",
"title": "Bake",
"url": "https://thelongnwindingroad.wordpress.com/tag/red-house-bakery"
}
]
}
]
}
}
Use http://jsonlint.com/ to help you out with JSON.
I got this...
Parse error on line 30:
... ] }
----------------------^
Expecting '}', ',', ']'

Resources