Refine search
/* package private */void compareMapTypes(Schema oldSchema, Schema newSchema, List<Message> messages, String name) { if(oldSchema == null || newSchema == null || oldSchema.getType() != Schema.Type.MAP) { throw new IllegalArgumentException("Old schema must be MAP type. Name=" + name + ". Type=" + oldSchema); } if(newSchema.getType() != Schema.Type.MAP) { messages.add(new Message(Level.ERROR, "Illegal type change from " + oldSchema.getType() + " to " + newSchema.getType() + " for field " + name)); return; } // Compare the array element types compareTypes(oldSchema.getValueType(), newSchema.getValueType(), messages, name + ".<map element>"); }
switch (schema.getType()) { case RECORD: queue.add(schema); break; case MAP: enqueue(schema.getValueType()); break; case ARRAY: enqueue(schema.getElementType()); break; case UNION:
/** * Check if schemas are equals to each other. * * @param s1 the schema one * @param s2 the schema two * @return boolean 'true' if the input schemas are equals */ public static boolean isEqualSchemas(Schema s1, Schema s2) { if (!(s1.getType().equals(s2.getType()) && s1.getFullName().equals(s2.getFullName()))) { return false; } switch (s1.getType()) { case RECORD: return isEqualRecords(s1, s2); case UNION: return isEqualUnions(s1, s2); case ARRAY: return isEqualSchemas(s1.getElementType(), s2.getElementType()); case MAP: return isEqualSchemas(s1.getValueType(), s2.getValueType()); case ENUM: return isEqualEnums(s1, s2); case FIXED: return s1.getFixedSize() == s2.getFixedSize(); default: return true; } }
public RuntimeMonitorClient(HttpRequestConfig requestConfig, KeyStore keyStore, KeyStore trustStore, Supplier<InetSocketAddress> serverAddressSupplier, Proxy proxy) { this.requestConfig = requestConfig; this.httpsEnabler = new HttpsEnabler().setKeyStore(keyStore, ""::toCharArray).setTrustStore(trustStore); this.responseDatumReader = new GenericDatumReader<>( MonitorSchemas.V1.MonitorResponse.SCHEMA.getValueType().getElementType()); this.serverAddressSupplier = serverAddressSupplier; this.proxy = proxy; }
aliases.put(alias, namedSchema.name); switch (schema.getType()) { case RECORD: if (seen.containsKey(schema)) return; // break loops break; case ARRAY: getAliases(schema.getElementType(), seen, aliases, fieldAliases); break; case MAP: getAliases(schema.getValueType(), seen, aliases, fieldAliases); break; case UNION:
switch (avroSchema.getType()) { case INT: { final LogicalType logicalType = avroSchema.getLogicalType(); final Object[] valueArray = new Object[list.size()]; for (int i = 0; i < list.size(); i++) { final Schema elementSchema = avroSchema.getElementType(); valueArray[i] = normalizeValue(list.get(i), elementSchema, fieldName + "[" + i + "]"); final Object[] valueArray = new Object[array.size()]; for (int i = 0; i < array.size(); i++) { final Schema elementSchema = avroSchema.getElementType(); valueArray[i] = normalizeValue(array.get(i), elementSchema, fieldName + "[" + i + "]"); obj = normalizeValue(obj, avroSchema.getValueType(), fieldName + "[" + key + "]");
public MapConverter(String fieldName, boolean nullable, String sourceType, Schema schemaNode, WorkUnitState state, List<String> ignoreFields) throws UnsupportedDateTypeException { super(fieldName, nullable, sourceType); super.setElementConverter( getConvertor(fieldName, schemaNode.getValueType().getType().getName(), schemaNode.getValueType(), state, isNullable(), ignoreFields)); }
public RuntimeMonitorClient(HttpRequestConfig requestConfig, KeyStore keyStore, KeyStore trustStore, Supplier<InetSocketAddress> serverAddressSupplier, Proxy proxy) { this.requestConfig = requestConfig; this.httpsEnabler = new HttpsEnabler().setKeyStore(keyStore, ""::toCharArray).setTrustStore(trustStore); this.responseDatumReader = new GenericDatumReader<>( MonitorSchemas.V1.MonitorResponse.SCHEMA.getValueType().getElementType()); this.serverAddressSupplier = serverAddressSupplier; this.proxy = proxy; }
private boolean isCustomCodable(Schema schema, Set<Schema> seen) { if (! seen.add(schema)) return true; if (schema.getLogicalType() != null) return false; boolean result = true; switch (schema.getType()) { case RECORD: for (Schema.Field f : schema.getFields()) result &= isCustomCodable(f.schema(), seen); break; case MAP: result = isCustomCodable(schema.getValueType(), seen); break; case ARRAY: result = isCustomCodable(schema.getElementType(), seen); break; case UNION: List<Schema> types = schema.getTypes(); // Only know how to handle "nulling" unions for now if (types.size() != 2 || ! types.contains(NULL_SCHEMA)) return false; for (Schema s : types) result &= isCustomCodable(s, seen); break; default: } return result; }
switch (sc.getType()) { case NULL: case BOOLEAN: case ARRAY: return Symbol.seq(Symbol.repeat(Symbol.ARRAY_END, Symbol.ITEM_END, generate(sc.getElementType(), seen)), Symbol.ARRAY_START); case MAP: return Symbol.seq(Symbol.repeat(Symbol.MAP_END, Symbol.ITEM_END, generate(sc.getValueType(), seen), Symbol.MAP_KEY_MARKER, Symbol.STRING), Symbol.MAP_START);
/** * Helper method that does the actual work for {@link #getField(Schema, String)} * @param schema passed from {@link #getFieldSchema(Schema, String)} * @param pathList passed from {@link #getFieldSchema(Schema, String)} * @param field keeps track of the index used to access the list pathList * @return the field */ private static Optional<Field> getFieldHelper(Schema schema, List<String> pathList, int field) { Field curField = schema.getField(pathList.get(field)); if (field + 1 == pathList.size()) { return Optional.fromNullable(curField); } Schema fieldSchema = curField.schema(); switch (fieldSchema.getType()) { case UNION: throw new AvroRuntimeException("Union of complex types cannot be handled : " + schema); case MAP: return AvroUtils.getFieldHelper(fieldSchema.getValueType(), pathList, ++field); case RECORD: return AvroUtils.getFieldHelper(fieldSchema, pathList, ++field); default: throw new AvroRuntimeException("Invalid type in schema : " + schema); } }
/** * Decode monitor messages from decoder * @param decoder Decoder to decode messages * @return list of decoded monitor messages * @throws IOException if failed to decode the message */ private Deque<MonitorMessage> decodeMessages(Decoder decoder) throws IOException { Deque<MonitorMessage> decodedMessages = new LinkedList<>(); long messages = decoder.readArrayStart(); while (messages > 0) { GenericRecord reuse = new GenericData.Record(MonitorSchemas.V1.MonitorResponse.SCHEMA.getValueType() .getElementType()); for (int j = 0; j < messages; j++) { reuse = responseDatumReader.read(reuse, decoder); decodedMessages.add(new MonitorMessage(reuse)); } messages = decoder.arrayNext(); } return decodedMessages; }
aliases.put(alias, namedSchema.name); switch (schema.getType()) { case RECORD: if (seen.containsKey(schema)) return; // break loops break; case ARRAY: getAliases(schema.getElementType(), seen, aliases, fieldAliases); break; case MAP: getAliases(schema.getValueType(), seen, aliases, fieldAliases); break; case UNION:
switch (sc.getType()) { case NULL: case BOOLEAN: case ARRAY: return Symbol.seq(Symbol.repeat(Symbol.ARRAY_END, Symbol.ITEM_END, generate(sc.getElementType(), seen)), Symbol.ARRAY_START); case MAP: return Symbol.seq(Symbol.repeat(Symbol.MAP_END, Symbol.ITEM_END, generate(sc.getValueType(), seen), Symbol.MAP_KEY_MARKER, Symbol.STRING), Symbol.MAP_START);
/** * Generate a TypeInfo for an Avro Map. This is made slightly simpler in that * Avro only allows maps with strings for keys. */ private static TypeInfo generateMapTypeInfo(Schema schema, Set<Schema> seenSchemas) throws AvroSerdeException { assert schema.getType().equals(Schema.Type.MAP); Schema valueType = schema.getValueType(); TypeInfo ti = generateTypeInfo(valueType, seenSchemas); return TypeInfoFactory.getMapTypeInfo(TypeInfoFactory.getPrimitiveTypeInfo("string"), ti); }
/** * Decode monitor messages from decoder * @param decoder Decoder to decode messages * @return list of decoded monitor messages * @throws IOException if failed to decode the message */ private Deque<MonitorMessage> decodeMessages(Decoder decoder) throws IOException { Deque<MonitorMessage> decodedMessages = new LinkedList<>(); long messages = decoder.readArrayStart(); while (messages > 0) { GenericRecord reuse = new GenericData.Record(MonitorSchemas.V1.MonitorResponse.SCHEMA.getValueType() .getElementType()); for (int j = 0; j < messages; j++) { reuse = responseDatumReader.read(reuse, decoder); decodedMessages.add(new MonitorMessage(reuse)); } messages = decoder.arrayNext(); } return decodedMessages; }
private static Appendable build(Map<String,String> env, Schema s, Appendable o) throws IOException { boolean firstTime = true; Schema.Type st = s.getType(); switch (st) { default: // boolean, bytes, double, float, int, long, null, string o.append("{\"type\":\"").append(st.getName()).append("\""); if (st == Schema.Type.ARRAY) build(env, s.getElementType(), o.append(",\"items\":")); else build(env, s.getValueType(), o.append(",\"values\":")); return o.append("}");
switch (schema.getType()) { case ARRAY: flattenedSchema = Schema.createArray(flatten(schema.getElementType(), false)); } else { flattenedSchema = Schema.createArray(schema.getElementType()); flattenedSchema = Schema.create(schema.getType()); break; case BYTES: flattenedSchema = Schema.create(schema.getType()); break; case DOUBLE: case MAP: if (flattenComplexTypes) { flattenedSchema = Schema.createMap(flatten(schema.getValueType(), false)); } else { flattenedSchema = Schema.createMap(schema.getValueType());
if (schema.getType() == Type.RECORD && schema.getField(pathList.get(field)) == null) { return Optional.absent(); switch (schema.getType()) { case UNION: if (AvroSerdeUtils.isNullableType(schema)) { case MAP: if ((field + 1) == pathList.size()) { return Optional.fromNullable(schema.getValueType()); return AvroUtils.getFieldSchemaHelper(schema.getValueType(), pathList, ++field); case RECORD: if ((field + 1) == pathList.size()) {
protected static Class propertyType(Schema fieldSchema, Property property) { AvroFieldDescriptor desc = AvroFieldUtil.fieldForProperty(fieldSchema, property); if (desc == null) { return null; } if (desc.isDynamic()) { return Object.class; } Schema typeSchema = desc.getField().schema(); if (desc.isAccessedByIndex()) { typeSchema = desc.getField().schema().getElementType(); } else if (desc.isAccessedByKey()) { typeSchema = desc.getField().schema().getValueType(); } return AvroTypeUtil.propertyType(typeSchema); }