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


Java Type.UNION屬性代碼示例

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


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

示例1: fromBytes

public Object fromBytes(Schema schema, byte data[]) throws GoraException {
  Schema fromSchema = null;
  if (schema.getType() == Type.UNION) {
    try {
      Decoder decoder = DecoderFactory.get().binaryDecoder(data, null);
      int unionIndex = decoder.readIndex();
      List<Schema> possibleTypes = schema.getTypes();
      fromSchema = possibleTypes.get(unionIndex);
      Schema effectiveSchema = possibleTypes.get(unionIndex);
      if (effectiveSchema.getType() == Type.NULL) {
        decoder.readNull();
        return null;
      } else {
        data = decoder.readBytes(null).array();
      }
    } catch (IOException e) {
      LOG.error(e.getMessage());
      throw new GoraException("Error decoding union type: ", e);
    }
  } else {
    fromSchema = schema;
  }
  return fromBytes(encoder, fromSchema, data);
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:24,代碼來源:AccumuloStore.java

示例2: toBytes

public byte[] toBytes(Schema toSchema, Object o) {
  if (toSchema != null && toSchema.getType() == Type.UNION) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    org.apache.avro.io.BinaryEncoder avroEncoder = EncoderFactory.get().binaryEncoder(baos, null);
    int unionIndex = 0;
    try {
      if (o == null) {
        unionIndex = firstNullSchemaTypeIndex(toSchema);
        avroEncoder.writeIndex(unionIndex);
        avroEncoder.writeNull();
      } else {
        unionIndex = firstNotNullSchemaTypeIndex(toSchema);
        avroEncoder.writeIndex(unionIndex);
        avroEncoder.writeBytes(toBytes(o));
      }
      avroEncoder.flush();
      return baos.toByteArray();
    } catch (IOException e) {
      LOG.error(e.getMessage());
      return toBytes(o);
    }
  } else {
    return toBytes(o);
  }
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:25,代碼來源:AccumuloStore.java

示例3: getFamilyMap

/**
 * Select the families that contain at least one column mapped to a query field.
 * @param query indicates the columns to select
 * @return a map which keys are the family names and values the 
 * corresponding column names required to get all the query fields.
 */
public Map<String, List<String>> getFamilyMap(Query<K, T> query) {
  Map<String, List<String>> map = new HashMap<>();
  Schema persistentSchema = query.getDataStore().newPersistent().getSchema();
  for (String field: query.getFields()) {
    String family = this.getMappingFamily(field);
    String column = this.getMappingColumn(field);
    
    // check if the family value was already initialized 
    List<String> list = map.get(family);
    if (list == null) {
      list = new ArrayList<>();
      map.put(family, list);
    }
    if (persistentSchema.getField(field).schema().getType() == Type.UNION)
      list.add(field + CassandraStore.UNION_COL_SUFIX);
    if (column != null) {
      list.add(column);
    }
  }
  
  return map;
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:28,代碼來源:CassandraClient.java

示例4: validate

public void validate(final Schema schema) {
    if (schema.getType() != Type.UNION)
        throw new IllegalArgumentException("Must be type " + Type.UNION);
    if (schema.getTypes().size() > TYPES_MAX_COUNT)
        throw new IllegalArgumentException("Only supports up to " + TYPES_MAX_COUNT + " types. Found " + schema.getTypes().size());
    for (Schema typeSchema : schema.getTypes()) {
        fieldCodec.validate(typeSchema);
    }
}
 
開發者ID:granthenke,項目名稱:avro-schema-compactor,代碼行數:9,代碼來源:UnionCodec.java

示例5: getReverseMap

/**
 * Select the field names according to the column names, which format 
 * if fully qualified: "family:column"
 * @param query
 * @return a map which keys are the fully qualified column 
 * names and values the query fields
 */
public Map<String, String> getReverseMap(Query<K, T> query) {
  Map<String, String> map = new HashMap<>();
  Schema persistentSchema = query.getDataStore().newPersistent().getSchema();
  for (String field: query.getFields()) {
    String family = this.getMappingFamily(field);
    String column = this.getMappingColumn(field);
    if (persistentSchema.getField(field).schema().getType() == Type.UNION)
      map.put(family + ":" + field + CassandraStore.UNION_COL_SUFIX, field + CassandraStore.UNION_COL_SUFIX);
    map.put(family + ":" + column, field);
  }
  
  return map;
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:20,代碼來源:CassandraClient.java

示例6: preferredTypeFor

protected static Type preferredTypeFor(Field fld) {
	
	Type type = fld.schema().getType();
	
	if (type == Type.UNION) {
		List<Schema> types = fld.schema().getTypes();
		if (isNullableSingleType(types)) {
			Schema sch = nonNullSchemaIn(types);
			return sch.getType();
		}
	}
	return type;
}
 
開發者ID:Comcast,項目名稱:pipeclamp,代碼行數:13,代碼來源:AvroSchemaTreeComposer.java

示例7: labelFor

private String labelFor(Schema sc) {
	
	Type typ = (sc.getType() == Type.ARRAY) ?
			sc.getElementType().getType() : 
			sc.getType();
	
	String typeText = formatType(typ.getName());
	String name = showFullNames ? sc.getFullName() : sc.getName();
	
	boolean isNullable = sc.getType() == Type.UNION && isNullableSingleType(sc.getTypes());
	
	return isNullable ?
		"<i>" + name + "</i>  " + typeText :
		name + "  " + typeText;
}
 
開發者ID:Comcast,項目名稱:pipeclamp,代碼行數:15,代碼來源:AvroSchemaTreeComposer.java

示例8: render

private void render(Schema sc, String parent, boolean isNullable) {

		String childId = newIdFor(parent, sc.getName());
		
		startNewLine();
		appendIds(childId, parent);
		append("type", typeFor(sc, isNullable), true);
		append("text", labelFor(sc), false);
		appendDoc(sc.getDoc());
		endLine();
		
		if (showConstraints) showConstraints(sc, childId);
		if (showMetrics) showMetrics(sc, childId);
		
		incrementDepth();
		
		if (sc.getType() == Type.RECORD) {
			for (Field fld : sc.getFields()) { 
				render(fld, childId); 
				}
			}

		if (sc.getType() == Type.ARRAY) {
			render(sc.getElementType(), childId, false);
			}
		
		if (sc.getType() == Type.UNION) {
			System.out.println("####!!!!!####");
			}
		
		decrementDepth();
	}
 
開發者ID:Comcast,項目名稱:pipeclamp,代碼行數:32,代碼來源:AvroSchemaTreeComposer.java

示例9: primaryTypeIn

public static Type primaryTypeIn(Schema schema) {

		if (schema.getType() == Type.UNION) {
			for (Schema sch : schema.getTypes()) {
				if (sch.getType() == Type.NULL) continue;
				return sch.getType();	// TODO what about more complex UNIONs ?
			}
		}
		return schema.getType();
	}
 
開發者ID:Comcast,項目名稱:pipeclamp,代碼行數:10,代碼來源:AvroUtil.java

示例10: allowsNull

public static boolean allowsNull(Schema schema) {

		if (schema.getType() == Type.UNION) {
			for (Schema sch : schema.getTypes()) {
				if (sch.getType() == Type.NULL) return true;
			}
		};
		return false;
	}
 
開發者ID:Comcast,項目名稱:pipeclamp,代碼行數:9,代碼來源:AvroUtil.java

示例11: allConstraintsIn

private static Collection<Constraint<?>> allConstraintsIn(JsonNode cstNode, Schema schema, ConstraintFactory<Schema.Type> factory) {

		if (Type.UNION == schema.getType() && schema.getTypes().size() > 2) throw new RuntimeException("Cannot currently handle more than two major datatypes in a UNION");

		Collection<Constraint<?>> constraints = new ArrayList<>(cstNode.size() + 2);
		Type type = AvroUtil.primaryTypeIn(schema);
		boolean allowsNulls = AvroUtil.allowsNull(schema);

		Iterator<JsonNode> iter = cstNode.getElements();
		while (iter.hasNext()) {
			Collection<Constraint<?>> csts = constraintsIn(iter.next(), type, allowsNulls, factory);
			if (csts != null) constraints.addAll(csts);
		}
		return constraints;
	}
 
開發者ID:Comcast,項目名稱:pipeclamp,代碼行數:15,代碼來源:AvroConstraintUtil.java

示例12: allMetricsIn

private static Map<String, MetricDescriptor> allMetricsIn(JsonNode cstNode, Schema schema) {

		if (Type.UNION == schema.getType() && schema.getTypes().size() > 2) throw new RuntimeException("Cannot currently handle more than two major datatypes in a UNION");

		Map<String, MetricDescriptor> metrics = new HashMap<>(cstNode.size() + 2);
		Type type = AvroUtil.primaryTypeIn(schema);
		boolean allowsNulls = AvroUtil.allowsNull(schema);

		Iterator<JsonNode> iter = cstNode.getElements();
		while (iter.hasNext()) {
			Map<String, MetricDescriptor> csts = metricsIn(iter.next(), type, allowsNulls);
			if (csts != null) metrics.putAll(csts);
		}
		return metrics;
	}
 
開發者ID:Comcast,項目名稱:pipeclamp,代碼行數:15,代碼來源:AvroMetricUtil.java

示例13: isNullableSingleType

public static boolean isNullableSingleType(Field field) {
	return field.schema().getType() == Type.UNION &&
			isNullableSingleType(field.schema().getTypes());
}
 
開發者ID:Comcast,項目名稱:pipeclamp,代碼行數:4,代碼來源:AvroUtil.java


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