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 = objectTypeInfo.getListElementTypeInfo();
}
if (objectTypeInfo.getCategory() != Category.STRUCT) {
throw new SemanticException(ErrorMsg.INVALID_DOT.getMsg(expr));
}
TypeInfo t = 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 constant integer index for now
if (!(children.get(1) instanceof exprNodeConstantDesc)
|| !(((exprNodeConstantDesc)children.get(1)).getValue() instanceof Integer)) {
throw new SemanticException(ErrorMsg.INVALID_ARRAYINDEX_CONSTANT.getMsg(expr));
}
// Calculate TypeInfo
TypeInfo t = myt.getListElementTypeInfo();
desc = new exprNodeIndexDesc(t, children.get(0), children.get(1));
}
else if (myt.getCategory() == Category.MAP) {
// Only allow only constant indexes for now
if (!(children.get(1) instanceof exprNodeConstantDesc)) {
throw new SemanticException(ErrorMsg.INVALID_MAPINDEX_CONSTANT.getMsg(expr));
}
if (!(((exprNodeConstantDesc)children.get(1)).getValue().getClass() ==
myt.getMapKeyTypeInfo().getPrimitiveClass())) {
throw new SemanticException(ErrorMsg.INVALID_MAPINDEX_TYPE.getMsg(expr));
}
// Calculate TypeInfo
TypeInfo t = myt.getMapValueTypeInfo();
desc = new exprNodeIndexDesc(t, children.get(0), children.get(1));
}
else {
throw new SemanticException(ErrorMsg.NON_COLLECTION_TYPE.getMsg(expr));