Create hive table for JSON data - hadoop

How to create hive table for the below twitter JSON data that is available in HDFS path. I tried some of the query from the web to create the table, but facing some issue.
{
"extended_entities": {
"media": [{
"display_url": "pic.twitter.com/9SoA83sVvP",
"indices": [100, 123],
"sizes": {
"small": {
"w": 340,
"h": 340,
"resize": "fit"
},
"large": {
"w": 480,
"h": 480,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"medium": {
"w": 480,
"h": 480,
"resize": "fit"
}
},
"id_str": "685710180164579329",
"expanded_url": "http://twitter.com/add7dave/status/685710518456209408/video/1",
"media_url_https": "https://pbs.twimg.com/ext_tw_video_thumb/685710180164579329/pu/img/4wOqavTprNIaMgjK.jpg",
"id": 685710180164579329,
"type": "video",
"media_url": "http://pbs.twimg.com/ext_tw_video_thumb/685710180164579329/pu/img/4wOqavTprNIaMgjK.jpg",
"url": "https://t.co/9SoA83sVvP",
"video_info": {
"aspect_ratio": [1, 1],
"duration_millis": 7567,
"variants": [{
"content_type": "application/x-mpegURL",
"url": "https://video.twimg.com/ext_tw_video/685710180164579329/pu/pl/6JnchC_1FWviydJV.m3u8"
}, {
"content_type": "application/dash+xml",
"url": "https://video.twimg.com/ext_tw_video/685710180164579329/pu/pl/6JnchC_1FWviydJV.mpd"
}, {
"content_type": "video/mp4",
"bitrate": 320000,
"url": "https://video.twimg.com/ext_tw_video/685710180164579329/pu/vid/240x240/W7suov-YC1Iq1-QT.mp4"
}, {
"content_type": "video/webm",
"bitrate": 832000,
"url": "https://video.twimg.com/ext_tw_video/685710180164579329/pu/vid/480x480/bDG_UfEw3jBM7z4e.webm"
}, {
"content_type": "video/mp4",
"bitrate": 832000,
"url": "https://video.twimg.com/ext_tw_video/685710180164579329/pu/vid/480x480/bDG_UfEw3jBM7z4e.mp4"
}]
}
}]
},
"in_reply_to_status_id_str": null,
"in_reply_to_status_id": null,
"created_at": "Sat Jan 09 06:31:42 +0000 2016",
"in_reply_to_user_id_str": null,
"source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android<\/a>",
"retweet_count": 0,
"retweeted": false,
"geo": null,
"filter_level": "low",
"in_reply_to_screen_name": null,
"is_quote_status": false,
"id_str": "685710518456209408",
"in_reply_to_user_id": null,
"favorite_count": 0,
"id": 685710518456209408,
"text": "New video NO-17\n#BritanniaFilmfareAwards\n#GoodDayCookies\n#BritanniaIndLtd\nAmitabh Bachchan dialogue https://t.co/9SoA83sVvP",
"place": null,
"lang": "en",
"favorited": false,
"possibly_sensitive": false,
"coordinates": null,
"truncated": false,
"timestamp_ms": "1452321102142",
"entities": {
"urls": [],
"hashtags": [{
"indices": [16, 40],
"text": "BritanniaFilmfareAwards"
}],
"media": [{
"display_url": "pic.twitter.com/9SoA83sVvP",
"indices": [100, 123],
"sizes": {
"small": {
"w": 340,
"h": 340,
"resize": "fit"
},
"large": {
"w": 480,
"h": 480,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"medium": {
"w": 480,
"h": 480,
"resize": "fit"
}
},
"id_str": "685710180164579329",
"expanded_url": "http://twitter.com/add7dave/status/685710518456209408/video/1",
"media_url_https": "https://pbs.twimg.com/ext_tw_video_thumb/685710180164579329/pu/img/4wOqavTprNIaMgjK.jpg",
"id": 685710180164579329,
"type": "photo",
"media_url": "http://pbs.twimg.com/ext_tw_video_thumb/685710180164579329/pu/img/4wOqavTprNIaMgjK.jpg",
"url": "https://t.co/9SoA83sVvP"
}],
"user_mentions": [{
"indices": [41, 56],
"screen_name": "GoodDayCookies",
"id_str": "2197439803",
"name": "Britannia Good Day",
"id": 2197439803
}, {
"indices": [57, 73],
"screen_name": "BritanniaIndLtd",
"id_str": "3281245460",
"name": "Britannia Industries",
"id": 3281245460
}],
"symbols": []
},
"contributors": null,
"user": {
"utc_offset": 19800,
"friends_count": 1517,
"profile_image_url_https": "https://pbs.twimg.com/profile_images/593327096736256001/TT8Ds75__normal.jpg",
"listed_count": 1,
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme19/bg.gif",
"default_profile_image": false,
"favourites_count": 25,
"description": "Sharukhan, Kapil sharma , Narendra modi Fan (Supporter) be happy *↓*",
"created_at": "Thu Sep 15 08:04:58 +0000 2011",
"is_translator": false,
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme19/bg.gif",
"protected": false,
"screen_name": "add7dave",
"id_str": "373836462",
"profile_link_color": "9266CC",
"id": 373836462,
"geo_enabled": false,
"profile_background_color": "FFF04D",
"lang": "en",
"profile_sidebar_border_color": "000000",
"profile_text_color": "000000",
"verified": false,
"profile_image_url": "http://pbs.twimg.com/profile_images/593327096736256001/TT8Ds75__normal.jpg",
"time_zone": "Chennai",
"url": null,
"contributors_enabled": false,
"profile_background_tile": false,
"profile_banner_url": "https://pbs.twimg.com/profile_banners/373836462/1428993069",
"statuses_count": 21397,
"follow_request_sent": null,
"followers_count": 438,
"profile_use_background_image": true,
"default_profile": false,
"following": null,
"name": "aditya dave",
"location": "Bhavnagar, Gujarat",
"profile_sidebar_fill_color": "000000",
"notifications": null
}
}
I tried the below table but it gives error.
hive> CREATE EXTERNAL TABLE tweets (
id BIGINT,
created_at STRING,
source STRING,
favorited BOOLEAN,
retweeted_status STRUCT<
text:STRING,
user:STRUCT<screen_name:STRING,name:STRING>,
retweet_count:INT>,
entities STRUCT<
urls:ARRAY<STRUCT<expanded_url:STRING>>,
user_mentions:ARRAY<STRUCT<screen_name:STRING,name:STRING>>,
hashtags:ARRAY<STRUCT<text:STRING>>>,
text STRING,
user STRUCT<
screen_name:STRING,
name:STRING,
friends_count:INT,
followers_count:INT,
statuses_count:INT,
verified:BOOLEAN,
utc_offset:INT,
time_zone:STRING>,
in_reply_to_screen_name STRING
)
PARTITIONED BY (datehour INT)
ROW FORMAT SERDE 'com.cloudera.hive.serde.JSONSerDe'
LOCATION '/user/flume/tweets/01092015';

You can use this utility https://github.com/quux00/hive-json-schema to create a hive schema from JSON. But as Ben Watson in his answer here if there are some columns like user that use a reserved name, you have to either enclose them with backticks or use a serde like https://github.com/rcongiu/Hive-JSON-Serde that can map hive columns to json elements.

Related

Download a PNG from URL LookIntoBitcoin

There is a page with URL:
https://www.lookintobitcoin.com/charts/1-year-hodl-wave/
I'm designing a page and I just want to reference the "image" of this URL.
It has a download PNG file, how can i just get the path/url to this png image file?
Here is the image icon, but i cant figure out how to get the url path to just the png file.
Can anyone show me how to get it?
This image is dynamically generated at client side (browser), so here is two ways to solve your problem:
Use Selenium or PhantomJS (both using headless browser technology) to emulate browser behaviour and automatically "press" download button at background.
Fetch JSON data and create graph by yourself (for example how to create PNG image based on txt file in python)
I recommend second way because it more flexible and you will be able to widely customize result image. But it may be more complicated than headless browser way.
If you want to use second way, you can fetch JSON data using python (for example):
import requests
import json
url = 'https://www.lookintobitcoin.com/django_plotly_dash/app/hodl_wave/_dash-update-component'
request_data = {
"output":"chart.figure",
"changedPropIds":["url.pathname"],
"inputs":[
{
"id":"url",
"property":"pathname",
"value":"/charts/1-year-hodl-wave/"
}
]
}
response = requests.post(url, json=request_data)
print(json.dumps(response.json(), indent=2))
And output will be:
{
"response": {
"props": {
"figure": {
"data": [
{
"line": {
"color": "#003366",
"width": 1.2
},
"name": "BTC Price",
"x": [
"2010-08-17",
"2020-09-13",
"2020-09-14",
...
"2021-09-07",
"2021-09-08"
],
"y": [
0.07,
0.07,
...
46215.0
],
"yaxis": "y2",
"type": "scatter"
},
{
"connectgaps": true,
"line": {
"color": "#ffa500",
"width": 0.8
},
"name": "1Yr+ HODL Wave",
"x": [
"2010-08-17",
...
"2021-12-16T00:00:00",
"2021-12-17T00:00:00"
],
"y": [
0.28032062150000003,
0.2807032645,
...
0.5101534705064048,
0.5090896880670537
],
"yaxis": "y",
"type": "scatter"
},
{
"hoverinfo": "skip",
"marker": {
"color": "rgba(255, 207, 209, 0.75)",
"size": 15
},
"mode": "markers",
"name": "Price Peak",
"showlegend": true,
"x": [
"2011-06-13"
],
"y": [
20.11
],
"yaxis": "y2",
"type": "scatter"
},
{
"hoverinfo": "skip",
"marker": {
"color": "rgba(255, 207, 209, 0.75)",
"size": 15
},
"mode": "markers",
"name": "Price Peak",
"showlegend": false,
"x": [
"2011-06-13"
],
"y": [
0.2979442568
],
"yaxis": "y",
"type": "scatter"
},
{
"hoverinfo": "skip",
"marker": {
"color": "rgba(255, 207, 209, 0.75)",
"size": 15
},
"mode": "markers",
"name": "Price Peak",
"showlegend": false,
"x": [
"2013-12-02"
],
"y": [
1047.9
],
"yaxis": "y2",
"type": "scatter"
},
{
"hoverinfo": "skip",
"marker": {
"color": "rgba(255, 207, 209, 0.75)",
"size": 15
},
"mode": "markers",
"name": "Price Peak",
"showlegend": false,
"x": [
"2013-12-02"
],
"y": [
0.3877138953
],
"yaxis": "y",
"type": "scatter"
},
{
"hoverinfo": "skip",
"marker": {
"color": "rgba(255, 207, 209, 0.75)",
"size": 15
},
"mode": "markers",
"name": "Price Peak",
"showlegend": false,
"x": [
"2017-12-20"
],
"y": [
16811.3
],
"yaxis": "y2",
"type": "scatter"
},
{
"hoverinfo": "skip",
"marker": {
"color": "rgba(255, 207, 209, 0.75)",
"size": 15
},
"mode": "markers",
"name": "Price Peak",
"showlegend": false,
"x": [
"2017-12-20"
],
"y": [
0.43133634880000005
],
"yaxis": "y",
"type": "scatter"
},
{
"hoverinfo": "skip",
"marker": {
"color": "rgba(211, 245, 231, 0.75)",
"size": 15
},
"mode": "markers",
"name": "Price Bottom",
"showlegend": false,
"x": [
"2011-11-22"
],
"y": [
2.31
],
"yaxis": "y2",
"type": "scatter"
},
{
"hoverinfo": "skip",
"marker": {
"color": "rgba(211, 245, 231, 0.75)",
"size": 15
},
"mode": "markers",
"name": "Price Bottom",
"showlegend": false,
"x": [
"2011-11-22"
],
"y": [
0.3073864328
],
"yaxis": "y",
"type": "scatter"
},
{
"hoverinfo": "skip",
"marker": {
"color": "rgba(211, 245, 231, 0.75)",
"size": 15
},
"mode": "markers",
"name": "Price Bottom",
"showlegend": false,
"x": [
"2015-01-17"
],
"y": [
201.75
],
"yaxis": "y2",
"type": "scatter"
},
{
"hoverinfo": "skip",
"marker": {
"color": "rgba(211, 245, 231, 0.75)",
"size": 15
},
"mode": "markers",
"name": "Price Bottom",
"showlegend": false,
"x": [
"2015-01-17"
],
"y": [
0.5363931366
],
"yaxis": "y",
"type": "scatter"
},
{
"hoverinfo": "skip",
"marker": {
"color": "rgba(211, 245, 231, 0.75)",
"size": 15
},
"mode": "markers",
"name": "Price Bottom",
"showlegend": true,
"x": [
"2018-12-20"
],
"y": [
3983.01
],
"yaxis": "y2",
"type": "scatter"
},
{
"hoverinfo": "skip",
"marker": {
"color": "rgba(211, 245, 231, 0.75)",
"size": 15
},
"mode": "markers",
"name": "Price Bottom",
"showlegend": false,
"x": [
"2018-12-20"
],
"y": [
0.5097358173
],
"yaxis": "y",
"type": "scatter"
}
],
"layout": {
"hovermode": "closest",
"images": [
{
"layer": "below",
"opacity": 0.1,
"sizex": 0.4,
"sizey": 0.4,
"source": "https://www.lookintobitcoin.com/static/img/logo/logo-stacked.png",
"x": 0.4,
"xref": "paper",
"y": 0.75,
"yref": "paper"
}
],
"legend": {
"font": {
"color": "#696969"
},
"orientation": "h",
"x": 0.1
},
"margin": {
"t": 10
},
"uirevision": "False",
"xaxis": {
"color": "#696969",
"gridcolor": "#d3d3d3",
"hoverformat": "%d-%b-%y",
"range": [
"2010-08-17",
"2021-12-17T00:00:00"
],
"showline": true,
"showspikes": true,
"spikecolor": "#696969",
"spikedash": "solid",
"spikemode": "toaxis+across",
"spikethickness": 1
},
"yaxis": {
"color": "#696969",
"hoverformat": "%",
"range": [
0,
1
],
"showgrid": false,
"showspikes": true,
...
"spikethickness": 1,
"tickformat": "%",
"title": {
"text": "1Yr+ HODL Wave"
}
},
"yaxis2": {
"color": "#696969",
"dtick": 1,
...
"spikethickness": 1,
"ticktext": [
"$0.001",
...
"$10,000",
"$100,000"
],
"tickvals": [
0.001,
...
100000
],
"title": {
"text": "BTC Price (USD)"
},
"type": "log",
"zeroline": true
}
}
}
}
}
}

Color for button for action.showCard Adaptive Card doesn't changes

Here is the image of the adaptive card, have a look it will better explain the question
we have built an app for MS teams, this app uses adaptive card in its flow, in the first step a number of images are shown, there are different categories buttons at the top from there client can select images, for each button we have attached action.showCard, so except the last button all other buttons are of the same color but the last one is of different color, this looks bad for the client. I have not used any style for action.showCard but still it shows different color. can anyone help to remove the color from the last button? Thanks in advance
Card Json
{
"task": {
"type": "continue",
"value": {
"title": "Select a non-monetary award",
"height": "medium",
"width": "medium",
"card": {
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"type": "AdaptiveCard",
"version": "1.2",
"body": [],
"actions": [{
"type": "Action.ShowCard",
"title": "SELF CARE",
"card": {
"type": "AdaptiveCard",
"version": "1.2",
"body": [{
"type": "ColumnSet",
"columns": [{
"type": "Column",
"width": "stretch",
"separator": true,
"spacing": "medium",
"style": "default",
"horizontalAlignment": "center",
"verticalContentAlignment": "center",
"bleed": false,
"items": [{
"type": "Image",
"url": "https://image",
"size": "Large",
"altText": "Health Warrior",
"selectAction": {
"type": "Action.Submit",
"title": "Health Warrior",
"data": {
"x": 2,
"Recipients": null,
"WorkFlow": null,
"badgeId": 1395,
"approverId": null,
"tags": null,
"awardValue": null,
"comment": null,
"businessJustification": null,
"msteams": null
}
},
"horizontalAlignment": "center",
"separator": true
}, {
"type": "TextBlock",
"text": "Health Warrior",
"horizontalAlignment": "center",
"size": "large",
"maxLines": 15,
"id": null,
"color": null,
"wrap": true
}, {
"type": "TextBlock",
"text": "",
"horizontalAlignment": "center",
"size": "medium",
"maxLines": 10,
"id": null,
"color": "Dark",
"wrap": false
}]
}],
"horizontalAlignment": "left",
"bleed": false,
"style": "emphasis"
}],
"style": "emphasis"
},
"style": "positive"
}, {
"type": "Action.ShowCard",
"title": "PERFORMANCE",
"card": {
"type": "AdaptiveCard",
"version": "1.2",
"body": [{
"type": "ColumnSet",
"columns": [{
"type": "Column",
"width": "stretch",
"separator": true,
"spacing": "medium",
"style": "default",
"horizontalAlignment": "center",
"verticalContentAlignment": "center",
"bleed": false,
"items": [{
"type": "Image",
"url": "https://image",
"size": "Large",
"altText": "Great Job",
"selectAction": {
"type": "Action.Submit",
"title": "Great Job",
"data": {
"x": 2,
"Recipients": null,
"WorkFlow": null,
"badgeId": 6,
"approverId": null,
"tags": null,
"awardValue": null,
"comment": null,
"businessJustification": null,
"msteams": null
}
},
"horizontalAlignment": "center",
"separator": true
}, {
"type": "TextBlock",
"text": "Great Job",
"horizontalAlignment": "center",
"size": "large",
"maxLines": 15,
"id": null,
"color": null,
"wrap": true
}, {
"type": "TextBlock",
"text": "",
"horizontalAlignment": "center",
"size": "medium",
"maxLines": 10,
"id": null,
"color": "Dark",
"wrap": false
}]
}, {
"type": "Column",
"width": "stretch",
"separator": true,
"spacing": "medium",
"style": "default",
"horizontalAlignment": "center",
"verticalContentAlignment": "center",
"bleed": false,
"items": [{
"type": "Image",
"url": "https://image",
"size": "Large",
"altText": "Thank You!",
"selectAction": {
"type": "Action.Submit",
"title": "Thank You!",
"data": {
"x": 2,
"Recipients": null,
"WorkFlow": null,
"badgeId": 11,
"approverId": null,
"tags": null,
"awardValue": null,
"comment": null,
"businessJustification": null,
"msteams": null
}
},
"horizontalAlignment": "center",
"separator": true
}, {
"type": "TextBlock",
"text": "Thank You!",
"horizontalAlignment": "center",
"size": "large",
"maxLines": 15,
"id": null,
"color": null,
"wrap": true
}, {
"type": "TextBlock",
"text": "",
"horizontalAlignment": "center",
"size": "medium",
"maxLines": 10,
"id": null,
"color": "Dark",
"wrap": false
}]
}],
"horizontalAlignment": "left",
"bleed": false,
"style": "emphasis"
}],
"style": "emphasis"
},
"style": "positive"
}]
}
}
}
}
}

Extract value from response and use it in next sampler request body specific

How to extract an id like 5105800, 5105801, 5105802 and his quantity 200, 50 , 40 from response Body and reuse it in the request body as show below?
Response Body:
{
"data": {
"callOrders": [
{
"promotionId": null,
"Promotion": null,
"Lines": [
{
"id": 5105800,
"quantity": 200,
"skuId": 85,
"callId": 494281,
"skuBatchId": 587,
"amountDetails": {
"rate": 144.22,
"grossAmount": 32593.72,
"netAmount": 32593.72,
"taxAmount": 3749.72,
"taxableAmount": 28844,
"subTotal": 28844,
"billDiscount": 0,
"tradeDiscount": 0,
"discountAmount": 0,
"promotionDiscount": 0,
"topUpDiscount": 0,
"__typename": "AmountDetail"
},
"rateDetails": {
"rlp": 144.22,
"rlpWithVat": 162.9686,
"netPrice": 144.22,
"netPriceWithVat": 162.9686,
"__typename": "RateDetail"
},
"SKU": {
"id": 85,
"title": "Ariel Oxyblu 500 gm x 48 [82262305]",
"__typename": "SKU"
},
"SKUBatch": {
"priceDetails": {
"rlp": 144.22,
"dlp": 137.35,
"vatPercentage": 0.13,
"mrpSrp": 176,
"mrpStatus": true,
"__typename": "SKUPrice"
},
"batchDetails": {
"batchNumber": "DEFAULT_BATCH",
"__typename": "SKUBatch"
},
"usageDate": {
"manufacture": "0000-00-00",
"expiry": "0000-00-00",
"__typename": "SKUUsage"
},
"updatedAt": "2018-12-01",
"active": true,
"__typename": "SKUBatchRate"
},
"Promotion": {
"id": null,
"title": null,
"type": null,
"scope": null,
"criteria": null,
"__typename": "Promotion"
},
"promotionId": null,
"distributorId": 16,
"__typename": "Line",
"inStock": "INSTOCK",
"freeSku": false,
"focusedSku": true
},
{
"id": 5105801,
"quantity": 50,
"skuId": 82,
"callId": 494281,
"skuBatchId": 551,
"amountDetails": {
"rate": 281.88,
"grossAmount": 15926.22,
"netAmount": 15926.22,
"taxAmount": 1832.22,
"taxableAmount": 14094,
"subTotal": 14094,
"billDiscount": 0,
"tradeDiscount": 0,
"discountAmount": 0,
"promotionDiscount": 0,
"topUpDiscount": 0,
"__typename": "AmountDetail"
},
"rateDetails": {
"rlp": 281.88,
"rlpWithVat": 318.5244,
"netPrice": 281.88,
"netPriceWithVat": 318.5244,
"__typename": "RateDetail"
},
"SKU": {
"id": 82,
"title": "Ariel Oxyblu 1 kg x 24 [82250306]",
"__typename": "SKU"
},
"SKUBatch": {
"priceDetails": {
"rlp": 281.88,
"dlp": 268.45,
"vatPercentage": 0.13,
"mrpSrp": 344,
"mrpStatus": true,
"__typename": "SKUPrice"
},
"batchDetails": {
"batchNumber": "DEFAULT_BATCH",
"__typename": "SKUBatch"
},
"usageDate": {
"manufacture": "0000-00-00",
"expiry": "0000-00-00",
"__typename": "SKUUsage"
},
"updatedAt": "2018-01-31",
"active": true,
"__typename": "SKUBatchRate"
},
"Promotion": {
"id": null,
"title": null,
"type": null,
"scope": null,
"criteria": null,
"__typename": "Promotion"
},
"promotionId": null,
"distributorId": 16,
"__typename": "Line",
"inStock": "INSTOCK",
"freeSku": false,
"focusedSku": true
},
{
"id": 5105802,
"quantity": 40,
"skuId": 769,
"callId": 494281,
"skuBatchId": 733,
"amountDetails": {
"rate": 197.53,
"grossAmount": 8928.356,
"netAmount": 8928.356,
"taxAmount": 1027.156,
"taxableAmount": 7901.2,
"subTotal": 7901.2,
"billDiscount": 0,
"tradeDiscount": 0,
"discountAmount": 0,
"promotionDiscount": 0,
"topUpDiscount": 0,
"__typename": "AmountDetail"
},
"rateDetails": {
"rlp": 197.53,
"rlpWithVat": 223.2089,
"netPrice": 197.53,
"netPriceWithVat": 223.2089,
"__typename": "RateDetail"
},
"SKU": {
"id": 769,
"title": "H&S 2in1 Active Protect 180 ml x 24 [82302894]",
"__typename": "SKU"
},
"SKUBatch": {
"priceDetails": {
"rlp": 197.53,
"dlp": 186.35,
"vatPercentage": 0.13,
"mrpSrp": 250,
"mrpStatus": true,
"__typename": "SKUPrice"
},
"batchDetails": {
"batchNumber": "DEFAULT_BATCH",
"__typename": "SKUBatch"
},
"usageDate": {
"manufacture": "0000-00-00",
"expiry": "0000-00-00",
"__typename": "SKUUsage"
},
"updatedAt": "2019-11-05",
"active": true,
"__typename": "SKUBatchRate"
},
"Promotion": {
"id": null,
"title": null,
"type": null,
"scope": null,
"criteria": null,
"__typename": "Promotion"
},
"promotionId": null,
"distributorId": 16,
"__typename": "Line",
"inStock": "INSTOCK",
"freeSku": false,
"focusedSku": false
}
],
"__typename": "PromotionOrder"
}
]
}
}
Request Body:
{
"operationName": null,
"variables": {
"input": {
"invoiceId": 3683663,
"orderDetails": [
{
"id": 5105800,
"quantity": 200
},
{
"id": 5105801,
"quantity": 50
},
{
"id": 5105802,
"quantity": 40
}
]
},
"type": "CatalogDetail"
},
"query": "mutation ($input: DispatchInput!) {\n dispatchInvoice(input: $input) {\n id\n __typename\n }\n}\n"
}
When you use JavaScript, you could use the following one :)
const responseBody = {
"data": {
"callOrders": [
{
"promotionId": null,
"Promotion": null,
"Lines": [
{
"id": 5105800,
"quantity": 200,
"skuId": 85,
"callId": 494281,
"skuBatchId": 587,
"amountDetails": {
"rate": 144.22,
"grossAmount": 32593.72,
"netAmount": 32593.72,
"taxAmount": 3749.72,
"taxableAmount": 28844,
"subTotal": 28844,
"billDiscount": 0,
"tradeDiscount": 0,
"discountAmount": 0,
"promotionDiscount": 0,
"topUpDiscount": 0,
"__typename": "AmountDetail"
},
"rateDetails": {
"rlp": 144.22,
"rlpWithVat": 162.9686,
"netPrice": 144.22,
"netPriceWithVat": 162.9686,
"__typename": "RateDetail"
},
"SKU": {
"id": 85,
"title": "Ariel Oxyblu 500 gm x 48 [82262305]",
"__typename": "SKU"
},
"SKUBatch": {
"priceDetails": {
"rlp": 144.22,
"dlp": 137.35,
"vatPercentage": 0.13,
"mrpSrp": 176,
"mrpStatus": true,
"__typename": "SKUPrice"
},
"batchDetails": {
"batchNumber": "DEFAULT_BATCH",
"__typename": "SKUBatch"
},
"usageDate": {
"manufacture": "0000-00-00",
"expiry": "0000-00-00",
"__typename": "SKUUsage"
},
"updatedAt": "2018-12-01",
"active": true,
"__typename": "SKUBatchRate"
},
"Promotion": {
"id": null,
"title": null,
"type": null,
"scope": null,
"criteria": null,
"__typename": "Promotion"
},
"promotionId": null,
"distributorId": 16,
"__typename": "Line",
"inStock": "INSTOCK",
"freeSku": false,
"focusedSku": true
},
{
"id": 5105801,
"quantity": 50,
"skuId": 82,
"callId": 494281,
"skuBatchId": 551,
"amountDetails": {
"rate": 281.88,
"grossAmount": 15926.22,
"netAmount": 15926.22,
"taxAmount": 1832.22,
"taxableAmount": 14094,
"subTotal": 14094,
"billDiscount": 0,
"tradeDiscount": 0,
"discountAmount": 0,
"promotionDiscount": 0,
"topUpDiscount": 0,
"__typename": "AmountDetail"
},
"rateDetails": {
"rlp": 281.88,
"rlpWithVat": 318.5244,
"netPrice": 281.88,
"netPriceWithVat": 318.5244,
"__typename": "RateDetail"
},
"SKU": {
"id": 82,
"title": "Ariel Oxyblu 1 kg x 24 [82250306]",
"__typename": "SKU"
},
"SKUBatch": {
"priceDetails": {
"rlp": 281.88,
"dlp": 268.45,
"vatPercentage": 0.13,
"mrpSrp": 344,
"mrpStatus": true,
"__typename": "SKUPrice"
},
"batchDetails": {
"batchNumber": "DEFAULT_BATCH",
"__typename": "SKUBatch"
},
"usageDate": {
"manufacture": "0000-00-00",
"expiry": "0000-00-00",
"__typename": "SKUUsage"
},
"updatedAt": "2018-01-31",
"active": true,
"__typename": "SKUBatchRate"
},
"Promotion": {
"id": null,
"title": null,
"type": null,
"scope": null,
"criteria": null,
"__typename": "Promotion"
},
"promotionId": null,
"distributorId": 16,
"__typename": "Line",
"inStock": "INSTOCK",
"freeSku": false,
"focusedSku": true
},
{
"id": 5105802,
"quantity": 40,
"skuId": 769,
"callId": 494281,
"skuBatchId": 733,
"amountDetails": {
"rate": 197.53,
"grossAmount": 8928.356,
"netAmount": 8928.356,
"taxAmount": 1027.156,
"taxableAmount": 7901.2,
"subTotal": 7901.2,
"billDiscount": 0,
"tradeDiscount": 0,
"discountAmount": 0,
"promotionDiscount": 0,
"topUpDiscount": 0,
"__typename": "AmountDetail"
},
"rateDetails": {
"rlp": 197.53,
"rlpWithVat": 223.2089,
"netPrice": 197.53,
"netPriceWithVat": 223.2089,
"__typename": "RateDetail"
},
"SKU": {
"id": 769,
"title": "H&S 2in1 Active Protect 180 ml x 24 [82302894]",
"__typename": "SKU"
},
"SKUBatch": {
"priceDetails": {
"rlp": 197.53,
"dlp": 186.35,
"vatPercentage": 0.13,
"mrpSrp": 250,
"mrpStatus": true,
"__typename": "SKUPrice"
},
"batchDetails": {
"batchNumber": "DEFAULT_BATCH",
"__typename": "SKUBatch"
},
"usageDate": {
"manufacture": "0000-00-00",
"expiry": "0000-00-00",
"__typename": "SKUUsage"
},
"updatedAt": "2019-11-05",
"active": true,
"__typename": "SKUBatchRate"
},
"Promotion": {
"id": null,
"title": null,
"type": null,
"scope": null,
"criteria": null,
"__typename": "Promotion"
},
"promotionId": null,
"distributorId": 16,
"__typename": "Line",
"inStock": "INSTOCK",
"freeSku": false,
"focusedSku": false
}
],
"__typename": "PromotionOrder"
}
]
}
};
const orderDetails = [];
responseBody.data.callOrders.forEach((entry) => {
entry.Lines.forEach(({ id, quantity }) => {
orderDetails.push({ id, quantity });
})
});
const requestBody = {
"operationName": null,
"variables": {
"input": {
"invoiceId": 3683663,
"orderDetails": orderDetails
},
"type": "CatalogDetail"
},
"query": "mutation ($input: DispatchInput!) {\n dispatchInvoice(input: $input) {\n id\n __typename\n }\n}\n"
};
console.log(requestBody);

Laravel: Advanced Polymorphic relationship

I am attempting to scope an answer to a User or Project via a polymorphic relationship via multiple levels but I am having some trouble getting my head around it.
It's tricky to explain, but I will show you what I have at the moment, minus the Answer model/relationship.
I have a Category and a Role model. These are in a belongsTo relationship (a role belongs to a category).
I also have a Question model, this also has a belongsTo relationship with a Role (a question belongs to a role).
I have created a roleables polymorphic relationship, allowing me to assign roles to either a User or a Project.
All of this is working as expected. I am able to return the assigned roles via my endpoint user/1/roles or project/1/roles, and in this endpoint, I am able to return the questions for that role (see example output below).
{
"data": [
{
"id": 20,
"name": "Actor",
"entity_id": 1,
"category_id": 3,
"questions": [
{
"id": 20,
"role_id": 20,
"field_type": "text",
"field_name": "Height",
"field_default_value": null,
"field_validation_rules": "required,string,max:5",
"field_options": false,
"order": 0
},
{
"id": 21,
"role_id": 20,
"field_type": "text",
"field_name": "Weight",
"field_default_value": null,
"field_validation_rules": "required,string,max:5",
"field_options": false,
"order": 1
},
{
"id": 22,
"role_id": 20,
"field_type": "select",
"field_name": "Race",
"field_default_value": null,
"field_validation_rules": "required,string,max:255",
"field_options": [
{
"id": "white",
"name": "White"
},
{
"id": "mixed",
"name": "Mixed"
}
],
"order": 2
},
{
"id": 23,
"role_id": 20,
"field_type": "select",
"field_name": "Gender",
"field_default_value": null,
"field_validation_rules": "required,string,max:255",
"field_options": [
{
"id": "male",
"name": "Male"
},
{
"id": "female",
"name": "Female"
},
{
"id": "other",
"name": "Other"
}
],
"order": 3
}
],
"created_at": {
"date": "2019-07-24 13:35:33.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2019-07-24 13:35:33.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"entity_type": "user"
},
{
"id": 23,
"name": "Singer",
"entity_id": 1,
"category_id": 3,
"questions": [
{
"id": 26,
"role_id": 23,
"field_type": "text",
"field_name": "Description",
"field_default_value": null,
"field_validation_rules": "required,string,max:255",
"field_options": false,
"order": 0
}
],
"created_at": {
"date": "2019-07-24 13:35:33.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2019-07-24 13:35:33.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"entity_type": "user"
},
{
"id": 32,
"name": "Console Operator",
"entity_id": 1,
"category_id": 5,
"questions": [
{
"id": 35,
"role_id": 32,
"field_type": "text",
"field_name": "Description",
"field_default_value": null,
"field_validation_rules": "required,string,max:255",
"field_options": false,
"order": 0
}
],
"created_at": {
"date": "2019-07-24 13:35:33.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2019-07-24 13:35:33.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"entity_type": "user"
},
{
"id": 60,
"name": "Composer",
"entity_id": 1,
"category_id": 7,
"questions": [
{
"id": 63,
"role_id": 60,
"field_type": "text",
"field_name": "Description",
"field_default_value": null,
"field_validation_rules": "required,string,max:255",
"field_options": false,
"order": 0
}
],
"created_at": {
"date": "2019-07-24 13:35:33.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2019-07-24 13:35:33.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"entity_type": "user"
}
]
}
The problem that I am trying to get my head around is Answers to the questions. Just a little background, which may help me explain this in writing:
In the front-end, I have a page in which the user can update their information, on this page they also have the ability to assign themselves some roles. When the click on a role the list of questions is displayed and they have the ability to answer them.
The same is also true for a Project. A user can create projects, and have the ability to assigned roles and answer the relevant questions.
So, I guess I will need to create a new table in the database to store the answers.
The question is how/what relationship should this new answers table have to the question, user/project in order to get all the roles, questions and any answers scoped to the entity (user/project) and it's roles?
I would love the each role in the output from my user/1/roleendpoint to look more like the following (notice the new answers key in questions):
{
"id": 60,
"name": "Composer",
"entity_id": 1,
"category_id": 7,
"questions": [
{
"id": 63,
"role_id": 60,
"field_type": "text",
"field_name": "Description",
"field_default_value": null,
"field_validation_rules": "required,string,max:255",
"field_options": false,
"order": 0,
"answers": { ... }
}
],
"created_at": {
"date": "2019-07-24 13:35:33.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2019-07-24 13:35:33.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"entity_type": "user"
}

How to filter laravel collection from given data

i have a collection data
{
"success": true,
"doctor": [
{
"id": 1,
"name": "Dr. Mayank",
"dob": "1975-01-01",
"about": "This is description",
"status": 1,
"rating": 2,
"rating_given_by": 1,
"alternative_number": "7686876876",
"profile_photo": [],
"speciality": [
{
"id": 3,
"name": "Acupuncture",
"image": null,
"dashboard_flag": 1
},
{
"id": 4,
"name": "Acupuncturist",
"image": null,
"dashboard_flag": 1
},
{
"id": 1,
"name": "Accident and emergency medicine",
"image": "http://192.168.16.21/remidify/media/174/detail.png",
"dashboard_flag": 1
}
],
"service": [
{
"id": 78,
"name": "Correction of gummy smile",
"cost": "12.00"
},
{
"id": 77,
"name": "Dental aesthetics",
"cost": "43.00"
}
],
"clinics": [
{
"id": 1,
"name": "akram",
"entity_id": 1,
"entity_type": "App\Doctor",
"contact_number": "2132132132132",
"status": 0,
"consultancy_fee": "12.00",
"available_today": "No",
"owner_name": "Dr. Mayank",
"pivot": {
"doctor_id": 1,
"clinic_id": 1
},
"address": {
"id": 1,
"address_1": "asdasdasdsa",
"address_2": "",
"locality": "downtown",
"city": "noida",
"state": "up",
"postal_code": "41561566"
},
"speciality": [],
"service": [
{
"id": 11,
"name": "Laminates",
"cost": "20.00"
},
{
"id": 12,
"name": "Dental surgery",
"cost": "300.00"
}
],
"clinic_image": [
{
"id": 7,
"model_id": 1,
"model_type": "App\Clinic",
"collection_name": "clinic_image",
"file_name": "1494863957588.566162.jpg",
"disk": "media",
"url": "http://192.168.16.21/remidify/media/7/1494863957588.566162.jpg"
}
],
"id_image": [
{
"id": 8,
"model_id": 1,
"model_type": "App\Clinic",
"collection_name": "id_image",
"file_name": "1494863966218.348877.jpg",
"disk": "media",
"url": "http://192.168.16.21/remidify/media/8/1494863966218.348877.jpg"
}
],
"location": {
"id": 1,
"latitude": 0,
"longitude": 0,
"entity_id": 1,
"entity_type": "App\Clinic",
"created_at": "2017-05-16 03:00:10",
"updated_at": "2017-05-16 03:00:10"
},
"clinic_timings": [
{
"day": "sun",
"opens_at": "09:28:00",
"closes_at": "21:28:00"
}
]
}
],
"education": [
{
"id": 19,
"degree": "MBBS",
"university": "Univercity",
"year": "2017",
"entity_id": 1,
"entity_type": "App\Doctor",
"created_at": "2017-05-16 05:44:11",
"updated_at": "2017-05-16 05:44:11",
"location": "Delhi"
}
],
"experience": [
{
"id": 19,
"hospital": "Hospital name",
"post": "pta ni hai",
"from": "1970-01-01",
"to": "0000-00-00",
"entity_id": 1,
"entity_type": "App\Doctor",
"created_at": "2017-05-16 05:44:12",
"updated_at": "2017-05-16 05:44:12",
"location": "Locations12",
"is_currently_working": 1
}
],
"registration": {
"id": 1,
"registration_number": "Reg # 2324324",
"registration_year": 1975,
"registration_council": "Council",
"experience": null,
"doctor_id": 1,
"created_at": "2017-05-16 02:56:37",
"updated_at": "2017-05-16 02:56:37",
"adhaar_number": "232131231232",
"id_proof": [
{
"id": 2,
"model_id": 1,
"model_type": "App\DoctorRegistration",
"collection_name": "id_proof",
"file_name": "1494863680447.329102.jpg",
"disk": "media",
"url": "http://192.168.16.21/remidify/media/2/1494863680447.329102.jpg"
}
],
"registration_proof": [
{
"id": 3,
"model_id": 1,
"model_type": "App\DoctorRegistration",
"collection_name": "registration_proof",
"file_name": "1494863687436.266846.jpg",
"disk": "media",
"url": "http://192.168.16.21/remidify/media/3/1494863687436.266846.jpg"
}
],
"qualification_proof": [
{
"id": 4,
"model_id": 1,
"model_type": "App\DoctorRegistration",
"collection_name": "qualification_proof",
"file_name": "1494863695576.803955.jpg",
"disk": "media",
"url": "http://192.168.16.21/remidify/media/4/1494863695576.803955.jpg"
}
]
},
"preference": {
"availability": 1,
"appointment_confirmation_method": "manual",
"average_time": 7,
"holiday_from": null,
"holiday_till": null,
"patients_per_hour": null,
"preferred_appointment_type": "timeslot",
"appointment_frequency": null,
"preferred_payment_method": [
{
"payment_method": "cash"
},
{
"payment_method": "online"
}
]
},
"user": null,
"doctor_clinic": [
{
"doctor_id": 1,
"clinic_id": 1,
"consultancy_fee": "12.00",
"deleted_at": null,
"workdays": [
{
"day": "sun",
"available": 1,
"workhours": [
{
"from": "09:28:00",
"to": "21:28:00"
}
]
}
],
"service": []
}
]
}
]
}
Now how can i find the doctors whose "about or specialty name" matches with some given search string.
Thanks in advance.
Try using dd() helper and use like this below
$youcollectionvariables = { "success": true, "doctor": [ { "id": 1, "name": "Dr. Mayank", "dob": "1975-01-01"................. }
dd($youcollectionvariables)
you will see a formatted data and can find what you need clearly.
Hope that helps.

Resources