How to design a flow that convert a json to multi table - apache-nifi

I have a JSON like this:
{
"f1": 1,
"f2": 2,
"f3": [
{
"fa1": "a1",
"fa2": "b1"
},
{
"fa1": "a2",
"fa2": "b2"
}
],
"f4": [
{
"fb1": "a1",
"fb2": "b1"
},
{
"fb1": "a2",
"fb2": "b2"
}
]
}
I want to convert this json to three table:
table1 columns:f1,f2
table2 columns: fa1,fa2
table3 columns: fb1,fb2
If flow fail,then all statement rollback.I don't know how to design flow to process exception.

Related

How to filter any data on any filed is present or not in object in GraphQL

Below is my sample data which store in Dgraph
{
"data": {
"comp": [
{
"topologytemplate": {
"namespace": "a",
"nodetemplates": [
{
"name": "a",
},
{
"name": "b",
}
]
}
},
{
"topologytemplate": {
"namespace": "c",
"nodetemplates": [
{
"name": "a",
},
{
"name": "b",
"directives": [
"a"
]
},
]
}
},
]
},
}
I want to filter data so that as a result we get data that does not contain "directives" filed. I am want to filter data using GraphQL query?
Currently, I am trying to filter data as follows:
query {
comp(func: eq(dgraph.type,"QQQ")){
name
topologytemplate{
nodetemplates #filter (eq(nodetypename,"a")){
name
directives
}
}
}
}
Query to check that directives filed are present or not in nodetemplate?

Jooq order by not in jsonArrayArg

The query statement which need to be executed is
dslContext.select(
jsonObject(
key("id").value(ENTITY.ID),
key("name").value(ENTITY.NAME),
key("attributes").value(
coalesce(
select(
jsonArrayAgg(
jsonObject(
key("id").value(ATTRIBUTE.ID),
key("name").value(ATTRIBUTE.NAME),
key("indexValue").value(ATTRIBUTE.INDEX_VALUE)
)
)
).from(ATTRIBUTE)
.where(ATTRIBUTE.ENTITY_ID.eq(ENTITY.ID))
.orderBy(ATTRIBUTE.INDEX_VALUE.asc()),
jsonArray()
)
)
)
).from(ENTITY).fetchInto(EntityDto.class)
Response for the above query:
[
{
"id": 2,
"name": "Address",
"attributes": [
{
"id": 3,
"name": "Pincode",
"indexValue": 4
},
{
"id": 4,
"name": "Country",
"indexValue": 3
},
{
"id": 5,
"name": "City",
"indexValue": 2
},
{
"id": 6,
"name": "Address",
"indexValue": 1
}
]
}
]
The attributes are not sorting in ascending order with respect to indexValue.
How to make the attributes sort in the ascending order?
Use the ORDER BY clause on JSON_ARRAYAGG:
jsonArrayAgg(...).orderBy(...)

Laravel join as array for json response

maybe you can help me find out a query. I do a query Like
$Customers = Customer::paginate();
return response()->json([$Customers]);
this returns (just part of response)
[
{
"current_page": 1,
"data": [{"id": 1,}]
}
]
If I do join with other table all data is just put into "data" output. What I want is this for my join: How to get this output??
[
{
"current_page": 1,
"data": [{
"id": 1,
"join": [{ "join_column" : 1 }],
}]
}
]

ReferenceManyFields (One to Many Relationship)

I am working on a project where I have to create one to many relationships which will get all the list of records referenced by id in another table and I have to display all the selected data in the multi-select field (selectArrayInput). Please help me out in this, if you help with an example that would be great.
Thanks in advance.
Example:
district
id name
1 A
2 B
3 C
block
id district_id name
1 1 ABC
2 1 XYZ
3 2 DEF
I am using https://github.com/Steams/ra-data-hasura-graphql hasura-graphql dataprovider for my application.
You're likely looking for "nested object queries" (see: https://hasura.io/docs/1.0/graphql/manual/queries/nested-object-queries.html#nested-object-queries)
An example...
query MyQuery {
district(where: {id: {_eq: 1}}) {
id
name
blocks {
id
name
}
}
}
result:
{
"data": {
"district": [
{
"id": 1,
"name": "A",
"blocks": [
{
"id": 1,
"name": "ABC"
},
{
"id": 2,
"name": "XYZ"
}
]
}
]
}
}
Or...
query MyQuery2 {
block(where: {district: {name: {_eq: "A"}}}) {
id
name
district {
id
name
}
}
}
result:
{
"data": {
"block": [
{
"id": 1,
"name": "ABC",
"district": {
"id": 1,
"name": "A"
}
},
{
"id": 2,
"name": "XYZ",
"district": {
"id": 1,
"name": "A"
}
}
]
}
}
Setting up the tables this way...
blocks:
districts:
Aside: I recommend using plural table names as they are more standard, "districts" and "blocks"

Extracting data from Deeply Nested JSON in Ruby on Rails

Have a Json out put like
{
"query": {
"results": {
"industry": [
{
"id": "112",
"name": "Agricultural Chemicals",
"company": [
{
"name": "Adarsh Plant",
"symbol": "ADARSHPL"
},
{
"name": "Agrium Inc",
"symbol": "AGU"
}
},
]
{
"id": "914",
"name": "Water Utilities",
"company": [
{
"name": "Acque Potabili",
"symbol": "ACP"
},
{
"name": "Water Resources Group",
"symbol": "WRG"
}
]
}
]
}
}
}
Need the out put like - Company Name, Company Symbol, Company id,
Company id name
and example of output would be
Adarsh Plant, ADARSHPL, 112, Agricultural Chemicals
Agrium Inc, AGU, 112, Agricultural Chemicals
Acque Potabili, ACP, 914, Water Utilities
Water Resources Group, WRG, 914, Water Utilities
Any suggestions
There's a typo in your sample json, but we'll talk about it later.
Assuming your json data converted to hash object already like this:
json={
"query"=> {
"results"=> {
"industry"=> [
{
"id"=> "112",
"name"=> "Agricultural Chemicals",
"company"=> [
{
"name"=> "Adarsh Plant",
"symbol"=> "ADARSHPL"
},
{
"name"=> "Agrium Inc",
"symbol"=> "AGU"
}
]
},
{
"id"=> "914",
"name"=> "Water Utilities",
"company"=> [
{
"name"=> "Acque Potabili",
"symbol"=> "ACP"
},
{
"name"=> "Water Resources Group",
"symbol"=> "WRG"
}
]
}
]
}
}
}
You can use inject and map to handle the two level array of industry, inject will iterate the outer array:
json["query"]["results"]["industry"].inject([]){|m,o|
m += o["company"].map{|x| [x["name"],x["symbol"],o["id"],o["name"]]}
}
result is an array of arrays with the order as you wish:
=> [["Adarsh Plant", "ADARSHPL", "112", "Agricultural Chemicals"],
["Agrium Inc", "AGU", "112", "Agricultural Chemicals"],
["Acque Potabili", "ACP", "914", "Water Utilities"],
["Water Resources Group", "WRG", "914", "Water Utilities"]]
If you want get a string delimited by comma, you could chain on .flatten.join(",") at the end.
json["query"]["results"]["industry"].inject([]){|m,o|
m += o["company"].map{|x| [x["name"],x["symbol"],o["id"],o["name"]]}
}.flatten.join(",")
Result:
=> Adarsh Plant,ADARSHPL,112,Agricultural Chemicals,Agrium Inc,AGU,112,Agricultural Chemicals,Acque Potabili,ACP,914,Water Utilities,Water Resources Group,WRG,914,Water Utilities
The typo of your json data:
In the middle }, ] { should be changed to ] },{ .
Convert json to hash
https://stackoverflow.com/a/7964378/3630826

Resources