| 188 | } |
| 189 | |
| 190 | private static byte extractTypeFromClass(Type t) { |
| 191 | Class c = (Class)t; |
| 192 | Class[] ioeInterfaces = c.getInterfaces(); |
| 193 | Class[] interfaces = null; |
| 194 | if(c.isInterface()){ |
| 195 | interfaces = new Class[ioeInterfaces.length+1]; |
| 196 | interfaces[0] = c; |
| 197 | for (int i = 1; i < interfaces.length; i++) { |
| 198 | interfaces[i] = ioeInterfaces[i-1]; |
| 199 | } |
| 200 | } else { |
| 201 | interfaces = ioeInterfaces; |
| 202 | } |
| 203 | boolean matchedWritableComparable = false; |
| 204 | for (int i = 0; i < interfaces.length; i++) { |
| 205 | if (interfaces[i].getName().equals("org.apache.pig.data.Tuple")) { |
| 206 | return TUPLE; |
| 207 | } else if (interfaces[i].getName().equals("org.apache.pig.data.DataBag")) { |
| 208 | return BAG; |
| 209 | } else if (interfaces[i].getName().equals("java.util.Map")) { |
| 210 | return MAP; |
| 211 | } else if (interfaces[i].getName().equals("org.apache.hadoop.io.WritableComparable")) { |
| 212 | // use GENERIC_WRITABLECOMPARABLE type only as last resort |
| 213 | matchedWritableComparable = true; |
| 214 | } |
| 215 | } |
| 216 | if(matchedWritableComparable) { |
| 217 | return GENERIC_WRITABLECOMPARABLE; |
| 218 | } |
| 219 | |
| 220 | return ERROR; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Return the number of types Pig knows about. |