本文整理汇总了Java中org.apache.avro.generic.IndexedRecord.getSchema方法的典型用法代码示例。如果您正苦于以下问题:Java IndexedRecord.getSchema方法的具体用法?Java IndexedRecord.getSchema怎么用?Java IndexedRecord.getSchema使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.generic.IndexedRecord
的用法示例。
在下文中一共展示了IndexedRecord.getSchema方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAdaptorFactoryWrapPrimitivesAsSingleColumnIndexedRecord
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
@Test
public void testAdaptorFactoryWrapPrimitivesAsSingleColumnIndexedRecord() {
// The input datum is a primitive String.
Object in = "hello";
// Get an adapter factory for it.
IndexedRecordConverter<?, ?> irff = new AvroRegistry().createIndexedRecordConverter(in.getClass());
assertThat(irff, not(nullValue()));
// The output is an IndexedRecord that contains one String column.
@SuppressWarnings({ "rawtypes", "unchecked" })
IndexedRecord out = (IndexedRecord) ((IndexedRecordConverter) irff).convertToAvro(in);
Schema s = out.getSchema();
assertThat(s.getType(), is(Schema.Type.RECORD));
assertThat(s.getFields(), hasSize(1));
assertThat(s.getFields().get(0).schema().getType(), is(Schema.Type.STRING));
// And it simply wraps the incoming data in the first column.
assertThat(out.get(0), sameInstance(in));
}
示例2: getWritingConsumer
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
private Consumer<IndexedRecord> getWritingConsumer(Encoder[] encoder) {
return new Consumer<IndexedRecord>() {
GenericDatumWriter<IndexedRecord> writer = null;
@Override
public void accept(IndexedRecord ir) {
if (writer == null) {
writer = new GenericDatumWriter<>(ir.getSchema());
try {
if (json) {
encoder[0] = EncoderFactory.get().jsonEncoder(ir.getSchema(), output);
} else {
encoder[0] = EncoderFactory.get().binaryEncoder(output, null);
}
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
writeIndexedRecord(writer, encoder[0], ir);
}
};
}
示例3: testColumnNameCaseSensitive
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
/**
* Test query mode fields of schema is not case sensitive
*/
@Test
public void testColumnNameCaseSensitive() throws Throwable {
TSalesforceInputProperties props = createTSalesforceInputProperties(false, false);
Schema schema = SchemaBuilder.builder().record("Schema").fields() //
.name("ID").type().stringType().noDefault() //
.name("type").type().stringType().noDefault() //
.name("NAME").type().stringType().noDefault().endRecord();
props.module.main.schema.setValue(schema);
props.condition.setValue("Id != null and name != null and type!=null Limit 1");
props.validateGuessSchema();
List<IndexedRecord> rows = readRows(props);
if (rows.size() > 0) {
assertEquals(1, rows.size());
IndexedRecord row = rows.get(0);
Schema runtimeSchema = row.getSchema();
assertEquals(3, runtimeSchema.getFields().size());
assertNotNull(row.get(schema.getField("ID").pos()));
assertNotNull(row.get(schema.getField("type").pos()));
assertNotEquals("Account",row.get(schema.getField("type").pos()));
assertNotNull(row.get(schema.getField("NAME").pos()));
} else {
LOGGER.warn("Query result is empty!");
}
}
示例4: testGetCustomObjectWithCompoundKey
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
@Test
public void testGetCustomObjectWithCompoundKey() throws Exception {
irProps.customObjectAction.setValue(CustomObjectAction.get);
irProps.customObjectName.setValue(TEST_CO_NAME_CAR);
irProps.validateFetchCustomObjectSchema();
irProps.useCompoundKey.setValue(true);
// "searchableFields": "[[\"customerId\",\"VIN\"],[\"marketoGUID\"],[\"customerId\"]]"
irProps.compoundKey.keyName.setValue(Arrays.asList("customerId", "VIN"));
irProps.compoundKey.keyValue.setValue(Arrays.asList("4137181", "WBA4R7C30HK896061"));// WBA4R7C55HK895912
MarketoSource source = new MarketoSource();
source.initialize(null, irProps);
MarketoRESTClient client = (MarketoRESTClient) source.getClientService(null);
MarketoRecordResult result = client.getCustomObjects(irProps, null);
LOG.debug("result = {}.", result);
assertNotNull(result.getRecords());
assertEquals(1, result.getRecords().size());
IndexedRecord record = result.getRecords().get(0);
Schema s = record.getSchema();
assertEquals(4137181, record.get(s.getField("customerId").pos()));
assertEquals("WBA4R7C30HK896061", record.get(s.getField("VIN").pos()));
assertEquals("FIT", record.get(s.getField("brand").pos()));
}
示例5: 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;
}
示例6: write
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
@Override
public void write(Object object) throws IOException {
if (object == null) {
return;
}
//
inputRecord = (IndexedRecord) object;
result.totalCount++;
// This for dynamic which would get schema from the first record
if (inputSchema == null) {
inputSchema = inputRecord.getSchema();
}
//
addRecordToListOperationParameters(inputRecord);
//
}
示例7: encodeRecord
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
public static byte[] encodeRecord(IndexedRecord record) throws IOException {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
EncoderFactory encoderFactory = EncoderFactory.get();
BinaryEncoder binaryEncoder = encoderFactory.binaryEncoder(stream, null);
SpecificDatumWriter<IndexedRecord> datumWriter = new SpecificDatumWriter<>(record.getSchema());
datumWriter.write(record, binaryEncoder);
binaryEncoder.flush();
} finally {
stream.close();
}
return stream.toByteArray();
}
示例8: toDocument
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
public static Document toDocument(IndexedRecord record) {
Document document = new Document();
Schema schema = record.getSchema();
for (Field field : schema.getFields()) {
Object value = record.get(field.pos());
if (value != null) {
document.put(getFieldName(field), getDocument(field.schema(), value));
}
}
return document;
}
示例9: isRootRecord
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
/**
* Checks whether input {@link IndexedRecord} is Root record
* It checks its {@link Schema}, it should be Root schema
*
* @param data data to check
* @return true if incoming {@link IndexedRecord} is Root record; false otherwise
*/
public static boolean isRootRecord(Object data) {
if (data == null) {
return false;
}
if (!(data instanceof IndexedRecord)) {
return false;
}
IndexedRecord record = (IndexedRecord) data;
Schema recordSchema = record.getSchema();
boolean result = RootSchemaUtils.isRootSchema(recordSchema);
return result;
}
示例10: copyValueFrom
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
private static IndexedRecord copyValueFrom(IndexedRecord record) {
Schema schema = record.getSchema();
IndexedRecord result = new GenericData.Record(schema);
List<Schema.Field> fields = schema.getFields();
for (int i = 0; i < fields.size(); i++) {
result.put(i, record.get(i));
}
return result;
}
示例11: testComplexSOQLQuery
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
@Test
public void testComplexSOQLQuery() throws Throwable {
TSalesforceInputProperties props = createTSalesforceInputProperties(false, false);
props.manualQuery.setValue(true);
// Manual query with foreign key
// Need to specify where clause to be sure that this record exists and has parent-to-child relation.
props.query.setValue("Select Id, Name,(Select Contact.Id,Contact.Name from Account.Contacts) from Account WHERE Name = 'United Oil & Gas, UK' Limit 1");
props.validateGuessSchema();
List<IndexedRecord> rows = readRows(props);
if (rows.size() > 0) {
for (IndexedRecord row : rows) {
Schema schema = row.getSchema();
assertNotNull(schema.getField("Id"));
assertNotNull(schema.getField("Name"));
assertNotNull(schema.getField("Account_Contacts_records_Contact_Id"));
assertNotNull(schema.getField("Account_Contacts_records_Contact_Name"));
assertNotNull(row.get(schema.getField("Id").pos()));
assertNotNull(row.get(schema.getField("Name").pos()));
assertNotNull(row.get(schema.getField("Account_Contacts_records_Contact_Id").pos()));
assertNotNull(row.get(schema.getField("Account_Contacts_records_Contact_Name").pos()));
}
} else {
LOGGER.warn("Query result is empty!");
}
}
示例12: write
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
/**
* Updates Jira resources according incoming data <br>
* Method should be called only after {@link JiraUpdateWriter#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();
Field jsonField = dataSchema.getField("json");
if (jsonField == null) {
throw new IOException(MESSAGES.getMessage("error.schemaNotContainJson"));
}
jsonPos = jsonField.pos();
}
String id = (String) record.get(idPos);
String resourceToUpdate = resource + "/" + id;
String json = (String) record.get(jsonPos);
validateRequestBody(json);
JiraResponse response = getConnection().put(resourceToUpdate, json);
handleResponse(response, json, record);
}
示例13: apply
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
@Override
public byte[] apply(IndexedRecord input) {
try {
DatumWriter<IndexedRecord> datumWriter = new GenericDatumWriter(input.getSchema());
ByteArrayOutputStream out = new ByteArrayOutputStream();
BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(out, null);
datumWriter.write(input, encoder);
encoder.flush();
byte[] result = out.toByteArray();
out.close();
return result;
} catch (IOException e) {
throw TalendRuntimeException.createUnexpectedException(e);
}
}
示例14: testManualQuery
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
@Test
public void testManualQuery() throws Throwable {
TSalesforceInputProperties props = createTSalesforceInputProperties(false, false);
props.manualQuery.setValue(true);
props.query.setValue("select Id from Account WHERE Name = '" + randomizedValue + "'");
List<IndexedRecord> outputRows = readRows(props);
assertEquals(100, outputRows.size());
props.module.main.schema.setValue(SchemaBuilder.builder().record("MakeRowRecord").fields()//
.name("Id").type().nullable().stringType().noDefault() //
.name("Name").type().nullable().stringType().noDefault() //
.name("Owner_Name").type().nullable().stringType().noDefault() //
.name("Owner_Id").type().nullable().stringType().noDefault().endRecord());
props.query
.setValue("SELECT Id, Name, Owner.Name ,Owner.Id FROM Account WHERE Name = '" + randomizedValue + "'");
List<IndexedRecord> rowsWithForeignKey = readRows(props);
props.module.main.schema.setValue(SchemaBuilder.builder().record("MakeRowRecord").fields()//
.name("Id").type().nullable().stringType().noDefault() //
.name("Name").type().nullable().stringType().noDefault() //
.name("OwnerId").type().nullable().stringType().noDefault().endRecord());
props.query.setValue("SELECT Id, Name, OwnerId FROM Account WHERE Name = '" + randomizedValue + "'");
outputRows = readRows(props);
assertEquals(rowsWithForeignKey.size(), outputRows.size());
assertEquals(100, rowsWithForeignKey.size());
IndexedRecord fkRecord = rowsWithForeignKey.get(0);
IndexedRecord commonRecord = outputRows.get(0);
assertNotNull(fkRecord);
assertNotNull(commonRecord);
Schema schemaFK = fkRecord.getSchema();
Schema schemaCommon = commonRecord.getSchema();
assertNotNull(schemaFK);
assertNotNull(schemaCommon);
assertEquals(commonRecord.get(schemaCommon.getField("OwnerId").pos()), fkRecord.get(schemaFK.getField("Owner_Id").pos()));
}
示例15: makeIndexedRecords
import org.apache.avro.generic.IndexedRecord; //导入方法依赖的package包/类
public static <T> List<IndexedRecord> makeIndexedRecords(
NetSuiteClientService<?> clientService, Schema schema,
AbstractNetSuiteTestBase.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;
}