本文整理汇总了Java中org.apache.avro.Schema.Field.pos方法的典型用法代码示例。如果您正苦于以下问题:Java Field.pos方法的具体用法?Java Field.pos怎么用?Java Field.pos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.Schema.Field
的用法示例。
在下文中一共展示了Field.pos方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateAppropriateWrapper
import org.apache.avro.Schema.Field; //导入方法依赖的package包/类
public static String generateAppropriateWrapper(Schema schema, Field field) {
if (DIRTY_BYTES_FIELD_NAME.equals(field.name())) {
return "java.nio.ByteBuffer.wrap(new byte["
+ getNumberOfBytesNeededForDirtyBits(schema) + "])";
} else {
switch (field.schema().getType()) {
case RECORD:
return field.schema().getName()+".newBuilder().build()";
case MAP:
return "new org.apache.gora.persistency.impl.DirtyMapWrapper((java.util.Map)defaultValue(fields()["+field.pos()+"]))";
case ARRAY:
return "new org.apache.gora.persistency.impl.DirtyListWrapper((java.util.List)defaultValue(fields()["+field.pos()+"]))";
default:
return "defaultValue(fields()["+field.pos()+"])";
}
}
}
示例2: getPersistent
import org.apache.avro.Schema.Field; //导入方法依赖的package包/类
/**
* Returns a clone with exactly the requested fields shallowly copied
*/
private static<T extends Persistent> T getPersistent(T obj, String[] fields) {
List<Field> otherFields = obj.getSchema().getFields();
String[] otherFieldStrings = new String[otherFields.size()];
for(int i = 0; i<otherFields.size(); i++ ){
otherFieldStrings[i] = otherFields.get(i).name();
}
if(Arrays.equals(fields, otherFieldStrings)) {
return obj;
}
T newObj = AvroUtils.deepClonePersistent(obj);
for (Field otherField : otherFields) {
int index = otherField.pos();
newObj.put(index, obj.get(index));
}
return newObj;
}
示例3: checkIfMutableFieldAndDirty
import org.apache.avro.Schema.Field; //导入方法依赖的package包/类
private boolean checkIfMutableFieldAndDirty(Field field) {
if (field.pos() == 0)
return false;
switch (field.schema().getType()) {
case RECORD:
case MAP:
case ARRAY:
Object value = get(field.pos());
return !(value instanceof Dirtyable) || value==null ? false : ((Dirtyable) value).isDirty();
case UNION:
value = get(field.pos());
return !(value instanceof Dirtyable) || value==null ? false : ((Dirtyable) value).isDirty();
default:
break;
}
return false;
}
示例4: convertToAvro
import org.apache.avro.Schema.Field; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public IndexedRecord convertToAvro(GettableT gettable) {
if (containerDataSpec == null) {
setContainerDataSpecFromInstance(gettable);
}
IndexedRecordAdapterWithCache record = new IndexedRecordAdapterWithCache(gettable);
// Create all of the readers for the record immediately.
if (fieldReader == null) {
fieldReader = new ContainerReaderByIndex[fieldType.length];
for (Field f : AvroUtils.unwrapIfNullable(getSchema()).getFields()) {
int i = f.pos();
fieldType[i] = getFieldDataSpec(i);
fieldReader[i] = getFieldReader(fieldType[i]);
}
}
return record;
}
示例5: write
import org.apache.avro.Schema.Field; //导入方法依赖的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: write
import org.apache.avro.Schema.Field; //导入方法依赖的package包/类
/**
* Inserts resources into Jira server formed from incoming data input <br>
* Method should be called only after {@link JiraInsertWriter#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 jsonField = dataSchema.getField("json");
if (jsonField == null) {
throw new IOException(MESSAGES.getMessage("error.schemaNotContainJson"));
}
jsonPos = jsonField.pos();
}
String json = (String) record.get(jsonPos);
validateRequestBody(json);
JiraResponse response = getConnection().post(resource, json);
handleResponse(response, json, record);
}
示例7: write
import org.apache.avro.Schema.Field; //导入方法依赖的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);
}
示例8: getConverter
import org.apache.avro.Schema.Field; //导入方法依赖的package包/类
@Override
public JDBCConverter getConverter(final Field f) {
final Schema basicSchema = AvroUtils.unwrapIfNullable(f.schema());
return null == basicSchema.getLogicalType() ? super.getConverter(f) : new JDBCConverter() {
@Override
public Object convertToAvro(ResultSet value) {
int index = f.pos() + 1;
try {
if (basicSchema.getLogicalType() == LogicalTypes.date()) {
// Snowflake stores the value as the number of days. So it is possible to retrieve that as an
// int value instead of converting it to Date first and then to days from milliseconds. If we
// convert it to date, Snowflake jdbc shifts the time to 00:00 in current timezone.
return value.getInt(index);
} else if (basicSchema.getLogicalType() == LogicalTypes.timeMillis()) {
java.sql.Time time = value.getTime(index);
return (time != null) ? (int) time.getTime() : null;
} else {
java.sql.Timestamp timestamp = value.getTimestamp(index);
return (timestamp != null) ? timestamp.getTime() : null;
}
} catch (SQLException e) {
throw new ComponentException(e);
}
}
};
}
示例9: getFieldValue
import org.apache.avro.Schema.Field; //导入方法依赖的package包/类
/**
* For every field within an object, we pass in a field schema, Type and value.
* This enables us to process fields (based on their characteristics)
* preparing them for persistence.
* @param fieldSchema the associated field schema
* @param type the field type
* @param fieldValue the field value.
* @return
*/
private Object getFieldValue(Schema fieldSchema, Type type, Object fieldValue ){
switch(type) {
case RECORD:
Persistent persistent = (Persistent) fieldValue;
Persistent newRecord = (Persistent) SpecificData.get().newRecord(persistent, persistent.getSchema());
for (Field member: fieldSchema.getFields()) {
if (member.pos() == 0 || !persistent.isDirty()) {
continue;
}
Schema memberSchema = member.schema();
Type memberType = memberSchema.getType();
Object memberValue = persistent.get(member.pos());
newRecord.put(member.pos(), getFieldValue(memberSchema, memberType, memberValue));
}
fieldValue = newRecord;
break;
case MAP:
Map<?, ?> map = (Map<?, ?>) fieldValue;
fieldValue = map;
break;
case ARRAY:
fieldValue = (List<?>) fieldValue;
break;
case UNION:
// storing the union selected schema, the actual value will
// be stored as soon as we get break out.
if (fieldValue != null){
int schemaPos = getUnionSchema(fieldValue,fieldSchema);
Schema unionSchema = fieldSchema.getTypes().get(schemaPos);
Type unionType = unionSchema.getType();
fieldValue = getFieldValue(unionSchema, unionType, fieldValue);
}
//p.put( schemaPos, p.getSchema().getField(field.name() + CassandraStore.UNION_COL_SUFIX));
//p.put(fieldPos, fieldValue);
break;
default:
break;
}
return fieldValue;
}