Java Code Examples for org.apache.avro.generic.IndexedRecord#get()

The following examples show how to use org.apache.avro.generic.IndexedRecord#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Array_of_record_GenericDeserializer_1629046702287533603_1629046702287533603.java    From avro-util with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public IndexedRecord deserializerecord0(Object reuse, Decoder decoder)
    throws IOException
{
    IndexedRecord record;
    if ((((reuse)!= null)&&((reuse) instanceof IndexedRecord))&&(((IndexedRecord)(reuse)).getSchema() == arrayArrayElemSchema0)) {
        record = ((IndexedRecord)(reuse));
    } else {
        record = new org.apache.avro.generic.GenericData.Record(arrayArrayElemSchema0);
    }
    int unionIndex0 = (decoder.readIndex());
    if (unionIndex0 == 0) {
        decoder.readNull();
    }
    if (unionIndex0 == 1) {
        if (record.get(0) instanceof Utf8) {
            record.put(0, (decoder).readString(((Utf8) record.get(0))));
        } else {
            record.put(0, (decoder).readString(null));
        }
    }
    return record;
}
 
Example 2
Source File: Map_of_UNION_GenericSerializer_2087096002965517991.java    From avro-util with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void serializeRecord0(IndexedRecord data, Encoder encoder)
    throws IOException
{
    CharSequence field0 = ((CharSequence) data.get(0));
    if (field0 == null) {
        (encoder).writeIndex(0);
        (encoder).writeNull();
    } else {
        if (field0 instanceof CharSequence) {
            (encoder).writeIndex(1);
            if (field0 instanceof Utf8) {
                (encoder).writeString(((Utf8) field0));
            } else {
                (encoder).writeString(field0 .toString());
            }
        }
    }
}
 
Example 3
Source File: SalesforceTestBase.java    From components with Apache License 2.0 6 votes vote down vote up
static public List<IndexedRecord> getAllTestRows(List<IndexedRecord> rows) {
    List<IndexedRecord> checkedRows = new ArrayList<>();

    for (IndexedRecord row : rows) {
        String check = (String) row.get(row.getSchema().getField("ShippingStreet").pos());
        if (check == null || !check.equals(TEST_KEY)) {
            continue;
        }
        LOGGER.debug("Test row is: " + row.get(row.getSchema().getField("Name").pos()) + " id: "
                + row.get(row.getSchema().getField("Id").pos()) + " post: "
                + row.get(row.getSchema().getField("BillingPostalCode").pos()) + " st: " + " post: "
                + row.get(row.getSchema().getField("BillingStreet").pos()));
        checkedRows.add(row);
    }
    return checkedRows;
}
 
Example 4
Source File: Array_of_UNION_GenericSerializer_585074122056792963.java    From avro-util with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void serializeRecord0(IndexedRecord data, Encoder encoder)
    throws IOException
{
    CharSequence field0 = ((CharSequence) data.get(0));
    if (field0 == null) {
        (encoder).writeIndex(0);
        (encoder).writeNull();
    } else {
        if (field0 instanceof CharSequence) {
            (encoder).writeIndex(1);
            if (field0 instanceof Utf8) {
                (encoder).writeString(((Utf8) field0));
            } else {
                (encoder).writeString(field0 .toString());
            }
        }
    }
}
 
Example 5
Source File: JDBCRowWriter.java    From components with Apache License 2.0 6 votes vote down vote up
private void handleSuccess(IndexedRecord input) {
    successCount++;

    if (outSchema == null || outSchema.getFields().size() == 0) {
        return;
    }

    IndexedRecord output = new GenericData.Record(outSchema);
    for (Schema.Field outField : output.getSchema().getFields()) {
        Object outValue = null;

        if (propagateQueryResultSet && outField.name().equals(setting.getUseColumn())) {
            output.put(outField.pos(), resultSet);
        } else {
            Schema.Field inField = input.getSchema().getField(outField.name());
            if (inField != null) {
                outValue = input.get(inField.pos());
            }
            output.put(outField.pos(), outValue);
        }
    }

    successfulWrites.add(output);
}
 
Example 6
Source File: FilterRowDoFnAvpathTest.java    From components with Apache License 2.0 6 votes vote down vote up
@Test
public void testHierarchical_TFD2119_B6_AllSubRecordsWithId1Or2HasValueGt10() throws Exception {
    DoFnTester<IndexedRecord, IndexedRecord> fnTester = DoFnTester.of( //
            new FilterRowDoFn(addCriteria(null, //
                    ".b1{.id == 1 || .id == 2}.value", //
                    null, //
                    ConditionsRowConstant.Operator.GREATER, //
                    "10") //
            ));

    List<IndexedRecord> output = fnTester.processBundle(inputB);

    for (IndexedRecord main : output) {
        boolean atLeastOne = false;
        for (IndexedRecord subrecord : getSubrecords(main)) {
            int id = (int) subrecord.get(0);
            if (id == 1 || id == 2) {
                atLeastOne = true;
                assertThat(main.toString(), (double) subrecord.get(2), greaterThan(10d));
            }
        }
        assertThat(main.toString(), atLeastOne, is(true));
    }
    assertThat(output, hasSize(42));
}
 
Example 7
Source File: MarketoOutputWriterTestIT.java    From components with Apache License 2.0 6 votes vote down vote up
public void testSyncLead(IndexedRecord record) throws Exception {
    props.outputOperation.setValue(OutputOperation.syncLead);
    writer = getWriter(props);
    writer.open("test");
    writer.write(record);
    MarketoResult result = (MarketoResult) writer.close();
    assertEquals(1, result.getApiCalls());
    assertEquals(1, result.getSuccessCount());
    assertEquals(0, result.getRejectCount());
    List<IndexedRecord> successes = writer.getSuccessfulWrites();
    List<IndexedRecord> rejects = writer.getRejectedWrites();
    assertEquals(Collections.emptyList(), rejects);
    assertEquals(1, successes.size());
    IndexedRecord success = successes.get(0);
    Schema s = props.schemaFlow.schema.getValue();
    assertNotNull(s);
    Integer leadId = (int) success.get(0);
    createdLeads.add(leadId);
    assertEquals("CREATED", success.get(s.getField("Status").pos()).toString().toUpperCase());
    LOG.debug("Added leadId = {} to createdLeads {}.", leadId, createdLeads);
}
 
Example 8
Source File: Array_of_record_GenericDeserializer_1629046702287533603_1629046702287533603.java    From avro-util with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public IndexedRecord deserializerecord0(Object reuse, Decoder decoder)
    throws IOException
{
    IndexedRecord record;
    if ((((reuse)!= null)&&((reuse) instanceof IndexedRecord))&&(((IndexedRecord)(reuse)).getSchema() == arrayArrayElemSchema0)) {
        record = ((IndexedRecord)(reuse));
    } else {
        record = new org.apache.avro.generic.GenericData.Record(arrayArrayElemSchema0);
    }
    int unionIndex0 = (decoder.readIndex());
    if (unionIndex0 == 0) {
        decoder.readNull();
    }
    if (unionIndex0 == 1) {
        if (record.get(0) instanceof Utf8) {
            record.put(0, (decoder).readString(((Utf8) record.get(0))));
        } else {
            record.put(0, (decoder).readString(null));
        }
    }
    return record;
}
 
Example 9
Source File: FieldSelectorDoFnTest.java    From components with Apache License 2.0 6 votes vote down vote up
@Test
public void testHierarchicalSubRecordHasValueGt10() throws Exception {
    FieldSelectorProperties properties = addSelector(null, "value", ".b1{.value > 10}");
    DoFnTester<IndexedRecord, IndexedRecord> fnTester = DoFnTester.of( //
            new FieldSelectorDoFn().withProperties(properties));

    List<IndexedRecord> output = fnTester.processBundle(inputB);
    for (IndexedRecord main : output) {
        List<Field> fields = main.getSchema().getFields();
        assertEquals(1, fields.size());
        assertEquals("value", fields.get(0).name());
        for (IndexedRecord element : (List<IndexedRecord>) main.get(0)) {
            List<Field> subFields = element.getSchema().getFields();
            assertEquals("id", subFields.get(0).name());
            assertEquals("name", subFields.get(1).name());
            assertEquals("value", subFields.get(2).name());
            assertEquals("b2", subFields.get(3).name());
            assertThat((Double) element.get(2), greaterThan(10d));
        }
    }
}
 
Example 10
Source File: TFilterRowWriter.java    From components with Apache License 2.0 5 votes vote down vote up
private Map<String, Object> prepareMap(IndexedRecord input) {
    Map<String, Object> valuesMap = new HashMap<>();
    for (Schema.Field f : input.getSchema().getFields()) {
        Object inputValue = input.get(f.pos());
        valuesMap.put(f.name(), inputValue);
    }
    return valuesMap;
}
 
Example 11
Source File: FieldSelectorDoFnTest.java    From components with Apache License 2.0 5 votes vote down vote up
@Test
public void testHierarchicalSubRecordsWithId1Or2HasValueGt10_Alternative() throws Exception {
    FieldSelectorProperties properties =
            addSelector(null, "expectedb1", ".b1{.id == 1 && .value > 10 || .id == 2 && .value > 10}");
    DoFnTester<IndexedRecord, IndexedRecord> fnTester = DoFnTester.of( //
            new FieldSelectorDoFn().withProperties(properties));

    List<IndexedRecord> output = fnTester.processBundle(inputB);
    for (IndexedRecord main : output) {
        boolean atLeastOne = false;
        for (IndexedRecord subrecord : getSubrecords(main)) {
            int id = (int) subrecord.get(0);
            if ((double) subrecord.get(2) > 10 && (id == 1 || id == 2))
                atLeastOne = true;
        }
        if (atLeastOne) {
            List<Field> fields = main.getSchema().getFields();
            assertEquals(1, fields.size());
            assertEquals("expectedb1", fields.get(0).name());
            List<IndexedRecord> subElements = (List<IndexedRecord>) main.get(0);
            for (IndexedRecord subElement : subElements) {
                List<Field> subFields = subElement.getSchema().getFields();
                assertEquals(4, subFields.size());
                assertEquals("id", subFields.get(0).name());
                assertEquals("name", subFields.get(1).name());
                assertEquals("value", subFields.get(2).name());
                assertEquals("b2", subFields.get(3).name());

                assertThat((Integer) subElement.get(0), isOneOf(1, 2));
                assertThat((Double) subElement.get(2), greaterThan(10d));
            }
        } else {
            assertFalse("You whould not create elements when there is not items", true);
        }
    }
}
 
Example 12
Source File: FastStringableTest_javaStringPropertyTest_GenericSerializer_713665344968052004.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void serializeFastStringableTest_javaStringPropertyTest0(IndexedRecord data, Encoder encoder)
    throws IOException
{
    if (data.get(0) instanceof Utf8) {
        (encoder).writeString(((Utf8) data.get(0)));
    } else {
        (encoder).writeString(data.get(0).toString());
    }
}
 
Example 13
Source File: NsObjectInputTransducerIT.java    From components with Apache License 2.0 5 votes vote down vote up
@Test
public void testIncludeAllFields() throws Exception {
    TypeDesc basicTypeDesc = connection.getBasicMetaData().getTypeInfo("Opportunity");
    Schema schema = getDynamicSchema();

    NsObjectInputTransducer transducer = new NsObjectInputTransducer(connection, schema, basicTypeDesc.getTypeName());

    SearchResultSet<Record> rs = connection.newSearch()
            .target(basicTypeDesc.getTypeName())
            .search();

    TypeDesc typeDesc = connection.getMetaDataSource().getTypeInfo(basicTypeDesc.getTypeName());

    int count = 0;
    while (count++ < connection.getSearchPageSize() && rs.next()) {
        Record record = rs.get();
        IndexedRecord indexedRecord = transducer.read(record);
        logger.debug("Indexed record: {}", indexedRecord);

        Schema recordSchema = indexedRecord.getSchema();
        assertEquals(typeDesc.getFields().size(), recordSchema.getFields().size());

        for (FieldDesc fieldDesc : typeDesc.getFields()) {
            String fieldName = fieldDesc.getName();
            Schema.Field field = recordSchema.getField(fieldName);
            assertNotNull(field);

            Object value = indexedRecord.get(field.pos());
        }
    }
    if (count == 0) {
        throw new IllegalStateException("No records");
    }
}
 
Example 14
Source File: FastStringableTest_javaStringPropertyTest_GenericSerializer_9185875457190242821.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void serializeFastStringableTest_javaStringPropertyTest0(IndexedRecord data, Encoder encoder)
    throws IOException
{
    if (data.get(0) instanceof Utf8) {
        (encoder).writeString(((Utf8) data.get(0)));
    } else {
        (encoder).writeString(data.get(0).toString());
    }
}
 
Example 15
Source File: TestCircularReferences.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
private long getId(IndexedRecord referenceable, Schema schema) {
  Referenceable info = (Referenceable) schema.getLogicalType();
  int idField = schema.getField(info.getIdFieldName()).pos();
  return (Long) referenceable.get(idField);
}
 
Example 16
Source File: FastGenericSerializerGeneratorTest_shouldWritePrimitives_GenericSerializer_5300080091170871849.java    From avro-util with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void serializeFastGenericSerializerGeneratorTest_shouldWritePrimitives0(IndexedRecord data, Encoder encoder)
    throws IOException
{
    (encoder).writeInt(((Integer) data.get(0)));
    Integer testIntUnion0 = ((Integer) data.get(1));
    if (testIntUnion0 == null) {
        (encoder).writeIndex(0);
        (encoder).writeNull();
    } else {
        if (testIntUnion0 instanceof Integer) {
            (encoder).writeIndex(1);
            (encoder).writeInt(((Integer) testIntUnion0));
        }
    }
    if (data.get(2) instanceof Utf8) {
        (encoder).writeString(((Utf8) data.get(2)));
    } else {
        (encoder).writeString(data.get(2).toString());
    }
    CharSequence testStringUnion0 = ((CharSequence) data.get(3));
    if (testStringUnion0 == null) {
        (encoder).writeIndex(0);
        (encoder).writeNull();
    } else {
        if (testStringUnion0 instanceof CharSequence) {
            (encoder).writeIndex(1);
            if (testStringUnion0 instanceof Utf8) {
                (encoder).writeString(((Utf8) testStringUnion0));
            } else {
                (encoder).writeString(testStringUnion0 .toString());
            }
        }
    }
    (encoder).writeLong(((Long) data.get(4)));
    Long testLongUnion0 = ((Long) data.get(5));
    if (testLongUnion0 == null) {
        (encoder).writeIndex(0);
        (encoder).writeNull();
    } else {
        if (testLongUnion0 instanceof Long) {
            (encoder).writeIndex(1);
            (encoder).writeLong(((Long) testLongUnion0));
        }
    }
    (encoder).writeDouble(((Double) data.get(6)));
    Double testDoubleUnion0 = ((Double) data.get(7));
    if (testDoubleUnion0 == null) {
        (encoder).writeIndex(0);
        (encoder).writeNull();
    } else {
        if (testDoubleUnion0 instanceof Double) {
            (encoder).writeIndex(1);
            (encoder).writeDouble(((Double) testDoubleUnion0));
        }
    }
    (encoder).writeFloat(((Float) data.get(8)));
    Float testFloatUnion0 = ((Float) data.get(9));
    if (testFloatUnion0 == null) {
        (encoder).writeIndex(0);
        (encoder).writeNull();
    } else {
        if (testFloatUnion0 instanceof Float) {
            (encoder).writeIndex(1);
            (encoder).writeFloat(((Float) testFloatUnion0));
        }
    }
    (encoder).writeBoolean(((Boolean) data.get(10)));
    Boolean testBooleanUnion0 = ((Boolean) data.get(11));
    if (testBooleanUnion0 == null) {
        (encoder).writeIndex(0);
        (encoder).writeNull();
    } else {
        if (testBooleanUnion0 instanceof Boolean) {
            (encoder).writeIndex(1);
            (encoder).writeBoolean(((Boolean) testBooleanUnion0));
        }
    }
    (encoder).writeBytes(((ByteBuffer) data.get(12)));
    ByteBuffer testBytesUnion0 = ((ByteBuffer) data.get(13));
    if (testBytesUnion0 == null) {
        (encoder).writeIndex(0);
        (encoder).writeNull();
    } else {
        if (testBytesUnion0 instanceof ByteBuffer) {
            (encoder).writeIndex(1);
            (encoder).writeBytes(((ByteBuffer) testBytesUnion0));
        }
    }
}
 
Example 17
Source File: ValueWriters.java    From iceberg with Apache License 2.0 4 votes vote down vote up
@Override
protected Object get(IndexedRecord struct, int pos) {
  return struct.get(pos);
}
 
Example 18
Source File: FastGenericSerializerGeneratorTest_shouldWriteEnum_GenericSerializer_2284596792420879769.java    From avro-util with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void serializeFastGenericSerializerGeneratorTest_shouldWriteEnum0(IndexedRecord data, Encoder encoder)
    throws IOException
{
    (encoder).writeEnum(((org.apache.avro.generic.GenericData.EnumSymbol) data.get(0)).getSchema().getEnumOrdinal(((org.apache.avro.generic.GenericData.EnumSymbol) data.get(0)).toString()));
    org.apache.avro.generic.GenericData.EnumSymbol testEnumUnion0 = ((org.apache.avro.generic.GenericData.EnumSymbol) data.get(1));
    if (testEnumUnion0 == null) {
        (encoder).writeIndex(0);
        (encoder).writeNull();
    } else {
        if ((testEnumUnion0 instanceof org.apache.avro.generic.GenericData.EnumSymbol)&&"com.adpilot.utils.generated.avro.testEnum".equals(((org.apache.avro.generic.GenericData.EnumSymbol) testEnumUnion0).getSchema().getFullName())) {
            (encoder).writeIndex(1);
            (encoder).writeEnum(((org.apache.avro.generic.GenericData.EnumSymbol) testEnumUnion0).getSchema().getEnumOrdinal(((org.apache.avro.generic.GenericData.EnumSymbol) testEnumUnion0).toString()));
        }
    }
    List<org.apache.avro.generic.GenericData.EnumSymbol> testEnumArray0 = ((List<org.apache.avro.generic.GenericData.EnumSymbol> ) data.get(2));
    (encoder).writeArrayStart();
    if ((testEnumArray0 == null)||testEnumArray0 .isEmpty()) {
        (encoder).setItemCount(0);
    } else {
        (encoder).setItemCount(testEnumArray0 .size());
        for (int counter0 = 0; (counter0 <testEnumArray0 .size()); counter0 ++) {
            (encoder).startItem();
            (encoder).writeEnum(((org.apache.avro.generic.GenericData.EnumSymbol) testEnumArray0 .get(counter0)).getSchema().getEnumOrdinal(((org.apache.avro.generic.GenericData.EnumSymbol) testEnumArray0 .get(counter0)).toString()));
        }
    }
    (encoder).writeArrayEnd();
    List<org.apache.avro.generic.GenericData.EnumSymbol> testEnumUnionArray0 = ((List<org.apache.avro.generic.GenericData.EnumSymbol> ) data.get(3));
    (encoder).writeArrayStart();
    if ((testEnumUnionArray0 == null)||testEnumUnionArray0 .isEmpty()) {
        (encoder).setItemCount(0);
    } else {
        (encoder).setItemCount(testEnumUnionArray0 .size());
        for (int counter1 = 0; (counter1 <testEnumUnionArray0 .size()); counter1 ++) {
            (encoder).startItem();
            org.apache.avro.generic.GenericData.EnumSymbol union0 = null;
            union0 = ((List<org.apache.avro.generic.GenericData.EnumSymbol> ) testEnumUnionArray0).get(counter1);
            if (union0 == null) {
                (encoder).writeIndex(0);
                (encoder).writeNull();
            } else {
                if ((union0 instanceof org.apache.avro.generic.GenericData.EnumSymbol)&&"com.adpilot.utils.generated.avro.testEnum".equals(((org.apache.avro.generic.GenericData.EnumSymbol) union0).getSchema().getFullName())) {
                    (encoder).writeIndex(1);
                    (encoder).writeEnum(((org.apache.avro.generic.GenericData.EnumSymbol) union0).getSchema().getEnumOrdinal(((org.apache.avro.generic.GenericData.EnumSymbol) union0).toString()));
                }
            }
        }
    }
    (encoder).writeArrayEnd();
}
 
Example 19
Source File: FastGenericSerializerGeneratorTest_shouldWriteFixed_GenericSerializer_3335671775395101159.java    From avro-util with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void serializeFastGenericSerializerGeneratorTest_shouldWriteFixed0(IndexedRecord data, Encoder encoder)
    throws IOException
{
    (encoder).writeFixed(((org.apache.avro.generic.GenericData.Fixed) data.get(0)).bytes());
    org.apache.avro.generic.GenericData.Fixed testFixedUnion0 = ((org.apache.avro.generic.GenericData.Fixed) data.get(1));
    if (testFixedUnion0 == null) {
        (encoder).writeIndex(0);
        (encoder).writeNull();
    } else {
        if ((testFixedUnion0 instanceof org.apache.avro.generic.GenericData.Fixed)&&"com.adpilot.utils.generated.avro.testFixed".equals(((org.apache.avro.generic.GenericData.Fixed) testFixedUnion0).getSchema().getFullName())) {
            (encoder).writeIndex(1);
            (encoder).writeFixed(((org.apache.avro.generic.GenericData.Fixed) testFixedUnion0).bytes());
        }
    }
    List<org.apache.avro.generic.GenericData.Fixed> testFixedArray0 = ((List<org.apache.avro.generic.GenericData.Fixed> ) data.get(2));
    (encoder).writeArrayStart();
    if ((testFixedArray0 == null)||testFixedArray0 .isEmpty()) {
        (encoder).setItemCount(0);
    } else {
        (encoder).setItemCount(testFixedArray0 .size());
        for (int counter0 = 0; (counter0 <testFixedArray0 .size()); counter0 ++) {
            (encoder).startItem();
            (encoder).writeFixed(((org.apache.avro.generic.GenericData.Fixed) testFixedArray0 .get(counter0)).bytes());
        }
    }
    (encoder).writeArrayEnd();
    List<org.apache.avro.generic.GenericData.Fixed> testFixedUnionArray0 = ((List<org.apache.avro.generic.GenericData.Fixed> ) data.get(3));
    (encoder).writeArrayStart();
    if ((testFixedUnionArray0 == null)||testFixedUnionArray0 .isEmpty()) {
        (encoder).setItemCount(0);
    } else {
        (encoder).setItemCount(testFixedUnionArray0 .size());
        for (int counter1 = 0; (counter1 <testFixedUnionArray0 .size()); counter1 ++) {
            (encoder).startItem();
            org.apache.avro.generic.GenericData.Fixed union0 = null;
            union0 = ((List<org.apache.avro.generic.GenericData.Fixed> ) testFixedUnionArray0).get(counter1);
            if (union0 == null) {
                (encoder).writeIndex(0);
                (encoder).writeNull();
            } else {
                if ((union0 instanceof org.apache.avro.generic.GenericData.Fixed)&&"com.adpilot.utils.generated.avro.testFixed".equals(((org.apache.avro.generic.GenericData.Fixed) union0).getSchema().getFullName())) {
                    (encoder).writeIndex(1);
                    (encoder).writeFixed(((org.apache.avro.generic.GenericData.Fixed) union0).bytes());
                }
            }
        }
    }
    (encoder).writeArrayEnd();
}
 
Example 20
Source File: KafkaOutputPTransformRuntime.java    From components with Apache License 2.0 4 votes vote down vote up
@Override
public byte[] apply(IndexedRecord input) {
    Object k = input.get(input.getSchema().getField(keyName).pos());
    return String.valueOf(k).getBytes(Charset.forName("UTF-8"));
}