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);
}
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();
}
Aggregations