本文整理汇总了Java中org.apache.avro.generic.IndexedRecord.get方法的典型用法代码示例。如果您正苦于以下问题:Java IndexedRecord.get方法的具体用法?Java IndexedRecord.get怎么用?Java IndexedRecord.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.generic.IndexedRecord
的用法示例。
在下文中一共展示了IndexedRecord.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: delete
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
private DeleteResult[] delete(IndexedRecord input) throws IOException {
// Calculate the field position of the Id the first time that it is used. The Id field must be present in the
// schema to delete rows.
if (deleteFieldId == -1) {
String ID = "Id";
Schema.Field idField = input.getSchema().getField(ID);
if (null == idField) {
throw new ComponentException(new DefaultErrorCode(HttpServletResponse.SC_BAD_REQUEST, "message"),
ExceptionContext.build().put("message", ID + " not found"));
}
deleteFieldId = idField.pos();
}
String id = (String) input.get(deleteFieldId);
if (id != null) {
deleteItems.add(input);
if (deleteItems.size() >= commitLevel) {
return doDelete();
}
}
return null;
}
示例2: createSObject
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
private SObject createSObject(IndexedRecord input) {
SObject so = new SObject();
so.setType(sprops.module.moduleName.getStringValue());
nullValueFields.clear();
for (Schema.Field f : input.getSchema().getFields()) {
// For "Id" column, we should ignore it for "INSERT" action
if (!("Id".equals(f.name())
&& SalesforceOutputProperties.OutputAction.INSERT.equals(sprops.outputAction.getValue()))) {
Object value = input.get(f.pos());
Schema.Field se = moduleSchema.getField(f.name());
if (se != null) {
if (value != null && !value.toString().isEmpty()) {
addSObjectField(so, se.schema(), se.name(), value);
} else {
if (UPDATE.equals(sprops.outputAction.getValue())) {
nullValueFields.add(f.name());
}
}
}
}
}
if (!sprops.ignoreNull.getValue()) {
so.setFieldsToNull(nullValueFields.toArray(new String[0]));
}
return so;
}
示例3: handleReject
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
private void handleReject(IndexedRecord input, SQLException e) throws IOException {
IndexedRecord rejectRecord = new GenericData.Record(schemaReject);
for (Schema.Field rejectedField : schemaReject.getFields()) {
Object value = null;
Schema.Field field = input.getSchema().getField(rejectedField.name());
if (field != null) {
value = input.get(field.pos());
} else if ("errorCode".equals(rejectedField.name())) {
value = e.getSQLState();
} else if ("errorMessage".equals(rejectedField.name())) {
value = e.getMessage();
} else {
continue;
}
rejectRecord.put(rejectedField.pos(), value);
}
result.totalCount++;
result.rejectCount++;
rejectedWrites.add(rejectRecord);
}
示例4: testConvertToAvroFailedIllegalRecordIndex
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
@Test (expected = IndexOutOfBoundsException.class)
public void testConvertToAvroFailedIllegalRecordIndex() {
ByteBuf buffer = Mockito.mock(ByteBuf.class);
// Mocking key object
Mockito.when(buffer.getByte(0)).thenReturn(MessageUtil.MAGIC_REQ);
Mockito.when(buffer.getByte(1)).thenReturn(MessageUtil.DCP_EXPIRATION_OPCODE);
Mockito.when(buffer.getByte(4)).thenReturn(OFFSET);
Mockito.when(buffer.getShort(2)).thenReturn(LENGTH);
ByteBuf key = Mockito.mock(ByteBuf.class);
Mockito.when(key.readableBytes()).thenReturn(4);
Mockito.when(buffer.slice(29, 10)).thenReturn(key);
IndexedRecord record = converter.convertToAvro(buffer);
record.get(10);
}
示例5: write
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
/**
* Removes input data resources from Jira server <br>
* Method should be called only after {@link JiraDeleteWriter#open(String)}
*
* @param datum input data
*/
@Override
public void write(Object datum) throws IOException {
if (!opened) {
throw new IOException(MESSAGES.getMessage("error.writerNotOpened"));
}
result.totalCount++;
if (datum == null) {
return;
}
IndexedRecord record = getFactory(datum).convertToAvro(datum);
if (dataSchema == null) {
dataSchema = record.getSchema();
Field idField = dataSchema.getField("id");
if (idField == null) {
throw new IOException(MESSAGES.getMessage("error.schemaNotContainId"));
}
idPos = idField.pos();
}
String id = (String) record.get(idPos);
String resourceToDelete = resource + "/" + id;
JiraResponse response = getConnection().delete(resourceToDelete, sharedParameters);
handleResponse(response, id, record);
}
示例6: getAllTestRows
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
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;
}
示例7: testHierarchical_TFD2119_B5_AtLeast1SubRecordsWithId1Or2HasValueGt10
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
@Ignore("Parenthesis are not correctly implemented in avpath.")
@Test
public void testHierarchical_TFD2119_B5_AtLeast1SubRecordsWithId1Or2HasValueGt10() throws Exception {
DoFnTester<Object, IndexedRecord> fnTester = DoFnTester.of( //
new FilterRowDoFn().withProperties(addCriteria(null, //
".b1{(.id == 1) || (.id == 2)) && .value > 10}", //
ConditionsRowConstant.Function.COUNT, //
ConditionsRowConstant.Operator.GREATER, //
"0") //
).withOutputSchema(true));
// TODO: for the moment, this just throws an exception.
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;
}
assertThat(main.toString(), atLeastOne, is(true));
}
assertThat(output, hasSize(57));
}
示例8: getValues
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
@Override
public List<String> getValues(Object datum) {
IndexedRecord input = getFactory(datum).convertToAvro((IndexedRecord) datum);
List<String> values = new ArrayList<String>();
for (Field f : input.getSchema().getFields()) {
if (checkDeleteOption(f.name())) {
continue;
}
if (input.get(f.pos()) == null) {
if (getBulkProperties().ignoreNull.getValue()) {
values.add("");
} else {
values.add("#N/A");
}
} else {
values.add(String.valueOf(input.get(f.pos())));
}
}
return values;
}
示例9: testHierarchical_TFD2119_B7_HasAtLeastOneSubrecordWithSubSubRecordValueGt10
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
@Test
public void testHierarchical_TFD2119_B7_HasAtLeastOneSubrecordWithSubSubRecordValueGt10() throws Exception {
DoFnTester<Object, IndexedRecord> fnTester = DoFnTester.of( //
new FilterRowDoFn().withProperties(addCriteria(null, //
".b1{.b2.value > 10}", //
ConditionsRowConstant.Function.COUNT, //
ConditionsRowConstant.Operator.GREATER, //
"0") //
).withOutputSchema(true));
List<IndexedRecord> output = fnTester.processBundle(inputB);
for (IndexedRecord main : output) {
boolean atLeastOne = false;
for (IndexedRecord subrecord : getSubrecords(main)) {
for (IndexedRecord subsubrecord : getSubrecords(subrecord)) {
if ((double) subsubrecord.get(2) > 10)
atLeastOne = true;
}
}
assertThat(main.toString(), atLeastOne, is(true));
}
assertThat(output, hasSize(311));
}
示例10: createSuccessRecord
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
/**
* Create record for outgoing {@code success} flow.
*
* @param response write response
* @param record indexed record which was written
* @return result record
*/
private IndexedRecord createSuccessRecord(NsWriteResponse<RefT> response, IndexedRecord record) {
NsRef ref = NsRef.fromNativeRef(response.getRef());
GenericData.Record targetRecord = new GenericData.Record(flowSchema);
for (Schema.Field field : schema.getFields()) {
Schema.Field targetField = flowSchema.getField(field.name());
if (targetField != null) {
Object value = record.get(field.pos());
targetRecord.put(targetField.name(), value);
}
}
Schema.Field internalIdField = NetSuiteDatasetRuntimeImpl.getNsFieldByName(flowSchema, "internalId");
if (internalIdField != null && targetRecord.get(internalIdField.pos()) == null) {
targetRecord.put(internalIdField.pos(), ref.getInternalId());
}
Schema.Field externalIdField = NetSuiteDatasetRuntimeImpl.getNsFieldByName(flowSchema, "externalId");
if (externalIdField != null && targetRecord.get(externalIdField.pos()) == null) {
targetRecord.put(externalIdField.pos(), ref.getExternalId());
}
if (ref.getRefType() == RefType.CUSTOMIZATION_REF) {
Schema.Field scriptIdField = NetSuiteDatasetRuntimeImpl.getNsFieldByName(flowSchema, "scriptId");
if (scriptIdField != null && targetRecord.get(scriptIdField.pos()) == null) {
targetRecord.put(scriptIdField.pos(), ref.getScriptId());
}
}
return targetRecord;
}
示例11: getSubrecords
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
/**
* @param main A main record.
* @return A list containing all of the subrecords that it contains, whether it is nested in an array or not.
*/
public static final List<IndexedRecord> getSubrecords(IndexedRecord main) {
ArrayList<IndexedRecord> result = new ArrayList<>();
for (Schema.Field f : main.getSchema().getFields()) {
if (AvroUtils.unwrapIfNullable(f.schema()).getType().equals(Schema.Type.ARRAY)) {
for (IndexedRecord r : (Iterable<IndexedRecord>) main.get(f.pos())) {
result.add(r);
}
} else if (AvroUtils.unwrapIfNullable(f.schema()).getType().equals(Schema.Type.RECORD)) {
result.add((IndexedRecord) main.get(f.pos()));
}
}
return result;
}
示例12: makeIndexedRecords
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
public static <T> List<IndexedRecord> makeIndexedRecords(
NetSuiteClientService<?> clientService, Schema schema,
ObjectComposer<T> objectComposer, int count) throws Exception {
NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, schema.getName());
List<IndexedRecord> recordList = new ArrayList<>();
while (count > 0) {
T nsRecord = objectComposer.composeObject();
IndexedRecord convertedRecord = transducer.read(nsRecord);
Schema recordSchema = convertedRecord.getSchema();
GenericRecord record = new GenericData.Record(recordSchema);
for (Schema.Field field : schema.getFields()) {
Object value = convertedRecord.get(field.pos());
record.put(field.pos(), value);
}
recordList.add(record);
count--;
}
return recordList;
}
示例13: write
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
@Override
public void write(Object datum) throws IOException {
if (!opened) {
throw new IOException("Writer is not opened");
}
result.totalCount++;
if (datum == null) {
return;
}
// Data object is always IndexedRecord
IndexedRecord record = (IndexedRecord) datum;
Schema schema = record.getSchema();
Schema.Field idField = schema.getField(idFieldName);
if (idField == null) {
throw new IOException("Schema does not contain ID field: " + idFieldName);
}
int idPos = idField.pos();
Object id = record.get(idPos);
if (id == null) {
handleException("Record is not processed. ID is null.", new IllegalArgumentException("ID field should not be null"));
return;
}
try {
connection.upsert(id.toString(), datum.toString());
result.successCount++;
} catch (Exception e) {
handleException("Record is not processed. Failed to upsert value - " + datum.toString(), e);
}
}
示例14: processElement
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
@ProcessElement
public void processElement(ProcessContext c) throws IOException {
// Join the strings with the delimiter.
IndexedRecord in = c.element();
int size = in.getSchema().getFields().size();
for (int i = 0; i < size; i++) {
Object valueToWrite = in.get(i);
if (valueToWrite instanceof ByteBuffer)
valueToWrite = new String(((ByteBuffer) valueToWrite).array());
format.print(valueToWrite, sb, sb.length() == 0);
}
c.output(KV.of(NullWritable.get(), new Text(sb.toString())));
sb.setLength(0);
}
示例15: prepareMap
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
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;
}