private static Object convertMapStrict( Map<CharSequence, Object> values, org.apache.avro.Schema valueAvroSchema, Schema.FieldType fieldType) { checkTypeName(fieldType.getTypeName(), Schema.TypeName.MAP, "map"); checkNotNull(fieldType.getMapKeyType()); checkNotNull(fieldType.getMapValueType()); if (!fieldType.getMapKeyType().equals(Schema.FieldType.STRING)) { throw new IllegalArgumentException( "Can't convert 'string' map keys to " + fieldType.getMapKeyType()); } Map<Object, Object> ret = new HashMap<>(); for (Map.Entry<CharSequence, Object> value : values.entrySet()) { ret.put( convertStringStrict(value.getKey(), fieldType.getMapKeyType()), convertAvroFieldStrict(value.getValue(), valueAvroSchema, fieldType.getMapValueType())); } return ret; }
checkArgument( schema.getFieldCount() == 1 && schema.getField(0).getType().equals(Schema.FieldType.STRING), "Table with type 'text' and format 'lines' " + "must have exactly one STRING/VARCHAR/CHAR column");
private boolean equivalent(FieldType other) { if (!other.getTypeName().equals(getTypeName())) { return false; } switch (getTypeName()) { case ROW: if (!other.getRowSchema().equivalent(getRowSchema())) { return false; } break; case ARRAY: if (!other.getCollectionElementType().equivalent(getCollectionElementType())) { return false; } break; case MAP: if (!other.getMapKeyType().equivalent(getMapKeyType()) || !other.getMapValueType().equivalent(getMapValueType())) { return false; } break; default: return other.equals(this); } return true; }
private boolean fieldPresent(Schema schema, String field, Schema.FieldType expectedType) { return schema.hasField(field) && expectedType.equals(schema.getField(field).getType()); }