public Path getDnsPath(Path path) throws MetaException { return getDnsPath(path, conf); }
/** * Resolve the configured warehouse root dir with respect to the configuration * This involves opening the FileSystem corresponding to the warehouse root * dir (but that should be ok given that this is only called during DDL * statements for non-external tables). */ public Path getWhRoot() throws MetaException { if (whRoot != null) { return whRoot; } whRoot = getDnsPath(new Path(whRootString)); return whRoot; }
public static String generateTempTableLocation(Configuration conf) throws MetaException { Path path = new Path(SessionState.getTempTableSpace(conf), UUID.randomUUID().toString()); path = Warehouse.getDnsPath(path, conf); return path.toString(); }
public Path getWhRootExternal() throws MetaException { if (whRootExternal != null) { return whRootExternal; } if (!hasExternalWarehouseRoot()) { whRootExternal = getWhRoot(); } else { whRootExternal = getDnsPath(new Path(whRootExternalString)); } return whRootExternal; }
public Path getDefaultTablePath(String dbName, String tableName, boolean isExternal) throws MetaException { Path dbPath = null; if (isExternal && hasExternalWarehouseRoot()) { dbPath = getDefaultExternalDatabasePath(dbName); } else { dbPath = getDefaultDatabasePath(dbName); } return getDnsPath( new Path(dbPath, MetaStoreUtils.encodeTableName(tableName.toLowerCase()))); }
public Path getDefaultTablePath(Database db, String tableName, boolean isExternal) throws MetaException { Path dbPath = null; if (isExternal && hasExternalWarehouseRoot()) { dbPath = getDefaultExternalDatabasePath(db.getName()); } else { dbPath = getDatabasePath(db); } return getDnsPath( new Path(dbPath, MetaStoreUtils.encodeTableName(tableName.toLowerCase()))); }
/** * @param db database * @param table table * @return array of FileStatus objects corresponding to the files making up the passed * unpartitioned table */ public List<FileStatus> getFileStatusesForUnpartitionedTable(Database db, Table table) throws MetaException { Path tablePath = getDnsPath(new Path(table.getSd().getLocation())); try { FileSystem fileSys = tablePath.getFileSystem(conf); return FileUtils.getFileStatusRecurse(tablePath, -1, fileSys); } catch (IOException ioe) { MetaStoreUtils.logAndThrowMetaException(ioe); } return null; }
/** * Build the database path based on catalog name and database name. This should only be used * when a database is being created or altered. If you just want to find out the path a * database is already using call {@link #getDatabasePath(Database)}. If the passed in * database already has a path set that will be used. If not the location will be built using * catalog's path and the database name. * @param cat catalog the database is in * @param db database object * @return Path representing the directory for the database * @throws MetaException when the file path cannot be properly determined from the configured * file system. */ public Path determineDatabasePath(Catalog cat, Database db) throws MetaException { if (db.isSetLocationUri()) { return getDnsPath(new Path(db.getLocationUri())); } if (cat == null || cat.getName().equalsIgnoreCase(DEFAULT_CATALOG_NAME)) { if (db.getName().equalsIgnoreCase(DEFAULT_DATABASE_NAME)) { return getWhRoot(); } else { return new Path(getWhRoot(), dbDirFromDbName(db)); } } else { return new Path(getDnsPath(new Path(cat.getLocationUri())), dbDirFromDbName(db)); } }
/** * Given a database, a table and the partition key value pairs this method returns the Path object * corresponding to the partition key value pairs. It uses the table location if available else * uses the database location for constructing the path corresponding to the partition key-value * pairs * * @param db - Parent database of the given table * @param table - Table for which the partition key-values are given * @param vals - List of values for the partition keys * @return Path corresponding to the partition key-value pairs * @throws MetaException */ public Path getPartitionPath(Database db, Table table, List<String> vals) throws MetaException { List<FieldSchema> partKeys = table.getPartitionKeys(); if (partKeys == null || (partKeys.size() != vals.size())) { throw new MetaException("Invalid number of partition keys found for " + table.getTableName()); } Map<String, String> pm = new LinkedHashMap<>(vals.size()); int i = 0; for (FieldSchema key : partKeys) { pm.put(key.getName(), vals.get(i)); i++; } if (table.getSd().getLocation() != null) { return getPartitionPath(getDnsPath(new Path(table.getSd().getLocation())), pm); } else { return getDefaultPartitionPath(db, table, pm); } }
protected Path getDbLocation(Database db) throws HiveException { try { initWh(); String location = db.getLocationUri(); if (location == null) { return wh.getDefaultDatabasePath(db.getName()); } else { return wh.getDnsPath(wh.getDatabasePath(db)); } } catch (MetaException ex) { throw hiveException(ex); } }
static TableLocationTuple tableLocation(ImportTableDesc tblDesc, Database parentDb, TableContext tableContext, Context context) throws MetaException, SemanticException { Warehouse wh = context.warehouse; Path defaultTablePath; if (parentDb == null) { defaultTablePath = wh.getDefaultTablePath(tblDesc.getDatabaseName(), tblDesc.getTableName(), tblDesc.isExternal()); } else { defaultTablePath = wh.getDefaultTablePath( parentDb, tblDesc.getTableName(), tblDesc.isExternal() ); } // dont use TableType.EXTERNAL_TABLE.equals(tblDesc.tableType()) since this comes in as managed always for tables. if (tblDesc.isExternal()) { if (tblDesc.getLocation() == null) { // this is the use case when the table got converted to external table as part of migration // related rules to be applied to replicated tables across different versions of hive. return new TableLocationTuple(wh.getDnsPath(defaultTablePath).toString(), true); } String currentLocation = new Path(tblDesc.getLocation()).toUri().getPath(); String newLocation = ReplExternalTables.externalTableLocation(context.hiveConf, currentLocation); LOG.debug("external table {} data location is: {}", tblDesc.getTableName(), newLocation); return new TableLocationTuple(newLocation, false); } Path path = tableContext.waitOnPrecursor() ? wh.getDnsPath(defaultTablePath) : wh.getDefaultTablePath(parentDb, tblDesc.getTableName(), tblDesc.isExternal()); return new TableLocationTuple(path.toString(), false); }
protected Path getDbLocation(Database db) throws HiveException { try { initWh(); String location = db.getLocationUri(); if (location == null) { return wh.getDefaultDatabasePath(db.getName()); } else { return wh.getDnsPath(wh.getDatabasePath(db)); } } catch (MetaException ex) { throw hiveException(ex); } }
fields.add(new FieldSchema("val", "int", null)); table.setFields(fields); table.setDataLocation(Warehouse.getDnsPath(new Path(SessionState.get().getTempTableSpace(), tableName), conf)); table.getTTable().setTemporary(true);
catName, table.getDbName()), table); } else { tablePath = wh.getDnsPath(new Path(table.getSd().getLocation()));
Path tablePath = new Path(tableObj.getSd().getLocation()); if (modifyDefaultManagedLocation && shouldModifyTableLocation(dbObj, tableObj)) { Path newTablePath = wh.getDnsPath( new Path(wh.getDefaultDatabasePath(dbName), MetaStoreUtils.encodeTableName(tableName.toLowerCase())));
newDB.setLocationUri(wh.getDnsPath(new Path(newDB.getLocationUri())).toString());
Path tblPath = wh.getDnsPath(new Path(tbl.getSd().getLocation())); if (tblPath == null) { throw new MetaException("Temp table path not set for " + tbl.getTableName());
throw new MetaException("Cannot specify location for a view partition"); partLocation = wh.getDnsPath(new Path(partLocationStr));
@Test public void testDBLocationChange() throws IOException, TException { final String dbName = "alterDbLocation"; String defaultUri = MetastoreConf.getVar(conf, ConfVars.WAREHOUSE) + "/default_location.db"; String newUri = MetastoreConf.getVar(conf, ConfVars.WAREHOUSE) + "/new_location.db"; new DatabaseBuilder() .setName(dbName) .setLocation(defaultUri) .create(client, conf); Database db = client.getDatabase(dbName); assertEquals("Incorrect default location of the database", warehouse.getDnsPath(new Path(defaultUri)).toString(), db.getLocationUri()); db.setLocationUri(newUri); client.alterDatabase(dbName, db); db = client.getDatabase(dbName); assertEquals("Incorrect new location of the database", warehouse.getDnsPath(new Path(newUri)).toString(), db.getLocationUri()); client.dropDatabase(dbName); silentDropDatabase(dbName); }
Path tblPath = wh.getDnsPath(new Path(tbl.getSd().getLocation())); if (tblPath == null) { throw new MetaException("Temp table path not set for " + tbl.getTableName());