/** * Returns the {@link DataSchema} for a member identified by its member key returned * from {@link Member#getUnionMemberKey()}. * * @param memberKey Union member key of the member. * @return the {@link DataSchema} if type is a member of the union, else return null. * * @deprecated Replaced by {@link #getTypeByMemberKey(String)}. This method exists only to help during the * migration phase. It will be removed in the later versions and SHOULD NOT be used for any new use cases. */ @Deprecated public DataSchema getType(String memberKey) { return getTypeByMemberKey(memberKey); }
private static DataSchema unionValueDataSchema(UnionDataSchema unionDataSchema, Object value) { DataSchema schema; if (value == null) { schema = null; } else if (value == Data.NULL) { schema = DataSchemaConstants.NULL_DATA_SCHEMA; } else { DataMap dataMap = (DataMap) value; Map.Entry<String, ?> mapEntry = dataMap.entrySet().iterator().next(); schema = unionDataSchema.getTypeByMemberKey(mapEntry.getKey()); assert(schema != null); } return schema; }
private void computeAddedUnionMembers(UnionDataSchema base, UnionDataSchema changed, List<String> added, List<UnionDataSchema.Member> commonMembers) { for (UnionDataSchema.Member member : changed.getMembers()) { String unionMemberKey = member.getUnionMemberKey(); boolean isMemberNewlyAdded = (base.getTypeByMemberKey(unionMemberKey) == null); if (isMemberNewlyAdded) { added.add(unionMemberKey); } else if (commonMembers != null) { commonMembers.add(member); } } }
/** * Set a new value into the union. * * This is a wrapping method. The value is a {@link DataTemplate}. * * @param memberSchema provides the {@link DataSchema} of the new value. * @param memberClass provides the expected class of the value. * @param key provides the key that identifies the member value. * @param value provides the value to set. * @param <T> type of the value. * @throws ClassCastException if input value does not match the expected class. * @throws NullUnionUnsupportedOperationException if the union is a null union. */ protected <T extends DataTemplate<?>> void selectWrapped(DataSchema memberSchema, Class<T> memberClass, String key, T value) throws ClassCastException, NullUnionUnsupportedOperationException { checkNotNull(); DataSchema memberType = _schema.getTypeByMemberKey(key); assert(memberType != null); // something is wrong with the generated code if this occurs. if (value.getClass() != memberClass) { throw new ClassCastException("Input " + value + " should be a " + memberClass.getName()); } _map.clear(); _map.put(key, value.data()); _cache = value; }
private Object translateAvroRecordToPegasusUnionWithAliases(Object value, UnionDataSchema unionDataSchema, Schema avroSchema) { Schema recordAvroSchema = extractNonnullSchema(avroSchema); GenericRecord record = (GenericRecord) value; Object fieldDiscriminatorValue = record.get(DataSchemaConstants.DISCRIMINATOR_FIELD); if (fieldDiscriminatorValue == null) { appendMessage("cannot find required field %1$s in record %2$s", DataSchemaConstants.DISCRIMINATOR_FIELD, record); return BAD_RESULT; } String fieldDiscriminator = fieldDiscriminatorValue.toString(); if (DataSchemaConstants.NULL_TYPE.equals(fieldDiscriminator)) { return Data.NULL; } else { Object fieldValue = record.get(fieldDiscriminator); Schema fieldAvroSchema = recordAvroSchema.getField(fieldDiscriminator).schema(); DataSchema memberDataSchema = unionDataSchema.getTypeByMemberKey(fieldDiscriminator); DataMap result = new DataMap(1); _path.add(fieldDiscriminator); result.put(fieldDiscriminator, translate(fieldValue, memberDataSchema, extractNonnullSchema(fieldAvroSchema))); _path.removeLast(); return result; } } }
DataSchema memberDataSchema = unionDataSchema.getTypeByMemberKey(key); if (memberDataSchema == null)
DataSchema memberType = _schema.getTypeByMemberKey(key); if (memberType == null)
key = memberAvroSchema.getType().toString().toLowerCase(); DataSchema memberDataSchema = unionDataSchema.getTypeByMemberKey(key); if (memberDataSchema == null)
private DataSchema currentSchema() { DataSchema schema; DataSchema mapSchema = _element.getSchema(); if (mapSchema == null) { schema = null; } else { DataSchema dereferencedSchema = mapSchema.getDereferencedDataSchema(); DataSchema.Type deferencedType = dereferencedSchema.getType(); switch (deferencedType) { case RECORD: RecordDataSchema.Field field = ((RecordDataSchema) dereferencedSchema).getField(_currentEntry.getKey()); schema = (field == null ? null : field.getType()); break; case UNION: schema = ((UnionDataSchema) dereferencedSchema).getTypeByMemberKey(_currentEntry.getKey()); break; case MAP: schema = ((MapDataSchema) dereferencedSchema).getValues(); break; default: throw new IllegalStateException("Unknown dereferenced type " + deferencedType + " for DataMap's schema " + mapSchema); } } return schema; }
/** * Set a new value into the union. * * This is a direct method. The value is not a {@link DataTemplate}. * * @param memberSchema provides the {@link DataSchema} of the new value. * @param memberClass provides the expected class of the value. * @param dataClass provides the class stored in the underlying {@link DataMap}. * @param key provides the key that identifies the member value. * @param value provides the value to set. * @param <T> type of the value. * @throws ClassCastException if the input value does not match the * expected class and the value cannot be coerced to the * expected class. * @throws NullUnionUnsupportedOperationException if the union is a null union. */ protected <T> void selectDirect(DataSchema memberSchema, Class<T> memberClass, Class<?> dataClass, String key, T value) throws ClassCastException, NullUnionUnsupportedOperationException { checkNotNull(); DataSchema memberType = _schema.getTypeByMemberKey(key); assert(memberType != null); // something is wrong with the generated code if this occurs. Object object = DataTemplateUtil.coerceInput(value, memberClass, dataClass); _map.clear(); _map.put(key, object); }
DataSchema memberDataSchema = unionDataSchema.getTypeByMemberKey(memberKey); if (memberDataSchema == null)
/** * Set a new value into the union whose type needs to be coerced by {@link DirectCoercer}. * * @param memberSchema provides the {@link DataSchema} of the new value. * @param memberClass provides the expected class of the value. * @param dataClass provides the class stored in the underlying {@link DataMap}. * @param key provides the key that identifies the member value. * @param value provides the value to set. * @param <T> type of the value. * @throws ClassCastException if the input value does not match the * expected class and the value cannot be coerced to the * expected class. * @throws NullUnionUnsupportedOperationException if the union is a null union. */ protected <T> void selectCustomType(DataSchema memberSchema, Class<T> memberClass, Class<?> dataClass, String key, T value) throws ClassCastException, NullUnionUnsupportedOperationException { checkNotNull(); DataSchema memberType = _schema.getTypeByMemberKey(key); assert(memberType != null); // something is wrong with the generated code if this occurs. Object object = DataTemplateUtil.coerceInput(value, memberClass, dataClass); _map.clear(); _map.put(key, object); _customTypeCache = value; }
if (schema.getTypeByMemberKey(DataSchemaConstants.NULL_TYPE) == null) DataSchema memberSchema = schema.getTypeByMemberKey(key); if (memberSchema == null)
case UNION: UnionDataSchema unionDataSchema = (UnionDataSchema) dataSchema; dataSchema = unionDataSchema.getTypeByMemberKey(path[i].toString()); if (dataSchema == null) return null; break;
break; case UNION: childSchema = ((UnionDataSchema) schema).getTypeByMemberKey((String) name); break; case RECORD:
@Override public void key(String key) throws IOException { DataSchema newSchema = null; if (_currentSchema != null) { switch (_currentSchema.getType()) { case RECORD: RecordDataSchema recordSchema = (RecordDataSchema) _currentSchema; RecordDataSchema.Field field = recordSchema.getField(key); if (field != null) { newSchema = field.getType(); } break; case UNION: UnionDataSchema unionSchema = (UnionDataSchema) _currentSchema; newSchema = unionSchema.getTypeByMemberKey(key); break; case MAP: MapDataSchema mapSchema = (MapDataSchema) _currentSchema; newSchema = mapSchema.getValues(); break; } } _pendingSchema = newSchema; super.key(key); }
addNullMemberType = unionDataSchema.getTypeByMemberKey(DataSchemaConstants.NULL_TYPE) == null; resultMemberTypes = unionDataSchema.getMembers().stream() .map(UnionDataSchema.Member::getType)
DataSchema memberDataSchema = unionDataSchema.getTypeByMemberKey(key); Map.Entry<String, Schema> memberAvroEntry = findUnionMember(memberDataSchema, avroSchema); if (memberAvroEntry == null) {
DataSchema olderSchema = older.getTypeByMemberKey(newerMember.getUnionMemberKey());