/** * Returns the default location of the table path using the parent database's location * @param db Database where the table is created * @param tableName table name * @return * @throws MetaException */ @Deprecated public Path getDefaultTablePath(Database db, String tableName) throws MetaException { return getDefaultTablePath(db, tableName, false); }
/** * Returns the default partition path of a table within a given database and partition key value * pairs. It uses the database location and appends it the table name and the partition key,value * pairs to create the Path for the partition directory * * @param db - parent database which is used to get the base location of the partition directory * @param tableName - table name for the partitions * @param pm - Partition key value pairs * @return * @throws MetaException */ public Path getDefaultPartitionPath(Database db, Table table, Map<String, String> pm) throws MetaException { return getPartitionPath(getDefaultTablePath(db, table), pm); }
public Path getDefaultTablePath(Database db, Table table) throws MetaException { return getDefaultTablePath(db, table.getTableName(), MetaStoreUtils.isExternalTable(table)); }
boolean shouldModifyTableLocation(Database dbObj, Table tableObj) throws IOException, MetaException { // Should only be managed tables passed in here. // Check if table is in the default table location based on the old warehouse root. // If so then change the table location to the default based on the current warehouse root. // The existing table directory will also be moved to the new default database directory. String tableLocation = tableObj.getSd().getLocation(); Path oldDefaultTableLocation = oldWh.getDefaultTablePath(dbObj, tableObj.getTableName()); if (arePathsEqual(conf, tableLocation, oldDefaultTableLocation.toString())) { if (hasEquivalentEncryption(encryptionShim, oldDefaultTableLocation, curWhRootPath)) { return true; } else { LOG.info("{} and {} are on different encryption zones. Will not change table location for {}", oldDefaultTableLocation, curWhRootPath, getQualifiedName(tableObj)); } } return false; }
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); }
/** * Helper method to set location properly in partSpec */ private static void fixLocationInPartSpec( FileSystem fs, ImportTableDesc tblDesc, Table table, Warehouse wh, ReplicationSpec replicationSpec, AddPartitionDesc.OnePartitionDesc partSpec, EximUtil.SemanticAnalyzerWrapperContext x) throws MetaException, HiveException, IOException { Path tgtPath = null; if (tblDesc.getLocation() == null) { if (table.getDataLocation() != null) { tgtPath = new Path(table.getDataLocation().toString(), Warehouse.makePartPath(partSpec.getPartSpec())); } else { Database parentDb = x.getHive().getDatabase(tblDesc.getDatabaseName()); tgtPath = new Path( wh.getDefaultTablePath( parentDb, tblDesc.getTableName()), Warehouse.makePartPath(partSpec.getPartSpec())); } } else { tgtPath = new Path(tblDesc.getLocation(), Warehouse.makePartPath(partSpec.getPartSpec())); } FileSystem tgtFs = FileSystem.get(tgtPath.toUri(), x.getConf()); checkTargetLocationEmpty(tgtFs, tgtPath, replicationSpec, x); partSpec.setLocation(tgtPath.toString()); }
Database parentDb = context.hiveDb.getDatabase(tableDesc.getDatabaseName()); return new Path( context.warehouse.getDefaultTablePath(parentDb, tableDesc.getTableName(), tableDesc.isExternal()), child); } else {
Database parentDb = x.getHive().getDatabase(tblDesc.getDatabaseName()); tgtPath = new Path( wh.getDefaultTablePath( parentDb, tblDesc.getTableName(), tblDesc.isExternal()), Warehouse.makePartPath(partSpec.getPartSpec()));
if (table.getSd().getLocation() == null || table.getSd().getLocation().isEmpty()) { String catName = getTableCatalog(table); tablePath = wh.getDefaultTablePath(hmsHandler.getMS().getDatabase( catName, table.getDbName()), table); } else {
tablePath = new Path(tblDesc.getLocation()); } else { tablePath = wh.getDefaultTablePath(parentDb, tblDesc.getTableName(), tblDesc.isExternal());
tablePath = new Path(tblDesc.getLocation()); } else { tablePath = wh.getDefaultTablePath(parentDb, tblDesc.getTableName());
private void handleLineage(LoadTableDesc ltd, Operator output) throws SemanticException { if (ltd != null) { queryState.getLineageState() .mapDirToOp(ltd.getSourcePath(), output); } else if ( queryState.getCommandType().equals(HiveOperation.CREATETABLE_AS_SELECT.getOperationName())) { Path tlocation = null; String tName = Utilities.getDbTableName(tableDesc.getTableName())[1]; try { Warehouse wh = new Warehouse(conf); tlocation = wh.getDefaultTablePath(db.getDatabase(tableDesc.getDatabaseName()), tName, tableDesc.isExternal()); } catch (MetaException|HiveException e) { throw new SemanticException(e); } queryState.getLineageState() .mapDirToOp(tlocation, output); } }
if (tbl.getSd().getLocation() == null || tbl.getSd().getLocation().isEmpty()) { tblPath = wh.getDefaultTablePath(db, tbl); } else { if (!isExternal(tbl) && !MetaStoreUtils.isNonNativeTable(tbl)) {
tblDesc.setLocation(wh.getDefaultTablePath(parentDb, tblDesc.getTableName()).toString()); } else { tblDesc.setLocation(
msc.createTable(tbl); Database db = Hive.get(hcatConf).getDatabase(dbName); Path dfsPath = clientWH.getDefaultTablePath(db, tblName); cleanupTbl(dbName, tblName, typeName); "-p", "rwx-wx---"}); assertEquals(ret, 0); dfsPath = clientWH.getDefaultTablePath(db, tblName); assertEquals(FsPermission.valueOf("drwx-wx---"), dfsPath.getFileSystem(hcatConf).getFileStatus(dfsPath).getPermission()); dfsPath = clientWH.getDefaultTablePath(db, tblName); try { dfsPath.getFileSystem(hcatConf).getFileStatus(dfsPath);
private Path getDefaultCtasLocation(final ParseContext pCtx) throws SemanticException { try { String protoName = null; boolean isExternal = false; if (pCtx.getQueryProperties().isCTAS()) { protoName = pCtx.getCreateTable().getTableName(); isExternal = pCtx.getCreateTable().isExternal(); } else if (pCtx.getQueryProperties().isMaterializedView()) { protoName = pCtx.getCreateViewDesc().getViewName(); } String[] names = Utilities.getDbTableName(protoName); if (!db.databaseExists(names[0])) { throw new SemanticException("ERROR: The database " + names[0] + " does not exist."); } Warehouse wh = new Warehouse(conf); return wh.getDefaultTablePath(db.getDatabase(names[0]), names[1], isExternal); } catch (HiveException e) { throw new SemanticException(e); } catch (MetaException e) { throw new SemanticException(e); } }
try { Warehouse wh = new Warehouse(conf); tlocation = wh.getDefaultTablePath(db.getDatabase(tableDesc.getDatabaseName()), tName); } catch (MetaException|HiveException e) { throw new SemanticException(e);
tblDesc.setLocation(wh.getDefaultTablePath(parentDb, tblDesc.getTableName(), tblDesc.isExternal()).toString()); } else { tblDesc.setLocation( wh.getDnsPath(wh.getDefaultTablePath(tblDesc.getDatabaseName(), tblDesc.getTableName(), tblDesc.isExternal()) ).toString());
targetPath = wh.getDefaultTablePath(db.getDatabase(names[0]), names[1]); } catch (HiveException e) { throw new SemanticException(e);
tbl.getRetention(), ft.getRetention()); assertEquals("Data location is not set correctly", wh.getDefaultTablePath(hm.getDatabase(DEFAULT_DATABASE_NAME), tableName).toString(), ft.getDataLocation().toString());