use of org.jkiss.dbeaver.ext.hive.model.HiveTable in project dbeaver by dbeaver.
the class HiveTableColumnManager method addObjectCreateActions.
@Override
protected void addObjectCreateActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectCreateCommand command, Map<String, Object> options) {
HiveTable table = (HiveTable) command.getObject().getParentObject();
actions.add(new SQLDatabasePersistAction("Add table column", "ALTER TABLE " + DBUtils.getObjectFullName(table, DBPEvaluationContext.DDL) + " ADD COLUMNS (" + getNestedDeclaration(monitor, table, command, options) + ")"));
}
use of org.jkiss.dbeaver.ext.hive.model.HiveTable in project dbeaver by serge-rider.
the class HiveTableColumnManager method addObjectCreateActions.
@Override
protected void addObjectCreateActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectCreateCommand command, Map<String, Object> options) {
HiveTable table = (HiveTable) command.getObject().getParentObject();
actions.add(new SQLDatabasePersistAction("Add table column", "ALTER TABLE " + DBUtils.getObjectFullName(table, DBPEvaluationContext.DDL) + " ADD COLUMNS (" + getNestedDeclaration(monitor, table, command, options) + ")"));
}
use of org.jkiss.dbeaver.ext.hive.model.HiveTable in project dbeaver by serge-rider.
the class HiveTableColumnManager method addObjectDeleteActions.
@Override
protected void addObjectDeleteActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectDeleteCommand command, Map<String, Object> options) throws DBException {
HiveTableColumn hiveTableColumn = (HiveTableColumn) command.getObject();
HiveTable table = (HiveTable) hiveTableColumn.getParentObject();
try {
List<? extends GenericTableColumn> attributes = table.getAttributes(monitor);
// It may not be the best option. Some of the column data may still be lost. It might be worth using a temporary table
StringBuilder ddl = new StringBuilder();
ddl.append("ALTER TABLE ").append(DBUtils.getObjectFullName(table, DBPEvaluationContext.DDL)).append(" REPLACE COLUMNS (");
if (attributes != null) {
for (int i = 0; i < attributes.size(); i++) {
GenericTableColumn column = attributes.get(i);
if (column != hiveTableColumn) {
if (i != 0) {
ddl.append(" ");
}
ddl.append(DBUtils.getQuotedIdentifier(column)).append(" ").append(column.getTypeName());
String typeModifiers = SQLUtils.getColumnTypeModifiers(table.getDataSource(), column, column.getTypeName(), column.getDataKind());
if (typeModifiers != null) {
ddl.append(typeModifiers);
}
String description = column.getDescription();
if (column.getDescription() != null) {
ddl.append(" COMMENT '").append(description).append("'");
}
if (i != attributes.size() - 1) {
ddl.append(",");
}
}
}
}
ddl.append(")");
actions.add(new SQLDatabasePersistAction("Drop table column", ddl.toString()));
} catch (DBException e) {
log.debug("Columns not found in table: " + table.getName(), e);
}
}
use of org.jkiss.dbeaver.ext.hive.model.HiveTable in project dbeaver by dbeaver.
the class HiveTableColumnManager method addObjectDeleteActions.
@Override
protected void addObjectDeleteActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectDeleteCommand command, Map<String, Object> options) throws DBException {
HiveTableColumn hiveTableColumn = (HiveTableColumn) command.getObject();
HiveTable table = (HiveTable) hiveTableColumn.getParentObject();
try {
List<? extends GenericTableColumn> attributes = table.getAttributes(monitor);
// It may not be the best option. Some of the column data may still be lost. It might be worth using a temporary table
StringBuilder ddl = new StringBuilder();
ddl.append("ALTER TABLE ").append(DBUtils.getObjectFullName(table, DBPEvaluationContext.DDL)).append(" REPLACE COLUMNS (");
if (attributes != null) {
for (int i = 0; i < attributes.size(); i++) {
GenericTableColumn column = attributes.get(i);
if (column != hiveTableColumn) {
if (i != 0) {
ddl.append(" ");
}
ddl.append(DBUtils.getQuotedIdentifier(column)).append(" ").append(column.getTypeName());
String typeModifiers = SQLUtils.getColumnTypeModifiers(table.getDataSource(), column, column.getTypeName(), column.getDataKind());
if (typeModifiers != null) {
ddl.append(typeModifiers);
}
String description = column.getDescription();
if (column.getDescription() != null) {
ddl.append(" COMMENT '").append(description).append("'");
}
if (i != attributes.size() - 1) {
ddl.append(",");
}
}
}
}
ddl.append(")");
actions.add(new SQLDatabasePersistAction("Drop table column", ddl.toString()));
} catch (DBException e) {
log.debug("Columns not found in table: " + table.getName(), e);
}
}
Aggregations