问题
Follow up on this question: Impala - Get for all tables in database concentenated columns
Lets say I have a database A with tables B1, B2, ... B300. B1 has columns C1 and C2
,B2 has columns D1, D2 and D3. ... and B300 has columns E1 and E2.
I am looking for an Impala query that yields the following desired output:
B1 | "C1+C2"
B2 | "D1+D2+D3"
...
B300 | "E1+E2"
where "D1+D2+D3", "C1+C2" and "E1+E2" are concatenated strings.
回答1:
First of all UNION all tables together and generate table_name for each table as you do this. You can copy your table names into excel and then automatically generate the SELECT and UNION statements for each table in excel (as a new column for each). Then you can run the UNION code in impala.
CREATE TABLE all_tables_unioned AS
SELECT
*
, "B1" AS table_name
FROM B1
UNION
SELECT
*
, "B2" AS table_name
FROM B2
Etc...
Then you can copy all of your column names in this new table from the hive metastore into excel and create a new column of commas (this is generating code in excel to save you typing the commas). Then copy and paste the two columns from excel into this code:
SELECT
CONCAT("all columns from excel")
FROM all_tables_unioned
来源:https://stackoverflow.com/questions/49338631/impala-get-for-multiple-tables-in-database-concentenated-columns