Search in sources :

Example 1 with HiveIndex

use of org.jkiss.dbeaver.ext.hive.model.HiveIndex in project dbeaver by dbeaver.

the class HiveIndexManager method addObjectCreateActions.

@Override
protected void addObjectCreateActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectCreateCommand command, Map<String, Object> options) {
    HiveIndex tableIndex = (HiveIndex) command.getObject();
    DBSIndexType indexType = tableIndex.getIndexType();
    String indexName = tableIndex.getName();
    String tableName = tableIndex.getTable().getName();
    String hiveIndexType;
    List<GenericTableIndexColumn> indexColumns = tableIndex.getAttributeReferences(monitor);
    if (indexType.getId().equals("COMPACT")) {
        hiveIndexType = "\'COMPACT\'";
    } else {
        hiveIndexType = "\'BITMAP\'";
    }
    StringBuilder ddl = new StringBuilder();
    ddl.append("CREATE INDEX ").append(indexName).append(" ON TABLE ").append(tableName).append(" (");
    if (indexColumns != null) {
        for (int i = 0; i < indexColumns.size(); i++) {
            if (i == 0) {
                ddl.append(DBUtils.getQuotedIdentifier(indexColumns.get(i)));
            } else {
                ddl.append(", ").append(DBUtils.getQuotedIdentifier(indexColumns.get(i)));
            }
        }
    }
    ddl.append(") AS ").append(hiveIndexType).append(" WITH DEFERRED REBUILD");
    actions.add(new SQLDatabasePersistAction("Create table index", ddl.toString()));
    actions.add(new SQLDatabasePersistAction("ALTER INDEX " + indexName + " ON " + tableName + " REBUILD"));
}
Also used : DBSIndexType(org.jkiss.dbeaver.model.struct.rdb.DBSIndexType) HiveIndex(org.jkiss.dbeaver.ext.hive.model.HiveIndex) GenericTableIndexColumn(org.jkiss.dbeaver.ext.generic.model.GenericTableIndexColumn) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 2 with HiveIndex

use of org.jkiss.dbeaver.ext.hive.model.HiveIndex in project dbeaver by serge-rider.

the class HiveIndexManager method addObjectCreateActions.

@Override
protected void addObjectCreateActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectCreateCommand command, Map<String, Object> options) {
    HiveIndex tableIndex = (HiveIndex) command.getObject();
    DBSIndexType indexType = tableIndex.getIndexType();
    String indexName = tableIndex.getName();
    String tableName = tableIndex.getTable().getName();
    String hiveIndexType;
    List<GenericTableIndexColumn> indexColumns = tableIndex.getAttributeReferences(monitor);
    if (indexType.getId().equals("COMPACT")) {
        hiveIndexType = "\'COMPACT\'";
    } else {
        hiveIndexType = "\'BITMAP\'";
    }
    StringBuilder ddl = new StringBuilder();
    ddl.append("CREATE INDEX ").append(indexName).append(" ON TABLE ").append(tableName).append(" (");
    if (indexColumns != null) {
        for (int i = 0; i < indexColumns.size(); i++) {
            if (i == 0) {
                ddl.append(DBUtils.getQuotedIdentifier(indexColumns.get(i)));
            } else {
                ddl.append(", ").append(DBUtils.getQuotedIdentifier(indexColumns.get(i)));
            }
        }
    }
    ddl.append(") AS ").append(hiveIndexType).append(" WITH DEFERRED REBUILD");
    actions.add(new SQLDatabasePersistAction("Create table index", ddl.toString()));
    actions.add(new SQLDatabasePersistAction("ALTER INDEX " + indexName + " ON " + tableName + " REBUILD"));
}
Also used : DBSIndexType(org.jkiss.dbeaver.model.struct.rdb.DBSIndexType) HiveIndex(org.jkiss.dbeaver.ext.hive.model.HiveIndex) GenericTableIndexColumn(org.jkiss.dbeaver.ext.generic.model.GenericTableIndexColumn) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Aggregations

GenericTableIndexColumn (org.jkiss.dbeaver.ext.generic.model.GenericTableIndexColumn)2 HiveIndex (org.jkiss.dbeaver.ext.hive.model.HiveIndex)2 SQLDatabasePersistAction (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)2 DBSIndexType (org.jkiss.dbeaver.model.struct.rdb.DBSIndexType)2