produce JSON files based on the Row combinations in SPARK-SQL
![Multi tool use Multi tool use](http://sgv.ssvwv.com/sg/ssvwvcomimagb.png)
Multi tool use
I need to create multiple JSON files based on the ROW combinations.
e.g. In below table there are 4 rows, so I need to produce 3 JSON files.
I have provided a sample table below to be taken as source and sample JSON as well which we need to produce.
In each JSON file, there should be data related to calendaryear|channel|division|gender|category
If combination of calendaryear|channel|division|gender|category
is repeated, we need to club those rows together in a single JSON file.
If the value is not present for some week it needs to be filled with zero as given in JSON example
calendaryear|channel|division|gender|category|netSales|salesUnits|weeknumber|
2018|Digital| APPAREL| KIDS| CRICKET|12009.599999999993| 199.0| 2|
2018|Digital| APPAREL| KIDS|COLLECTIONS| 8192.699999999999| 111.0| 2|
2018|Digital|FOOTWEAR| MENS|COLLECTIONS|3767.3999999999996| 55.0| 2|
2018|Digital| APPAREL| KIDS|COLLECTIONS| 808.24| 7.0| 4|
diff JSON files have to be produced based on the uniqueKey,calendaryear|channel|division|gender|category
{
"uniqueKey":"RY18_DIGITAL_APPAREL_KIDS_COLLECTIONS",
"division":"APPAREL",
"gender":"KIDS",
"category":"COLLECTIONS",
"channel":"DIGITAL",
"year":"RY18",
"dataRows":[
{
"rowId":"Net Sales",
"dataRow":[
{
"W1":5000,
"W2":0,
"W3":0,
"W4":0,
"W5":0,
"W6":0,
"W7":0,
"W8":0,
"W9":0,
"W10":0,
"W11":0,
"W12":0,
"W13":0,
"W14":2000,
"W15":0,
"W16":0,
"W17":3000,
"W18":0,
"W19":0,
"W20":0,
"W21":0,
"W22":0,
"W23":0,
"W24":0,
"W25":0,
"W26":0,
"W27":0,
"W28":0,
"W29":0,
"W30":0,
"W31":0,
"W32":0,
"W33":0,
"W34":0,
"W35":0,
"W36":0,
"W37":0,
"W38":0,
"W39":0,
"W40":0,
"W41":0,
"W42":0,
"W43":0,
"W44":0,
"W45":0,
"W46":0,
"W47":0,
"W48":0,
"W49":0,
"W50":0,
"W51":0,
"W52":0
}
]
},
{
"rowId":"Sales Units",
"dataRow":[
{
"W1":50,
"W2":0,
"W3":0,
"W4":0,
"W5":0,
"W6":0,
"W7":0,
"W8":0,
"W9":0,
"W10":0,
"W11":0,
"W12":0,
"W13":0,
"W14":20,
"W15":0,
"W16":0,
"W17":30,
"W18":0,
"W19":0,
"W20":0,
"W21":0,
"W22":0,
"W23":0,
"W24":0,
"W25":0,
"W26":0,
"W27":0,
"W28":0,
"W29":0,
"W30":0,
"W31":0,
"W32":0,
"W33":0,
"W34":0,
"W35":0,
"W36":0,
"W37":0,
"W38":0,
"W39":0,
"W40":0,
"W41":0,
"W42":0,
"W43":0,
"W44":0,
"W45":0,
"W46":0,
"W47":0,
"W48":0,
"W49":0,
"W50":0,
"W51":0,
"W52":0
}
]
}
]
}
scala apache-spark apache-spark-sql
add a comment |
I need to create multiple JSON files based on the ROW combinations.
e.g. In below table there are 4 rows, so I need to produce 3 JSON files.
I have provided a sample table below to be taken as source and sample JSON as well which we need to produce.
In each JSON file, there should be data related to calendaryear|channel|division|gender|category
If combination of calendaryear|channel|division|gender|category
is repeated, we need to club those rows together in a single JSON file.
If the value is not present for some week it needs to be filled with zero as given in JSON example
calendaryear|channel|division|gender|category|netSales|salesUnits|weeknumber|
2018|Digital| APPAREL| KIDS| CRICKET|12009.599999999993| 199.0| 2|
2018|Digital| APPAREL| KIDS|COLLECTIONS| 8192.699999999999| 111.0| 2|
2018|Digital|FOOTWEAR| MENS|COLLECTIONS|3767.3999999999996| 55.0| 2|
2018|Digital| APPAREL| KIDS|COLLECTIONS| 808.24| 7.0| 4|
diff JSON files have to be produced based on the uniqueKey,calendaryear|channel|division|gender|category
{
"uniqueKey":"RY18_DIGITAL_APPAREL_KIDS_COLLECTIONS",
"division":"APPAREL",
"gender":"KIDS",
"category":"COLLECTIONS",
"channel":"DIGITAL",
"year":"RY18",
"dataRows":[
{
"rowId":"Net Sales",
"dataRow":[
{
"W1":5000,
"W2":0,
"W3":0,
"W4":0,
"W5":0,
"W6":0,
"W7":0,
"W8":0,
"W9":0,
"W10":0,
"W11":0,
"W12":0,
"W13":0,
"W14":2000,
"W15":0,
"W16":0,
"W17":3000,
"W18":0,
"W19":0,
"W20":0,
"W21":0,
"W22":0,
"W23":0,
"W24":0,
"W25":0,
"W26":0,
"W27":0,
"W28":0,
"W29":0,
"W30":0,
"W31":0,
"W32":0,
"W33":0,
"W34":0,
"W35":0,
"W36":0,
"W37":0,
"W38":0,
"W39":0,
"W40":0,
"W41":0,
"W42":0,
"W43":0,
"W44":0,
"W45":0,
"W46":0,
"W47":0,
"W48":0,
"W49":0,
"W50":0,
"W51":0,
"W52":0
}
]
},
{
"rowId":"Sales Units",
"dataRow":[
{
"W1":50,
"W2":0,
"W3":0,
"W4":0,
"W5":0,
"W6":0,
"W7":0,
"W8":0,
"W9":0,
"W10":0,
"W11":0,
"W12":0,
"W13":0,
"W14":20,
"W15":0,
"W16":0,
"W17":30,
"W18":0,
"W19":0,
"W20":0,
"W21":0,
"W22":0,
"W23":0,
"W24":0,
"W25":0,
"W26":0,
"W27":0,
"W28":0,
"W29":0,
"W30":0,
"W31":0,
"W32":0,
"W33":0,
"W34":0,
"W35":0,
"W36":0,
"W37":0,
"W38":0,
"W39":0,
"W40":0,
"W41":0,
"W42":0,
"W43":0,
"W44":0,
"W45":0,
"W46":0,
"W47":0,
"W48":0,
"W49":0,
"W50":0,
"W51":0,
"W52":0
}
]
}
]
}
scala apache-spark apache-spark-sql
add a comment |
I need to create multiple JSON files based on the ROW combinations.
e.g. In below table there are 4 rows, so I need to produce 3 JSON files.
I have provided a sample table below to be taken as source and sample JSON as well which we need to produce.
In each JSON file, there should be data related to calendaryear|channel|division|gender|category
If combination of calendaryear|channel|division|gender|category
is repeated, we need to club those rows together in a single JSON file.
If the value is not present for some week it needs to be filled with zero as given in JSON example
calendaryear|channel|division|gender|category|netSales|salesUnits|weeknumber|
2018|Digital| APPAREL| KIDS| CRICKET|12009.599999999993| 199.0| 2|
2018|Digital| APPAREL| KIDS|COLLECTIONS| 8192.699999999999| 111.0| 2|
2018|Digital|FOOTWEAR| MENS|COLLECTIONS|3767.3999999999996| 55.0| 2|
2018|Digital| APPAREL| KIDS|COLLECTIONS| 808.24| 7.0| 4|
diff JSON files have to be produced based on the uniqueKey,calendaryear|channel|division|gender|category
{
"uniqueKey":"RY18_DIGITAL_APPAREL_KIDS_COLLECTIONS",
"division":"APPAREL",
"gender":"KIDS",
"category":"COLLECTIONS",
"channel":"DIGITAL",
"year":"RY18",
"dataRows":[
{
"rowId":"Net Sales",
"dataRow":[
{
"W1":5000,
"W2":0,
"W3":0,
"W4":0,
"W5":0,
"W6":0,
"W7":0,
"W8":0,
"W9":0,
"W10":0,
"W11":0,
"W12":0,
"W13":0,
"W14":2000,
"W15":0,
"W16":0,
"W17":3000,
"W18":0,
"W19":0,
"W20":0,
"W21":0,
"W22":0,
"W23":0,
"W24":0,
"W25":0,
"W26":0,
"W27":0,
"W28":0,
"W29":0,
"W30":0,
"W31":0,
"W32":0,
"W33":0,
"W34":0,
"W35":0,
"W36":0,
"W37":0,
"W38":0,
"W39":0,
"W40":0,
"W41":0,
"W42":0,
"W43":0,
"W44":0,
"W45":0,
"W46":0,
"W47":0,
"W48":0,
"W49":0,
"W50":0,
"W51":0,
"W52":0
}
]
},
{
"rowId":"Sales Units",
"dataRow":[
{
"W1":50,
"W2":0,
"W3":0,
"W4":0,
"W5":0,
"W6":0,
"W7":0,
"W8":0,
"W9":0,
"W10":0,
"W11":0,
"W12":0,
"W13":0,
"W14":20,
"W15":0,
"W16":0,
"W17":30,
"W18":0,
"W19":0,
"W20":0,
"W21":0,
"W22":0,
"W23":0,
"W24":0,
"W25":0,
"W26":0,
"W27":0,
"W28":0,
"W29":0,
"W30":0,
"W31":0,
"W32":0,
"W33":0,
"W34":0,
"W35":0,
"W36":0,
"W37":0,
"W38":0,
"W39":0,
"W40":0,
"W41":0,
"W42":0,
"W43":0,
"W44":0,
"W45":0,
"W46":0,
"W47":0,
"W48":0,
"W49":0,
"W50":0,
"W51":0,
"W52":0
}
]
}
]
}
scala apache-spark apache-spark-sql
I need to create multiple JSON files based on the ROW combinations.
e.g. In below table there are 4 rows, so I need to produce 3 JSON files.
I have provided a sample table below to be taken as source and sample JSON as well which we need to produce.
In each JSON file, there should be data related to calendaryear|channel|division|gender|category
If combination of calendaryear|channel|division|gender|category
is repeated, we need to club those rows together in a single JSON file.
If the value is not present for some week it needs to be filled with zero as given in JSON example
calendaryear|channel|division|gender|category|netSales|salesUnits|weeknumber|
2018|Digital| APPAREL| KIDS| CRICKET|12009.599999999993| 199.0| 2|
2018|Digital| APPAREL| KIDS|COLLECTIONS| 8192.699999999999| 111.0| 2|
2018|Digital|FOOTWEAR| MENS|COLLECTIONS|3767.3999999999996| 55.0| 2|
2018|Digital| APPAREL| KIDS|COLLECTIONS| 808.24| 7.0| 4|
diff JSON files have to be produced based on the uniqueKey,calendaryear|channel|division|gender|category
{
"uniqueKey":"RY18_DIGITAL_APPAREL_KIDS_COLLECTIONS",
"division":"APPAREL",
"gender":"KIDS",
"category":"COLLECTIONS",
"channel":"DIGITAL",
"year":"RY18",
"dataRows":[
{
"rowId":"Net Sales",
"dataRow":[
{
"W1":5000,
"W2":0,
"W3":0,
"W4":0,
"W5":0,
"W6":0,
"W7":0,
"W8":0,
"W9":0,
"W10":0,
"W11":0,
"W12":0,
"W13":0,
"W14":2000,
"W15":0,
"W16":0,
"W17":3000,
"W18":0,
"W19":0,
"W20":0,
"W21":0,
"W22":0,
"W23":0,
"W24":0,
"W25":0,
"W26":0,
"W27":0,
"W28":0,
"W29":0,
"W30":0,
"W31":0,
"W32":0,
"W33":0,
"W34":0,
"W35":0,
"W36":0,
"W37":0,
"W38":0,
"W39":0,
"W40":0,
"W41":0,
"W42":0,
"W43":0,
"W44":0,
"W45":0,
"W46":0,
"W47":0,
"W48":0,
"W49":0,
"W50":0,
"W51":0,
"W52":0
}
]
},
{
"rowId":"Sales Units",
"dataRow":[
{
"W1":50,
"W2":0,
"W3":0,
"W4":0,
"W5":0,
"W6":0,
"W7":0,
"W8":0,
"W9":0,
"W10":0,
"W11":0,
"W12":0,
"W13":0,
"W14":20,
"W15":0,
"W16":0,
"W17":30,
"W18":0,
"W19":0,
"W20":0,
"W21":0,
"W22":0,
"W23":0,
"W24":0,
"W25":0,
"W26":0,
"W27":0,
"W28":0,
"W29":0,
"W30":0,
"W31":0,
"W32":0,
"W33":0,
"W34":0,
"W35":0,
"W36":0,
"W37":0,
"W38":0,
"W39":0,
"W40":0,
"W41":0,
"W42":0,
"W43":0,
"W44":0,
"W45":0,
"W46":0,
"W47":0,
"W48":0,
"W49":0,
"W50":0,
"W51":0,
"W52":0
}
]
}
]
}
scala apache-spark apache-spark-sql
scala apache-spark apache-spark-sql
edited Dec 27 at 14:22
asked Dec 27 at 13:23
![](https://i.stack.imgur.com/aqroC.jpg?s=32&g=1)
![](https://i.stack.imgur.com/aqroC.jpg?s=32&g=1)
Yogesh Rustagi
65
65
add a comment |
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53945823%2fproduce-json-files-based-on-the-row-combinations-in-spark-sql%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53945823%2fproduce-json-files-based-on-the-row-combinations-in-spark-sql%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2lYmG A AxL,D45,qB4 aPsVk