Strange error message - couchdb

I have defined the following view:
{ "_id":"_design/test",
"language":"javascript",
"views":
{ "test":
{ "map": "function(doc) { for (var k in doc.data) emit(doc.data[k],null);}",
"options": {"collation":"raw"}
}
}
}
When querying the view without any parameters, I get the expected result (sorted as "AB...ab" instead of "aAbB" because I specified a raw collation):
http://localhost:5985/test/_design/test/_view/test
{"total_rows":13,"offset":0,"rows":[
{"id":"-","key":"A","value":null},
{"id":"-","key":"B","value":null},
{"id":"-","key":"C","value":null},
{"id":"-","key":"D","value":null},
{"id":"-","key":"E","value":null},
{"id":"-","key":"F","value":null},
{"id":"-","key":"a","value":null},
{"id":"-","key":"b","value":null},
{"id":"-","key":"c","value":null},
{"id":"-","key":"d","value":null},
{"id":"-","key":"e","value":null},
{"id":"-","key":"f","value":null},
{"id":"-","key":"g","value":null}
]}
I then use startkey and endkey to ask for the range between B and a, and I expect to receive keys BCDEFa, but instead I receive the following error message:
http://localhost:5985/test/_design/test/_view/test?startkey=%22B%22&endkey=%22a%22
{ "error": "query_parse_error",
"reason": "No rows can match your key range, reverse your start_key and
end_key or set descending=true"
}
Why does it say that no rows can match the key range, when rows B,C,D,E,F and a will match ?
EDIT: I have a single document (revision and ID omitted):
{ "_id": "-",
"_rev": "-",
"data": [ "A", "B", "C", "D", "E", "F", "a", "b", "c", "d", "e", "f", "g" ]
}

I can confirm that I experience the same behaviour in version 1.1 on Ubuntu 10.04.
To elaborate:
curl http://localhost:5984/test/_design/test/_view/view?startkey=%22B%22\&endkey=%22a%22
returns the error
{"error":"query_parse_error","reason":"No rows can match your key range, reverse your start_key and end_key or set descending=true"}
while
curl http://localhost:5984/test/_design/test/_view/view?startkey=%22B%22\&endkey=%22D%22
gives
{"total_rows":12,"offset":1,"rows":[
{"id":"stuff","key":"B","value":null},
{"id":"stuff","key":"C","value":null},
{"id":"stuff","key":"D","value":null}
]}
So quoting issues don't look to be the problem.
I am using a single document:
{
"_id": "stuff",
"_rev": "2-0507028fcab427a1b28ed6b3d4a6c05e",
"data": [
"A",
"B",
"C",
"D",
"E",
"F",
"a",
"b",
"c",
"d",
"e",
"f"
]
}

I have found this tip on http://guide.couchdb.org/draft/views.html (paragraph Reversed Results).
hoping that could help you.
Reversed ResultsTo retrieve view results in reverse order, use the descending=true query parameter. If you are using a startkey parameter, you will find that CouchDB returns different rows or no rows at all. What’s up with that?
It’s pretty easy to understand when you see how view query options work under the hood. A view is stored in a tree structure for fast lookups. Whenever you query a view, this is how CouchDB operates:
Starts reading at the top, or at the position that startkey specifies, if present.
Returns one row at a time until the end or until it hits endkey, if present.
If you specify descending=true, the reading direction is reversed, not the sort order of the rows in the view. In addition, the same two-step procedure is followed.
Say you have a view result that looks like this:
KeyValue
0"foo"
1"bar"
2"baz"
Here are potential query options: ?startkey=1&descending=true. What will CouchDB do? See #1 above: it jumps to startkey, which is the row with the key 1, and starts reading backward until it hits the end of the view. So the particular result would be:
KeyValue
1"bar"
0"foo"
This is very likely not what you want. To get the rows with the indexes 1 and 2 in reverse order, you need to switch the startkey to endkey: endkey=1&descending=true:
KeyValue
2"baz"
1"bar"
Now that looks a lot better. CouchDB started reading at the bottom of the view and went backward until it hit endkey.

After looking again through wads of documentation and asking around, it seems that this behavior is unintended. I have submitted a JIRA bug for this. I currently have no general-purpose workaround to suggest, though I have been able to work around the problem in my specific situation.

Related

How to get all dictionaries in a list that match a given criteron

Suppose I have a list of dictionary entries:
list = (
{"hammer" : "woodwork", "name" : "Mjolnir", "country": "NO"},
{"chisel" : "woodwork", "name" : "Cold Chisel", "country": "AU"},
{"chisel" : "masonry", "name" : "Bolster", "country": "AU"},
{"drill" : "masonry/woodwork", "name" : "All purpose Drill", "country": "NO"}
)
Can someone guide me as to the most Pythonic way to retrieve all dictionaries from the list where the value for the key country contains "NO"?
Bonus points for how to repeat the iteration so that if I then want to select from that subset anything which has a value from the other seemingly random keys of woodwork
Thanks in advance for any/all assistance received.
Note
As yet, I've failed to fully grasp how a list of dictionaries can be handled other than by iterating over them one by one. This strikes me as achievable but probably (definitely) massively inefficient, hence my request for a more Pythonic way to deal with this.

How do you return a value within a 2D array in Azure Data Flows Open Expression Builder?

Background: I have a CSV file with a column that has a list of tags for a given row. The tag list is not in any specific order and varies for each cell in the tags column. I am looking for the value for a row which matches the string "Owner". When pulling in the CSV file, the entire cell is 1 string per cell. An example cell in this column looks like following:
"Organization": "Microsoft", "Owner": "Eric Holmes", "DateCreated": "07/09/2021"
Goal: I would like to find a way in Azure Data Flows or Azure Data Factory to make a new column with a value for a specific key in a list.
Example:
Current Column
Tags
"Department": "Business", "Owner": "Karen Singh", "DateCreated": "09/20/2019"
"Owner": "Henry Francis", "AppName": "physics-engine", "Department": "GeospatialServices"
"Department": "Fashion", "DateCreated": "01/10/2015", "Owner": "Xiuxiang Long"
Desired Column
Owner
"Karen Singh"
"Henry Francis"
"Xiuxiang Long"
Work So Far: I have taken each string in the tags column split it into an array by breaking it apart and the commas (,). Then I have split each string at each index by the colon (:). This makes the values look like:
Tags
[["Department", "Business"], ["Owner", "Karen Singh"], ["DateCreated", "09/20/2019"]]
[["Owner", "Henry Francis"], ["AppName", "physics-engine"], ["Department", "GeospatialServices"]]
[[Department", "Fashion"], ["DateCreated", "01/10/2015"], ["Owner", "Xiuxiang Long"]]
To split the strings, I've used this open expression
mapIndex(split(replace(Tags, '"', ''), ','), split(#item, ':'))
Problems
I am new to Open Expressions and Azure Data Factory and Data Flows. Does anyone know how I would:
Search for the desired tag like "Owner"
And return the value associated to it
Sorry I know this question sounds very simple but using only open expression functions makes this more convoluted than necessary. Additionally, if there is a better way to go about this problem I'd appreciate any input! I've been banging my head against the wall and any leads help. Thank you!
I have tried to repro it, could achieve it using Derived Column, where you could Split():
Use Derived Column transformation and use below expression:
split(split(tags,'"Owner":')[2],'"')[2]
Data Preview:

Mongoose: Try finding a document with multiple conditions stored in an array

What I am trying to achieve is to find a document by its name and the language.
My current attempt looks like the following one:
Model.find({"name.language": languageIso2, "name.value": { "$regex": search, "$options": "i" }}, (error, SpecialConditons) => {...})
Unfortunately, it doesn't work, because of the following case:
lets say the language is "gb" and you use "a" as a filter for the name, this would send you the model shown in the picture above, because the array "name" contains both (1) the language "gb" and (2) the "a" in the object containing the Finnish translation "Touretten syndrooma".
What I want to achieve is to look for the object that contains "gb" as a language and if the object containing the "gb" also includes an "a" in the value field then it should send me the model back. In this case the value for "gb" doesn't contain an "a", so it should not send it back.
Any idea how to achieve this? Thanks in advance

Get a value associated with a key in an array of JSON objects in a Logic App expression

Given this JSON hash:
{
"id": 55555,
"name": "111111",
"custom_data_field": [
{
"id": 1,
"label": "Vehicle Type",
"value": "Coach"
},
{
"id": 2,
"label": "Vendor",
"value": 1
}
]
}
I need the value associated with each label.
I'm able to get the value using the array's index:
#item()?['custom_data_field'][0]['value'] # Coach
#item()?['custom_data_field'][1]['value'] # 1
But this is a bit fragile.
This syntax doesn't work:
#item()?['custom_data_field'][#label=='Vehicle Type']['value'] # Coach
#item()?['custom_data_field'][#label=='Vendor']['value'] # 1
Is there a way to do this reliably?
According to the description of your question, it seems the data {"id": 55555, "name": "111111"....} you provided is an item of a array list because your expression begins with item() (I guess you use this expression in a "For each" or something else loop action). And custom_data_field is array under the item, you want to do filter/select operation to get the value which its label equals Vehicle Type just by the expression. I don't think we can do it just in one expression (because the label and value are not key-value map, we can not do the filter/select in expression easily).
To meet the requirement, we need to use a more sophisticated approach such as "Filter array" action mentioned by Scott in comments. We need to set the array custom_data_field to the input box("From" box) of the "Filter array" action.
And then add the filter condition.
After running the logic app, it will filter the items by the filter condition.
As the filter action don't know how many items match the condition, so the output will always be a array but not an item or a record even if there is only one item matches the condition(label equals "Vehicle Type") in your custom_data_field list.
So if you want to get the value, you need to get it by writing an expression as below screenshot.
Hope it helps~

Updating ArangoDB sub document

I am currently evaluating whether ArangoDB can be a future alternative for us. As a part of this evaluation I am porting code that talks to our current NoSQL db into code that speaks ArangoDB. While it has been a fairly smooth ride so far, I am having surprisingly difficult to wrap my head around on how to update sub documents. Assuming we have something like this:
{
"_key": "12345",
"subdoc": {
"0": {
"num_sold": 6,
"other_attribute": "important"
},
"1": {
"num_sold": 4,
"other_attribute": "important"
}
}
}
What I would like to accomplish now it to atomically increase num_sold.
A very first naive approach was of course to try something similar to:
FOR d in ##collection
FILTER d._key == "12345"
UPDATE d WITH { subdoc.0.num_sold : subdoc.0.num_sold + 1 } IN ##collection
RETURN d
(Spoiler alert for the copy-pasters out there: move on. This snippet will just make your life miserable.)
This obviously didn't work and most likely for more than one reason. Arango does not seem to like me referencing the attribute using dot notation, the attribute starting with a number ("0") might also be an issue etc. While having found an example here it seemed both a bit complicated and convoluted for what I am trying to do. There is also another discussion here that is close to what I would like to do. However, the proposed solution in that discussion uses the keyword OLD that creates an error in my case as well as the code replacing all keys in "0".
1) What is the best way to atomically increase num_sold?
2) When is an operation atomic? (Trying to stay away from transactions as long as possible)
3) When can the dot notation be used and when can it not be used?
4) Can I bind parameters to an attribute? For instance letting some #attribute be subdoc.0.num_sold?
Thanks!
ArangoDB can't parse the query if you use numbers in the dot notation.
However there is an easy way - simply use brackets instead of the dot notation as you did.
Example - not working:
db._query(`
LET testdoc = {subdoc: {"0": "abc"}}
RETURN testdoc.subdoc.0`)
ArangoError 1501: syntax error, unexpected integer number,
expecting identifier or bind parameter near '0' at
position 1:60 (while parsing)
Example - fixed:
db._query(`
LET testdoc = {subdoc: {"0": "abc"}}
RETURN testdoc.subdoc.[0]`)
[
"abc"
]
Using bind variables - not working:
db._query(`
LET testdoc = {subdoc: {"0": "abc"}}
RETURN testdoc.subdoc.#bv`, {bv: 0})
ArangoError 1501: syntax error, unexpected integer number,
expecting identifier or bind parameter near '0' at
position 1:60 (while parsing)
Using bind variables - fixed:
db._query(`
LET testdoc = {subdoc: {"0": "abc"}}
RETURN testdoc.subdoc.[#bv]`, {bv:0})
[
"abc"
]

Resources