當前位置: 首頁>>代碼示例>>Java>>正文


Java Field.schema方法代碼示例

本文整理匯總了Java中org.apache.avro.Schema.Field.schema方法的典型用法代碼示例。如果您正苦於以下問題:Java Field.schema方法的具體用法?Java Field.schema怎麽用?Java Field.schema使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.avro.Schema.Field的用法示例。


在下文中一共展示了Field.schema方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: findField

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
private static Field findField(Schema schema, String name) {
	if (schema.getField(name) != null) {
		return schema.getField(name);
	}
	
	Field foundField = null;
	
	for (Field field : schema.getFields()) {
		Schema fieldSchema = field.schema();
		if (Type.RECORD.equals(fieldSchema.getType())) {
			foundField = findField(fieldSchema, name);
		} else if (Type.ARRAY.equals(fieldSchema.getType())) {
			foundField = findField(fieldSchema.getElementType(), name);
		} else if (Type.MAP.equals(fieldSchema.getType())) {
			foundField = findField(fieldSchema.getValueType(), name);
		}
		
		if (foundField != null) {
			return foundField;
		}
	}
	
	return foundField;
}
 
開發者ID:Celos,項目名稱:avro-json-decoder,代碼行數:25,代碼來源:ExtendedJsonDecoder.java

示例2: parseField

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
protected FieldNode parseField(Field field, AvroNode parentNode) {

		FieldNode fieldNode = new FieldNode(context);
		// init attributes
		fieldAttributeInitializer.setField(field);
		fieldNode.init(fieldAttributeInitializer);
		linkNodes(parentNode, fieldNode);
		registerNode(fieldNode);
		
		// type
		Schema fieldSchema = field.schema();
		if (!PrimitiveType.isPrimitive(fieldSchema)) {
			// add child node representing the complex type
			parseSchema(fieldSchema, fieldNode);			
		}		
		
		return fieldNode;
	}
 
開發者ID:Talend,項目名稱:avro-schema-editor,代碼行數:19,代碼來源:AvroSchemaParserImpl.java

示例3: newInstance

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
/**
 * Creates a new Persistent instance with the values in 'result' for the fields listed.
 * @param result result form a HTable#get()
 * @param fields List of fields queried, or null for all
 * @return A new instance with default values for not listed fields
 *         null if 'result' is null.
 * @throws IOException
 */
public T newInstance(Result result, String[] fields)
throws IOException {
  if(result == null || result.isEmpty())
    return null;

  T persistent = newPersistent();
  for (String f : fields) {
    HBaseColumn col = mapping.getColumn(f);
    if (col == null) {
      throw new  RuntimeException("HBase mapping for field ["+ f +"] not found. " +
          "Wrong gora-hbase-mapping.xml?");
    }
    Field field = fieldMap.get(f);
    Schema fieldSchema = field.schema();
    setField(result,persistent, col, field, fieldSchema);
  }
  persistent.clearDirty();
  return persistent;
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:28,代碼來源:HBaseStore.java

示例4: getColumnType

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
public static DataType getColumnType(Field field) {
  org.apache.avro.Schema fieldSchema = field.schema();
  fieldSchema = extractSchemaFromUnionIfNeeded(fieldSchema);

  final Type type = fieldSchema.getType();
  if (type == Type.ARRAY) {
    org.apache.avro.Schema elementSchema = extractSchemaFromUnionIfNeeded(fieldSchema.getElementType());
    if (elementSchema.getType() == Type.RECORD) {
      if (elementSchema.getFields().size() == 1) {
        elementSchema = elementSchema.getFields().get(0).schema();
      } else {
        throw new RuntimeException("More than one schema in Multi-value column!");
      }
      elementSchema = extractSchemaFromUnionIfNeeded(elementSchema);
    }
    return DataType.valueOf(elementSchema.getType());
  } else {
    return DataType.valueOf(type);
  }
}
 
開發者ID:Hanmourang,項目名稱:Pinot,代碼行數:21,代碼來源:AvroQueryGenerator.java

示例5: getHeader

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
/**
 * Builds the Meta Data of from the Avro Schema
 * 
 * @return
 */
protected InstanceInformation getHeader() {

  String relation = schema.getName();
  attributes = new ArrayList<Attribute>();

  /** By Definition, the returned list is in the order of their positions. **/
  List<Schema.Field> fields = schema.getFields();

  for (Field field : fields) {
    Schema attributeSchema = field.schema();

    /** Currently SAMOA supports only NOMINAL & Numeric Types. **/
    if (attributeSchema.getType() == Schema.Type.ENUM)
    {
      List<String> attributeLabels = attributeSchema.getEnumSymbols();
      attributes.add(new Attribute(field.name(), attributeLabels));
    }
    else if (isNumeric(field))
      attributes.add(new Attribute(field.name()));
  }
  return new InstanceInformation(relation, attributes);
}
 
開發者ID:apache,項目名稱:incubator-samoa,代碼行數:28,代碼來源:AvroLoader.java

示例6: isSparseData

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
/**
 * Identifies if the dataset is is Sparse or Dense
 * 
 * @return boolean
 */
protected boolean isSparseData()
{
  List<Schema.Field> fields = schema.getFields();
  for (Field field : fields) {
    Schema attributeSchema = field.schema();

    /** If even one attribute has a null union (nullable attribute) consider it as sparse data **/
    if (attributeSchema.getType() == Schema.Type.UNION)
    {
      List<Schema> unionTypes = attributeSchema.getTypes();
      for (Schema unionSchema : unionTypes) {
        if (unionSchema.getType() == Schema.Type.NULL)
          return true;
      }
    }

  }
  return false;
}
 
開發者ID:apache,項目名稱:incubator-samoa,代碼行數:25,代碼來源:AvroLoader.java

示例7: initConverters

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
/**
 * Initialize converters per each schema field
 * 
 * @param schema
 *            design schema
 */
private void initConverters(Schema schema) {
	converters = new StringConverter[size];
	List<Field> fields = schema.getFields();
	for (int i = 0; i < size; i++) {
		Field field = fields.get(i);
		Schema fieldSchema = field.schema();
		fieldSchema = AvroUtils.unwrapIfNullable(fieldSchema);
		if (LogicalTypeUtils.isLogicalTimestampMillis(fieldSchema)) {
			String datePattern = field.getProp(SchemaConstants.TALEND_COLUMN_PATTERN);
			converters[i] = new StringTimestampConverter(datePattern);
		} else {
			Type type = fieldSchema.getType();
			converters[i] = converterRegistry.get(type);
		}
	}
}
 
開發者ID:Talend,項目名稱:components,代碼行數:23,代碼來源:DelimitedStringConverter.java

示例8: updatePartitionKeyAndRowKey

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
public void updatePartitionKeyAndRowKey() {
    Schema inputSchema = schema.schema.getValue();
    List<String> possibleValues = new ArrayList<String>();
    for (Field field : inputSchema.getFields()) {
        Schema fSchema = field.schema();
        if (fSchema.getType() == Type.UNION) {
            for (Schema s : field.schema().getTypes()) {
                if (s.getType() != Type.NULL) {
                    fSchema = s;
                    break;
                }
            }
        }
        if (fSchema.getType().equals(Type.STRING)) {
            possibleValues.add(field.name());
        }
    }
    partitionKey.setPossibleValues(possibleValues);
    rowKey.setPossibleValues(possibleValues);
}
 
開發者ID:Talend,項目名稱:components,代碼行數:21,代碼來源:TAzureStorageOutputTableProperties.java

示例9: newInstance

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
public T newInstance(SolrDocument doc, String[] fields) throws IOException {
  T persistent = newPersistent();
  if (fields == null) {
    fields = fieldMap.keySet().toArray(new String[fieldMap.size()]);
  }
  String pk = mapping.getPrimaryKey();
  for (String f : fields) {
    Field field = fieldMap.get(f);
    Schema fieldSchema = field.schema();
    String sf = null;
    if (pk.equals(f)) {
      sf = f;
    } else {
      sf = mapping.getSolrField(f);
    }
    Object sv = doc.get(sf);
    if (sv == null) {
      continue;
    }

    Object v = deserializeFieldValue(field, fieldSchema, sv, persistent);
    persistent.put(field.pos(), v);
    persistent.setDirty(field.pos());

  }
  persistent.clearDirty();
  return persistent;
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:29,代碼來源:SolrStore.java

示例10: put

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
@Override
public void put(K key, T persistent) {
  Schema schema = persistent.getSchema();
  if (!persistent.isDirty()) {
    // nothing to do
    return;
  }
  SolrInputDocument doc = new SolrInputDocument();
  // add primary key
  doc.addField(mapping.getPrimaryKey(), key);
  // populate the doc
  List<Field> fields = schema.getFields();
  for (Field field : fields) {
    String sf = mapping.getSolrField(field.name());
    // Solr will append values to fields in a SolrInputDocument, even the key
    // mapping won't find the primary
    if (sf == null) {
      continue;
    }
    Schema fieldSchema = field.schema();
    Object v = persistent.get(field.pos());
    if (v == null) {
      continue;
    }
    v = serializeFieldValue(fieldSchema, v);
    doc.addField(sf, v);

  }
  LOG.info("Putting DOCUMENT: " + doc);
  batch.add(doc);
  if (batch.size() >= batchSize) {
    try {
      add(batch, commitWithin);
      batch.clear();
    } catch (Exception e) {
      LOG.error(e.getMessage(), e);
    }
  }
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:40,代碼來源:SolrStore.java

示例11: getValue

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
/**
 * Deserialize a String into an typed Object, according to the field schema.
 * @see org.apache.gora.cassandra.query.CassandraColumn#getValue()
 */
public Object getValue() {
  Field field = getField();
  Schema fieldSchema = field.schema();
  Type type = fieldSchema.getType();
  ByteBuffer byteBuffer = hColumn.getValue();
  if (byteBuffer == null) {
    return null;
  }

  Object value = getFieldValue(type, fieldSchema, byteBuffer);
  return value;
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:17,代碼來源:CassandraSubColumn.java

示例12: getValue

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
public Object getValue() {
  Field field = getField();
  Schema fieldSchema = field.schema();
  Type type = fieldSchema.getType();
  
  Object value = getSuperValue(field, fieldSchema, type);
  
  return value;
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:10,代碼來源:CassandraSuperColumn.java

示例13: newInstance

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
/**
 * Build a new instance of the persisted class from the {@link DBObject}
 * retrieved from the database.
 * 
 * @param obj
 *          the {@link DBObject} that results from the query to the database
 * @param fields
 *          the list of fields to be mapped to the persistence class instance
 * @return a persistence class instance which content was deserialized from
 *         the {@link DBObject}
 * @throws IOException
 */
public T newInstance(final DBObject obj, final String[] fields) {
  if (obj == null)
    return null;
  BSONDecorator easybson = new BSONDecorator(obj);
  // Create new empty persistent bean instance
  T persistent = newPersistent();
  String[] dbFields = getFieldsToQuery(fields);

  // Populate each field
  for (String f : dbFields) {
    // Check the field exists in the mapping and in the db
    String docf = mapping.getDocumentField(f);
    if (docf == null || !easybson.containsField(docf))
      continue;

    DocumentFieldType storeType = mapping.getDocumentFieldType(docf);
    Field field = fieldMap.get(f);
    Schema fieldSchema = field.schema();

    LOG.debug(
        "Load from DBObject (MAIN), field:{}, schemaType:{}, docField:{}, storeType:{}",
        new Object[] { field.name(), fieldSchema.getType(), docf, storeType });
    Object result = fromDBObject(fieldSchema, storeType, field, docf,
        easybson);
    persistent.put(field.pos(), result);
  }
  persistent.clearDirty();
  return persistent;
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:42,代碼來源:MongoStore.java

示例14: fromMongoRecord

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
@SuppressWarnings({ "unchecked", "rawtypes" })
private Object fromMongoRecord(final Schema fieldSchema, final String docf,
    final DBObject rec) {
  Object result;
  BSONDecorator innerBson = new BSONDecorator(rec);
  Class<?> clazz = null;
  try {
    clazz = ClassLoadingUtils.loadClass(fieldSchema.getFullName());
  } catch (ClassNotFoundException e) {
  }
  Persistent record = new BeanFactoryImpl(keyClass, clazz).newPersistent();
  for (Field recField : fieldSchema.getFields()) {
    Schema innerSchema = recField.schema();
    DocumentFieldType innerStoreType = mapping
        .getDocumentFieldType(innerSchema.getName());
    String innerDocField = mapping.getDocumentField(recField.name()) != null ? mapping
        .getDocumentField(recField.name()) : recField.name();
    String fieldPath = docf + "." + innerDocField;
    LOG.debug(
        "Load from DBObject (RECORD), field:{}, schemaType:{}, docField:{}, storeType:{}",
        new Object[] { recField.name(), innerSchema.getType(), fieldPath,
            innerStoreType });
    record.put(
        recField.pos(),
        fromDBObject(innerSchema, innerStoreType, recField, innerDocField,
            innerBson));
  }
  result = record;
  return result;
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:31,代碼來源:MongoStore.java

示例15: isSingleValueField

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
private static boolean isSingleValueField(Field field) {
  org.apache.avro.Schema fieldSchema = field.schema();
  fieldSchema = extractSchemaFromUnionIfNeeded(fieldSchema);

  final Type type = fieldSchema.getType();
  if (type == Type.ARRAY) {
    return false;
  }
  return true;
}
 
開發者ID:Hanmourang,項目名稱:Pinot,代碼行數:11,代碼來源:AvroQueryGenerator.java


注:本文中的org.apache.avro.Schema.Field.schema方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。