I've simplified the scenario for brevity.
The initial data:
| EngineerId | FirstName | LastName | BirthdateOn | CupsOfCoffee | HoursOfSleep |
| ---------- | --------- | -------- | ----------- | ------------ | ------------ |
| 1 | John | Doe | 1990-01-01 | 5 | 8 |
| 2 | James | Bond | 1990-01-01 | 1 | 6 |
| 3 | Leeroy | Jenkins | 2000-06-20 | 16 | 10 |
| 4 | Jane | Doe | 2000-06-20 | 8 | 2 |
| 5 | Lorem | Ipsum | 2010-12-25 | 4 | 5 |
db.engineers.insertMany([
{ FirstName: 'John', LastName: 'Doe', BirthdateOn: ISODate('1990-01-01'), CupsOfCoffee: 5, HoursOfSleep: 8 },
{ FirstName: 'James', LastName: 'Bond', BirthdateOn: ISODate('1990-01-01'), CupsOfCoffee: 1, HoursOfSleep: 6 },
{ FirstName: 'Leeroy', LastName: 'Jenkins', BirthdateOn: ISODate('2000-06-20'), CupsOfCoffee: 16, HoursOfSleep: 10 },
{ FirstName: 'Jane', LastName: 'Doe', BirthdateOn: ISODate('2000-06-20'), CupsOfCoffee: 8, HoursOfSleep: 2 },
{ FirstName: 'Lorem', LastName: 'Ipsum', BirthdateOn: ISODate('2010-12-25'), CupsOfCoffee: 4, HoursOfSleep: 5 }
])
We want to see:
the cups of coffee consumed by the engineer
the row number sorted descending by cups of coffee
the count of engineers with the same birthdate
the sum of coffees consumed by engineers with a common birthdate
the average hours of sleep for engineers with a common birthdate
The SQL query is:
SELECT
FirstName,
LastName,
BirthdateOn,
CupsOfCoffee,
ROW_NUMBER() OVER (PARTITION BY BirthdateOn ORDER BY CupsOfCoffee DESC) AS 'Row Number',
COUNT(EngineerId) OVER (PARTITION BY BirthdateOn) AS TotalEngineers,
SUM(CupsOfCoffee) OVER (PARTITION BY BirthdateOn) AS TotalCupsOfCoffee,
AVG(HoursOfSleep) OVER (PARTITION BY BirthdateOn) AS AvgHoursOfSleep
FROM Engineers
Resulting in the following:
| FirstName | LastName | BirthdateOn | Row Number | CupsOfCoffee | TotalEngineers | TotalCupsOfCoffee | AvgHoursOfSleep |
| --------- | -------- | ----------- | ---------- | ------------ | -------------- | ----------------- | --------------- |
| John | Doe | 1990-01-01 | 1 | 5 | 2 | 6 | 7 |
| James | Bond | 1990-01-01 | 2 | 1 | 2 | 6 | 7 |
| Leeroy | Jenkins | 2000-06-20 | 1 | 16 | 2 | 24 | 6 |
| Jane | Doe | 2000-06-20 | 2 | 8 | 2 | 24 | 6 |
| Lorem | Ipsum | 2010-12-25 | 1 | 4 | 1 | 4 | 5 |
I've done quite a bit of reading on the MongoDB Aggregate Pipeline, but haven't been able to find a good solution yet. I understand that this is not SQL and the solution might not yield results in this exact format (although that would be amazing). One thing I've considered is combining the results of an aggregate and the collection, but that's either not possible or I've been searching with the wrong terms. $merge looked promising, but AFAIU it would modify the original collection and that's no good.
I've gotten as far as the following, but the results do not include the "row number", cups consumed by specific engineers, or IDs and names of the engineers.
db.engineers.aggregate([
{
$group: {
_id: '$BirthdateOn',
TotalEngineers: {
$count: { }
},
TotalCupsOfCoffee: {
$sum: '$CupsOfCoffee'
},
AvgHoursOfSleep: {
$avg: '$HoursOfSleep'
}
}
}
])
My thought with combining would be to find all of the engineers and then run the aggregate and "join" it to the engineers by BirthdateOn.
Thank you for any help! It's much appreciated.
You did a good start. To get the input data you can use with the $push operator.
Would be this:
db.engineers.aggregate([
{
$group: {
_id: "$BirthdateOn",
TotalEngineers: { $count: {} },
TotalCupsOfCoffee: { $sum: "$CupsOfCoffee" },
AvgHoursOfSleep: { $avg: "$HoursOfSleep" },
data: { $push: "$$ROOT" }
}
}
])
Regarding proper output try:
db.engineers.aggregate([
{
$group: {
_id: "$BirthdateOn",
TotalEngineers: { $count: {} },
TotalCupsOfCoffee: { $sum: "$CupsOfCoffee" },
AvgHoursOfSleep: { $avg: "$HoursOfSleep" },
data: { $push: "$$ROOT" }
}
},
{ $unwind: "$data" },
{ $replaceWith: { $mergeObjects: ["$$ROOT", "$data"] } }
])
Often it is pointless to run $group and afterwards $unwind which basically revert the former operation.
MongoDB version 5.0 introduced the $setWindowFields stage, which is quite similar to the SQL Windowing function:
I think it would be this one:
db.engineers.aggregate([
{
$setWindowFields: {
partitionBy: "$BirthdateOn",
sortBy: { CupsOfCoffee: 1 },
output: {
TotalEngineers: { $count: {} },
TotalCupsOfCoffee: { $sum: "$CupsOfCoffee" },
AvgHoursOfSleep: { $avg: "$HoursOfSleep" },
"Row Number": { $documentNumber: {} }
}
}
}
])
I am using Laravel 8 and I want to display list of event by joining tables that have many to many relationship.
Here is how my tables look:
Users Table
| id | firstname | status |
|----|------------|--------|
| 1 | Amy | 0 |
| 2 | 2 amy | 0 |
| 3 | 3 amy | 1 |
| 4 | 4 amy | 0 |
| 5 | 5 amy | 1 |
| 6 | 6 amy | 1 |
Here is my pivot table
events_users Table
| id | event_id | user_id |
|----|------------|---------|
| 1 | 123 | 1 |
| 1 | 123 | 2 |
| 1 | 123 | 3 |
| 1 | 123 | 4 |
Here is my events table
events Table
| id | eventid | title |
|----|------------|---------|
| 1 | 123 | title |
| 1 | 124 | title 1 |
| 1 | 125 | title 2 |
| 1 | 126 | title 3 |
Here is my model fetching the results:
$events = DB::table('events')
->join('events_users', 'events.eventid', '=', 'events_users.event_id')
->join('users', 'users.id', '=', 'events_users.user_id')
->when($sortBy, function ($query, $sortBy) {
return $query->orderBy($sortBy);
}, function ($query) {
return $query->orderBy('events.created_at', 'desc');
})
->when($search_query, function ($query, $search_query) {
return $query->where('title', 'like', '%'. $search_query . '%');
})
->select(
'title', 'eventuid', 'description', 'start_date',
'end_date', 'start_time', 'end_time', 'status',
'venue', 'address_line_1', 'address_line_2', 'address_line_3',
'postcode', 'city', 'city_id', 'country', 'image',
'users.firstname', 'users.lastname', 'users.avatar'
)
->simplePaginate(15);
This results in duplicate entries:
Current Result:
{
"current_page": 1,
"data": [
{
"title": "Who in the newspapers, at the mushroom (she had.",
"eventuid": "be785bac-70d5-379f-a6f8-b35e66c8e494",
"description": "I'd been the whiting,' said Alice, 'and why it is I hate cats and dogs.' It was opened by another footman in livery came running out of sight before the trial's over!' thought Alice. 'I'm glad they.",
"start_date": "2000-11-17",
"end_date": "1988-02-24",
"start_time": "1972",
"end_time": "2062",
"status": 1,
"venue": "4379",
"address_line_1": "Kuhn Expressway",
"address_line_2": "2295 Kerluke Drive Suite 335",
"address_line_3": "Fredtown",
"postcode": "57094",
"city": "New Cassidyburgh",
"city_id": 530,
"country": "Cocos (Keeling) Islands",
"image": "https://via.placeholder.com/1280x720.png/00dd99?text=repellat",
"firstname": "Marielle",
"lastname": "Tremblay",
"avatar": "https://via.placeholder.com/640x480.png/002277?text=eum"
},
{
"title": "Who in the newspapers, at the mushroom (she had.",
"eventuid": "be785bac-70d5-379f-a6f8-b35e66c8e494",
"description": "I'd been the whiting,' said Alice, 'and why it is I hate cats and dogs.' It was opened by another footman in livery came running out of sight before the trial's over!' thought Alice. 'I'm glad they.",
"start_date": "2000-11-17",
"end_date": "1988-02-24",
"start_time": "1972",
"end_time": "2062",
"status": 1,
"venue": "4379",
"address_line_1": "Kuhn Expressway",
"address_line_2": "2295 Kerluke Drive Suite 335",
"address_line_3": "Fredtown",
"postcode": "57094",
"city": "New Cassidyburgh",
"city_id": 530,
"country": "Cocos (Keeling) Islands",
"image": "https://via.placeholder.com/1280x720.png/00dd99?text=repellat",
"firstname": "Floyd",
"lastname": "Waelchi",
"avatar": "https://via.placeholder.com/640x480.png/0033cc?text=inventore"
},
...
]
}
What I want to retrieve is something like this:
Expecting:
{
"current_page": 1,
"data": [
{
"title": "Who in the newspapers, at the mushroom (she had.",
"eventuid": "be785bac-70d5-379f-a6f8-b35e66c8e494",
"description": "I'd been the whiting,' said Alice, 'and why it is I hate cats and dogs.' It was opened by another footman in livery came running out of sight before the trial's over!' thought Alice. 'I'm glad they.",
"start_date": "2000-11-17",
"end_date": "1988-02-24",
"start_time": "1972",
"end_time": "2062",
"status": 1,
"venue": "4379",
"address_line_1": "Kuhn Expressway",
"address_line_2": "2295 Kerluke Drive Suite 335",
"address_line_3": "Fredtown",
"postcode": "57094",
"city": "New Cassidyburgh",
"city_id": 530,
"country": "Cocos (Keeling) Islands",
"image": "https://via.placeholder.com/1280x720.png/00dd99?text=repellat",
"users" : {[
{
"firstname": "Marielle",
"lastname": "Tremblay",
"avatar": "https://via.placeholder.com/640x480.png/002277?text=eum"
},
{
"firstname": "Amy",
"lastname": "Bond",
"avatar": "https://via.placeholder.com/640x480.png/005277?text=eum"
}
]}
},
...
]
}
Could somebody help me to create an SQL statement to flatten JSON data in Snowflake Table1 table, in one JSON_DATA column that has an array?
JSON_DATA:
{
"scopes": [
{
"scope_name": "IN SCOPE",
"company_code": "01",
"lob_codes": ["01","07","09"]
},
{
"scope_name": "IN SCOPE",
"company_code": "02",
"lob_codes": ["07","13","20"]
},
{
"scope_name": "OUT OF SCOPE",
"company_code": "01",
"lob_codes": ["30","35","40"]
},
{
"scope_name": "OUT OF SCOPE",
"company_code": "02",
"lob_codes": ["02","03","05"]
}
]
}
I need to flatten it to:
|scope_name | company_code| lob_codes|
|--------------|----------------|------------|
|IN SCOPE | 1 | 01 |
|IN SCOPE | 1 | 07 |
|IN SCOPE | 1 | 09 |
|IN SCOPE | 2 | 07 |
|IN SCOPE | 2 | 13 |
|IN SCOPE | 2 | 20 |
|OUT OF SCOPE | 1 | 30 |
|OUT OF SCOPE | 1 | 35 |
|OUT OF SCOPE | 1 | 40 |
|OUT OF SCOPE | 2 | 02 |
|OUT OF SCOPE | 2 | 03 |
|OUT OF SCOPE | 2 | 05 |
I believe you are looking for something along these lines. Focus on the SELECT statement at the end. The top piece is just emulating the data you provided.
WITH x AS (
SELECT parse_json('{
"scopes": [
{
"scope_name": "IN SCOPE",
"company_code": "01",
"lob_codes": ["01","07","09"]
},
{
"scope_name": "IN SCOPE",
"company_code": "02",
"lob_codes": ["07","13","20"]
},
{
"scope_name": "OUT OF SCOPE",
"company_code": "01",
"lob_codes": ["30","35","40"]
},
{
"scope_name": "OUT OF SCOPE",
"company_code": "02",
"lob_codes": ["02","03","05"]
}
]
}') as json_data
)
SELECT
y.value:company_code::varchar as company_code,
y.value:scope_name::varchar as scope_name,
z.value::varchar as lob_codes
FROM x,
LATERAL FLATTEN (input=>x.json_data:scopes) y,
LATERAL FLATTEN (input=>y.value:lob_codes) z;
Hi I am new to react and I am trying to implement a responsive bar using the library "NIVO". I am currently following the codes shown in the following link. I have directly copied and pasted the codes from there to see if it works the codes I used can be found below
graphBar.js (My implementation of Responsive Bar)
import ResponsiveBar from '../node_modules/nivo/lib/components/charts/bar/ResponsiveBar'
import ResponsiveHeatMap from '../node_modules/nivo/lib/components/charts/heatmap/ResponsiveHeatMap'
import React from 'react';
// make sure parent container have a defined height when using
// responsive component, otherwise height will be 0 and
// no chart will be rendered.
// website examples showcase many properties,
// you'll often use just a few of them.
const MyResponsiveBar = (props) => {
const data = [
{
"country": "AD",
"hot dog": 87,
"hot dogColor": "hsl(260, 70%, 50%)",
"burger": 142,
"burgerColor": "hsl(84, 70%, 50%)",
"sandwich": 191,
"sandwichColor": "hsl(20, 70%, 50%)",
"kebab": 193,
"kebabColor": "hsl(357, 70%, 50%)",
"fries": 9,
"friesColor": "hsl(283, 70%, 50%)",
"donut": 78,
"donutColor": "hsl(75, 70%, 50%)"
},
{
"country": "AE",
"hot dog": 111,
"hot dogColor": "hsl(359, 70%, 50%)",
"burger": 78,
"burgerColor": "hsl(182, 70%, 50%)",
"sandwich": 193,
"sandwichColor": "hsl(65, 70%, 50%)",
"kebab": 32,
"kebabColor": "hsl(123, 70%, 50%)",
"fries": 57,
"friesColor": "hsl(232, 70%, 50%)",
"donut": 176,
"donutColor": "hsl(118, 70%, 50%)"
},
{
"country": "AF",
"hot dog": 105,
"hot dogColor": "hsl(348, 70%, 50%)",
"burger": 87,
"burgerColor": "hsl(103, 70%, 50%)",
"sandwich": 140,
"sandwichColor": "hsl(327, 70%, 50%)",
"kebab": 49,
"kebabColor": "hsl(347, 70%, 50%)",
"fries": 154,
"friesColor": "hsl(332, 70%, 50%)",
"donut": 168,
"donutColor": "hsl(158, 70%, 50%)"
},
{
"country": "AG",
"hot dog": 115,
"hot dogColor": "hsl(11, 70%, 50%)",
"burger": 68,
"burgerColor": "hsl(33, 70%, 50%)",
"sandwich": 73,
"sandwichColor": "hsl(209, 70%, 50%)",
"kebab": 78,
"kebabColor": "hsl(247, 70%, 50%)",
"fries": 157,
"friesColor": "hsl(141, 70%, 50%)",
"donut": 86,
"donutColor": "hsl(195, 70%, 50%)"
},
{
"country": "AI",
"hot dog": 91,
"hot dogColor": "hsl(88, 70%, 50%)",
"burger": 69,
"burgerColor": "hsl(233, 70%, 50%)",
"sandwich": 158,
"sandwichColor": "hsl(106, 70%, 50%)",
"kebab": 31,
"kebabColor": "hsl(184, 70%, 50%)",
"fries": 189,
"friesColor": "hsl(98, 70%, 50%)",
"donut": 199,
"donutColor": "hsl(195, 70%, 50%)"
},
{
"country": "AL",
"hot dog": 91,
"hot dogColor": "hsl(298, 70%, 50%)",
"burger": 165,
"burgerColor": "hsl(68, 70%, 50%)",
"sandwich": 23,
"sandwichColor": "hsl(299, 70%, 50%)",
"kebab": 135,
"kebabColor": "hsl(159, 70%, 50%)",
"fries": 187,
"friesColor": "hsl(200, 70%, 50%)",
"donut": 138,
"donutColor": "hsl(38, 70%, 50%)"
},
{
"country": "AM",
"hot dog": 0,
"hot dogColor": "hsl(126, 70%, 50%)",
"burger": 105,
"burgerColor": "hsl(295, 70%, 50%)",
"sandwich": 24,
"sandwichColor": "hsl(120, 70%, 50%)",
"kebab": 158,
"kebabColor": "hsl(212, 70%, 50%)",
"fries": 42,
"friesColor": "hsl(171, 70%, 50%)",
"donut": 7,
"donutColor": "hsl(99, 70%, 50%)"
}
]
return (
<ResponsiveBar
data={data}
keys={[ 'hot dog', 'burger', 'sandwich', 'kebab', 'fries', 'donut' ]}
indexBy="country"
margin={{ top: 50, right: 130, bottom: 50, left: 60 }}
padding={0.3}
colors={{ scheme: 'nivo' }}
defs={[
{
id: 'dots',
type: 'patternDots',
background: 'inherit',
color: '#38bcb2',
size: 4,
padding: 1,
stagger: true
},
{
id: 'lines',
type: 'patternLines',
background: 'inherit',
color: '#eed312',
rotation: -45,
lineWidth: 6,
spacing: 10
}
]}
fill={[
{
match: {
id: 'fries'
},
id: 'dots'
},
{
match: {
id: 'sandwich'
},
id: 'lines'
}
]}
borderColor={{ from: 'color', modifiers: [ [ 'darker', 1.6 ] ] }}
axisTop={null}
axisRight={null}
axisBottom={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
legend: 'country',
legendPosition: 'middle',
legendOffset: 32
}}
axisLeft={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
legend: 'food',
legendPosition: 'middle',
legendOffset: -40
}}
labelSkipWidth={12}
labelSkipHeight={12}
labelTextColor={{ from: 'color', modifiers: [ [ 'darker', 1.6 ] ] }}
legends={[
{
dataFrom: 'keys',
anchor: 'bottom-right',
direction: 'column',
justify: false,
translateX: 120,
translateY: 0,
itemsSpacing: 2,
itemWidth: 100,
itemHeight: 20,
itemDirection: 'left-to-right',
itemOpacity: 0.85,
symbolSize: 20,
effects: [
{
on: 'hover',
style: {
itemOpacity: 1
}
}
]
}
]}
animate={true}
motionStiffness={90}
motionDamping={15}
/>
)
}
export default MyResponsiveBar;
index.js (My implementation of rendering the Bar)
import React, { Fragment } from "react";
import ReactDOM from "react-dom";
import MyResponsiveBar from './graphBar'
const App = () => (
<div className="App">
<div style={{height:500}}>
<MyResponsiveBar />
</div>
</div>
);
ReactDOM.render(<App />, document.getElementById("root"));
As stated in the title running this code will result in an error stating TypeError: instruction.match is not a function
Webpage Error Report
TypeError: instruction.match is not a function
getInheritedColorGenerator
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/nivo/lib/lib/colors/inherit.js:78
75 | }
76 |
77 | if (instruction === 'inherit') return inheritGenerator;
> 78 | var inheritMatches = instruction.match(/inherit:(darker|brighter)\(([0-9.]+)\)/);
| ^ 79 |
80 | if (inheritMatches) {
81 | var method = inheritMatches[1];
View compiled
(anonymous function)
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/nivo/lib/components/charts/bar/enhance.js:53
50 | }), (0, _withPropsOnChange2.default)(['labelTextColor'], function (_ref2) {
51 | var labelTextColor = _ref2.labelTextColor;
52 | return {
> 53 | getLabelTextColor: (0, _colors.getInheritedColorGenerator)(labelTextColor, 'axis.textColor')
| ^ 54 | };
55 | }), (0, _withPropsOnChange2.default)(['labelLinkColor'], function (_ref3) {
56 | var labelLinkColor = _ref3.labelLinkColor;
View compiled
new WithPropsOnChange
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/recompose/withPropsOnChange.js:96
93 | args[_key] = arguments[_key];
94 | }
95 |
> 96 | return _ret = (_temp = (_this = _possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.computedProps = propsMapper(_this.props), _temp), _possibleConstructorReturn(_this, _ret);
| ^ 97 | }
98 |
99 | WithPropsOnChange.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
View compiled
constructClassInstance
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:11786
11783 | new ctor(props, context); // eslint-disable-line no-new
11784 | }
11785 | }
> 11786 | var instance = new ctor(props, context);
| ^ 11787 | var state = workInProgress.memoizedState = instance.state !== null && instance.state !== undefined ? instance.state : null;
11788 | adoptClassInstance(workInProgress, instance);
11789 | {
View compiled
updateClassComponent
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:15264
15261 | } // In the initial pass we might need to construct the instance.
15262 |
15263 |
> 15264 | constructClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
| ^ 15265 | mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
15266 | shouldUpdate = true;
15267 | } else if (current$$1 === null) {
View compiled
beginWork
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:16262
16259 |
16260 | var _resolvedProps = workInProgress.elementType === _Component2 ? _unresolvedProps : resolveDefaultProps(_Component2, _unresolvedProps);
16261 |
> 16262 | return updateClassComponent(current$$1, workInProgress, _Component2, _resolvedProps, renderExpirationTime);
| ^ 16263 | }
16264 |
16265 | case HostRoot:
View compiled
performUnitOfWork
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:20279
20276 | startProfilerTimer(workInProgress);
20277 | }
20278 |
> 20279 | next = beginWork(current$$1, workInProgress, nextRenderExpirationTime);
| ^ 20280 | workInProgress.memoizedProps = workInProgress.pendingProps;
20281 |
20282 | if (workInProgress.mode & ProfileMode) {
View compiled
workLoop
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:20320
20317 | if (!isYieldy) {
20318 | // Flush work without yielding
20319 | while (nextUnitOfWork !== null) {
> 20320 | nextUnitOfWork = performUnitOfWork(nextUnitOfWork);
| ^ 20321 | }
20322 | } else {
20323 | // Flush asynchronous work until there's a higher priority event
View compiled
HTMLUnknownElement.callCallback
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:147
144 | window.event = windowEvent;
145 | }
146 |
> 147 | func.apply(context, funcArgs);
| ^ 148 | didError = false;
149 | } // Create a global error event handler. We use this to capture the value
150 | // that was thrown. It's possible that this error handler will fire more
View compiled
invokeGuardedCallbackDev
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:196
193 | // errors, it will trigger our global error handler.
194 |
195 | evt.initEvent(evtType, false, false);
> 196 | fakeNode.dispatchEvent(evt);
| ^ 197 |
198 | if (windowEventDescriptor) {
199 | Object.defineProperty(window, 'event', windowEventDescriptor);
View compiled
invokeGuardedCallback
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:250
247 | function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
248 | hasError = false;
249 | caughtError = null;
> 250 | invokeGuardedCallbackImpl$1.apply(reporter, arguments);
| ^ 251 | }
252 | /**
253 | * Same as invokeGuardedCallback, but instead of returning an error, it stores
View compiled
replayUnitOfWork
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:19503
19500 |
19501 | isReplayingFailedUnitOfWork = true;
19502 | originalReplayError = thrownValue;
> 19503 | invokeGuardedCallback(null, workLoop, null, isYieldy);
| ^ 19504 | isReplayingFailedUnitOfWork = false;
19505 | originalReplayError = null;
19506 |
View compiled
renderRoot
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:20433
20430 | if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
20431 | if (mayReplay) {
20432 | var failedUnitOfWork = nextUnitOfWork;
> 20433 | replayUnitOfWork(failedUnitOfWork, thrownValue, isYieldy);
| ^ 20434 | }
20435 | } // TODO: we already know this isn't true in some cases.
20436 | // At least this shows a nicer error message until we figure out the cause.
View compiled
performWorkOnRoot
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:21357
21354 | cancelTimeout(timeoutHandle);
21355 | }
21356 |
> 21357 | renderRoot(root, isYieldy);
| ^ 21358 | finishedWork = root.finishedWork;
21359 |
21360 | if (finishedWork !== null) {
View compiled
performWork
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:21267
21264 | }
21265 | } else {
21266 | while (nextFlushedRoot !== null && nextFlushedExpirationTime !== NoWork && minExpirationTime <= nextFlushedExpirationTime) {
> 21267 | performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, false);
| ^ 21268 | findHighestPriorityRoot();
21269 | }
21270 | } // We're done flushing work. Either we ran out of time in this callback,
View compiled
performSyncWork
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:21241
21238 | }
21239 |
21240 | function performSyncWork() {
> 21241 | performWork(Sync, false);
| ^ 21242 | }
21243 |
21244 | function performWork(minExpirationTime, isYieldy) {
View compiled
requestWork
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:21096
21093 |
21094 |
21095 | if (expirationTime === Sync) {
> 21096 | performSyncWork();
| ^ 21097 | } else {
21098 | scheduleCallbackWithExpirationTime(root, expirationTime);
21099 | }
View compiled
scheduleWork
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:20909
20906 | !isWorking || isCommitting$1 || // ...unless this is a different root than the one we're rendering.
20907 | nextRoot !== root) {
20908 | var rootExpirationTime = root.expirationTime;
> 20909 | requestWork(root, rootExpirationTime);
| ^ 20910 | }
20911 |
20912 | if (nestedUpdateCount > NESTED_UPDATE_LIMIT) {
View compiled
scheduleRootUpdate
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:21604
21601 |
21602 | flushPassiveEffects();
21603 | enqueueUpdate(current$$1, update);
> 21604 | scheduleWork(current$$1, expirationTime);
| ^ 21605 | return expirationTime;
21606 | }
21607 |
View compiled
updateContainerAtExpirationTime
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:21630
21627 | container.pendingContext = context;
21628 | }
21629 |
> 21630 | return scheduleRootUpdate(current$$1, element, expirationTime, callback);
| ^ 21631 | }
21632 |
21633 | function findHostInstance(component) {
View compiled
updateContainer
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:21698
21695 | var current$$1 = container.current;
21696 | var currentTime = requestCurrentTime();
21697 | var expirationTime = computeExpirationForFiber(currentTime, current$$1);
> 21698 | return updateContainerAtExpirationTime(element, container, parentComponent, expirationTime, callback);
| ^ 21699 | }
21700 |
21701 | function getPublicRootInstance(container) {
View compiled
ReactRoot.push../node_modules/react-dom/cjs/react-dom.development.js.ReactRoot.render
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:22011
22008 | work.then(callback);
22009 | }
22010 |
> 22011 | updateContainer(children, root, null, work._onCommit);
| ^ 22012 | return work;
22013 | };
22014 |
View compiled
(anonymous function)
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:22163
22160 | if (parentComponent != null) {
22161 | root.legacy_renderSubtreeIntoContainer(parentComponent, children, callback);
22162 | } else {
> 22163 | root.render(children, callback);
| ^ 22164 | }
22165 | });
22166 | } else {
View compiled
unbatchedUpdates
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:21486
21483 | }
21484 | }
21485 |
> 21486 | return fn(a);
| ^ 21487 | } // TODO: Batching should be implemented at the renderer level, not within
21488 | // the reconciler.
21489 |
View compiled
legacyRenderSubtreeIntoContainer
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:22159
22156 | } // Initial mount should not be batched.
22157 |
22158 |
> 22159 | unbatchedUpdates(function () {
| ^ 22160 | if (parentComponent != null) {
22161 | root.legacy_renderSubtreeIntoContainer(parentComponent, children, callback);
22162 | } else {
View compiled
render
C:/Users/admin/Desktop/ReactCollection/songs/node_modules/react-dom/cjs/react-dom.development.js:22234
22231 | {
22232 | !!container._reactHasBeenPassedToCreateRootDEV ? warningWithoutStack$1(false, 'You are calling ReactDOM.render() on a container that was previously ' + 'passed to ReactDOM.%s(). This is not supported. ' + 'Did you mean to call root.render(element)?', enableStableConcurrentModeAPIs ? 'createRoot' : 'unstable_createRoot') : void 0;
22233 | }
> 22234 | return legacyRenderSubtreeIntoContainer(null, element, container, false, callback);
| ^ 22235 | },
22236 | unstable_renderSubtreeIntoContainer: function (parentComponent, element, containerNode, callback) {
22237 | !isValidContainer(containerNode) ? invariant(false, 'Target container is not a DOM element.') : void 0;
View compiled
Module../src/index.js
C:/Users/admin/Desktop/ReactCollection/songs/src/index.js:12
9 | </div>
10 | </div>
11 | );
> 12 | ReactDOM.render(<App />, document.getElementById("root"));
13 | // import React, { Fragment } from "react";
14 | // import ReactDOM from "react-dom";
15 | // import { line, area } from "d3-shape";
View compiled
__webpack_require__
C:/Users/admin/Desktop/ReactCollection/songs/webpack/bootstrap:781
778 | };
779 |
780 | // Execute the module function
> 781 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^ 782 |
783 | // Flag the module as loaded
784 | module.l = true;
View compiled
fn
C:/Users/admin/Desktop/ReactCollection/songs/webpack/bootstrap:149
146 | );
147 | hotCurrentParents = [];
148 | }
> 149 | return __webpack_require__(request);
| ^ 150 | };
151 | var ObjectFactory = function ObjectFactory(name) {
152 | return {
View compiled
0
http://localhost:3000/static/js/main.chunk.js:392:18
__webpack_require__
C:/Users/admin/Desktop/ReactCollection/songs/webpack/bootstrap:781
778 | };
779 |
780 | // Execute the module function
> 781 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^ 782 |
783 | // Flag the module as loaded
784 | module.l = true;
View compiled
checkDeferredModules
C:/Users/admin/Desktop/ReactCollection/songs/webpack/bootstrap:45
42 | }
43 | if(fulfilled) {
44 | deferredModules.splice(i--, 1);
> 45 | result = __webpack_require__(__webpack_require__.s = deferredModule[0]);
| ^ 46 | }
47 | }
48 | return result;
View compiled
Array.webpackJsonpCallback [as push]
C:/Users/admin/Desktop/ReactCollection/songs/webpack/bootstrap:32
29 | deferredModules.push.apply(deferredModules, executeModules || []);
30 |
31 | // run deferred modules when all chunks ready
> 32 | return checkDeferredModules();
| ^ 33 | };
34 | function checkDeferredModules() {
35 | var result;
Any tips or advise would be greatly appreciated.
Issue was found the syntax used labelTextColor={{ from: 'color', modifiers: [ [ 'darker', 1.6 ] ] }} is not a valid syntax. Hence variables such as labelTextColor or borderColor requires a color code assigned to it.
I have a multidimensional JSON array, I am accessing the JSON array in SQL Server and using 'OPENJSON' to convert JSON data to SQL. I am currently facing problem in fetching the data from multidimensional array
Declare #Json nvarchar(max)
Set #Json= '[{
"id": 0,
"healthandSafety": "true",
"estimationCost": "7878",
"comments": "\"Comments\"",
"image": [{
"imageData": "1"
}, {
"imageData": "2"
}, {
"imageData": "3"
}, {
"imageData": "4"
}, {
"imageData": "5"
}]
}, {
"id": 1,
"healthandSafety": "false",
"estimationCost": "90",
"comments": "\"89089\"",
"image": [{
"imageData": "6"
}, {
"imageData": "7"
}, {
"imageData": "8"
}, {
"imageData": "9"
}, {
"imageData": "10"
}, {
"imageData": "11"
}]
}]'
Select ImageJsonFile from OPENJSON (#Json) with (ImageJsonFile nvarchar(max) '$.image[0].imageData')
When I tried the above code I obtained the following output:
ImageJsonFile
1
6
The output what I am expecting :
ImageJsonFile
1
2
3
4
5
You need to define query path:
Select * from OPENJSON (#Json,'$[0].image') with (ImageJsonFile nvarchar(max) '$.imageData')
You've got an answer already, so this is just to add some more details:
The following will bring back all data from your multi dimensional array, not just one array index you'd have to specify explictly.
DECLARE #Json NVARCHAR(MAX)=
N'[{
"id": 0,
"healthandSafety": "true",
"estimationCost": "7878",
"comments": "\"Comments\"",
"image": [{
"imageData": "1"
}, {
"imageData": "2"
}, {
"imageData": "3"
}, {
"imageData": "4"
}, {
"imageData": "5"
}]
}, {
"id": 1,
"healthandSafety": "false",
"estimationCost": "90",
"comments": "\"89089\"",
"image": [{
"imageData": "6"
}, {
"imageData": "7"
}, {
"imageData": "8"
}, {
"imageData": "9"
}, {
"imageData": "10"
}, {
"imageData": "11"
}]
}]';
--The query
SELECT A.id
,A.healthandSafety
,A.estimationCost
,A.comments
,B.imageData
FROM OPENJSON(#Json)
WITH(id INT
,healthandSafety BIT
,estimationCost INT
,comments NVARCHAR(1000)
,[image] NVARCHAR(MAX) AS JSON ) A
CROSS APPLY OPENJSON(A.[image])
WITH(imageData INT) B;
The result
+----+-----------------+----------------+----------+-----------+
| id | healthandSafety | estimationCost | comments | imageData |
+----+-----------------+----------------+----------+-----------+
| 0 | 1 | 7878 | Comments | 1 |
+----+-----------------+----------------+----------+-----------+
| 0 | 1 | 7878 | Comments | 2 |
+----+-----------------+----------------+----------+-----------+
| 0 | 1 | 7878 | Comments | 3 |
+----+-----------------+----------------+----------+-----------+
| 0 | 1 | 7878 | Comments | 4 |
+----+-----------------+----------------+----------+-----------+
| 0 | 1 | 7878 | Comments | 5 |
+----+-----------------+----------------+----------+-----------+
| 1 | 0 | 90 | 89089 | 6 |
+----+-----------------+----------------+----------+-----------+
| 1 | 0 | 90 | 89089 | 7 |
+----+-----------------+----------------+----------+-----------+
| 1 | 0 | 90 | 89089 | 8 |
+----+-----------------+----------------+----------+-----------+
| 1 | 0 | 90 | 89089 | 9 |
+----+-----------------+----------------+----------+-----------+
| 1 | 0 | 90 | 89089 | 10 |
+----+-----------------+----------------+----------+-----------+
| 1 | 0 | 90 | 89089 | 11 |
+----+-----------------+----------------+----------+-----------+
The idea in short:
We use the first OPENJSON to get the elements of the first level. The WITH clause will name all elements and return the [image] with NVARCHAR(MAX) AS JSON. This allows to use another OPENJSON to read the numbers from imageData, your nested dimension, while the id-column is the grouping key.