Refine search
return null; switch (schema.getType()) { case RECORD: if (object instanceof Row) { return new GenericData.EnumSymbol(schema, object.toString()); case ARRAY: final Schema elementSchema = schema.getElementType(); final Object[] array = (Object[]) object; final GenericData.Array<Object> convertedArray = new GenericData.Array<>(array.length, schema); for (Object element : array) { convertedArray.add(convertFlinkType(elementSchema, element)); convertedMap.put( new Utf8(entry.getKey().toString()), convertFlinkType(schema.getValueType(), entry.getValue()));
switch (avroSchema.getType()) { case INT: { final LogicalType logicalType = avroSchema.getLogicalType(); if (logicalType == null) { return value; final LogicalType logicalType = avroSchema.getLogicalType(); if (logicalType == null) { return value; } else { final GenericData.Array<?> array = (GenericData.Array<?>) value; 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 + "]");
@SuppressWarnings(value="unchecked") private Object generate(Schema schema, Random random, int d) { switch (schema.getType()) { case RECORD: GenericRecord record = new GenericData.Record(schema); for (Schema.Field field : schema.getFields()) { Object value = (field.getObjectProp(USE_DEFAULT) == null) ? generate(field.schema(), random, d+1) : List<String> symbols = schema.getEnumSymbols(); return new GenericData.EnumSymbol (schema, symbols.get(random.nextInt(symbols.size()))); @SuppressWarnings("rawtypes") GenericArray<Object> array = new GenericData.Array(length<=0?0:length, schema); for (int i = 0; i < length; i++) array.add(generate(schema.getElementType(), random, d+1));
for (Schema.Field field : sourceRootSchema.getFields()) { String sourceChildname = field.name(); Object sourceChild = sourceRoot.get(field.pos()); if (destinationRoot.get(field.pos()) == null) { GenericRecord defRec = confGenerator.getConfigurationByName( sourceRootSchema.getName(), sourceRootSchema.getNamespace()); destinationRoot.put(field.pos(), defRec.get(field.pos())); case REPLACE: if (sourceArray.getSchema().getElementType().getType() == Schema.Type.RECORD) { GenericArray destArray = new GenericData.Array<>(sourceArray.size(), sourceArray.getSchema()); for (Object item : sourceArray) {
if ( arrayI >= array.size() || arrayI < 0 ) { return null; Object element = array.get( arrayI ); Schema elementType = s.getElementType(); if ( elementType.getType() == Schema.Type.UNION ) { if ( element instanceof GenericContainer ) { for ( Schema ts : elementType.getTypes() ) { if ( ts.getType() == Schema.Type.MAP ) { mapSchema = ts;
Schema elementType = s.getElementType(); Object[][] result = new Object[array.size()][m_outputRowMeta.size() + RowDataUtil.OVER_ALLOCATE_SIZE]; for ( int i = 0; i < array.size(); i++ ) { Object value = array.get( i ); sf.reset( space ); if ( elementType.getType() == Schema.Type.RECORD ) { result[i][sf.m_outputIndex] = sf.convertToKettleValue( (Record) value, elementType, defaultSchema, ignoreMissing ); } else if ( elementType.getType() == Schema.Type.ARRAY ) { result[i][sf.m_outputIndex] = sf.convertToKettleValue( (GenericData.Array) value, elementType, defaultSchema, ignoreMissing ); if ( arrayI >= array.size() || arrayI < 0 ) { Object value = array.get( arrayI ); Schema elementType = s.getElementType();
String newStr = new String(baosNew.toByteArray(), "UTF-8"); BaseData oldData = new BaseData(new BaseSchema(schema.toString()), oldStr); BaseData newData = new BaseData(new BaseSchema(schema.toString()), newStr); RawBinaryDelta deltaResult = calculator.calculate(oldData, newData); GenericFixed uuid1 = new GenericData.Fixed(delta1.getSchema().getField("__uuid").schema(), rawUuid1); delta1.put("testField4", 36); delta1.put("__uuid", uuid1); GenericRecord testField21 = new GenericData.Record(getSchemaByFullName(delta2.getSchema().getField("testField2").schema().getTypes(), "org.kaa.config.testRecordT")); GenericArray<GenericFixed> testField31 = new GenericData.Array<GenericFixed>(1, getArraySchema(testField21, "testField3")); byte[] rawUuidToDelete = new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; GenericFixed uuidToDelete = new GenericData.Fixed(getSchemaByFullName(testField31.getSchema().getElementType().getTypes(), GenericRecord testField22 = new GenericData.Record(getSchemaByFullName(delta3.getSchema().getField("testField2").schema().getTypes(), "org.kaa.config.testRecordT")); GenericArray<GenericRecord> testField32 = new GenericData.Array<GenericRecord>(1, getArraySchema(testField22, "testField3")); GenericRecord itemRecord = new GenericData.Record(getSchemaByFullName(testField32.getSchema().getElementType().getTypes(), "org.kaa.config.testRecordItemT"));
/** * Processes array type. * * @return generated value for input array type. */ private Object processArray() { Schema elementTypeSchema = Schema.create(Type.NULL); return new GenericData.Array<>(0, Schema.createArray(elementTypeSchema)); }
String newStr = new String(baosNew.toByteArray(), "UTF-8"); BaseData oldData = new BaseData(new BaseSchema(schema.toString()), oldStr); BaseData newData = new BaseData(new BaseSchema(schema.toString()), newStr); RawBinaryDelta deltaResult = calculator.calculate(oldData, newData); GenericEnumSymbol reset = new GenericData.EnumSymbol(getSchemaByFullName(delta1.getSchema().getField("testField1").schema().getTypes(), "org.kaaproject.configuration.resetT"), "reset"); byte[] rawUuid = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; GenericArray<Integer> testField1 = new GenericData.Array<Integer>(3, getArraySchema(delta2, "testField1")); testField1.add(321); testField1.add(456);
@Test public void testToStringSameValues() throws IOException { List<Field> fields = new ArrayList<>(); fields.add(new Field("nullstring1", Schema.create(Type.STRING), null, (Object)null)); fields.add(new Field("nullstring2", Schema.create(Type.STRING), null, (Object)null)); fields.add(new Field("string1", Schema.create(Type.STRING ), null, (Object)null)); fields.add(new Field("string2", Schema.create(Type.STRING ), null, (Object)null)); testRecord.put("record2", record); GenericArray<String> array = new GenericData.Array<>(1, arraySchema); array.clear(); array.add("42");
java.util.List<java.lang.String> a0 = this.productsInCart; if (a0 == null) { a0 = new SpecificData.Array<java.lang.String>((int)size0, SCHEMA$.getField("productsInCart").schema()); this.productsInCart = a0; } else a0.clear(); for ( ; 0 < size0; size0 = in.arrayNext()) { for ( ; size0 != 0; size0--) { java.lang.String e0 = (ga0 != null ? ga0.peek() : null); e0 = in.readString(); a0.add(e0); java.util.List<java.lang.String> a0 = this.productsInCart; if (a0 == null) { a0 = new SpecificData.Array<java.lang.String>((int)size0, SCHEMA$.getField("productsInCart").schema()); this.productsInCart = a0; } else a0.clear(); for ( ; 0 < size0; size0 = in.arrayNext()) { for ( ; size0 != 0; size0--) { java.lang.String e0 = (ga0 != null ? ga0.peek() : null); e0 = in.readString(); a0.add(e0);
public static void fillArrayFullResyncDelta(GenericRecord delta) { byte[] rawUuid = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; GenericFixed uuid = new GenericData.Fixed(delta.getSchema() .getField("__uuid").schema(), rawUuid); delta.put("__uuid", uuid); GenericArray testField1 = new GenericData.Array(3, getArraySchema(delta, "testField1")); delta.put("testField1", testField1); testField1.getSchema().getElementType().getTypes(), "org.kaa.config.testRecordItemT")); itemRecord1.put("testField2", 1);
private GenericRecord generateRecordWithArrays() { ArrayList<Schema.Field> fields = new ArrayList<Schema.Field>(); String fieldName = "array1"; Schema fieldSchema = Schema.createArray(Schema.create(Schema.Type.STRING)); String docString = "doc"; fields.add(new Schema.Field(fieldName, fieldSchema, docString, null)); Schema schema = Schema.createRecord("name", docString, "test", false); schema.setFields(fields); GenericData.Record record = new GenericData.Record(schema); GenericData.Array<String> arr = new GenericData.Array<>(2, fieldSchema); arr.add("foobar"); arr.add("foobaz"); record.put("array1", arr); return record; } }
Schema newSchema = newRoot.getSchema(); if (oldSchema.getField(UUID_FIELD) != null) { lastUuidDelta = new RecordTuple(oldRoot, newRoot); fieldQueue.clear(); for (Field newField : newSchema.getFields()) { Object oldValue = oldRoot.get(newField.name()); Object newValue = newRoot.get(newField.name()); GenericRecord oldItemRecord = (GenericRecord) oldItem; Schema oldItemSchema = oldItemRecord.getSchema(); if (oldItemSchema.getField(UUID_FIELD) != null) { GenericArray deltaArray = new GenericData.Array(newArrayItems.size(), arraySchema); GenericArray deltaArray = new GenericData.Array(arraySchema, newArrayItems); delta.put(newField.name(), deltaArray); hasChanges = true; new GenericData.Array(0, getArraySchema(delta, newField.name()))); hasChanges = true; } else if (!oldArrayItems.isEmpty()) {
Queue<FieldAttribute> fieldQueue) throws DeltaCalculatorException { List<Schema.Field> fields = delta.getSchema().getFields(); GenericArray arrayField = new GenericData.Array(uuids.size(), arraySchema); for (byte[] uuid : uuids) { GenericFixed uuidFixed = new GenericData.Fixed(uuidSchema, uuid);
DataMap map = (DataMap) value; DataSchema valueDataSchema = ((MapDataSchema) dereferencedDataSchema).getValues(); Schema valueAvroSchema = avroSchema.getValueType(); Map<String, Object> avroMap = new HashMap<String, Object>(map.size()); for (Map.Entry<String, Object> entry : map.entrySet()) DataList list = (DataList) value; DataSchema elementDataSchema = ((ArrayDataSchema) dereferencedDataSchema).getItems(); Schema elementAvroSchema = avroSchema.getElementType(); GenericData.Array<Object> avroList = new GenericData.Array<Object>(list.size(), avroSchema); for (int i = 0; i < list.size(); i++) Object entryAvroValue = translate(list.get(i), elementDataSchema, elementAvroSchema); _path.removeLast(); avroList.add(entryAvroValue); Schema.Field avroField = avroSchema.getField(fieldName); if (avroField == null)
@SuppressWarnings("unchecked") @Test public void testRemoveUuid() { Schema uuidSchema = Schema.createFixed("uuidT", "", "org.kaaproject.configuration", 16); Schema.Field uuidField = new Schema.Field("__uuid", uuidSchema, "", null); Schema recordSchema = Schema.createRecord(Arrays.asList(uuidField)); Assert.assertNull("Uuid is still present after removal in recordWithoutUuid", recordWithUuid.get("__uuid")); Schema otherFixedSchema = Schema.createFixed("__uuid", "", "not.a", 1); Schema.Field otherFixed = new Schema.Field("some_field", otherFixedSchema, "", null); byte[] otherFixedValue = {1}; Schema arraySchema = Schema.createArray(inArrayRecordSchema); Schema.Field arrayField = new Schema.Field("array1", arraySchema, "", null); GenericArray<GenericRecord> array1 = new GenericData.Array<GenericRecord>(2, arraySchema); array1.add(inArrayRecord1); array1.add(inArrayRecord2);
@SuppressWarnings("unchecked") @Test public void testCanonizeRecord() { Schema arrayASchema = Schema.createArray(Schema.create(Type.INT)); Schema arrayBSchema = Schema.createArray(Schema.create(Type.STRING)); Schema.Field arrayAField = new Schema.Field("arrayA", arrayASchema, "", null); Schema.Field arrayBField = new Schema.Field("arrayB", arrayBSchema, "", null); GenericArray<Integer> arrayA = new GenericData.Array<Integer>(4, arrayASchema); arrayA.add(9); arrayA.add(8); GenericArray<String> arrayB = new GenericData.Array<String>(5, arrayBSchema); arrayB.add("abc"); arrayB.add("jkl");
java.util.List<java.lang.String> a1 = this.nullableArray; if (a1 == null) { a1 = new SpecificData.Array<java.lang.String>((int)size1, SCHEMA$.getField("nullableArray").schema().getTypes().get(1)); this.nullableArray = a1; } else a1.clear(); for ( ; 0 < size1; size1 = in.arrayNext()) { for ( ; size1 != 0; size1--) { java.lang.String e1 = (ga1 != null ? ga1.peek() : null); e1 = in.readString(); a1.add(e1); java.util.List<java.lang.String> a1 = this.nullableArray; if (a1 == null) { a1 = new SpecificData.Array<java.lang.String>((int)size1, SCHEMA$.getField("nullableArray").schema().getTypes().get(1)); this.nullableArray = a1; } else a1.clear(); for ( ; 0 < size1; size1 = in.arrayNext()) { for ( ; size1 != 0; size1--) { java.lang.String e1 = (ga1 != null ? ga1.peek() : null); e1 = in.readString(); a1.add(e1);
/** * Packs a Pig DataBag into an Avro array. * @param db the Pig databad to pack into the avro array * @param s The avro schema for which to determine the type * @return the avro array corresponding to the input bag * @throws IOException */ public static GenericData.Array<Object> packIntoAvro( final DataBag db, final Schema s) throws IOException { try { GenericData.Array<Object> array = new GenericData.Array<Object>(new Long(db.size()).intValue(), s); for (Tuple t : db) { if (s.getElementType() != null && s.getElementType().getType() == Type.RECORD) { array.add(packIntoAvro(t, s.getElementType())); } else if (t.size() == 1) { array.add(t.get(0)); } else { throw new IOException( "AvroStorageDataConversionUtilities.packIntoAvro: Can't pack " + t + " into schema " + s); } } return array; } catch (Exception e) { throw new IOException( "exception in AvroStorageDataConversionUtilities.packIntoAvro", e); } }