private String concat(final String fieldPrefix, final RecordField field) { return fieldPrefix + "/" + field.getFieldName(); } }
private Record createRecord(final AnonymousIpResponse anonymousIp) { if (anonymousIp == null) { return null; } final Map<String, Object> values = new HashMap<>(5); values.put(AnonymousIpSchema.ANONYMOUS.getFieldName(), anonymousIp.isAnonymous()); values.put(AnonymousIpSchema.ANONYMOUS_VPN.getFieldName(), anonymousIp.isAnonymousVpn()); values.put(AnonymousIpSchema.HOSTING_PROVIDER.getFieldName(), anonymousIp.isHostingProvider()); values.put(AnonymousIpSchema.PUBLIC_PROXY.getFieldName(), anonymousIp.isPublicProxy()); values.put(AnonymousIpSchema.TOR_EXIT_NODE.getFieldName(), anonymousIp.isTorExitNode()); return new MapRecord(AnonymousIpSchema.ANONYMOUS_IP_SCHEMA, values); }
private Record createRecord(final IspResponse isp) { if (isp == null) { return null; } final Map<String, Object> values = new HashMap<>(4); values.put(IspSchema.ASN.getFieldName(), isp.getAutonomousSystemNumber()); values.put(IspSchema.ASN_ORG.getFieldName(), isp.getAutonomousSystemOrganization()); values.put(IspSchema.NAME.getFieldName(), isp.getIsp()); values.put(IspSchema.ORG.getFieldName(), isp.getOrganization()); return new MapRecord(IspSchema.ISP_SCHEMA, values); }
public static String getHiveSchema(RecordSchema recordSchema, boolean hiveFieldNames) throws IllegalArgumentException { List<RecordField> recordFields = recordSchema.getFields(); if (recordFields != null) { List<String> hiveFields = new ArrayList<>(recordFields.size()); recordFields.forEach(recordField -> { hiveFields.add((hiveFieldNames ? recordField.getFieldName().toLowerCase() : recordField.getFieldName()) + ":" + getHiveTypeFromFieldType(recordField.getDataType(), hiveFieldNames)); }); return "STRUCT<" + StringUtils.join(hiveFields, ", ") + ">"; } return null; }
private JsonNode getChildNode(final JsonNode jsonNode, final RecordField field) { if (jsonNode.has(field.getFieldName())) { return jsonNode.get(field.getFieldName()); } for (final String alias : field.getAliases()) { if (jsonNode.has(alias)) { return jsonNode.get(alias); } } return null; }
private Record createRecord(final Subdivision subdivision) { if (subdivision == null) { return null; } final Map<String, Object> values = new HashMap<>(2); values.put(CitySchema.SUBDIVISION_NAME.getFieldName(), subdivision.getName()); values.put(CitySchema.SUBDIVISION_ISO.getFieldName(), subdivision.getIsoCode()); return new MapRecord(CitySchema.SUBDIVISION_SCHEMA, values); }
private Record createRecord(final Country country) { if (country == null) { return null; } final Map<String, Object> values = new HashMap<>(2); values.put(CitySchema.COUNTRY_NAME.getFieldName(), country.getName()); values.put(CitySchema.COUNTRY_ISO.getFieldName(), country.getIsoCode()); return new MapRecord(CitySchema.COUNTRY_SCHEMA, values); }
private JsonNode getChildNode(final JsonNode jsonNode, final RecordField field) { if (jsonNode.has(field.getFieldName())) { return jsonNode.get(field.getFieldName()); } for (final String alias : field.getAliases()) { if (jsonNode.has(alias)) { return jsonNode.get(alias); } } return null; }
private List<String> getColumnNames(final RecordSchema schema) { final List<String> columnNames = new ArrayList<>(); for (final RecordField field : schema.getFields()) { columnNames.add(field.getFieldName()); for (final String alias : field.getAliases()) { columnNames.add(alias); } } return columnNames; }
private boolean isFieldPresent(final RecordField field, final Record record) { final Set<String> rawFieldNames = record.getRawFieldNames(); if (rawFieldNames.contains(field.getFieldName())) { return true; } for (final String alias : field.getAliases()) { if (rawFieldNames.contains(alias)) { return true; } } return false; }
public static TypeInfo getOrcSchema(RecordSchema recordSchema, boolean hiveFieldNames) throws IllegalArgumentException { List<RecordField> recordFields = recordSchema.getFields(); if (recordFields != null) { List<String> orcFieldNames = new ArrayList<>(recordFields.size()); List<TypeInfo> orcFields = new ArrayList<>(recordFields.size()); recordFields.forEach(recordField -> { String fieldName = hiveFieldNames ? recordField.getFieldName().toLowerCase() : recordField.getFieldName(); orcFieldNames.add(fieldName); orcFields.add(getOrcField(recordField.getDataType(), hiveFieldNames)); }); return TypeInfoFactory.getStructTypeInfo(orcFieldNames, orcFields); } return null; }
private boolean recordHasField(RecordField field, Record record) { Set<String> recordFieldNames = record.getRawFieldNames(); if (recordFieldNames.contains(field.getFieldName())) { return true; } for (String alias : field.getAliases()) { if (recordFieldNames.contains(alias)) { return true; } } return false; } }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } RecordField other = (RecordField) obj; return dataType.equals(other.getDataType()) && fieldName.equals(other.getFieldName()) && aliases.equals(other.getAliases()) && Objects.equals(defaultValue, other.defaultValue) && nullable == other.nullable; }
private Optional<RecordField> resolveField(final RecordField field) { Optional<RecordField> resolved = schema.getField(field.getFieldName()); if (resolved.isPresent()) { return resolved; } for (final String alias : field.getAliases()) { resolved = schema.getField(alias); if (resolved.isPresent()) { return resolved; } } return Optional.empty(); }
protected Record createRecord(final ResultSet rs) throws SQLException { final Map<String, Object> values = new HashMap<>(schema.getFieldCount()); for (final RecordField field : schema.getFields()) { final String fieldName = field.getFieldName(); final Object value; if (rsColumnNames.contains(fieldName)) { value = normalizeValue(rs.getObject(fieldName)); } else { value = null; } values.put(fieldName, value); } return new MapRecord(schema, values); }
@Override public Stream<FieldValue> evaluate(final RecordPathEvaluationContext context) { final Stream<FieldValue> fieldValues = recordPath.evaluate(context); return fieldValues.map(fv -> new StandardFieldValue(fv.getField().getFieldName(), fv.getField(), fv.getParent().orElse(null))); }
@Override public void updateValue(final Object newValue) { getParentRecord().get().setMapValue(getField().getFieldName(), getMapKey(), newValue); }
@Override public void updateValue(final Object newValue) { getParentRecord().get().setArrayValue(getField().getFieldName(), getArrayIndex(), newValue); }
private static Field buildAvroField(final RecordField recordField) { final Schema schema = buildAvroSchema(recordField.getDataType(), recordField.getFieldName(), recordField.isNullable()); final Field field = new Field(recordField.getFieldName(), schema, null, recordField.getDefaultValue()); for (final String alias : recordField.getAliases()) { field.addAlias(alias); } return field; }
@Override public Stream<FieldValue> evaluate(final RecordPathEvaluationContext context) { final Stream<FieldValue> parentResult = getParentPath().evaluate(context); return parentResult .filter(Filters.fieldTypeFilter(RecordFieldType.MAP)) .map(fieldValue -> { final DataType valueType = ((MapDataType) fieldValue.getField().getDataType()).getValueType(); final RecordField elementField = new RecordField(fieldValue.getField().getFieldName(), valueType); return new MapEntryFieldValue(getMapValue(fieldValue), elementField, fieldValue, mapKey); }); }