ExprNodeConstantDesc fieldName = (ExprNodeConstantDesc) children.get(1);
assert (fieldName.getValue() instanceof String);
// Calculate result TypeInfo
String fieldNameString = (String) fieldName.getValue();
TypeInfo objectTypeInfo = object.getTypeInfo();
// Allow accessing a field of list element structs directly from a list
boolean isList = (object.getTypeInfo().getCategory() == ObjectInspector.Category.LIST);
if (isList) {
objectTypeInfo = ((ListTypeInfo) objectTypeInfo)
.getListElementTypeInfo();
}
if (objectTypeInfo.getCategory() != Category.STRUCT) {
throw new SemanticException(ErrorMsg.INVALID_DOT.getMsg(expr));
}
TypeInfo t = ((StructTypeInfo) objectTypeInfo)
.getStructFieldTypeInfo(fieldNameString);
if (isList) {
t = TypeInfoFactory.getListTypeInfo(t);
}
desc = new ExprNodeFieldDesc(t, children.get(0), fieldNameString,
isList);
} else if (funcText.equals("[")) {
// "[]" : LSQUARE/INDEX Expression
assert (children.size() == 2);
// Check whether this is a list or a map
TypeInfo myt = children.get(0).getTypeInfo();
if (myt.getCategory() == Category.LIST) {
// Only allow integer index for now
if (!(children.get(1) instanceof ExprNodeConstantDesc)
|| !(((ExprNodeConstantDesc) children.get(1)).getTypeInfo()
.equals(TypeInfoFactory.intTypeInfo))) {
throw new SemanticException(SemanticAnalyzer.generateErrorMessage(
expr,
ErrorMsg.INVALID_ARRAYINDEX_CONSTANT.getMsg()));
}
// Calculate TypeInfo
TypeInfo t = ((ListTypeInfo) myt).getListElementTypeInfo();
desc = new ExprNodeGenericFuncDesc(t, FunctionRegistry
.getGenericUDFForIndex(), children);
} else if (myt.getCategory() == Category.MAP) {
// Only allow constant map key for now
if (!(children.get(1) instanceof ExprNodeConstantDesc)) {
throw new SemanticException(SemanticAnalyzer.generateErrorMessage(
expr,
ErrorMsg.INVALID_MAPINDEX_CONSTANT.getMsg()));
}
if (!(((ExprNodeConstantDesc) children.get(1)).getTypeInfo()
.equals(((MapTypeInfo) myt).getMapKeyTypeInfo()))) {
throw new SemanticException(ErrorMsg.INVALID_MAPINDEX_TYPE
.getMsg(expr));
}
// Calculate TypeInfo
TypeInfo t = ((MapTypeInfo) myt).getMapValueTypeInfo();
desc = new ExprNodeGenericFuncDesc(t, FunctionRegistry
.getGenericUDFForIndex(), children);
} else {
throw new SemanticException(ErrorMsg.NON_COLLECTION_TYPE.getMsg(expr,
myt.getTypeName()));