private void verifyTableNotExists(String newDatabaseName, String newTableName) { if (getTable(newDatabaseName, newTableName).isPresent()) { throw new TableAlreadyExistsException(new SchemaTableName(newDatabaseName, newTableName)); } }
case ALTER: case INSERT_EXISTING: throw new TableAlreadyExistsException(schemaTableName); default: throw new IllegalStateException("Unknown action type");
throw new TableAlreadyExistsException(schemaTableName);
@Override public synchronized void alterTable(String databaseName, String tableName, Table newTable) { SchemaTableName oldName = new SchemaTableName(databaseName, tableName); SchemaTableName newName = new SchemaTableName(newTable.getDbName(), newTable.getTableName()); // if the name did not change, this is a simple schema change if (oldName.equals(newName)) { if (relations.replace(oldName, newTable) == null) { throw new TableNotFoundException(oldName); } return; } // remove old table definition and add the new one Table table = relations.get(oldName); if (table == null) { throw new TableNotFoundException(oldName); } if (relations.putIfAbsent(newName, newTable) != null) { throw new TableAlreadyExistsException(newName); } relations.remove(oldName); }
@Override public void createTable(Table table, PrincipalPrivileges principalPrivileges) { try { TableInput input = GlueInputConverter.convertTable(table); glueClient.createTable(new CreateTableRequest() .withDatabaseName(table.getDatabaseName()) .withTableInput(input)); } catch (AlreadyExistsException e) { throw new TableAlreadyExistsException(new SchemaTableName(table.getDatabaseName(), table.getTableName())); } catch (EntityNotFoundException e) { throw new SchemaNotFoundException(table.getDatabaseName()); } catch (AmazonServiceException e) { throw new PrestoException(HIVE_METASTORE_ERROR, e); } }
@Override public void createTable(Table table) { try { retry() .stopOn(AlreadyExistsException.class, InvalidObjectException.class, MetaException.class, NoSuchObjectException.class) .stopOnIllegalExceptions() .run("createTable", stats.getCreateTable().wrap(() -> { try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) { client.createTable(table); } return null; })); } catch (AlreadyExistsException e) { throw new TableAlreadyExistsException(new SchemaTableName(table.getDbName(), table.getTableName())); } catch (NoSuchObjectException e) { throw new SchemaNotFoundException(table.getDbName()); } catch (TException e) { throw new PrestoException(HIVE_METASTORE_ERROR, e); } catch (Exception e) { throw propagate(e); } }
throw new TableAlreadyExistsException(schemaTableName);
throw new TableAlreadyExistsException(schemaTableName);
@Override public synchronized void alterTable(String databaseName, String tableName, Table newTable) { SchemaTableName oldName = new SchemaTableName(databaseName, tableName); SchemaTableName newName = new SchemaTableName(newTable.getDbName(), newTable.getTableName()); // if the name did not change, this is a simple schema change if (oldName.equals(newName)) { if (relations.replace(oldName, newTable) == null) { throw new TableNotFoundException(oldName); } return; } // remove old table definition and add the new one Table table = relations.get(oldName); if (table == null) { throw new TableNotFoundException(oldName); } if (relations.putIfAbsent(newName, newTable) != null) { throw new TableAlreadyExistsException(newName); } relations.remove(oldName); }
@Override public void alterTable(String databaseName, String tableName, Table newTable) { SchemaTableName oldName = new SchemaTableName(databaseName, tableName); SchemaTableName newName = new SchemaTableName(newTable.getDbName(), newTable.getTableName()); // if the name did not change, this is a simple schema change if (oldName.equals(newName)) { if (relations.replace(oldName, newTable) != null) { throw new TableNotFoundException(oldName); } return; } // remove old table definition and add the new one // TODO: use locking to do this properly Table table = relations.get(oldName); if (table == null) { throw new TableNotFoundException(oldName); } if (relations.putIfAbsent(newName, newTable) != null) { throw new TableAlreadyExistsException(newName); } relations.remove(oldName); }
throw new TableAlreadyExistsException(new SchemaTableName(table.getDbName(), table.getTableName()));
@Override public void createTable(final ConnectorSession session, final ConnectorTableMetadata tableMetadata) { Preconditions.checkArgument(!Strings.isNullOrEmpty(tableMetadata.getOwner()), "Table owner is null or empty"); final SchemaTableName schemaTableName = tableMetadata.getTable(); if (tableDao.getBySourceDatabaseTableName(connectorId.toString(), schemaTableName.getSchemaName(), schemaTableName.getTableName()) != null) { throw new TableAlreadyExistsException(schemaTableName); } final Database database = databaseDao .getBySourceDatabaseName(connectorId.toString(), schemaTableName.getSchemaName()); if (database == null) { throw new SchemaNotFoundException(schemaTableName.getSchemaName()); } final Table table = new Table(); table.setName(schemaTableName.getTableName()); table.setDatabase(database); final Location location = converterUtil.toLocation(tableMetadata); if (location != null) { location.setTable(table); table.setLocation(location); } tableDao.save(table); }
@Override public void renameTable(final ConnectorSession session, final ConnectorTableHandle tableHandle, final SchemaTableName newTableName) { final HiveTableHandle hiveTableHandle = (HiveTableHandle) tableHandle; final Table table = tableDao.getBySourceDatabaseTableName(connectorId.toString(), hiveTableHandle.getSchemaName(), hiveTableHandle.getTableName()); if (table == null) { throw new TableNotFoundException( new SchemaTableName(hiveTableHandle.getSchemaName(), hiveTableHandle.getTableName())); } final Table newTable = tableDao.getBySourceDatabaseTableName(connectorId.toString(), newTableName.getSchemaName(), newTableName.getTableName()); if (newTable == null) { table.setName(newTableName.getTableName()); tableDao.save(table); } else { throw new TableAlreadyExistsException(newTableName, "Table with new name already exists"); } }