org.apache.hadoop.hive.ql.metadata.Hive Java Examples

The following examples show how to use org.apache.hadoop.hive.ql.metadata.Hive. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestSentryHiveAuthorizationTaskFactory.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
  conf = new HiveConf();
  baseDir = Files.createTempDir();
  baseDir.setWritable(true, false);
  conf.setVar(HiveConf.ConfVars.SCRATCHDIR, baseDir.getAbsolutePath());
  SessionState.start(conf);
  conf.setVar(ConfVars.HIVE_AUTHORIZATION_TASK_FACTORY,
      SentryHiveAuthorizationTaskFactoryImpl.class.getName());

  db = Mockito.mock(Hive.class);
  table = new Table(DB, TABLE);
  partition = new Partition(table);
  context = new Context(conf);
  parseDriver = new ParseDriver();
  analyzer = new DDLSemanticAnalyzer(conf, db);
  SessionState.start(conf);
  Mockito.when(db.getTable(TABLE, false)).thenReturn(table);
  Mockito.when(db.getPartition(table, new HashMap<String, String>(), false))
  .thenReturn(partition);

  HadoopDefaultAuthenticator auth = new HadoopDefaultAuthenticator();
  auth.setConf(conf);
  currentUser = auth.getUserName();

}
 
Example #2
Source File: HiveClientImpl.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
void connect() throws MetaException {
  Preconditions.checkState(this.client == null,
      "Already connected. If need to reconnect use reconnect() method.");
  reloginExpiringKeytabUser();

  try {
    doAsCommand(
      (PrivilegedExceptionAction<Void>) () -> {
        try(ContextClassLoaderSwapper ccls = ContextClassLoaderSwapper.newInstance()) {
          client = Hive.get(hiveConf).getMSC();
        }
        return null;
      },
        HiveImpersonationUtil.getProcessUserUGI(),
        "Failed to connect to Hive Metastore"
    );
  } catch (UndeclaredThrowableException e) {
    // If an exception is thrown from doAsCommand() above (internally in UserGroupInformation#doAs), it will get
    // wrapped as an UndeclaredThrowableException. We want to identify and rethrow MetaExceptions that have occurred.
    Throwables.propagateIfInstanceOf(e.getUndeclaredThrowable(), MetaException.class);
    throw e;
  }
}
 
Example #3
Source File: HiveMetaStoreBridge.java    From atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a HiveMetaStoreBridge.
 * @param hiveConf {@link HiveConf} for Hive component in the cluster
 */
public HiveMetaStoreBridge(Configuration atlasProperties, HiveConf hiveConf, AtlasClientV2 atlasClientV2) throws Exception {
    this.metadataNamespace          = getMetadataNamespace(atlasProperties);
    this.hiveClient                 = Hive.get(hiveConf);
    this.atlasClientV2              = atlasClientV2;
    this.convertHdfsPathToLowerCase = atlasProperties.getBoolean(HDFS_PATH_CONVERT_TO_LOWER_CASE, false);
}
 
Example #4
Source File: SentryFilterDDLTask.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
/**
 * Filter the command "show columns in table"
 *
 */
private int showFilterColumns(ShowColumnsDesc showCols) throws HiveException {
  Table table = Hive.get(conf).getTable(showCols.getTableName());

  // write the results in the file
  DataOutputStream outStream = null;
  try {
    Path resFile = new Path(showCols.getResFile());
    FileSystem fs = resFile.getFileSystem(conf);
    outStream = fs.create(resFile);

    List<FieldSchema> cols = table.getCols();
    cols.addAll(table.getPartCols());
    // In case the query is served by HiveServer2, don't pad it with spaces,
    // as HiveServer2 output is consumed by JDBC/ODBC clients.
    boolean isOutputPadded = !SessionState.get().isHiveServerQuery();
    outStream.writeBytes(MetaDataFormatUtils.getAllColumnsInformation(
        fiterColumns(cols, table), false, isOutputPadded, null));
    outStream.close();
    outStream = null;
  } catch (IOException e) {
    throw new HiveException(e, ErrorMsg.GENERIC_ERROR);
  } finally {
    IOUtils.closeStream(outStream);
  }
  return 0;
}
 
Example #5
Source File: AtlasHiveHookContext.java    From atlas with Apache License 2.0 5 votes vote down vote up
public AtlasHiveHookContext(HiveHook hook, HiveOperation hiveOperation, HookContext hiveContext, HiveHookObjectNamesCache knownObjects,
                            HiveMetastoreHook metastoreHook, ListenerEvent listenerEvent) throws Exception {
    this.hook             = hook;
    this.hiveOperation    = hiveOperation;
    this.hiveContext      = hiveContext;
    this.hive             = hiveContext != null ? Hive.get(hiveContext.getConf()) : null;
    this.knownObjects     = knownObjects;
    this.metastoreHook    = metastoreHook;
    this.metastoreEvent   = listenerEvent;
    this.metastoreHandler = (listenerEvent != null) ? metastoreEvent.getIHMSHandler() : null;

    init();
}
 
Example #6
Source File: HiveMetaStoreBridgeTest.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private List<Table> setupTables(Hive hiveClient, String databaseName, String... tableNames) throws HiveException {
    List<Table> tables = new ArrayList<>();
    when(hiveClient.getAllTables(databaseName)).thenReturn(Arrays.asList(tableNames));
    for(String tableName : tableNames) {
        Table testTable = createTestTable(databaseName, tableName);
        when(hiveClient.getTable(databaseName, tableName)).thenReturn(testTable);
        tables.add(testTable);
    }
    return tables;
}
 
Example #7
Source File: HiveMetaStoreBridgeTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
private List<Table> setupTables(Hive hiveClient, String databaseName, String... tableNames) throws HiveException {
    List<Table> tables = new ArrayList<>();
    when(hiveClient.getAllTables(databaseName)).thenReturn(Arrays.asList(tableNames));
    for(String tableName : tableNames) {
        Table testTable = createTestTable(databaseName, tableName);
        when(hiveClient.getTable(databaseName, tableName)).thenReturn(testTable);
        tables.add(testTable);
    }
    return tables;
}
 
Example #8
Source File: HiveClientWithAuthz.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
void connect() throws MetaException {
  doAsCommand(
    (PrivilegedExceptionAction<Void>) () -> {
      client = Hive.get(hiveConf).getMSC();
      return null;
    },
      ugiForRpc,
      "Failed to connect to Hive metastore"
  );

  // Hive authorization helper needs the query user
  // (not the user from metastore client used to communicate with metastore)
  this.authorizer = new HiveAuthorizationHelper(client, hiveConf, userName);
}
 
Example #9
Source File: HoodieHiveClient.java    From hudi with Apache License 2.0 5 votes vote down vote up
public void close() {
  try {
    if (connection != null) {
      connection.close();
    }
    if (client != null) {
      Hive.closeCurrent();
      client = null;
    }
  } catch (SQLException e) {
    LOG.error("Could not close connection ", e);
  }
}
 
Example #10
Source File: SentryHiveAuthorizationTaskFactoryImplV2.java    From incubator-sentry with Apache License 2.0 4 votes vote down vote up
public SentryHiveAuthorizationTaskFactoryImplV2(HiveConf conf, Hive db) {
  super(conf, db);
}
 
Example #11
Source File: HiveMetaStoreBridgeTest.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
private void setupDB(Hive hiveClient, String databaseName) throws HiveException {
    when(hiveClient.getAllDatabases()).thenReturn(Arrays.asList(new String[]{databaseName}));
    when(hiveClient.getDatabase(databaseName)).thenReturn(
            new Database(databaseName, "Default database", "/user/hive/default", null));
}
 
Example #12
Source File: HiveMetaStoreBridge.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
HiveMetaStoreBridge(String clusterName, Hive hiveClient, AtlasClient atlasClient) {
    this.clusterName = clusterName;
    this.hiveClient = hiveClient;
    this.atlasClient = atlasClient;
}
 
Example #13
Source File: HiveMetaStoreBridgeTest.java    From atlas with Apache License 2.0 4 votes vote down vote up
private void setupDB(Hive hiveClient, String databaseName) throws HiveException {
    when(hiveClient.getAllDatabases()).thenReturn(Arrays.asList(new String[]{databaseName}));
    when(hiveClient.getDatabase(databaseName)).thenReturn(
            new Database(databaseName, "Default database", "/user/hive/default", null));
}
 
Example #14
Source File: BaseHiveEvent.java    From atlas with Apache License 2.0 4 votes vote down vote up
protected Hive getHive() {
    return context.getHive();
}
 
Example #15
Source File: AtlasHiveHookContext.java    From atlas with Apache License 2.0 4 votes vote down vote up
public Hive getHive() {
    return hive;
}
 
Example #16
Source File: HiveMetaStoreBridge.java    From atlas with Apache License 2.0 4 votes vote down vote up
public Hive getHiveClient() {
    return hiveClient;
}
 
Example #17
Source File: HiveMetaStoreBridge.java    From atlas with Apache License 2.0 4 votes vote down vote up
HiveMetaStoreBridge(String metadataNamespace, Hive hiveClient, AtlasClientV2 atlasClientV2, boolean convertHdfsPathToLowerCase) {
    this.metadataNamespace          = metadataNamespace;
    this.hiveClient                 = hiveClient;
    this.atlasClientV2              = atlasClientV2;
    this.convertHdfsPathToLowerCase = convertHdfsPathToLowerCase;
}
 
Example #18
Source File: HiveMetaStoreBridge.java    From atlas with Apache License 2.0 4 votes vote down vote up
HiveMetaStoreBridge(String metadataNamespace, Hive hiveClient, AtlasClientV2 atlasClientV2) {
    this(metadataNamespace, hiveClient, atlasClientV2, true);
}
 
Example #19
Source File: HiveMetaStoreBridge.java    From incubator-atlas with Apache License 2.0 2 votes vote down vote up
/**
 * Construct a HiveMetaStoreBridge.
 * @param hiveConf {@link HiveConf} for Hive component in the cluster
 */
public HiveMetaStoreBridge(Configuration atlasProperties, HiveConf hiveConf, AtlasClient atlasClient) throws Exception {
    this(atlasProperties.getString(HIVE_CLUSTER_NAME, DEFAULT_CLUSTER_NAME), Hive.get(hiveConf), atlasClient);
}
 
Example #20
Source File: SentryHiveAuthorizationTaskFactoryImpl.java    From incubator-sentry with Apache License 2.0 2 votes vote down vote up
public SentryHiveAuthorizationTaskFactoryImpl(HiveConf conf, Hive db) { //NOPMD

  }