private Table createTestTbl(String dbName, String tblName, String tblOwner, List<FieldSchema> cols, List<FieldSchema> ptnCols) { String serdeLocation = "file:/tmp"; Map<String, String> serdeParams = new HashMap<>(); Map<String, String> tblParams = new HashMap<>(); SerDeInfo serdeInfo = new SerDeInfo("serde", "seriallib", new HashMap<>()); StorageDescriptor sd = new StorageDescriptor(cols, serdeLocation, "input", "output", false, 0, serdeInfo, null, null, serdeParams); sd.setStoredAsSubDirectories(false); Table tbl = new Table(tblName, dbName, tblOwner, 0, 0, 0, sd, ptnCols, tblParams, null, null, TableType.MANAGED_TABLE.toString()); tbl.setCatName(DEFAULT_CATALOG_NAME); return tbl; }
tbl.setCatName(defaultCat); if (primaryKeys != null) { primaryKeys.forEach(pk -> pk.setCatName(defaultCat));
public void createTable(Table tbl, EnvironmentContext envContext) throws AlreadyExistsException, InvalidObjectException, MetaException, NoSuchObjectException, TException { if (!tbl.isSetCatName()) { tbl.setCatName(getDefaultCatalog(conf)); } HiveMetaHook hook = getHook(tbl); if (hook != null) { hook.preCreateTable(tbl); } boolean success = false; try { // Subclasses can override this step (for example, for temporary tables) create_table_with_environment_context(tbl, envContext); if (hook != null) { hook.commitCreateTable(tbl); } success = true; } finally { if (!success && (hook != null)) { try { hook.rollbackCreateTable(tbl); } catch (Exception e){ LOG.error("Create rollback failed with", e); } } } }
public Table build(Configuration conf) throws MetaException { if (tableName == null) { throw new MetaException("You must set the table name"); } if (ownerType == null) { ownerType = PrincipalType.USER; } if (owner == null) { try { owner = SecurityUtils.getUser(); } catch (IOException e) { throw MetaStoreUtils.newMetaException(e); } } if (catName == null) catName = MetaStoreUtils.getDefaultCatalog(conf); Table t = new Table(tableName, dbName, owner, createTime, lastAccessTime, retention, buildSd(), partCols, tableParams, viewOriginalText, viewExpandedText, type); if (rewriteEnabled) t.setRewriteEnabled(true); if (temporary) t.setTemporary(temporary); t.setCatName(catName); if (!mvReferencedTables.isEmpty()) { CreationMetadata cm = new CreationMetadata(catName, dbName, tableName, mvReferencedTables); if (mvValidTxnList != null) cm.setValidTxnList(mvValidTxnList); t.setCreationMetadata(cm); } return t; }
newTable.setCatName(catName);
try { if (!tbl.isSetCatName()) { tbl.setCatName(getDefaultCatalog(conf));
new Table(tblName, dbName, null, 0, 0, 0, sd, partCols, new HashMap<>(), null, null, TableType.MANAGED_TABLE.toString()); tbl.setCatName(DEFAULT_CATALOG_NAME); cachedStore.createTable(tbl);
new Table(tblName, dbName, null, 0, 0, 0, sd, partCols, new HashMap<>(), null, null, TableType.MANAGED_TABLE.toString()); tbl.setCatName(DEFAULT_CATALOG_NAME); cachedStore.createTable(tbl);
private Table createPartitionedTable(String catName, String dbName, String tableName) throws Exception { try { db.dropTable(catName, dbName, tableName); Table table = new Table(); table.setCatName(catName); table.setDbName(dbName); table.setTableName(tableName); FieldSchema col1 = new FieldSchema("key", "string", ""); FieldSchema col2 = new FieldSchema("value", "int", ""); FieldSchema col3 = new FieldSchema("city", "string", ""); StorageDescriptor sd = new StorageDescriptor(); sd.setSerdeInfo(new SerDeInfo()); sd.setInputFormat(TextInputFormat.class.getCanonicalName()); sd.setOutputFormat(HiveIgnoreKeyTextOutputFormat.class.getCanonicalName()); sd.setCols(Arrays.asList(col1, col2)); table.setPartitionKeys(Arrays.asList(col3)); table.setSd(sd); db.createTable(table); return db.getTable(catName, dbName, tableName); } catch (Exception exception) { fail("Unable to drop and create table " + StatsUtils.getFullyQualifiedTableName(dbName, tableName) + " because " + StringUtils.stringifyException(exception)); throw exception; } }
private Table createPartitionedTable(String catName, String dbName, String tableName) throws Exception { try { db.dropTable(catName, dbName, tableName); Table table = new Table(); table.setCatName(catName); table.setDbName(dbName); table.setTableName(tableName); FieldSchema col1 = new FieldSchema("key", "string", ""); FieldSchema col2 = new FieldSchema("value", "int", ""); FieldSchema col3 = new FieldSchema("city", "string", ""); StorageDescriptor sd = new StorageDescriptor(); sd.setSerdeInfo(new SerDeInfo()); sd.setInputFormat(TextInputFormat.class.getCanonicalName()); sd.setOutputFormat(HiveIgnoreKeyTextOutputFormat.class.getCanonicalName()); sd.setCols(Arrays.asList(col1, col2)); table.setPartitionKeys(Arrays.asList(col3)); table.setSd(sd); db.createTable(table); return db.getTable(catName, dbName, tableName); } catch (Exception exception) { fail("Unable to drop and create table " + StatsUtils .getFullyQualifiedTableName(dbName, tableName) + " because " + StringUtils .stringifyException(exception)); throw exception; } }
t.setCatName(mtbl.getDatabase().getCatalogName()); t.setWriteId(mtbl.getWriteId()); return t;
new Table(tblName, dbName, null, 0, 0, 0, sd, partCols, new HashMap<>(), null, null, TableType.MANAGED_TABLE.toString()); tbl.setCatName(DEFAULT_CATALOG_NAME); cachedStore.createTable(tbl);
private TableWrapper createTableWrapper(String catName, String dbName, String tblName, Table tbl) { TableWrapper wrapper; Table tblCopy = tbl.deepCopy(); tblCopy.setCatName(normalizeIdentifier(catName)); tblCopy.setDbName(normalizeIdentifier(dbName)); tblCopy.setTableName(normalizeIdentifier(tblName)); if (tblCopy.getPartitionKeys() != null) { for (FieldSchema fs : tblCopy.getPartitionKeys()) { fs.setName(normalizeIdentifier(fs.getName())); } } if (tbl.getSd() != null) { byte[] sdHash = MetaStoreServerUtils.hashStorageDescriptor(tbl.getSd(), md); StorageDescriptor sd = tbl.getSd(); increSd(sd, sdHash); tblCopy.setSd(null); wrapper = new TableWrapper(tblCopy, sdHash, sd.getLocation(), sd.getParameters()); } else { wrapper = new TableWrapper(tblCopy, null, null, null); } return wrapper; }
@Test(expected = InvalidOperationException.class) public void moveTablesBetweenCatalogsOnAlter() throws TException { String catName = "move_table_between_catalogs_on_alter"; Catalog cat = new CatalogBuilder() .setName(catName) .setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName)) .build(); client.createCatalog(cat); String dbName = "a_db"; // For this one don't specify a location to make sure it gets put in the catalog directory Database db = new DatabaseBuilder() .setName(dbName) .setCatalogName(catName) .create(client, metaStore.getConf()); String tableName = "non_movable_table"; Table before = new TableBuilder() .inDb(db) .setTableName(tableName) .addCol("col1", ColumnType.STRING_TYPE_NAME) .addCol("col2", ColumnType.INT_TYPE_NAME) .create(client, metaStore.getConf()); Table after = before.deepCopy(); after.setCatName(DEFAULT_CATALOG_NAME); client.alter_table(catName, dbName, tableName, after); }
unsetCatName(); } else { setCatName((String)value);
public Table build(Configuration conf) throws MetaException { if (tableName == null) { throw new MetaException("You must set the table name"); } if (owner == null) { try { owner = SecurityUtils.getUser(); } catch (IOException e) { throw MetaStoreUtils.newMetaException(e); } } if (catName == null) catName = MetaStoreUtils.getDefaultCatalog(conf); Table t = new Table(tableName, dbName, owner, createTime, lastAccessTime, retention, buildSd(), partCols, tableParams, viewOriginalText, viewExpandedText, type); if (rewriteEnabled) t.setRewriteEnabled(true); if (temporary) t.setTemporary(temporary); t.setCatName(catName); if (!mvReferencedTables.isEmpty()) { CreationMetadata cm = new CreationMetadata(catName, dbName, tableName, mvReferencedTables); if (mvValidTxnList != null) cm.setValidTxnList(mvValidTxnList); t.setCreationMetadata(cm); } return t; }
newTable.setCatName(catName);
try { if (!tbl.isSetCatName()) { tbl.setCatName(getDefaultCatalog(conf));
t.setCatName(mtbl.getDatabase().getCatalogName()); return t;
unsetCatName(); } else { setCatName((String)value);