Search in sources :

Example 1 with HiveTable

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) + ")"));
}
Also used : HiveTable(org.jkiss.dbeaver.ext.hive.model.HiveTable) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 2 with HiveTable

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) + ")"));
}
Also used : HiveTable(org.jkiss.dbeaver.ext.hive.model.HiveTable) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 3 with HiveTable

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);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) HiveTableColumn(org.jkiss.dbeaver.ext.hive.model.HiveTableColumn) GenericTableColumn(org.jkiss.dbeaver.ext.generic.model.GenericTableColumn) HiveTable(org.jkiss.dbeaver.ext.hive.model.HiveTable) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 4 with HiveTable

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);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) HiveTableColumn(org.jkiss.dbeaver.ext.hive.model.HiveTableColumn) GenericTableColumn(org.jkiss.dbeaver.ext.generic.model.GenericTableColumn) HiveTable(org.jkiss.dbeaver.ext.hive.model.HiveTable) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Aggregations

HiveTable (org.jkiss.dbeaver.ext.hive.model.HiveTable)4 SQLDatabasePersistAction (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)4 DBException (org.jkiss.dbeaver.DBException)2 GenericTableColumn (org.jkiss.dbeaver.ext.generic.model.GenericTableColumn)2 HiveTableColumn (org.jkiss.dbeaver.ext.hive.model.HiveTableColumn)2