Search in sources :

Example 1 with IndexType

use of org.apache.hadoop.hive.ql.index.HiveIndex.IndexType in project hive by apache.

the class DDLSemanticAnalyzer method analyzeCreateIndex.

private void analyzeCreateIndex(ASTNode ast) throws SemanticException {
    String indexName = unescapeIdentifier(ast.getChild(0).getText());
    String typeName = unescapeSQLString(ast.getChild(1).getText());
    String[] qTabName = getQualifiedTableName((ASTNode) ast.getChild(2));
    List<String> indexedCols = getColumnNames((ASTNode) ast.getChild(3));
    IndexType indexType = HiveIndex.getIndexType(typeName);
    if (indexType != null) {
        typeName = indexType.getHandlerClsName();
    } else {
        try {
            JavaUtils.loadClass(typeName);
        } catch (Exception e) {
            throw new SemanticException("class name provided for index handler not found.", e);
        }
    }
    String indexTableName = null;
    boolean deferredRebuild = false;
    String location = null;
    Map<String, String> tblProps = null;
    Map<String, String> idxProps = null;
    String indexComment = null;
    RowFormatParams rowFormatParams = new RowFormatParams();
    StorageFormat storageFormat = new StorageFormat(conf);
    for (int idx = 4; idx < ast.getChildCount(); idx++) {
        ASTNode child = (ASTNode) ast.getChild(idx);
        if (storageFormat.fillStorageFormat(child)) {
            continue;
        }
        switch(child.getToken().getType()) {
            case HiveParser.TOK_TABLEROWFORMAT:
                rowFormatParams.analyzeRowFormat(child);
                break;
            case HiveParser.TOK_CREATEINDEX_INDEXTBLNAME:
                ASTNode ch = (ASTNode) child.getChild(0);
                indexTableName = getUnescapedName(ch);
                break;
            case HiveParser.TOK_DEFERRED_REBUILDINDEX:
                deferredRebuild = true;
                break;
            case HiveParser.TOK_TABLELOCATION:
                location = unescapeSQLString(child.getChild(0).getText());
                addLocationToOutputs(location);
                break;
            case HiveParser.TOK_TABLEPROPERTIES:
                tblProps = DDLSemanticAnalyzer.getProps((ASTNode) child.getChild(0));
                break;
            case HiveParser.TOK_INDEXPROPERTIES:
                idxProps = DDLSemanticAnalyzer.getProps((ASTNode) child.getChild(0));
                break;
            case HiveParser.TOK_TABLESERIALIZER:
                child = (ASTNode) child.getChild(0);
                storageFormat.setSerde(unescapeSQLString(child.getChild(0).getText()));
                if (child.getChildCount() == 2) {
                    readProps((ASTNode) (child.getChild(1).getChild(0)), storageFormat.getSerdeProps());
                }
                break;
            case HiveParser.TOK_INDEXCOMMENT:
                child = (ASTNode) child.getChild(0);
                indexComment = unescapeSQLString(child.getText());
        }
    }
    storageFormat.fillDefaultStorageFormat(false, false);
    if (indexTableName == null) {
        indexTableName = MetaStoreUtils.getIndexTableName(qTabName[0], qTabName[1], indexName);
        // on same database with base table
        indexTableName = qTabName[0] + "." + indexTableName;
    } else {
        indexTableName = getDotName(Utilities.getDbTableName(indexTableName));
    }
    inputs.add(new ReadEntity(getTable(qTabName)));
    CreateIndexDesc crtIndexDesc = new CreateIndexDesc(getDotName(qTabName), indexName, indexedCols, indexTableName, deferredRebuild, storageFormat.getInputFormat(), storageFormat.getOutputFormat(), storageFormat.getStorageHandler(), typeName, location, idxProps, tblProps, storageFormat.getSerde(), storageFormat.getSerdeProps(), rowFormatParams.collItemDelim, rowFormatParams.fieldDelim, rowFormatParams.fieldEscape, rowFormatParams.lineDelim, rowFormatParams.mapKeyDelim, indexComment);
    Task<?> createIndex = TaskFactory.get(new DDLWork(getInputs(), getOutputs(), crtIndexDesc), conf);
    rootTasks.add(createIndex);
}
Also used : LockException(org.apache.hadoop.hive.ql.lockmgr.LockException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) InvalidTableException(org.apache.hadoop.hive.ql.metadata.InvalidTableException) ReadEntity(org.apache.hadoop.hive.ql.hooks.ReadEntity) CreateIndexDesc(org.apache.hadoop.hive.ql.plan.CreateIndexDesc) DDLWork(org.apache.hadoop.hive.ql.plan.DDLWork) IndexType(org.apache.hadoop.hive.ql.index.HiveIndex.IndexType)

Example 2 with IndexType

use of org.apache.hadoop.hive.ql.index.HiveIndex.IndexType in project hive by apache.

the class MetaDataFormatUtils method getIndexInformation.

public static String getIndexInformation(Index index, boolean isOutputPadded) {
    StringBuilder indexInfo = new StringBuilder(DEFAULT_STRINGBUILDER_SIZE);
    List<String> indexColumns = new ArrayList<String>();
    indexColumns.add(index.getIndexName());
    indexColumns.add(index.getOrigTableName());
    // index key names
    List<FieldSchema> indexKeys = index.getSd().getCols();
    StringBuilder keyString = new StringBuilder();
    boolean first = true;
    for (FieldSchema key : indexKeys) {
        if (!first) {
            keyString.append(", ");
        }
        keyString.append(key.getName());
        first = false;
    }
    indexColumns.add(keyString.toString());
    indexColumns.add(index.getIndexTableName());
    // index type
    String indexHandlerClass = index.getIndexHandlerClass();
    IndexType indexType = HiveIndex.getIndexTypeByClassName(indexHandlerClass);
    indexColumns.add(indexType.getName());
    String comment = index.getParameters().get("comment");
    indexColumns.add(comment == null ? null : HiveStringUtils.escapeJava(comment));
    formatOutput(indexColumns.toArray(new String[0]), indexInfo, isOutputPadded);
    return indexInfo.toString();
}
Also used : FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) ArrayList(java.util.ArrayList) IndexType(org.apache.hadoop.hive.ql.index.HiveIndex.IndexType)

Aggregations

IndexType (org.apache.hadoop.hive.ql.index.HiveIndex.IndexType)2 FileNotFoundException (java.io.FileNotFoundException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 ReadEntity (org.apache.hadoop.hive.ql.hooks.ReadEntity)1 LockException (org.apache.hadoop.hive.ql.lockmgr.LockException)1 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)1 InvalidTableException (org.apache.hadoop.hive.ql.metadata.InvalidTableException)1 CreateIndexDesc (org.apache.hadoop.hive.ql.plan.CreateIndexDesc)1 DDLWork (org.apache.hadoop.hive.ql.plan.DDLWork)1