Query for a result within a result using Logic Apps - sql

I have a JSON document within CosmosDB that looks like this
{
"id":"1234-11111-22222-2222"
"Feedbacks": [
{ "id": "abc"
}
]
}
I would like to first find all the documents where the ids are >15 and then loop over and find all the feedbacks that are associated with this result. How would I do this using the LogicApp? I have an idea and this is what I have done so far:
I am not sure if I have to perform another query? if so, what would this be?
Select c.Feedbacks from ...?
Any help or suggestion is appreciated.

Just ad I know about logic, we can not do that. Your really purpose is that get the all the data which id>15 and update the Feedback ids.
I think Data Factory is more suitable for you.
You could using Data flow to achieve that. Create Cosmos DB as Source, using Mapping data flow transformation to update the Feedback ids.
Ref tutorial: Copy and transform data in Azure Cosmos DB (SQL API) by using Azure Data Factory
Update:
We can do a nested query like: for each (document d array) // iterate over documents array do for each (feedback f in d.feedback) // iterate over feedback array in each document do something with f ... done done
Thanks for the sharing.

Related

Understanding GraphQL

I started experimenting with the GraphQL wp api.
I am querying the menus. As for the documentation, the query is very long
I would expect that querying
{
menus
}
only would bring about all the data nested in menus, it does not.
Why is this? What is the way to getting all nested data in an object as to see what's in there?
Thank you for your time
The rule is that every "leaf" fields in a GraphQL query should be a Scalar something like Int , Boolean , String etc. So if the meuns field in the root Query type is a Scalar , it is a valid query and will return you something.
If not , you have to continue navigating the Menu type and pick the fields that you want to include in the GraphQL query such as :
{
menus {
id
createdDate
}
}
There is no wildcard that can represent all fields in current GraphQL spec.You have to explicitly declare all fields you want to select in the query.By looking at the GraphQL schema, you can know the available fields for each type. One of the tips is to rely on the GraphQL introspection system .It basically means that you can use some of the GraphQL client such as Altair, Graphiql, or GraphQL Playground etc. which most of them will have some auto-suggest function that will guide you to compose a query by suggesting you what fields are available to be included for a type .
P.S. A similar analogy to SQL is that there is no select * from foo , you have to explicitly define the columns that you want to select in the select clause such as select id,name,address from foo.
If you keep in mind that you're getting back a JSON object, you can think of your GraphQL query as defining the left-hand side of the response (this is intentional in how it was designed), e.g. just the keys. So unless there are null values, what you get back should exactly match the shape of the query.
If you want to see what can be queried, you need access to the schema itself. If it's a schema provided by someone else (looks like WordPress in this case), they should also have provided the means to explore and understand it.
That is the main feature of GraphQL, you can specify what data you need from a query. And because of that, you can't just query menus in that way, you need to specify every nested field in menus you need and only then it'll work :)

Does Tableau support complex data type of hive columns and flatten it?

I am trying to create a dashboard from the data present in the Hive. The catch is the column which I want to visualize is a nested JSON type. So will tableau able to parse and flatten the JSON column and list out all possible attributes? thanks!
Unfortunately Tableau will not automatically flatten the JSON structure of the field for you, but you can manually do so.
Here is an article that explains the use of Regex within Tableau to extract pertinent information from your JSON field.
I realize this may not be the answer you were looking for, but hopefully it gets you started down the right path.
(In case it helps, Tableau does have a JSON connector in the event you are able to connect directly to your JSON as a datasource instead of embedded in your Hive connection as a complex field type.)

coldfusion and reading JSON data from web service into a cf query

I am using the following code to obtain data from a webservice and it returns the data in json format
<cfhttp url="http://api.sensis.com.au/v1/test/search?key=czsjp3f8xhd835vg6xfw8ber&query=vetinary%20and%20clinic&radius=1&location=-37.7833,144.9667">
<cfdump var="#cfhttp.FileContent#">
I want to be able to output the data into a table, for that reason, I need to be able to bring the data into a query object and then I can cfloop or cfoutput the query to display each row of data for the selected data fields I choose.
However, I have not been successful in trying to achieve the above. I would appreciate, if I could be given some assistance with the code to achieve the result mentioned.
I believe, the answers by #Leigh and #J.T to this question would help you understand the structure of JSON and how to handle it in ColdFusion.
As already commented, you don't need to convert the result to a query object in order to represent the data you want in a tabular format. That is the beauty and simplicity of ColdFusion, you can easily loop through an array, a collection (or struct) or a complex arrangement such as an array of structures. Learn from here.
The JSON result of the http call in your question has a 'results' object with more nested objects. You first begin by deserializing the http result using DeSerializeJSON() get the results object and dump it, analyze the data structure within and finally form your solution.
I will recommend you to start by building up your understanding on the subject.

Couchbase wildcard / variable keys in view

After doing some research and testing with Couchbase, I am getting some good results.
However, it seems strange that views must be created a head of time and are not very flexible.
Basically, if I have a view like this..
function(doc, meta) {
emit([doc.name, doc.location, doc.gender, doc.birthYear, doc.birthMonth], null);
}
And I want to query but different keys. Such as, maybe name = "John" and gender = "M"
It doesnt seem I can do startKey = ["John", {}, "M"], endKey = ["John", {}, "M", {}].
Similarly, what if I just want to filter the above by gender and birth month?
It seems i have to manually crate an individual view for every possible type of query, which with lots of data points if less than optimal.
I havnt seen any questions addressing this. Also, I looked into passing args to map or reduce to do any of it dynamically but that cant be done. I'd be stuck pulling ALL records across all group levels then having to manually sort/aggregate this data.
Can this be done?
Thank you
As of Couchbase version 4.x you have N1QL query language. You can specify a filter criteria to select your json objects without having any views in place.
So as per your example, you should be able issue a query like that:
SELECT *
FROM your_bucket_name
WHERE name = 'John' AND gender = 'M'
Here is a N1QL tutorial to get feel of it.
Yet another way is to use Couchbase integration with ElasticSearch and execute search query in ElasticSearch engine that will return you all the keys it found based on your search criteria.
http://www.couchbase.com/communities/n1ql
N1QL is more rich wuering language to couchbase data, which does not as limited as views

Difference between JSON and SQL

I'm a newbie at web development, so here's a simple question. I've been doing a few tutorials in Django, setting up an SQL database, which is all good. I have now come across the JSON format, which I am not fully understanding. The definition on Wikipedia is: It is used primarily to transmit data between a server and web application, as an alternative to XML. Does this mean that JSON is a database like SQL? If not, what is the difference between SQL and JSON?
Thank you!
JSON is data markup format. You use it to define what the data is and means. eg: This car is blue, it has 4 seats.
{
"colour": "blue",
"seats": 4
}
SQL is a data manipulation language. You use it to define the operations you want to perform on the data. eg: Find me all the green cars. Change all the red cars to blue cars.
select * from cars where colour = 'green'
update cars set colour='blue' where colour='red'
A SQL database is a database that uses SQL to query the data stored within, in whatever format that might be. Other types of databases are available.
They are 2 completely different things.
SQL is used to communicate with databases, usually to Create, Update and Delete data entries.
JSON provides a standardized object notation/structure to talk to web services.
Why standardized?
Because JSON is relatively easy to process both on the front end (with javascript) and the backend. With no-SQL databases becoming the norm, JSON/JSON-like documents/objects are being used in the database as well.
Absolutely not. JSON is the data format in order to pass the data from the sender to the receiver. SQL is the language used by relational databases in order to define data structures and query the information from them. JSON is not associated with any way to store or retrieve the data.
JSON isn't a database, but there isn't anything stopping you from using JSON in a database. Mongo DB is a database that uses JSON (it's actually BSON behind closed doors) to communicate with the database. If you enjoy using JSON and you understand it, I recommend looking into Mongo!