11

Does Hive have a dynamic pivot functionality? I'm able to find regular pivoting (ie here) but they appear to be hard coded pivots (all values known at runtime) not dynamic (all values determined at runtime).

If it exists or someone has user defined code that they could share that would be appreciated.

screechOwl
  • 27,310
  • 61
  • 158
  • 267
  • Hive does not have dynamic pivot functionality, you have to invent your own dynamic SQL solution or using third party tools. – leftjoin Feb 16 '18 at 09:57

1 Answers1

1

HiveQL doesn't support dynamic pivot like you describe. If you want to do something like this you need to use straight dynamic SQL and construct the query in whatever orchestration tool you're using.

I haven't used it, but this is apparently supported in HPL/SQL through use of the EXEC keyword. This will allow execution of strings of dynamic SQL and provides a more transactional layer on top of traditional Hive. HPL/SQL is included in Hive 2.0. If you use Hive 2.0 it should be available for you.

Personally I have always done this type of query construction in Python, which I use to drive all my operations.

Kirk Broadhurst
  • 27,836
  • 16
  • 104
  • 169