Java Code Examples for org.elasticsearch.hadoop.mr.LinkedMapWritable#get()
The following examples show how to use
org.elasticsearch.hadoop.mr.LinkedMapWritable#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HadoopFormatIOElasticTest.java From beam with Apache License 2.0 | 4 votes |
@Override public String apply(LinkedMapWritable mapw) { return mapw.get(new Text("id")) + "|" + mapw.get(new Text("scientist")); }
Example 2
Source File: UtilES.java From deep-spark with Apache License 2.0 | 4 votes |
/** * converts from JSONObject to an entity class with deep's anotations * * @param classEntity the entity name. * @param jsonObject the instance of the JSONObject to convert. * @param <T> return type. * @return the provided JSONObject converted to an instance of T. * @throws IllegalAccessException * @throws InstantiationException * @throws java.lang.reflect.InvocationTargetException */ public static <T> T getObjectFromJson(Class<T> classEntity, LinkedMapWritable jsonObject) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException { T t = classEntity.newInstance(); Field[] fields = AnnotationUtils.filterDeepFields(classEntity); Object insert; for (Field field : fields) { Method method = Utils.findSetter(field.getName(), classEntity, field.getType()); Class<?> classField = field.getType(); String key = AnnotationUtils.deepFieldName(field); Text text = new org.apache.hadoop.io.Text(key); Writable currentJson = jsonObject.get(text); if (currentJson != null) { if (Iterable.class.isAssignableFrom(classField)) { Type type = field.getGenericType(); insert = subDocumentListCase(type, (ArrayWritable) currentJson); method.invoke(t, (insert)); } else if (IDeepType.class.isAssignableFrom(classField)) { insert = getObjectFromJson(classField, (LinkedMapWritable) currentJson); method.invoke(t, (insert)); } else { insert = currentJson; try { method.invoke(t, getObjectFromWritable((Writable) insert)); } catch (Exception e) { LOG.error("impossible to convert field " + t + " :" + field + " error: " + e.getMessage()); method.invoke(t, Utils.castNumberType(getObjectFromWritable((Writable) insert), t.getClass())); } } } } return t; }
Example 3
Source File: UtilESTest.java From deep-spark with Apache License 2.0 | 3 votes |
@Test public void testGetCellFromJson() throws UnknownHostException, NoSuchFieldException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException { LinkedMapWritable bson = createJsonTest(); Cells cells = UtilES.getCellFromJson(bson, "book"); Map<Writable, Writable> mapMetadata = (Map<Writable, Writable>) bson.get(new Text("metadata")); assertEquals(mapMetadata.get(new Text("author")).toString(), ((Cells) cells.getCellByName("metadata").getCellValue()).getCellByName("author").getCellValue()); assertEquals(mapMetadata.get(new Text("title")).toString(), ((Cells) cells.getCellByName("metadata").getCellValue()).getCellByName("title").getCellValue()); assertEquals(mapMetadata.get(new Text("source")).toString(), ((Cells) cells.getCellByName("metadata").getCellValue()).getCellByName("source").getCellValue()); // Check list Oject List<Cells> list = (List<Cells>) cells.getCellByName("cantos").getCellValue(); LinkedMapWritable[] mapCantos = (LinkedMapWritable[]) ((ArrayWritable) bson.get(new Text("cantos"))).get(); assertEquals(mapCantos[0].get(new Text("canto")).toString(), list.get(0).getCellByName("canto").getCellValue()); assertEquals(mapCantos[0].get(new Text("text")).toString(), list.get(0).getCellByName("text").getCellValue()); assertEquals(mapCantos[1].get(new Text("canto")).toString(), list.get(1).getCellByName("canto").getCellValue()); assertEquals(mapCantos[1].get(new Text("text")).toString(), list.get(1).getCellByName("text").getCellValue()); }