SHARE
TWEET

Untitled

a guest Oct 15th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.medium.hive.metastore.listerner;
  2.  
  3. import org.apache.hadoop.conf.Configuration;
  4.  
  5. import org.apache.hadoop.hive.metastore.events.AlterTableEvent;
  6. import org.apache.hadoop.hive.metastore.MetaStoreEventListener;
  7. import org.apache.hadoop.hive.metastore.events.CreateTableEvent;
  8.  
  9. import org.codehaus.jackson.map.ObjectMapper;
  10.  
  11. import org.slf4j.Logger;
  12. import org.slf4j.LoggerFactory;
  13.  
  14. import java.io.IOException;
  15.  
  16. public class CustomListener extends MetaStoreEventListener {
  17.     private static final Logger LOGGER = LoggerFactory.getLogger(CustomListener.class);
  18.     private static final  ObjectMapper objMapper = new ObjectMapper();
  19.  
  20.     public CustomListener(Configuration config) {
  21.         super(config);
  22.         logWithHeader(" created ");
  23.     }
  24.  
  25.     @Override
  26.     public void onCreateTable(CreateTableEvent event) {
  27.         logWithHeader(event.getTable());
  28.     }
  29.  
  30.     @Override
  31.     public void onAlterTable(AlterTableEvent event) {
  32.         logWithHeader(event.getOldTable());
  33.         logWithHeader(event.getNewTable());
  34.     }
  35.  
  36.     private void logWithHeader(Object obj){
  37.         LOGGER.info("[CustomListener][Thread: " + Thread.currentThread().getName()+"] | " + objToStr(obj));
  38.     }
  39.  
  40.     private String objToStr(Object obj){
  41.         try {
  42.             return objMapper.writeValueAsString(obj);
  43.         } catch (IOException e) {
  44.             LOGGER.error("Error on conversion", e);
  45.         }
  46.         return null;
  47.     }
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top