本文整理汇总了Java中org.apache.avro.generic.IndexedRecord.put方法的典型用法代码示例。如果您正苦于以下问题:Java IndexedRecord.put方法的具体用法?Java IndexedRecord.put怎么用?Java IndexedRecord.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.generic.IndexedRecord
的用法示例。
在下文中一共展示了IndexedRecord.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cleanupEntities
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
public void cleanupEntities(String table) throws Throwable {
properties.dieOnError.setValue(false);
properties.tableName.setValue(table);
properties.schema.schema.setValue(getDeleteSchema());
properties.actionOnData.setValue(ActionOnData.Delete);
properties.schemaListener.afterSchema();
Writer<?> writer = createWriter(properties);
writer.open("test-uid");
for (String p : partitions) {
for (String r : rows_all) {
IndexedRecord entity = new GenericData.Record(getWriteSchema());
entity.put(0, p);
entity.put(1, r);
writer.write(entity);
}
}
writer.close();
properties.dieOnError.setValue(true);
}
示例2: testWriteErrorMessage
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
/**
* Checks {@link JiraInsertWriter#write()} throws {@link IOException} which error message contains:
* "Reason: record is invalid"
*
* @throws IOException
*/
@Test
public void testWriteErrorMessage() throws IOException {
IndexedRecord badIssueTypeRecord = new GenericData.Record(INSERT_SCHEMA);
String insertIssue1 = "{\"fields\":{\"project\":{\"key\":\"TP\"},\"summary\":\"Integration test issue 1\",\"issuetype\":{\"id\":\"12345\"}}}";
badIssueTypeRecord.put(0, insertIssue1);
thrown.expect(IOException.class);
thrown.expectMessage("Reason: record is invalid");
thrown.expectMessage("Record: " + insertIssue1);
thrown.expectMessage("Error: ");
thrown.expectMessage("{\"errorMessages\":[],\"errors\":{\"issuetype\":\"valid issue type is required\"}}");
JiraWriter insertIssueWriter = JiraTestsHelper.createWriter(HOST_PORT, USER, PASS, Resource.ISSUE, Action.INSERT);
insertIssueWriter.open("ins");
try {
insertIssueWriter.write(badIssueTypeRecord);
} finally {
insertIssueWriter.close();
}
}
示例3: testWriteNotOpened
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
/**
* Checks {@link JiraUpdateWriter#write()} {@link IOException} which message is
*
* if {@link JiraUpdateWriter#open()} wasn't called
*
* @throws IOException
*/
@Test
public void testWriteNotOpened() throws IOException {
IndexedRecord wrongProjectRecord = new GenericData.Record(UPDATE_SCHEMA);
String wrongProject = "{\"name\":\"Updated Integration Test Project\",\"assigneeType\":\"PROJECT_LEAD\"}";
wrongProjectRecord.put(0, "WP");
wrongProjectRecord.put(1, wrongProject);
thrown.expect(IOException.class);
thrown.expectMessage("Writer wasn't opened");
JiraWriter updateProjectWriter = JiraTestsHelper.createWriter(HOST_PORT, WRONG_USER, PASS, Resource.PROJECT,
Action.UPDATE);
updateProjectWriter.write(wrongProjectRecord);
}
示例4: testWriteUnauthorized
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
/**
* Checks {@link JiraDeleteWriter#write()} throws {@link IOException} which message contains
* "User is not authenticated. Record wasn't deleted"
* in case server responses with 401 Unauthorized status code
*
* @throws IOException
*/
@Test
public void testWriteUnauthorized() throws IOException {
String expectedError = "User is not authenticated. Record wasn't deleted";
IndexedRecord badJsonRecord = new GenericData.Record(DELETE_SCHEMA);
badJsonRecord.put(0, "TP");
thrown.expect(IOException.class);
thrown.expectMessage("Reason: user is not authenticated. Record wasn't deleted");
thrown.expectMessage("Record: TP");
thrown.expectMessage("Error: ");
JiraWriter deleteProjectWriter = JiraTestsHelper.createWriter(HOST_PORT, WRONG_USER, PASS, Resource.PROJECT,
Action.DELETE);
deleteProjectWriter.open("del");
try {
deleteProjectWriter.write(badJsonRecord);
fail();
} catch (DataRejectException e) {
String rejectError = e.getRejectInfo().get("error").toString();
assertEquals(expectedError, rejectError);
} finally {
deleteProjectWriter.close();
}
}
示例5: insertTestValues
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
public void insertTestValues(String table) throws Throwable {
properties.schema.schema.setValue(getDynamicSchema());
properties.actionOnData.setValue(ActionOnData.Insert);
properties.schemaListener.afterSchema();
properties.tableName.setValue(table);
Writer<?> writer = createWriter(properties);
writer.open("test-uid");
for (String p : partitions) {
for (String r : rows) {
IndexedRecord entity = new GenericData.Record(getWriteSchema());
entity.put(0, p);
entity.put(1, r);
entity.put(2, testTimestamp);
entity.put(3, true);
entity.put(4, 1000);
entity.put(5, testString);
entity.put(6, 1000000L);
entity.put(7, 100.5562);
entity.put(8, "ABCDEFGH".getBytes(Charset.defaultCharset()));
writer.write(entity);
}
}
writer.close();
}
示例6: testSyncLeadSOAP
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
@Test
public void testSyncLeadSOAP() throws Exception {
props = getSOAPProperties();
// test attributes
List<Field> fields = new ArrayList<>();
Field field = new Schema.Field("FirstName", Schema.create(Schema.Type.STRING), null, (Object) null);
fields.add(field);
field = new Schema.Field("LastName", Schema.create(Schema.Type.STRING), null, (Object) null);
fields.add(field);
field = new Schema.Field("AccountType", Schema.create(Schema.Type.STRING), null, (Object) null);
fields.add(field);
Schema s = MarketoUtils.newSchema(props.schemaInput.schema.getValue(), "leadAttribute", fields);
props.schemaInput.schema.setValue(s);
props.updateOutputSchemas();
props.beforeMappingInput();
//
IndexedRecord record = new GenericData.Record(s);
record.put(0, null);
record.put(1, "[email protected]");
record.put(2, "Foreign0Person_Sys_Id");
record.put(3, "SFDC");// CUSTOM, SFDC, NETSUITE;
record.put(5, "My0firstName");
record.put(6, "My1lastName");
record.put(7, "Conservative customer1");
//
testSyncLead(record);
}
示例7: testRemoveFromSOAP
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
@Test
public void testRemoveFromSOAP() throws Exception {
props = getSOAPProperties();
props.listOperation.setValue(ListOperation.removeFrom);
//
Schema s = props.schemaInput.schema.getValue();
IndexedRecord record = new GenericData.Record(s);
record.put(0, "MKTOLISTNAME");
record.put(1, UNDX_TEST_LIST_SMALL);
record.put(2, "IDNUM");
// record.put(3, 2767254);
record.put(3, createdLeads.get(3));
//
writer = getWriter(props);
writer.open("test");
writer.write(record);
assertEquals(1, writer.result.getTotalCount());
assertEquals(1, writer.result.getSuccessCount());
assertEquals(0, writer.result.getRejectCount());
//
props.listOperation.setValue(ListOperation.isMemberOf);
writer = getWriter(props);
writer.open("test");
writer.write(record);
for (IndexedRecord success : writer.getSuccessfulWrites()) {
assertFalse((Boolean) success.get(props.schemaFlow.schema.getValue().getField(FIELD_SUCCESS).pos()));
}
assertEquals(1, writer.result.getTotalCount());
assertEquals(1, writer.result.getSuccessCount());
assertEquals(0, writer.result.getRejectCount());
assertEquals(1, writer.result.getApiCalls());
}
示例8: advance
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
@Override
public boolean advance() throws IOException {
advanceable = blobsIterator.hasNext();
if (advanceable) {
dataCount++;
currentBlob = blobsIterator.next();
IndexedRecord dataRecord = new GenericData.Record(properties.schema.schema.getValue());
dataRecord.put(0, currentBlob.getName());
currentRecord.put(0, dataRecord);
currentRecord.put(1, dataRecord);
}
return advanceable;
}
示例9: testReplace
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Test
public void testReplace() throws Throwable {
currentTable = tbl_test + "Replace";
insertTestValues(currentTable);
properties.schema.schema.setValue(getSimpleTestSchema());
properties.actionOnData.setValue(ActionOnData.Replace);
properties.schemaListener.afterSchema();
Writer<?> writer = createWriter(properties);
writer.open("test-uid");
for (String p : partitions) {
for (String r : rows) {
// IndexedRecord entity = new GenericData.Record(getWriteSchema());
IndexedRecord entity = new GenericData.Record(getSimpleTestSchema());
entity.put(0, p);
entity.put(1, r);
entity.put(2, "NewValue");
writer.write(entity);
}
}
writer.close();
// check results...
BoundedReader reader = createReader(currentTable, filter, false);
int counted = 0;
assertTrue(reader.start());
do {
counted++;
IndexedRecord current = (IndexedRecord) reader.getCurrent();
assertEquals(current.get(current.getSchema().getField("StringValue").pos()), "NewValue");
assertEquals(4, current.getSchema().getFields().size());
} while (reader.advance());
reader.close();
// we should have read 9 rows...
assertEquals(9, counted);
}
示例10: testWriteNotOpened
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
/**
* Checks {@link JiraInsertWriter#write()} throws {@link IOException} with
* "Writer wasn't opened" message if {@link JiraInsertWriter#open()} wasn't called
*
* @throws IOException
*/
@Test
public void testWriteNotOpened() throws IOException {
IndexedRecord badJsonRecord = new GenericData.Record(INSERT_SCHEMA);
String badProject = "{\"name\":\"Updated Integration Test Project\"\"assigneeType\":\"PROJECT_LEAD\"}";
badJsonRecord.put(0, badProject);
thrown.expect(IOException.class);
thrown.expectMessage("Writer wasn't opened");
JiraWriter insertProjectWriter = JiraTestsHelper.createWriter(HOST_PORT, WRONG_USER, PASS, Resource.PROJECT,
Action.INSERT);
insertProjectWriter.write(badJsonRecord);
}
示例11: testAddToREST
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
@Test
public void testAddToREST() throws Exception {
props = getRESTProperties();
props.listOperation.setValue(ListOperation.addTo);
//
Schema s = props.schemaInput.schema.getValue();
IndexedRecord record = new GenericData.Record(s);
record.put(0, UNDX_TEST_LIST_SMALL_ID);
record.put(1, createdLeads.get(9));
//
writer = getWriter(props);
writer.open("test");
writer.write(record);
assertEquals(1, writer.result.getTotalCount());
assertEquals(1, writer.result.getSuccessCount());
assertEquals(0, writer.result.getRejectCount());
//
props.listOperation.setValue(ListOperation.isMemberOf);
writer = getWriter(props);
writer.open("test");
writer.write(record);
for (IndexedRecord success : writer.getSuccessfulWrites()) {
assertEquals("memberof", success.get(props.schemaFlow.schema.getValue().getField(FIELD_STATUS).pos()));
}
assertEquals(1, writer.result.getTotalCount());
assertEquals(1, writer.result.getSuccessCount());
assertEquals(0, writer.result.getRejectCount());
assertEquals(1, writer.result.getApiCalls());
}
示例12: testSyncLead
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
@Test
public void testSyncLead() throws Exception {
outProperties.outputOperation.setValue(OutputOperation.syncLead);
outProperties.operationType.setValue(OperationType.createOrUpdate);
outProperties.lookupField.setValue(RESTLookupFields.email);
outProperties.deDupeEnabled.setValue(false);
outProperties.updateSchemaRelated();
outProperties.updateOutputSchemas();
MarketoSource source = new MarketoSource();
source.initialize(null, outProperties);
MarketoClientService client = source.getClientService(null);
//
// test attributes
List<Field> fields = new ArrayList<>();
Field field = new Schema.Field("accountType", Schema.create(Schema.Type.STRING), null, (Object) null);
fields.add(field);
Schema s = MarketoUtils.newSchema(outProperties.schemaInput.schema.getValue(), "leadAttribute", fields);
IndexedRecord record = new GenericData.Record(s);
record.put(0, null);
record.put(1, "[email protected]");
record.put(2, "ForeignPersonSysId");
record.put(3, "SFDC");// CUSTOM, SFDC, NETSUITE;
record.put(4, "My firstName");
List<IndexedRecord> leads = Arrays.asList(record);
outProperties.schemaInput.schema.setValue(s);
outProperties.beforeMappingInput();
///
MarketoSyncResult result = client.syncLead(outProperties, record);
LOG.debug("result = {}.", result);
List<SyncStatus> changes = result.getRecords();
assertTrue(changes.size() > 0);
for (SyncStatus r : changes) {
assertNotNull(r);
assertNotNull(r.getId());
LOG.debug("r = {}.", r);
}
}
示例13: createVehicleCollection
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
public static final IndexedRecord createVehicleCollection(Collection<IndexedRecord> automobiles,
Collection<IndexedRecord> motorcycles) {
IndexedRecord r = new Record(RECORD_VEHICLE_COLLECTION);
r.put(0, new GenericData.Array<IndexedRecord>(RECORD_VEHICLE_COLLECTION.getFields().get(0).schema(), automobiles));
r.put(1, new GenericData.Array<IndexedRecord>(RECORD_VEHICLE_COLLECTION.getFields().get(1).schema(), motorcycles));
return r;
}
示例14: testMerge
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Test
public void testMerge() throws Throwable {
currentTable = tbl_test + "Merge";
insertTestValues(currentTable);
properties.schema.schema.setValue(getMergeSchema());
properties.actionOnData.setValue(ActionOnData.Merge);
properties.schemaListener.afterSchema();
Writer<?> writer = createWriter(properties);
writer.open("test-uid");
for (String p : partitions) {
for (String r : rows) {
IndexedRecord entity = new GenericData.Record(getMergeSchema());
assertEquals(3, entity.getSchema().getFields().size());
entity.put(0, p);
entity.put(1, r);
entity.put(2, 1000000L * 2);
writer.write(entity);
}
}
writer.close();
// check results...
BoundedReader reader = createReader(currentTable, filter, false);
int counted = 0;
assertTrue(reader.start());
do {
counted++;
IndexedRecord current = (IndexedRecord) reader.getCurrent();
assertEquals(1000000L * 2, current.get(current.getSchema().getField("longy").pos()));
// checks that other fields remained the sames...
assertEquals(current.get(current.getSchema().getField("daty").pos()), testTimestamp);
assertEquals(current.get(current.getSchema().getField("inty").pos()), 1000);
assertEquals(current.get(current.getSchema().getField("stringy").pos()), testString);
assertEquals(current.get(current.getSchema().getField("doubly").pos()), 100.5562);
assertEquals(new String((byte[]) current.get(current.getSchema().getField("bytys").pos())), "ABCDEFGH");
assertEquals(10, current.getSchema().getFields().size());
} while (reader.advance());
reader.close();
// we should have read 9 rows...
assertEquals(9, counted);
}
示例15: testMultipleOperationsSOAP
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
@Test
public void testMultipleOperationsSOAP() throws Exception {
props = getSOAPProperties();
props.listOperation.setValue(ListOperation.addTo);
props.multipleOperation.setValue(true);
//
Schema s = props.schemaInput.schema.getValue();
writer = getWriter(props);
writer.open("test");
List<IndexedRecord> testRecords = new ArrayList<>();
for (Integer leadid : createdLeads) {
IndexedRecord record = new GenericData.Record(s);
record.put(0, "MKTOLISTNAME");
record.put(1, UNDX_TEST_LIST_SMALL);
record.put(2, "IDNUM");
// record.put(3, 2767254);
record.put(3, leadid);
//
testRecords.add(record);
//
writer.write(record);
}
writer.close();
assertEquals(TEST_NB_LEADS, writer.result.getTotalCount());
assertEquals(TEST_NB_LEADS, writer.result.getSuccessCount() + writer.result.getRejectCount());
//
props.listOperation.setValue(ListOperation.isMemberOf);
writer = getWriter(props);
writer.open("test");
for (IndexedRecord r : testRecords) {
writer.write(r);
for (IndexedRecord success : writer.getSuccessfulWrites()) {
assertTrue((Boolean) success.get(props.schemaFlow.schema.getValue().getField(FIELD_SUCCESS).pos()));
}
}
writer.close();
assertEquals(TEST_NB_LEADS, writer.result.getTotalCount());
assertEquals(TEST_NB_LEADS, writer.result.getSuccessCount() + writer.result.getRejectCount());
}