Extract XML data from Hive Table and Parse the data - mysql

I want to extract particular column values from a hive table. That column has XML data. How to parse through XML data and extract name and values from that particular XML column. Also I want to insert the extracted data into another Hive table.

Option 1 : LanguageManual XPathUDF
Example :
select xpath ('<a><b id="1"><c/></b><b id="2"><c/></b></a>','/descendant::c/ancestor::b/#id') from t1 limit 1 ;
[1","2]
Option2 : Another way of achieving this is Hive-XML-SerDe
In both option you need to have Xpath expression knowledge.
If you want to insert extracted data in to another table then use create table as select xxx from xxxxx (Create Table As Select (CTAS))

Related

How to write select query in mysql with dynamic table name and dynamic column name

Above is the table structure of database. For each ‘form_id’ in ‘ap_forms ‘ there is a dynamic table with dynamic column names like ap_form_{form_id}.
Columns in this table will created dynamically by element_id and option_id combination. (eg: for element_id=1 and option_id=2 then column name= element_1_2).
I want the query result from these tables and this will looks like
I tried with dynamic query and I think we can’t create dynamic query with dynamic table name and dynamic column name. Please help me to get the above query result.

Multiple same kind of column concatenation in another column of same table in mysql

I have one table "Mytable" and in this i have multiple columns and now in this columns i have 100 columns with same name like "type1", "type2"..,"type99" and i am importing this value from csv. so now what i want to do is i want to combined all this column value in one single column in json format.
Can any one suggest me how can i achieve?
You can create the json object as:
select json_object('type1', type1, 'type2', type2, . . . )
Alternatively, you might want an array.
You can then insert this into a new table.

Mysql: Put output of select as new column in table

I have mysql table
surname | name | complete
Now i want to connect "surname" and "name" with a SELECT CONCAT and put the output into the "complete" column.
Any Idea?
If you really want to do this the answer by #scaisEdge shows you how. But you really shouldn't! To do so would mean to introduce redunancy. That means your database wouldn't properly normalized. As a rule, you do not store data that is the result of a simple operation on one or more columns.
Consider using a VIEW instead.
CREATE VIEW extended_table AS SELECT surname, name, CONCAT(name,surname) AS complete
This does not have any storage overhead. Alternatively you can use a generated column.
ALTER TABLE users add column complete as CONCAT(name, surname);
Both these options allow you to maintain your table in it's normalized form and you are not saving any redundant data to disk.
#jarlh has raised a very valid point in the comments, how to deal with null
CREATE VIEW extended_table AS SELECT surname, name, CONCAT(COALESCE(name,''),COALESCE(surname,'')) AS complete
You can use update
update my_table
set complete = concat(surname, name)

SQL: I need copy data from one field to another field in one table base on id of category

SQL: I need copy data from one field to another field in one table base on id of category
Like this (but this not work)
UPDATE z_jlogica_awards SET desc=desclong
FROM z_jlogica_awards WHERE z_jlogica_awards.parent='1';
Your query syntax is wrong. try this:
UPDATE z_jlogica_awards SET longdesc=desc WHERE z_jlogica_awards.parent='1'

Pick Linked table named as an input table in the append MS query

I need to append the data to a Access Table ULAE. I wants parameters to be picked from another table LAE.This table has 4 columns(Group,le,qtr,Table name) that will be an input and some parameters will be part of where condition. However there is one column table name that will have linked tables. Is it possible to pick the table name (that would be a linked table in the same access file, from where the data would be appended to ULAE).Is it possible to implement this in MSquery?
What i need is to pick the table name from LAE and append the data into ULAE from the table name specified in the LAE.
my query is like
INSERT INTO ULAE( vdate, profile_id, le, ibu)
SELECT PERSIAN.vdate, PERSIAN.profile_id, PERSIAN.le, PERSIAN.ibu
FROM **PERSIAN**;
**Persion is the linked table name coming from LAE**
Thanks in advance.