Flatten multiple names arrays within variant json column in snowflake - sql

I have a web scraper dumping data into a variant column in a Snowflake database.
This is acraping page data as then creates json arrays for various tables found within the page.
Here is an example of the type of json i would find using a Soccer analogy:
{
"dom_url": "https://www.soccertables.com/european_tables",
"event_id": "01b2722a-d8e6-4f67-95d0-8dd7ba088a4a",
"event_utc_time": "2020-05-11 09:01:14.821",
"ip_address": "125.238.134.96",
"table_1": [
{
"position": "1",
"team_name": "Liverpool",
"games_played": "29",
"games_won": "26",
"games_drawn": "2",
"games_lost": "1",
"goals_for": "75",
"goals_against": "35"
"points": "80"
},
{
"position": "2",
"team_name": "Man. City",
"games_played": "29",
"games_won": "20",
"games_drawn": "5",
"games_lost": "4",
"goals_for": "60",
"goals_against": "45"
"points": "65"
},
{
"position": "...",
"team_name": "...",
"games_played": "...",
"games_won": "...",
"games_drawn": "...",
"games_lost": "...",
"goals_for": "...",
"goals_against": "..."
"points": "..."
}
],
"table_2": [
{
"position": "1",
"team_name": "Bayern Munich",
"games_played": "29",
"games_won": "26",
"games_drawn": "2",
"games_lost": "1",
"goals_for": "75",
"goals_against": "35"
"points": "80"
},
{
"position": "2",
"team_name": "Bayer Leverkussen",
"games_played": "29",
"games_won": "20",
"games_drawn": "5",
"games_lost": "4",
"goals_for": "60",
"goals_against": "45"
"points": "65"
},
{
"position": "...",
"team_name": "...",
"games_played": "...",
"games_won": "...",
"games_drawn": "...",
"games_lost": "...",
"goals_for": "...",
"goals_against": "..."
"points": "..."
}
],
"referrer_url": "https://www.soccertables.com",
}
Ideally, i'd like the output of this to be a flat, relational table:
table_name position team_name games_played etc...
table_1 1 Liverpool 29 ...
table_1 2 Man. City 29 ...
table_2 1 Bayern Munich 29 ...
....
I know that if i were only interested in table_1 i could do this:
SELECT v.value:position::NUMBER POSITION
, v.value:team_name::STRING TEAM_NAME
, v.value:games_played::NUMBER GAMES_PLAYED
, ...
FROM JSON_TABLE a1, LATERAL FLATTEN(JSON_DATA:table_1) v
and that i could do the same for table_2 and union them, but there can be N possibilities with regards to the table_N placeholder.
I've looked at doing LATERAL FLATTEN multiple times:
SELECT v.value:position::NUMBER POSITION
, v.value:team_name::STRING TEAM_NAME
, v.value:games_played::NUMBER GAMES_PLAYED
, ...
FROM JSON_TABLE a1, LATERAL FLATTEN(JSON_DATA:table_1) v, LATERAL FLATTEN(JSON_DATA:table_2) v2
But this results in duplication of data, and does not allow me to put each tables columns all in a single relational structure.
I'm sure there is something simple that i am missing here, but i've reached a point where i think i've been staring at this too long, and just can';t see it.
Thanks in advance,
S

If you are trying to create a single, flattened view of the table_n data, as well as the attributes of at the first level, then something like this would work.
WITH x AS (
SELECT '{
"dom_url": "https://www.soccertables.com/european_tables",
"event_id": "01b2722a-d8e6-4f67-95d0-8dd7ba088a4a",
"event_utc_time": "2020-05-11 09:01:14.821",
"ip_address": "125.238.134.96",
"table_1": [
{
"position": "1",
"team_name": "Liverpool",
"games_played": "29",
"games_won": "26",
"games_drawn": "2",
"games_lost": "1",
"goals_for": "75",
"goals_against": "35",
"points": "80"
},
{
"position": "2",
"team_name": "Man. City",
"games_played": "29",
"games_won": "20",
"games_drawn": "5",
"games_lost": "4",
"goals_for": "60",
"goals_against": "45",
"points": "65"
},
{
"position": "...",
"team_name": "...",
"games_played": "...",
"games_won": "...",
"games_drawn": "...",
"games_lost": "...",
"goals_for": "...",
"goals_against": "...",
"points": "..."
}
],
"table_2": [
{
"position": "1",
"team_name": "Bayern Munich",
"games_played": "29",
"games_won": "26",
"games_drawn": "2",
"games_lost": "1",
"goals_for": "75",
"goals_against": "35",
"points": "80"
},
{
"position": "2",
"team_name": "Bayer Leverkussen",
"games_played": "29",
"games_won": "20",
"games_drawn": "5",
"games_lost": "4",
"goals_for": "60",
"goals_against": "45",
"points": "65"
},
{
"position": "...",
"team_name": "...",
"games_played": "...",
"games_won": "...",
"games_drawn": "...",
"games_lost": "...",
"goals_for": "...",
"goals_against": "...",
"points": "..."
}
],
"referrer_url": "https://www.soccertables.com",
}' as var)
SELECT
parse_json(x.var):dom_url::string,
parse_json(x.var):event_id::string,
parse_json(x.var):event_utc_time::string,
parse_json(x.var):ip_address::string,
x3.value:games_drawn::string,
x3.value:games_lost::string,
x3.value:games_played::string,
x3.value:games_won::string,
x3.value:goals_against::string,
x3.value:goals_for::string,
x3.value:points::string,
x3.value:position::string,
x3.value:team_name::string
FROM x
,LATERAL FLATTEN(parse_json(x.var)) x2
,LATERAL FLATTEN(X2.VALUE) x3;
The CTE is obviously just to show the example with the sample JSON you provided. If you care about which records came from which table, you can also include x2.key as an element in your SELECT.

Related

JPA - Create document tree with specific elements from database

I have a web app where you select documents and display them. The document tree is generated from a sql table with a one to many relationship on itself.
What it looks like on the frontend
This tree is generated from an sql table with the following columns :
(page_id, position, title, version, parent_id)
The sql table in question
I can already query this table and retrieve a tree like the following :
{
"position": 0,
"version": 51,
"children": [
{
"position": 0,
"version": 51,
"children": [
{
"position": 0,
"version": 51,
"parentId": "2",
"id": "5",
"name": "Page 1"
},
{
"position": 1,
"version": 51,
"parentId": "2",
"id": "6",
"name": "Page 2"
},
{
"position": 2,
"version": 51,
"parentId": "2",
"id": "7",
"name": "Page 3"
}
],
"parentId": "1",
"id": "2",
"name": "Category 1"
},
{
"position": 1,
"version": 51,
"children": [
{
"position": 0,
"version": 51,
"parentId": "3",
"id": "8",
"name": "Page 4"
},
{
"position": 1,
"version": 51,
"parentId": "3",
"id": "9",
"name": "Page 5"
},
{
"position": 2,
"version": 51,
"parentId": "3",
"id": "10",
"name": "Page 6"
},
{
"position": 3,
"version": 51,
"children": [
{
"position": 0,
"version": 51,
"parentId": "4",
"id": "11",
"name": "Page 7"
},
{
"position": 1,
"version": 51,
"parentId": "4",
"id": "12",
"name": "Page 8"
},
{
"position": 2,
"version": 51,
"parentId": "4",
"id": "13",
"name": "Page 9"
}
],
"parentId": "3",
"id": "4",
"name": "Category 3"
}
],
"parentId": "1",
"id": "3",
"name": "Category 2"
}
],
"parentId": "0",
"id": "1",
"name": "Doc Root"
}
This is the entity class :
#Entity
#Table
#AllArgsConstructor
#NoArgsConstructor
#Getter
#Setter
#JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Node {
#Id
#JsonProperty("id")
private Long pageId;
public String getPageId() {
return pageId.toString();
}
#ManyToOne(cascade = CascadeType.ALL)
#JsonBackReference
#JoinColumn(name = "parent_id")
private Node parent;
public String getParentId() {
return parent.getPageId();
}
private Long position;
private Long version;
#JsonProperty("name")
private String title;
#OneToMany(mappedBy = "parent")
#OrderBy(value = "position asc")
#JsonManagedReference
private List<Node> children;
}
What I am trying to do is to retrieve only parts of this tree depending on the selected nodes. For reference, with the above selections, I'd like to receive a tree with the following content :
{
"position": 0,
"version": 51,
"children": [
{
"position": 0,
"version": 51,
"children": [
{
"position": 0,
"version": 51,
"parentId": "2",
"id": "5",
"name": "Page 1"
},
{
"position": 1,
"version": 51,
"parentId": "2",
"id": "6",
"name": "Page 2"
},
{
"position": 2,
"version": 51,
"parentId": "2",
"id": "7",
"name": "Page 3"
}
],
"parentId": "1",
"id": "2",
"name": "Category 1"
},
{
"position": 1,
"version": 51,
"children": [
{
"position": 3,
"version": 51,
"children": [
{
"position": 0,
"version": 51,
"parentId": "4",
"id": "11",
"name": "Page 7"
},
{
"position": 1,
"version": 51,
"parentId": "4",
"id": "12",
"name": "Page 8"
},
{
"position": 2,
"version": 51,
"parentId": "4",
"id": "13",
"name": "Page 9"
}
],
"parentId": "3",
"id": "4",
"name": "Category 3"
}
],
"parentId": "1",
"id": "3",
"name": "Category 2"
}
],
"parentId": "0",
"id": "1",
"name": "Doc Root"
}

All data from first table is not showing proper data in sql

I am trying to add two tables, in which first table contains all the video details, and in second table details of video seen by the user with user_id and video_id. I just want to add both the tables and it will show all the list of videos from first table but if the video is seen by the user, status will show 1 else 1.
Here is my query,
SELECT
videos.id, videos.lang_id, videos.medical_type_id, videos.name,
videos.description, videos.thumbnail, videos.video, videos.video_type,
videos.delete_status,
CASE
WHEN video_quews.user_id = $user_id
THEN $user_id
ELSE 'ok'
END AS user_id,
video_quews.video_id, video_quews.created_at,
CASE
WHEN video_quews.video_id = videos.id
THEN 1
ELSE 0
END AS status
FROM
videos
LEFT JOIN
video_quews ON videos.id = video_quews.video_id
ORDER BY
video_quews.video_id DESC
Currently, videos are repeating.
Please help me out
here is my response,
{
"message": "All related videos",
"status": "success",
"code": 200,
"videos": [
{
"id": "30",
"lang_id": "2",
"medical_type_id": "15",
"name": "Fracture",
"thumbnail": "thumbnail_images/1579869167.png",
"video": "videos/fracture.m4v",
"video_type": "2",
"delete_status": "1",
"user_id": "6",
"video_id": "30",
"created_at": "2021-03-04 23:29:50",
"status": "1"
},
{
"id": "16",
"lang_id": "2",
"medical_type_id": "14",
"name": "Electrocution",
"thumbnail": "thumbnail_images/1579698529.png",
"video": "videos/ELECTROCUTION.m4v",
"video_type": "2",
"delete_status": "1",
"user_id": "ok",
"video_id": "16",
"created_at": "2021-03-05 08:19:29",
"status": "1"
},
{
"id": "15",
"lang_id": "2",
"medical_type_id": "13",
"name": "Adult CPR & AED(Cardiac Arrest)",
"thumbnail": "thumbnail_images/1579698505.png",
"video": "videos/CPR1.mp4",
"video_type": "2",
"delete_status": "1",
"user_id": "ok",
"video_id": "15",
"created_at": "2021-03-05 08:18:38",
"status": "1"
},
{
"id": "14",
"lang_id": "2",
"medical_type_id": "12",
"name": "Choking",
"thumbnail": "thumbnail_images/1579698405.png",
"video": "videos/Choking.mp4",
"video_type": "2",
"delete_status": "1",
"user_id": "ok",
"video_id": "14",
"created_at": "2021-03-05 08:17:47",
"status": "1"
},
{
"id": "13",
"lang_id": "2",
"medical_type_id": "11",
"name": "Chest pain",
"thumbnail": "thumbnail_images/1579698381.png",
"video": "videos/CHESTPAIN.mp4",
"video_type": "2",
"delete_status": "1",
"user_id": "ok",
"video_id": "13",
"created_at": "2021-03-05 08:17:20",
"status": "1"
},
{
"id": "12",
"lang_id": "2",
"medical_type_id": "10",
"name": "Burns",
"thumbnail": "thumbnail_images/1579698360.png",
"video": "videos/Burns.mp4",
"video_type": "2",
"delete_status": "1",
"user_id": "ok",
"video_id": "12",
"created_at": "2021-03-05 08:16:39",
"status": "1"
},
{
"id": "11",
"lang_id": "2",
"medical_type_id": "9",
"name": "Breathing Difficulties",
"thumbnail": "thumbnail_images/1579698344.png",
"video": "videos/BreathingDifficulties.mp4",
"video_type": "2",
"delete_status": "1",
"user_id": "ok",
"video_id": "11",
"created_at": "2021-03-05 08:16:19",
"status": "1"
},
{
"id": "8",
"lang_id": "2",
"medical_type_id": "6",
"name": "Asthma",
"thumbnail": "thumbnail_images/1579698286.png",
"video": "videos/ASTHMA.mp4",
"video_type": "2",
"delete_status": "1",
"user_id": "ok",
"video_id": "8",
"created_at": "2021-03-05 08:15:59",
"status": "1"
},
{
"id": "24",
"lang_id": "2",
"medical_type_id": "22",
"name": "Fits/Seizures",
"thumbnail": "thumbnail_images/1579698775.png",
"video": "videos/SEIZURES.m4v",
"video_type": "2",
"delete_status": "1",
"user_id": "ok",
"video_id": null,
"created_at": null,
"status": "0"
},
{
"id": "26",
"lang_id": "2",
"medical_type_id": "24",
"name": "Sprain, strain",
"thumbnail": "thumbnail_images/1579698853.png",
"video": "videos/SPRAIN&STRAIN.mp4",
"video_type": "2",
"delete_status": "1",
"user_id": "ok",
"video_id": null,
"created_at": null,
"status": "0"
},
{
"id": "28",
"lang_id": "2",
"medical_type_id": "26",
"name": "Disposing Glove",
"thumbnail": "thumbnail_images/1579698903.png",
"video": "videos/disposingglove.mp4",
"video_type": "1",
"delete_status": "1",
"user_id": "ok",
"video_id": null,
"created_at": null,
"status": "0"
},
{
"id": "31",
"lang_id": "2",
"medical_type_id": "8",
"name": "Bleeding",
"thumbnail": "thumbnail_images/1581498917.png",
"video": "videos/bleeding.mp4",
"video_type": "2",
"delete_status": "1",
"user_id": "ok",
"video_id": null,
"created_at": null,
"status": "0"
},
{
"id": "18",
"lang_id": "2",
"medical_type_id": "16",
"name": "Gunshot Wound",
"thumbnail": "thumbnail_images/1579698550.png",
"video": "videos/Gunshot.mp4",
"video_type": "2",
"delete_status": "1",
"user_id": "ok",
"video_id": null,
"created_at": null,
"status": "0"
},
{
"id": "20",
"lang_id": "2",
"medical_type_id": "18",
"name": "Hypoglycemia",
"thumbnail": "thumbnail_images/1579698684.png",
"video": "videos/Hypoglycemia.mp4",
"video_type": "2",
"delete_status": "1",
"user_id": "ok",
"video_id": null,
"created_at": null,
"status": "0"
},
{
"id": "22",
"lang_id": "2",
"medical_type_id": "20",
"name": "Nose Bleeding",
"thumbnail": "thumbnail_images/1579698728.png",
"video": "videos/nosebleeding.mp4",
"video_type": "2",
"delete_status": "1",
"user_id": "ok",
"video_id": null,
"created_at": null,
"status": "0"
},
{
"id": "25",
"lang_id": "2",
"medical_type_id": "23",
"name": "Snake Bite",
"thumbnail": "thumbnail_images/1579698801.png",
"video": "videos/SnakeBite.mp4",
"video_type": "2",
"delete_status": "1",
"user_id": "ok",
"video_id": null,
"created_at": null,
"status": "0"
},
{
"id": "27",
"lang_id": "2",
"medical_type_id": "25",
"name": "Stroke",
"thumbnail": "thumbnail_images/1579698879.png",
"video": "videos/STROKE.m4v",
"video_type": "2",
"delete_status": "1",
"user_id": "ok",
"video_id": null,
"created_at": null,
"status": "0"
},
{
"id": "29",
"lang_id": "2",
"medical_type_id": "27",
"name": "Dog Bite",
"thumbnail": "thumbnail_images/1579698934.png",
"video": "videos/Dogbite.mp4",
"video_type": "2",
"delete_status": "1",
"user_id": "ok",
"video_id": null,
"created_at": null,
"status": "0"
},
{
"id": "32",
"lang_id": "2",
"medical_type_id": "7",
"name": "Allergy",
"thumbnail": "thumbnail_images/1581580973.png",
"video": "videos/Allergy.mp4",
"video_type": "2",
"delete_status": "1",
"user_id": "ok",
"video_id": null,
"created_at": null,
"status": "0"
},
{
"id": "19",
"lang_id": "2",
"medical_type_id": "17",
"name": "Hyperthermia(Heat Exhaustion)",
"thumbnail": "thumbnail_images/1579698575.png",
"video": "videos/Hyperthermia.mp4",
"video_type": "2",
"delete_status": "1",
"user_id": "ok",
"video_id": null,
"created_at": null,
"status": "0"
},
{
"id": "21",
"lang_id": "2",
"medical_type_id": "19",
"name": "Introduction",
"thumbnail": "thumbnail_images/1579698707.png",
"video": "videos/intro.mp4",
"video_type": "1",
"delete_status": "1",
"user_id": "ok",
"video_id": null,
"created_at": null,
"status": "0"
},
{
"id": "23",
"lang_id": "2",
"medical_type_id": "21",
"name": "Recovery Position",
"thumbnail": "thumbnail_images/1579698747.png",
"video": "videos/RecoveryPosition.mp4",
"video_type": "2",
"delete_status": "1",
"user_id": "ok",
"video_id": null,
"created_at": null,
"status": "0"
}
],
}
Below is my database,
enter image description here
I just want to add both the tables and it will show all the list of videos from first table but if the video is seen by the user, status will show 1 else 1.
I think you want a flag indicating if a user has seen a video. For this, I suggest EXISTS:
select v.*,
(case when exists (select 1
from video_quews vq
where v.id = vq.video_id and vq.user_id = $user_id
)
then 1 else 0
end) as has_user_flag
from videos v

Vega: x-axis bar ploted out of range

I'm just trying to draw a grouped bar chart with Vega. But the bar that drew on the x-axis out of the range.
I tried to check the code but with limited knowledge of Vega, I failed. :-(
Here is my code. What I'm trying to do is to draw a vertical bar chat of value grouped by the country code which variable name is "category":
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"description": "A basic grouped bar chart example.",
"width": 400,
"height": 500,
"padding": 5,
"data": [
{
"name": "table",
"values": [
{"position": "0", "value": "0.017220172", "category": "ARG", "snapshots": "2020/10/21"},
{"position": "1", "value": "0.026153846", "category": "ARG", "snapshots": "2020/5/21"},
{"position": "2", "value": "0.031484258", "category": "ARG", "snapshots": "2020/6/3"},
{"position": "3", "value": "0.022488756", "category": "ARG", "snapshots": "2020/6/17"},
{"position": "4", "value": "0.024390244", "category": "ARG", "snapshots": "2020/7/2"},
{"position": "5", "value": "0.015130674", "category": "ARG", "snapshots": "2020/7/29"},
{"position": "6", "value": "0.017173052", "category": "ARG", "snapshots": "2020/8/26"},
{"position": "7", "value": "0.025510204", "category": "ARG", "snapshots": "2020/9/24"},
{"position": "0", "value": "0.002949853", "category": "BRA", "snapshots": "2020/10/21"},
{"position": "1", "value": "0.012944984", "category": "BRA", "snapshots": "2020/5/21"},
{"position": "2", "value": "0.018987342", "category": "BRA", "snapshots": "2020/6/3"},
{"position": "3", "value": "0.006309148", "category": "BRA", "snapshots": "2020/6/17"},
{"position": "4", "value": "0.003125", "category": "BRA", "snapshots": "2020/7/2"},
{"position": "5", "value": "0.009202454", "category": "BRA", "snapshots": "2020/7/29"},
{"position": "6", "value": "0.011976048", "category": "BRA", "snapshots": "2020/8/26"},
{"position": "7", "value": "0.00295858", "category": "BRA", "snapshots": "2020/9/24"},
{"position": "0", "value": "0", "category": "CAN", "snapshots": "2020/10/21"},
{"position": "1", "value": "0", "category": "CAN", "snapshots": "2020/5/21"},
{"position": "2", "value": "0", "category": "CAN", "snapshots": "2020/6/3"},
{"position": "3", "value": "0", "category": "CAN", "snapshots": "2020/6/17"},
{"position": "4", "value": "0", "category": "CAN", "snapshots": "2020/7/2"},
{"position": "5", "value": "0", "category": "CAN", "snapshots": "2020/7/29"},
{"position": "6", "value": "0", "category": "CAN", "snapshots": "2020/8/26"},
{"position": "7", "value": "0", "category": "CAN", "snapshots": "2020/9/24"},
{"position": "0", "value": "0.002159827", "category": "CHL", "snapshots": "2020/10/21"},
{"position": "1", "value": "0.0302267", "category": "CHL", "snapshots": "2020/5/21"},
{"position": "2", "value": "0.024813896", "category": "CHL", "snapshots": "2020/6/3"},
{"position": "3", "value": "0.009975062", "category": "CHL", "snapshots": "2020/6/17"},
{"position": "4", "value": "0.00486618", "category": "CHL", "snapshots": "2020/7/2"},
{"position": "5", "value": "0.01891253", "category": "CHL", "snapshots": "2020/7/29"},
{"position": "6", "value": "0.004555809", "category": "CHL", "snapshots": "2020/8/26"},
{"position": "7", "value": "0.013274336", "category": "CHL", "snapshots": "2020/9/24"},
{"position": "0", "value": "0.010989011", "category": "COL", "snapshots": "2020/10/21"},
{"position": "1", "value": "0.016393443", "category": "COL", "snapshots": "2020/5/21"},
{"position": "2", "value": "0", "category": "COL", "snapshots": "2020/6/3"},
{"position": "3", "value": "0", "category": "COL", "snapshots": "2020/6/17"},
{"position": "4", "value": "0.014492754", "category": "COL", "snapshots": "2020/7/2"},
{"position": "5", "value": "0", "category": "COL", "snapshots": "2020/7/29"},
{"position": "6", "value": "0.024096386", "category": "COL", "snapshots": "2020/8/26"},
{"position": "7", "value": "0.011494253", "category": "COL", "snapshots": "2020/9/24"}
]
}
],
"scales": [
{
"name": "xscale",
"type": "band",
"domain": {"data": "table", "field": "category"},
"range": "width",
"padding": 0.2
},
{
"name": "yscale",
"type": "linear",
"domain": {"data": "table", "field": "value"},
"range": "height",
"round": true,
"zero": true,
"nice": true
},
{
"name": "color",
"type": "ordinal",
"domain": {"data": "table", "field": "position"},
"range": {"scheme": "category20"}
}
],
"axes": [
{"orient": "left", "scale": "yscale"},
{"orient": "bottom", "scale": "xscale", "tickSize": 2, "labelPadding": 4, "zindex": 1}
],
"marks": [
{
"type": "group",
"from": {
"facet": {
"data": "table",
"name": "facet",
"groupby": "category"
}
},
"encode": {
"enter": {
"x": {"scale": "xscale", "field": "category"}
}
},
"scales": [
{
"name": "pos",
"type": "band",
"range": "width",
"domain": {"data": "facet", "field": "position"}
}
],
"marks": [
{
"name": "bars",
"from": {"data": "facet"},
"type": "rect",
"encode": {
"enter": {
"x": {"scale": "pos", "field": "position"},
"width": {"scale": "pos", "band": 1},
"y": {"scale": "yscale", "field": "value"},
"y2": {"scale": "yscale", "value": 0},
"fill": {"scale": "color", "field": "position"}
}
}
}
]
}
]
}
Here is the result that I got:
Thanks to this post:
https://gist.github.com/AlexAbes/c17703ce10f7f4a272324ea317e7afce;
The x-scale needs to be updated.
"signals": [
{"name": "width", "update": "bandwidth('xscale')"}
],

Azure stream analytics how to flatten json array

I have a task where i need to flatten some json arrays
say my sample json is and i want to flatten the two arrays temperature_Readings and airpollution readings i.e my result must have 5 rows and the columns for air_pollution(array value) should be empty
How do I do this?
Sample JSON
{
"sensor_readings": {
"readings":{
"temperature_readings": [
{
"date": "02-02-2020",
"hour": "12",
"second": "00",
"temperature": "22.12C"
},
{
"date": "02-02-2020",
"hour": "13",
"second": "00",
"temperature": "22.2C"
},
{
"date": "02-02-2020",
"hour": "14",
"second": "00",
"temperature": "12.12C"
},
{
"date": "02-02-2020",
"hour": "15",
"second": "00",
"temperature": "22.12C"
},
{
"date": "02-02-2020",
"hour": "16",
"second": "00",
"temperature": "22.12C"
}
]
,
"air_pollution_readings":
[
{
"date": "02-02-2020",
"hour": "12",
"second": "00",
"element":"o3",
"particulate": "2.2"
},
{
"date": "02-02-2020",
"hour": "13",
"second": "00",
"element":"o3",
"particulate": "2.1"
}
]}
}
,
"siteid": "a1234566",
"deviceid": "2343434"
}
Thanks
Regards
Priya
Here is an idea of how you can 'unpack' your array of readings.
with sensorReadings as (Select sensor_readings.readings.temperature_readings from input),
inputValues as (Select message.ArrayValue as Data from sensorReadings CROSS APPLY GetArrayElements(sensorReadings.temperature_readings) as message)
SELECT *
INTO output
FROM inputValues

Docusign List Population with Rest Endpoint (Modify Existing Recipient Tabs)

We are trying to populate an existing empty list on a DocuSign Template with some contact methods. The list needs to be populated on the fly since the number and default selected contact method varies with each recipient.
Here is our JSON request we PUT to https://demo.docusign.net/restapi/v2/accounts/:accountId/envelopes/:envelopeId/recipients/:recipientId/tabs (we have confirmed at the necessary variables in the URL have been filled in).
{
"accountId":"163051",
"checkboxTabs":[],
"companyTabs":[],
"dateTabs":[],
"emailTabs":[],
"envelopeId":"048f9ee2-df6e-482d-9e04-abb5e630bf83",
"fullNameTabs":[],
"initialHereTabs":[],
"listTabs":[{
"documentId":"1",
"locked":"False",
"name":"Preferred Contact Method",
"pageNumber":"1",
"tabId":"661499f2-4dda-419d-82ad-f943871407e9",
"tabLabel":"Preferred Contact Method",
"value":"Any",
"listItems":[{
"selected":"True",
"text":"Any",
"value":"1"},{
"selected":"False",
"text":"E-mail",
"value":"2"},{
"selected":"False",
"text":"Phone",
"value":"3"},{
"selected":"False",
"text":"Fax",
"value":"4"},{
"selected":"False",
"text":"Mail",
"value":"5"},{
"selected":"False",
"text":"Home Phone",
"value":"6"},{
"selected":"False",
"text":"Mobile Phone",
"value":"7"},{
"selected":"False",
"text":"Text",
"value":"8"},{
"selected":"False",
"text":"Facebook",
"value":"9"}]
}],
"noteTabs":[],
"radioGroupTabs":[],
"recipientId":"1",
"signHereTabs":[],
"textTabs":[],
"titleTabs":[],
"zipTabs":[]
}
And the response we are getting back:
The remote server returned an error: (500) Internal Server Error.
{
"errorCode": "INVALID_TAB_OPERATION",
"message": "The Tab specified is not valid for the requested operation. Attempt to create 'text' tab from invalid tab type.
}
There are no text tabs in our request. There is a tab with ID 661499f2-4dda-419d-82ad-f943871407e9 of type List on the template.
We were able to get this working a few months ago but fear a new version may have broken this functionality.
In case it is needed here is the "Get Recipient Tabs" response for the same envelope we are trying to modify. The list tab in question is at the bottom.
{
"signHereTabs": [
{
"name": "Sign Here",
"tabLabel": "Signature 12",
"scaleValue": 1,
"optional": "false",
"documentId": "1",
"recipientId": "1",
"pageNumber": "4",
"xPosition": "106",
"yPosition": "270",
"tabId": "00de6704-729d-4726-b102-829f914fda56"
}
],
"dateSignedTabs": [
{
"name": "Date Signed",
"value": "",
"tabLabel": "Date Signed",
"documentId": "1",
"recipientId": "1",
"pageNumber": "4",
"xPosition": "385",
"yPosition": "303",
"tabId": "6236a6cc-2d13-452e-af9b-6fe9706ff500"
}
],
"textTabs": [
{
"height": 11,
"validationPattern": "",
"validationMessage": "",
"shared": "false",
"requireInitialOnSharedChange": "false",
"name": "Text",
"value": "",
"width": 42,
"required": "true",
"locked": "false",
"concealValueOnDocument": "false",
"disableAutoSize": "false",
"tabLabel": "Last Name",
"documentId": "1",
"recipientId": "1",
"pageNumber": "4",
"xPosition": "36",
"yPosition": "146",
"tabId": "5aaee6db-a26a-4102-b77e-2eb4fb6e0c5b"
},
{
"height": 11,
"validationPattern": "",
"validationMessage": "",
"shared": "false",
"requireInitialOnSharedChange": "false",
"name": "Text",
"value": "",
"width": 42,
"required": "true",
"locked": "false",
"concealValueOnDocument": "false",
"disableAutoSize": "false",
"tabLabel": "First Name",
"documentId": "1",
"recipientId": "1",
"pageNumber": "4",
"xPosition": "224",
"yPosition": "147",
"tabId": "999d3f04-99b5-4fae-b69f-bd3e6b27e30d"
},
{
"height": 11,
"validationPattern": "",
"validationMessage": "",
"shared": "false",
"requireInitialOnSharedChange": "false",
"name": "Text",
"value": "",
"width": 42,
"required": "false",
"locked": "false",
"concealValueOnDocument": "false",
"disableAutoSize": "false",
"maxLength": 1,
"tabLabel": "Middle Initial",
"documentId": "1",
"recipientId": "1",
"pageNumber": "4",
"xPosition": "368",
"yPosition": "145",
"tabId": "fdb77bb3-bbe0-4a0c-bf66-ac9fbaa4bb26"
},
{
"height": 11,
"validationPattern": "",
"validationMessage": "",
"shared": "false",
"requireInitialOnSharedChange": "false",
"name": "Text",
"value": "",
"width": 42,
"required": "false",
"locked": "false",
"concealValueOnDocument": "false",
"disableAutoSize": "false",
"tabLabel": "Maiden Name",
"documentId": "1",
"recipientId": "1",
"pageNumber": "4",
"xPosition": "427",
"yPosition": "145",
"tabId": "ae99f579-0016-4839-b179-444fae166f71"
},
{
"height": 11,
"validationPattern": "",
"validationMessage": "",
"shared": "false",
"requireInitialOnSharedChange": "false",
"name": "Text",
"value": "",
"width": 42,
"required": "true",
"locked": "false",
"concealValueOnDocument": "false",
"disableAutoSize": "false",
"tabLabel": "Address Street",
"documentId": "1",
"recipientId": "1",
"pageNumber": "4",
"xPosition": "36",
"yPosition": "175",
"tabId": "506abe87-b144-4d93-8576-b33a2abc4d85"
},
{
"height": 11,
"validationPattern": "",
"validationMessage": "",
"shared": "false",
"requireInitialOnSharedChange": "false",
"name": "Text",
"value": "",
"width": 42,
"required": "false",
"locked": "false",
"concealValueOnDocument": "false",
"disableAutoSize": "false",
"tabLabel": "Apt",
"documentId": "1",
"recipientId": "1",
"pageNumber": "4",
"xPosition": "367",
"yPosition": "173",
"tabId": "7eaa32ef-b9b3-40e5-a5d3-5975134fb90d"
},
{
"height": 11,
"validationPattern": "",
"validationMessage": "",
"shared": "false",
"requireInitialOnSharedChange": "false",
"name": "Text",
"value": "",
"width": 42,
"required": "true",
"locked": "false",
"concealValueOnDocument": "false",
"disableAutoSize": "false",
"tabLabel": "DOB",
"documentId": "1",
"recipientId": "1",
"pageNumber": "4",
"xPosition": "429",
"yPosition": "175",
"tabId": "8f895bec-4f7a-4040-be77-f17374b30765"
},
{
"height": 11,
"validationPattern": "",
"validationMessage": "",
"shared": "false",
"requireInitialOnSharedChange": "false",
"name": "Text",
"value": "",
"width": 42,
"required": "true",
"locked": "false",
"concealValueOnDocument": "false",
"disableAutoSize": "false",
"tabLabel": "Address City",
"documentId": "1",
"recipientId": "1",
"pageNumber": "4",
"xPosition": "36",
"yPosition": "202",
"tabId": "af6cbd27-072f-494d-8cb0-f60578b5e6c9"
},
{
"height": 11,
"validationPattern": "",
"validationMessage": "",
"shared": "false",
"requireInitialOnSharedChange": "false",
"name": "Text",
"value": "",
"width": 42,
"required": "true",
"locked": "false",
"concealValueOnDocument": "false",
"disableAutoSize": "false",
"tabLabel": "Address State",
"documentId": "1",
"recipientId": "1",
"pageNumber": "4",
"xPosition": "212",
"yPosition": "202",
"tabId": "1ecc4a85-5252-4f4f-97d8-22238f46aae5"
},
{
"height": 11,
"validationPattern": "",
"validationMessage": "",
"shared": "false",
"requireInitialOnSharedChange": "false",
"name": "Text",
"value": "",
"width": 42,
"required": "true",
"locked": "false",
"concealValueOnDocument": "false",
"disableAutoSize": "false",
"tabLabel": "Address Zip",
"documentId": "1",
"recipientId": "1",
"pageNumber": "4",
"xPosition": "368",
"yPosition": "202",
"tabId": "0dfb3731-7ce4-4c10-81f2-784428427ee7"
},
{
"height": 11,
"validationPattern": "",
"validationMessage": "",
"shared": "false",
"requireInitialOnSharedChange": "false",
"name": "Text",
"value": "",
"width": 42,
"required": "false",
"locked": "false",
"concealValueOnDocument": "false",
"disableAutoSize": "false",
"tabLabel": "Data Field 17",
"documentId": "1",
"recipientId": "1",
"pageNumber": "4",
"xPosition": "446",
"yPosition": "256",
"tabId": "cb9a86c5-6ecf-4593-8c54-4b7e7d08ffb8"
},
{
"height": 11,
"validationPattern": "",
"validationMessage": "",
"shared": "false",
"requireInitialOnSharedChange": "false",
"name": "Text",
"value": "",
"width": 42,
"required": "false",
"locked": "false",
"concealValueOnDocument": "false",
"disableAutoSize": "false",
"tabLabel": "Data Field 18",
"documentId": "1",
"recipientId": "1",
"pageNumber": "4",
"xPosition": "497",
"yPosition": "270",
"tabId": "0fc2dc21-7916-431f-aa38-a3b4df6c7bcf"
},
{
"height": 11,
"validationPattern": "",
"validationMessage": "",
"shared": "false",
"requireInitialOnSharedChange": "false",
"name": "Text",
"value": "",
"width": 42,
"required": "false",
"locked": "false",
"concealValueOnDocument": "false",
"disableAutoSize": "false",
"tabLabel": "Data Field 19",
"documentId": "1",
"recipientId": "1",
"pageNumber": "4",
"xPosition": "498",
"yPosition": "283",
"tabId": "e0f8676f-6f98-43ee-81db-63734bfe3155"
},
{
"height": 11,
"validationPattern": "",
"validationMessage": "",
"shared": "false",
"requireInitialOnSharedChange": "false",
"name": "Text",
"value": "I am willing to travel.",
"width": 162,
"required": "true",
"locked": "false",
"concealValueOnDocument": "false",
"disableAutoSize": "false",
"tabLabel": "Data Field 49",
"documentId": "1",
"recipientId": "1",
"pageNumber": "5",
"xPosition": "55",
"yPosition": "15",
"tabId": "5c3ddd45-c36c-4214-8b80-d800e0fa5b61"
},
{
"height": 11,
"validationPattern": "",
"validationMessage": "",
"shared": "false",
"requireInitialOnSharedChange": "false",
"name": "Text",
"value": "I am NOT willing to travel.",
"width": 162,
"required": "true",
"locked": "false",
"concealValueOnDocument": "false",
"disableAutoSize": "false",
"tabLabel": "Data Field 50",
"documentId": "1",
"recipientId": "1",
"pageNumber": "5",
"xPosition": "56",
"yPosition": "41",
"tabId": "47d7d2ff-2a4f-4de7-9f67-311cd0b172c8"
},
{
"height": 11,
"validationPattern": "",
"validationMessage": "",
"shared": "false",
"requireInitialOnSharedChange": "false",
"name": "Text",
"value": "Preferred Contact Method",
"width": 138,
"required": "true",
"locked": "false",
"concealValueOnDocument": "false",
"disableAutoSize": "false",
"tabLabel": "Data Field 52",
"documentId": "1",
"recipientId": "1",
"pageNumber": "1",
"xPosition": "81",
"yPosition": "21",
"tabId": "75b83aa1-c906-4827-9fc2-6cc4177843c6"
}
],
"ssnTabs": [
{
"validationPattern": "",
"validationMessage": "",
"shared": "false",
"requireInitialOnSharedChange": "false",
"name": "SSNTOOLTIP",
"value": "",
"width": 48,
"required": "true",
"locked": "false",
"concealValueOnDocument": "false",
"disableAutoSize": "false",
"tabLabel": "SSN",
"documentId": "1",
"recipientId": "1",
"pageNumber": "4",
"xPosition": "429",
"yPosition": "204",
"tabId": "11b62284-7613-48df-8498-fa019f3a42a3"
}
],
"radioGroupTabs": [
{
"documentId": "1",
"recipientId": "1",
"groupName": "Radio Button 13",
"radios": [
{
"pageNumber": "4",
"xPosition": "297",
"yPosition": "229",
"value": "Radio",
"selected": "false",
"tabId": "2b2312d2-3ed6-469e-8aeb-8de588ae16d3"
},
{
"pageNumber": "4",
"xPosition": "297",
"yPosition": "243",
"value": "Radio",
"selected": "false",
"tabId": "1a997301-f5d8-4e86-8ead-9d706490faf2"
},
{
"pageNumber": "4",
"xPosition": "297",
"yPosition": "256",
"value": "Radio",
"selected": "false",
"tabId": "705df9df-9e1d-478b-b991-9b31e919c85c"
},
{
"pageNumber": "4",
"xPosition": "297",
"yPosition": "271",
"value": "Radio",
"selected": "false",
"tabId": "d74742c2-742e-43d5-b1c5-04854ec8a7c5"
}
]
},
{
"groupName": "Radio Button Group Test",
"radios": [
{
"pageNumber": "5",
"xPosition": "28",
"yPosition": "15",
"value": "TravelYes",
"selected": "false",
"tabId": "30962105-0337-4d98-b4dd-058ae736d6fb"
},
{
"pageNumber": "5",
"xPosition": "27",
"yPosition": "40",
"value": "TravelNo",
"selected": "false",
"tabId": "351ba656-80dd-43ea-936a-fd322d63c0c0"
}
]
}
],
"listTabs": [
{
"listItems": [
{
"text": "",
"value": "",
"selected": "true"
},
{
"text": "",
"value": "",
"selected": "true"
}
],
"value": "",
"width": 77,
"shared": "false",
"requireInitialOnSharedChange": "false",
"tabLabel": "Preferred Contact Method",
"documentId": "1",
"recipientId": "1",
"pageNumber": "1",
"xPosition": "220",
"yPosition": "20",
"tabId": "661499f2-4dda-419d-82ad-f943871407e9"
}
]
}
This is a confirmed bug with DocuSign. I'm hoping this will get fixed in the next release but can't confirm yet. Once fixed I will update this answer to include the elements of a proper api call to modify an existing listTab, which I believe you're currently doing.