1

How to select all column exclude columns 'date' and 'cst_id' in hive?

CD_Lee
  • 99
  • 1
  • 13

2 Answers2

7

Try below -

For single session - set hive.support.quoted.identifiers=none;

select `(date|cst_id)?+.+` from myTable.

refer quotedIdentifiers for more information on hive select using regular expressions

Vijiy
  • 1,187
  • 6
  • 21
0

The accepted answer and the example regex on the hive manual page is flawed. If you want to exclude two columns day and day_hour, (day|day_hour)?+.+ will still match day_hour column. That's because regex engine is eager on |. Although changing the order to (day_hour|day)?+.+ can solve this issue, the better method is using negative lookahead, (?!(day|day_hour)$).+.

lovetl2002
  • 910
  • 9
  • 23