if (entry == null) { if (FieldType.isCompound(field.type())) { if (!previousField.type().equals(field.type())) { if (!previousField.type().equals(resolvedType)) { previousField = new Field(previousField.name(), resolvedType, previousField.properties()); entry[0] = previousField; if (FieldType.isCompound(field.type())) { Map<String, Object[]> subTable = (Map<String, Object[]>)entry[1]; String prefix = fullName + ".";
fieldType = FieldType.parse(type.toString()); if (FieldType.isRelevant(fieldType)) { if (!FieldType.isCompound(fieldType)) { return new Field(key, fieldType);
public static FieldType parse(String name) { if (name == null) { return null; } String n = name.toUpperCase(Locale.ENGLISH); return (KNOWN_TYPES.contains(n) ? FieldType.valueOf(n) : null); }
@SuppressWarnings("unchecked") private static Field[] collapseFields(Map<String, Object[]> fieldTable) { List<Field> fields = new ArrayList<Field>(); for (Map.Entry<String, Object[]> fieldInfo : fieldTable.entrySet()) { Field currentField = (Field)(fieldInfo.getValue()[0]); if (FieldType.isCompound(currentField.type())) { Map<String, Object[]> subTable = (Map<String, Object[]>)(fieldInfo.getValue()[1]); Field[] children = collapseFields(subTable); fields.add(new Field(currentField.name(), currentField.type(), children)); } else { fields.add(currentField); } } return fields.size() == 0 ? Field.NO_FIELDS : fields.toArray(new Field[fields.size()]); }
if ((esType != null && esType.equals(FieldType.NESTED)) || isArrayField(fieldMapping)) {
if (FieldType.isGeo(mapping(fieldMapping, parser))) { toggleGeo = true; insideGeo = true;
private static FieldType resolveTypeConflict(String fullName, FieldType existing, FieldType incoming) { // Prefer to upcast the incoming field to the existing first LinkedHashSet<FieldType> incomingSuperTypes = incoming.getCastingTypes(); if (incomingSuperTypes.contains(existing)) { // Incoming can be cast to existing. return existing; } // See if existing can be upcast to the incoming field's type next LinkedHashSet<FieldType> existingSuperTypes = existing.getCastingTypes(); if (existingSuperTypes.contains(incoming)) { // Existing can be cast to incoming return incoming; } // Finally, Try to pick the lowest common super type for both fields if it exists if (incomingSuperTypes.size() > 0 && existingSuperTypes.size() > 0) { LinkedHashSet<FieldType> combined = new LinkedHashSet<FieldType>(incomingSuperTypes); combined.retainAll(existingSuperTypes); if (combined.size() > 0) { return combined.iterator().next(); } } // If none of the above options succeed, the fields are conflicting throw new EsHadoopIllegalArgumentException("Incompatible types found in multi-mapping: " + "Field ["+fullName+"] has conflicting types of ["+existing+"] and ["+ incoming+"]."); }
private static void addSubFieldToMap(Map<String, FieldType> fields, Field field, String parentName) { String fieldName = (parentName != null ? parentName + "." + field.name() : field.name()); fields.put(fieldName, field.type()); if (FieldType.isCompound(field.type())) { for (Field nestedField : field.properties()) { addSubFieldToMap(fields, nestedField, fieldName); } } }
private static Field skipHeaders(Field field) { Field[] props = field.properties(); // handle the common case of mapping by removing the first field (mapping.) if (props.length > 0 && props[0] != null && "mappings".equals(props[0].name()) && FieldType.OBJECT.equals(props[0].type())) { // can't return the type as it is an object of properties return props[0].properties()[0]; } return field; }
if (FieldType.isGeo(mapping(fieldMapping))) { toggleGeo = true; insideGeo = true;
private static FieldType resolveTypeConflict(String fullName, FieldType existing, FieldType incoming) { // Prefer to upcast the incoming field to the existing first LinkedHashSet<FieldType> incomingSuperTypes = incoming.getCastingTypes(); if (incomingSuperTypes.contains(existing)) { // Incoming can be cast to existing. return existing; } // See if existing can be upcast to the incoming field's type next LinkedHashSet<FieldType> existingSuperTypes = existing.getCastingTypes(); if (existingSuperTypes.contains(incoming)) { // Existing can be cast to incoming return incoming; } // Finally, Try to pick the lowest common super type for both fields if it exists if (incomingSuperTypes.size() > 0 && existingSuperTypes.size() > 0) { LinkedHashSet<FieldType> combined = new LinkedHashSet<FieldType>(incomingSuperTypes); combined.retainAll(existingSuperTypes); if (combined.size() > 0) { return combined.iterator().next(); } } // If none of the above options succeed, the fields are conflicting throw new EsHadoopIllegalArgumentException("Incompatible types found in multi-mapping: " + "Field ["+fullName+"] has conflicting types of ["+existing+"] and ["+ incoming+"]."); }
for (Entry<String, Object> subfield : fields.entrySet()) { Map<String, Object> subFieldDef = (Map<String, Object>) subfield.getValue(); FieldType subFieldType = FieldType.parse(subFieldDef.get("type").toString()); if (defaultType != null) { if (defaultType != subFieldType) { defaultType = FieldType.parse(defaultField.get("type").toString()); fieldType = FieldType.parse(type.toString()); if (FieldType.isRelevant(fieldType)) { if (!FieldType.isCompound(fieldType)) { return new Field(key, fieldType);
private static void findGeo(Field field, String parentName, Map<String, GeoType> geoFields) { String fieldName = (parentName != null ? parentName + "." + field.name() : field.name()); if (FieldType.GEO_POINT == field.type()) { geoFields.put(fieldName, GeoType.GEO_POINT); } else if (FieldType.GEO_SHAPE == field.type()) { geoFields.put(fieldName, GeoType.GEO_SHAPE); } else if (FieldType.isCompound(field.type())) { for (Field nestedField : field.properties()) { findGeo(nestedField, fieldName, geoFields); } } }
if (entry == null) { if (FieldType.isCompound(field.type())) { if (!previousField.type().equals(field.type())) { if (!previousField.type().equals(resolvedType)) { previousField = new Field(previousField.name(), resolvedType, previousField.properties()); entry[0] = previousField; if (FieldType.isCompound(field.type())) { Map<String, Object[]> subTable = (Map<String, Object[]>)entry[1]; String prefix = fullName + ".";
private static Field skipHeaders(Field field) { Field[] props = field.properties(); // handle the common case of mapping by removing the first field (mapping.) if (props.length > 0 && props[0] != null && "mappings".equals(props[0].name()) && FieldType.OBJECT.equals(props[0].type())) { // can't return the type as it is an object of properties return props[0].properties()[0]; } return field; }
public static FieldType parse(String name) { if (name == null) { return null; } String n = name.toUpperCase(Locale.ENGLISH); return (KNOWN_TYPES.contains(n) ? FieldType.valueOf(n) : null); }
if (FieldType.isGeo(mapping(fieldMapping, parser))) { toggleGeo = true; insideGeo = true;
private static FieldType resolveTypeConflict(String fullName, FieldType existing, FieldType incoming) { // Prefer to upcast the incoming field to the existing first LinkedHashSet<FieldType> incomingSuperTypes = incoming.getCastingTypes(); if (incomingSuperTypes.contains(existing)) { // Incoming can be cast to existing. return existing; } // See if existing can be upcast to the incoming field's type next LinkedHashSet<FieldType> existingSuperTypes = existing.getCastingTypes(); if (existingSuperTypes.contains(incoming)) { // Existing can be cast to incoming return incoming; } // Finally, Try to pick the lowest common super type for both fields if it exists if (incomingSuperTypes.size() > 0 && existingSuperTypes.size() > 0) { LinkedHashSet<FieldType> combined = new LinkedHashSet<FieldType>(incomingSuperTypes); combined.retainAll(existingSuperTypes); if (combined.size() > 0) { return combined.iterator().next(); } } // If none of the above options succeed, the fields are conflicting throw new EsHadoopIllegalArgumentException("Incompatible types found in multi-mapping: " + "Field ["+fullName+"] has conflicting types of ["+existing+"] and ["+ incoming+"]."); }
fieldType = FieldType.parse(type.toString()); if (FieldType.isRelevant(fieldType)) { if (!FieldType.isCompound(fieldType)) { return new Field(key, fieldType);
private static boolean filterField(Field field, String parentName, List<Field> filtered, Collection<FieldFilter.NumberedInclude> includes, Collection<String> excludes) { String fieldName = (parentName != null ? parentName + "." + field.name() : field.name()); boolean intact = true; if (FieldFilter.filter(fieldName, includes, excludes).matched) { if (FieldType.isCompound(field.type())) { List<Field> nested = new ArrayList<Field>(); for (Field nestedField : field.properties()) { intact &= filterField(nestedField, fieldName, nested, includes, excludes); } filtered.add(new Field(field.name(), field.type(), nested)); } else { filtered.add(field); } } else { intact = false; } return intact; }