I need to create a new column or alter the original from array to map where int values are in new table for respective stringSQL Server: How to Join to first rowWhat are the options for storing hierarchical data in a relational database?Hadoop/Hive query to split one column into several onesUpdate table new column with values from another table (MySQL)Need to add a constant value in a column while loading a hive tableWant to join table1 with table2 but want output of rows in the same sequence as in table2, but I am getting output as in table1SQL SELECT only rows having MAX value of a column from two different tablesDelete a record in Hive based on a table records in another databaseHow to map each distinct value of a column in one table with each distinct value of a column in another table in HiveHow to calculate the percentage of records when comparing hive tables?

What is this symbol: semicircles facing eachother

How would one country purchase another?

Which household object drew this pattern?

How to compare two different formulations of a problem?

LeetCode: Pascal's Triangle C#

Avoiding racist tropes in fantasy

What professions would a medieval village with a population of 100 need?

Why don't electrons take the shorter path in coils

How is "sein" conjugated in this sub-sentence?

In what ways can a Non-paladin access Paladin spells?

Is there a known non-euclidean geometry where two concentric circles of different radii can intersect? (as in the novel "The Universe Between")

Fried gnocchi with spinach, bacon, cream sauce in a single pan

Why didn’t Doctor Strange stay in the original winning timeline?

What is the hex versus octal timeline?

Why does The Ancient One think differently about Doctor Strange in Endgame than the film Doctor Strange?

Script that helps people make better choices

Can I switch to third-person while not in 'town' in Destiny 2?

If the first law of thermodynamics ensures conservation of energy, why does it allow systems to lose energy?

Science fiction short story where aliens contact a drunk about Earth's impending destruction

On the feasibility of space battleships

If all stars rotate, why was there a theory developed, that requires non-rotating stars?

Is a butterfly one or two animals?

Do ability scores have any effect on casting the Wish spell?

Does an object count as "being moved" when placed in a Bag of Holding before its wielder moves, and then after moving they take the object out again?



I need to create a new column or alter the original from array to map where int values are in new table for respective string


SQL Server: How to Join to first rowWhat are the options for storing hierarchical data in a relational database?Hadoop/Hive query to split one column into several onesUpdate table new column with values from another table (MySQL)Need to add a constant value in a column while loading a hive tableWant to join table1 with table2 but want output of rows in the same sequence as in table2, but I am getting output as in table1SQL SELECT only rows having MAX value of a column from two different tablesDelete a record in Hive based on a table records in another databaseHow to map each distinct value of a column in one table with each distinct value of a column in another table in HiveHow to calculate the percentage of records when comparing hive tables?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have two tables.
1.table1:(string,array(string))


abc ["s","m"]
def ["m","a","l"]
xyz ["s","a"]
2.table2:(string,int)
m 12
s 26
l 57
a 45
Now i want a table like below:(string,map(string,int))
abc ["s":26,"m":12]
def ["m":12,"a":45,"l":57]
xyz ["s":26,"a":45]
1. I need HIVE query for doing this.
2. How to interate for a purticular row sum like
abc 38









share|improve this question





















  • 1





    I removed the MySQL tag, since it has nothing to do with your question.

    – Tim Biegeleisen
    Mar 27 at 6:36











  • representation is not map(string,int)) it's array<string: string>

    – Gaurang Shah
    Mar 27 at 16:00

















0















I have two tables.
1.table1:(string,array(string))


abc ["s","m"]
def ["m","a","l"]
xyz ["s","a"]
2.table2:(string,int)
m 12
s 26
l 57
a 45
Now i want a table like below:(string,map(string,int))
abc ["s":26,"m":12]
def ["m":12,"a":45,"l":57]
xyz ["s":26,"a":45]
1. I need HIVE query for doing this.
2. How to interate for a purticular row sum like
abc 38









share|improve this question





















  • 1





    I removed the MySQL tag, since it has nothing to do with your question.

    – Tim Biegeleisen
    Mar 27 at 6:36











  • representation is not map(string,int)) it's array<string: string>

    – Gaurang Shah
    Mar 27 at 16:00













0












0








0








I have two tables.
1.table1:(string,array(string))


abc ["s","m"]
def ["m","a","l"]
xyz ["s","a"]
2.table2:(string,int)
m 12
s 26
l 57
a 45
Now i want a table like below:(string,map(string,int))
abc ["s":26,"m":12]
def ["m":12,"a":45,"l":57]
xyz ["s":26,"a":45]
1. I need HIVE query for doing this.
2. How to interate for a purticular row sum like
abc 38









share|improve this question
















I have two tables.
1.table1:(string,array(string))


abc ["s","m"]
def ["m","a","l"]
xyz ["s","a"]
2.table2:(string,int)
m 12
s 26
l 57
a 45
Now i want a table like below:(string,map(string,int))
abc ["s":26,"m":12]
def ["m":12,"a":45,"l":57]
xyz ["s":26,"a":45]
1. I need HIVE query for doing this.
2. How to interate for a purticular row sum like
abc 38






sql hadoop hive hiveql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 6:36









Tim Biegeleisen

267k13 gold badges116 silver badges177 bronze badges




267k13 gold badges116 silver badges177 bronze badges










asked Mar 27 at 6:35









maneeshmaneesh

1121 silver badge13 bronze badges




1121 silver badge13 bronze badges










  • 1





    I removed the MySQL tag, since it has nothing to do with your question.

    – Tim Biegeleisen
    Mar 27 at 6:36











  • representation is not map(string,int)) it's array<string: string>

    – Gaurang Shah
    Mar 27 at 16:00












  • 1





    I removed the MySQL tag, since it has nothing to do with your question.

    – Tim Biegeleisen
    Mar 27 at 6:36











  • representation is not map(string,int)) it's array<string: string>

    – Gaurang Shah
    Mar 27 at 16:00







1




1





I removed the MySQL tag, since it has nothing to do with your question.

– Tim Biegeleisen
Mar 27 at 6:36





I removed the MySQL tag, since it has nothing to do with your question.

– Tim Biegeleisen
Mar 27 at 6:36













representation is not map(string,int)) it's array<string: string>

– Gaurang Shah
Mar 27 at 16:00





representation is not map(string,int)) it's array<string: string>

– Gaurang Shah
Mar 27 at 16:00












1 Answer
1






active

oldest

votes


















0













This will do the trick



select t1.cat, collect_list(concat_ws(":", t1.subs, cast(t2.cnt as string))) from 
(select cat, subs from temp.table1
lateral view explode(sub) s as subs) t1
join
temp.table2 t2
on
t1.subs = t2.sub
group by t1.cat


And if you want to do a sum based on the above table.



select cat, sum(split(sub, ":")[1]) from temp.test3
lateral view explode(`_c1`) c as sub
group by cat





share|improve this answer


























    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
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55371174%2fi-need-to-create-a-new-column-or-alter-the-original-from-arraystring-to-mapst%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0













    This will do the trick



    select t1.cat, collect_list(concat_ws(":", t1.subs, cast(t2.cnt as string))) from 
    (select cat, subs from temp.table1
    lateral view explode(sub) s as subs) t1
    join
    temp.table2 t2
    on
    t1.subs = t2.sub
    group by t1.cat


    And if you want to do a sum based on the above table.



    select cat, sum(split(sub, ":")[1]) from temp.test3
    lateral view explode(`_c1`) c as sub
    group by cat





    share|improve this answer































      0













      This will do the trick



      select t1.cat, collect_list(concat_ws(":", t1.subs, cast(t2.cnt as string))) from 
      (select cat, subs from temp.table1
      lateral view explode(sub) s as subs) t1
      join
      temp.table2 t2
      on
      t1.subs = t2.sub
      group by t1.cat


      And if you want to do a sum based on the above table.



      select cat, sum(split(sub, ":")[1]) from temp.test3
      lateral view explode(`_c1`) c as sub
      group by cat





      share|improve this answer





























        0












        0








        0







        This will do the trick



        select t1.cat, collect_list(concat_ws(":", t1.subs, cast(t2.cnt as string))) from 
        (select cat, subs from temp.table1
        lateral view explode(sub) s as subs) t1
        join
        temp.table2 t2
        on
        t1.subs = t2.sub
        group by t1.cat


        And if you want to do a sum based on the above table.



        select cat, sum(split(sub, ":")[1]) from temp.test3
        lateral view explode(`_c1`) c as sub
        group by cat





        share|improve this answer















        This will do the trick



        select t1.cat, collect_list(concat_ws(":", t1.subs, cast(t2.cnt as string))) from 
        (select cat, subs from temp.table1
        lateral view explode(sub) s as subs) t1
        join
        temp.table2 t2
        on
        t1.subs = t2.sub
        group by t1.cat


        And if you want to do a sum based on the above table.



        select cat, sum(split(sub, ":")[1]) from temp.test3
        lateral view explode(`_c1`) c as sub
        group by cat






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 27 at 16:26

























        answered Mar 27 at 16:15









        Gaurang ShahGaurang Shah

        4,2842 gold badges22 silver badges45 bronze badges




        4,2842 gold badges22 silver badges45 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55371174%2fi-need-to-create-a-new-column-or-alter-the-original-from-arraystring-to-mapst%23new-answer', 'question_page');

            );

            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







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript