0
votes

I have multiple tables with very similar schema except one column, which can have different names. I want to make some complicated calculations using Hive and would like to have one code for all tables with possible parametrisation. For some reasons, I can't parametrise queries using language like Python, Scala etc, so decided to go with pure Hive SQL.

I want to conditionally select appropriate column, but it seems, that Hive evaluates all parts of conditional expression/statement regardless of condition. What did I wrong?

DROP TABLE IF EXISTS `so_sample`;
CREATE TABLE `so_sample` (
  `app_version` string
);
SELECT
  if (true, app_version, software_version) AS firmware
FROM so_sample
;

Output:

Error: Error while compiling statement: FAILED: SemanticException [Error 10004]: Line 2:25 Invalid table alias or column reference 'software_version': (possible column names are: app_version) (state=42000,code=10004)

Regards Pawel

1

1 Answers

0
votes

Try to use regex to select the column with different names, for more information see manual and don't forget

set hive.support.quoted.identifiers=none;