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


Java GenericData.Array方法代碼示例

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


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

示例1: serialize

import org.apache.avro.generic.GenericData; //導入方法依賴的package包/類
public Record serialize(AdvancedEmployee employee)
{
   Record record = new Record(schema);

   AvroUtils.put("name", employee.getName(), record);
   AvroUtils.put("age", employee.getAge(), record);
   AvroUtils.put("gender", employee.getGender(), record);

   int numberOfEmails = (employee.getMails() != null) ? employee.getMails().size() : 0;
   GenericData.Array<Utf8> emails = new GenericData.Array<>(numberOfEmails, schema.getField("emails").schema());

   for(int i = 0; i < numberOfEmails; ++i)
   {
      emails.add(new Utf8(employee.getMails().get(i)));
   }

   record.put("emails", emails);

   return record;
}
 
開發者ID:developerSid,項目名稱:AwesomeJavaLibraryExamples,代碼行數:21,代碼來源:AvroWriteSerializer.java

示例2: listTables

import org.apache.avro.generic.GenericData; //導入方法依賴的package包/類
public GenericArray<ATableDescriptor> listTables() throws AIOError {
     try {
       HTableDescriptor[] tables = admin.listTables();
Schema atdSchema = Schema.createArray(ATableDescriptor.SCHEMA$);
       GenericData.Array<ATableDescriptor> result = null;
result = new GenericData.Array<ATableDescriptor>(tables.length, atdSchema);
       for (HTableDescriptor table : tables) {
  result.add(AvroUtil.htdToATD(table));
}
       return result;
     } catch (IOException e) {
AIOError ioe = new AIOError();
ioe.message = new Utf8(e.getMessage());
       throw ioe;
     }
   }
 
開發者ID:fengchen8086,項目名稱:LCIndex-HBase-0.94.16,代碼行數:17,代碼來源:AvroServer.java

示例3: htdToATD

import org.apache.avro.generic.GenericData; //導入方法依賴的package包/類
static public ATableDescriptor htdToATD(HTableDescriptor table) throws IOException {
   ATableDescriptor atd = new ATableDescriptor();
   atd.name = ByteBuffer.wrap(table.getName());
   Collection<HColumnDescriptor> families = table.getFamilies();
   Schema afdSchema = Schema.createArray(AFamilyDescriptor.SCHEMA$);
   GenericData.Array<AFamilyDescriptor> afamilies = null;
   if (families.size() > 0) {
     afamilies = new GenericData.Array<AFamilyDescriptor>(families.size(), afdSchema);
     for (HColumnDescriptor hcd : families) {
AFamilyDescriptor afamily = hcdToAFD(hcd);
       afamilies.add(afamily);
     }
   } else {
     afamilies = new GenericData.Array<AFamilyDescriptor>(0, afdSchema);
   }
   atd.families = afamilies;
   atd.maxFileSize = table.getMaxFileSize();
   atd.memStoreFlushSize = table.getMemStoreFlushSize();
   atd.rootRegion = table.isRootRegion();
   atd.metaRegion = table.isMetaRegion();
   atd.metaTable = table.isMetaTable();
   atd.readOnly = table.isReadOnly();
   atd.deferredLogFlush = table.isDeferredLogFlush();
   return atd;
 }
 
開發者ID:fengchen8086,項目名稱:LCIndex-HBase-0.94.16,代碼行數:26,代碼來源:AvroUtil.java

示例4: resultToAResult

import org.apache.avro.generic.GenericData; //導入方法依賴的package包/類
static public AResult resultToAResult(Result result) {
   AResult aresult = new AResult();
   byte[] row = result.getRow();
   aresult.row = ByteBuffer.wrap(row != null ? row : new byte[1]);
   Schema s = Schema.createArray(AResultEntry.SCHEMA$);
   GenericData.Array<AResultEntry> entries = null;
   List<KeyValue> resultKeyValues = result.list();
   if (resultKeyValues != null && resultKeyValues.size() > 0) {
     entries = new GenericData.Array<AResultEntry>(resultKeyValues.size(), s);
     for (KeyValue resultKeyValue : resultKeyValues) {
AResultEntry entry = new AResultEntry();
entry.family = ByteBuffer.wrap(resultKeyValue.getFamily());
entry.qualifier = ByteBuffer.wrap(resultKeyValue.getQualifier());
entry.value = ByteBuffer.wrap(resultKeyValue.getValue());
entry.timestamp = resultKeyValue.getTimestamp();
entries.add(entry);
     }
   } else {
     entries = new GenericData.Array<AResultEntry>(0, s);
   }
   aresult.entries = entries;
   return aresult;
 }
 
開發者ID:fengchen8086,項目名稱:LCIndex-HBase-0.94.16,代碼行數:24,代碼來源:AvroUtil.java

示例5: getAvroValue

import org.apache.avro.generic.GenericData; //導入方法依賴的package包/類
private static Object getAvroValue(Object input, Schema schema) {
    if (input instanceof byte[] && Schema.Type.FIXED.equals(schema.getType())) {
        return new GenericData.Fixed(schema, (byte[]) input);
    } else if (input instanceof Map && !((Map) input).isEmpty()) {
        GenericRecord result;
        result = new GenericData.Record(schema);
        for (Map.Entry<String, Object> entry: ((Map<String, Object>) input).entrySet()) {
            result.put(entry.getKey(), getAvroValue(entry.getValue(), schema.getField(entry.getKey()).schema()));
        }
        return result;
    } else if (input instanceof Collection && !((Collection) input).isEmpty()) {
        // for array even though we(Schema in streamline registry) support different types of elements in an array, avro expects an array
        // schema to have elements of same type. Hence, for now we will restrict array to have elements of same type. Other option is convert
        // a  streamline Schema Array field to Record in avro. However, with that the issue is that avro Field constructor does not allow a
        // null name. We could potentiall hack it by plugging in a dummy name like arrayfield, but seems hacky so not taking that path
        List<Object> values = new ArrayList<>(((Collection) input).size());
        for (Object value: (Collection) input) {
            values.add(getAvroValue(value, schema.getElementType()));
        }
        return new GenericData.Array<Object>(schema, values);
    } else {
        return input;
    }
}
 
開發者ID:hortonworks,項目名稱:streamline,代碼行數:25,代碼來源:StreamlineEventSerializer.java

示例6: jsonColumn

import org.apache.avro.generic.GenericData; //導入方法依賴的package包/類
@Override
public GenericArray<Object> jsonColumn(Value value) {
    if (!value.isArrayValue())
        throw new RuntimeException("Support only array type json record");

    List<Value> list = value.asArrayValue().list();

    GenericArray<Object> array = new GenericData.Array<>(list.size(), avroSchema);
    for (Value val : list) {
        switch (val.getValueType()) {
            case STRING:
                array.add(elementConverter.stringColumn(val.asStringValue().toString()));
                break;
            case INTEGER:
                array.add(elementConverter.longColumn(val.asIntegerValue().toLong()));
                break;
            case FLOAT:
                array.add(elementConverter.doubleColumn(val.asFloatValue().toDouble()));
                break;
            case BOOLEAN:
                array.add(elementConverter.booleanColumn(val.asBooleanValue().getBoolean()));
                break;
            case ARRAY:
                array.add(elementConverter.jsonColumn(val.asArrayValue()));
                break;
            case MAP:
                array.add(elementConverter.jsonColumn(val.asMapValue()));
                break;
            default:
                throw new RuntimeException("Irregular Messagepack type");
        }
    }
    return array;
}
 
開發者ID:joker1007,項目名稱:embulk-formatter-avro,代碼行數:35,代碼來源:AvroArrayConverter.java

示例7: getArray

import org.apache.avro.generic.GenericData; //導入方法依賴的package包/類
public static <T, R> List<R> getArray(GenericData.Record record, String fieldName, Function<T, R> transformer)
{
   GenericData.Array<T> array = (GenericData.Array<T>)record.get(fieldName);

   return array.stream()
      .map(transformer)
      .collect(Collectors.toList());
}
 
開發者ID:developerSid,項目名稱:AwesomeJavaLibraryExamples,代碼行數:9,代碼來源:AvroUtils.java

示例8: wrapOption

import org.apache.avro.generic.GenericData; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private Object wrapOption(Schema schema, Object option) {
  if (schema.getType() == Schema.Type.BYTES && option instanceof String) {
    option = ByteBuffer.wrap(((String) option).getBytes(Charset.defaultCharset()));
  } else if (schema.getType() == Schema.Type.FLOAT && option instanceof Double) {
    option = ((Double) option).floatValue();
  } else if (schema.getType() == Schema.Type.LONG && option instanceof Integer) {
    option = ((Integer) option).longValue();
  } else if (schema.getType() == Schema.Type.ARRAY && option instanceof Collection) {
    option = new GenericData.Array(schema, (Collection) option);
  } else if (schema.getType() == Schema.Type.ENUM && option instanceof String) {
    option = new GenericData.EnumSymbol(schema, (String) option);
  } else if (schema.getType() == Schema.Type.FIXED && option instanceof String) {
    option =
        new GenericData.Fixed(schema, ((String) option).getBytes(Charset.defaultCharset()));
  } else if (schema.getType() == Schema.Type.RECORD && option instanceof Map) {
    Map optionMap = (Map) option;
    GenericRecordBuilder optionBuilder = new GenericRecordBuilder(schema);
    for (Schema.Field field : schema.getFields()) {
      if (optionMap.containsKey(field.name())) {
        optionBuilder.set(field, optionMap.get(field.name()));
      }
    }
    option = optionBuilder.build();
  }
  return option;
}
 
開發者ID:C0urante,項目名稱:avro-random-generator,代碼行數:28,代碼來源:Generator.java

示例9: convertAvroValToDrill

import org.apache.avro.generic.GenericData; //導入方法依賴的package包/類
private Object convertAvroValToDrill(Object value, boolean root) {
  if (value instanceof ByteBuffer) {
    ByteBuffer bb = ((ByteBuffer)value);
    byte[] drillVal = new byte[((ByteBuffer)value).remaining()];
    bb.get(drillVal);
    bb.position(0);
    value = drillVal;
  } else if (!root && value instanceof CharSequence) {
    value = new Text(value.toString());
  } else if (value instanceof GenericData.Array) {
    GenericData.Array array = ((GenericData.Array) value);
    final JsonStringArrayList<Object> drillList = new JsonStringArrayList<>();
    for (Object o : array) {
      drillList.add(convertAvroValToDrill(o, false));
    }
    value = drillList;
  } else if (value instanceof GenericData.EnumSymbol) {
    value = value.toString();
  } else if (value instanceof GenericData.Record) {
    GenericData.Record rec = ((GenericData.Record) value);
    final JsonStringHashMap<String, Object> newRecord = new JsonStringHashMap<>();
    for (Schema.Field field : rec.getSchema().getFields()) {
      Object val = rec.get(field.name());
      newRecord.put(field.name(), convertAvroValToDrill(val, false));
    }
    value = newRecord;
  }
  return value;
}
 
開發者ID:axbaretto,項目名稱:drill,代碼行數:30,代碼來源:AvroTestUtil.java

示例10: enforceFieldType

import org.apache.avro.generic.GenericData; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private Object enforceFieldType(Schema fieldSchema, Object value) {

  switch (fieldSchema.type()) {
    case BOOLEAN:
    case INT32:
    case INT64:
    case FLOAT64:
      return value;
    case STRING:
      if (value != null) {
        return value.toString();
      } else {
        return value;
      }

    case ARRAY:
      GenericData.Array genericArray = (GenericData.Array) value;
      Class elementClass = SchemaUtil.getJavaType(fieldSchema.valueSchema());
      Object[] arrayField =
          (Object[]) java.lang.reflect.Array.newInstance(elementClass, genericArray.size());
      for (int i = 0; i < genericArray.size(); i++) {
        Object obj = enforceFieldType(fieldSchema.valueSchema(), genericArray.get(i));
        arrayField[i] = obj;
      }
      return arrayField;
    case MAP:
      Map valueMap = (Map) value;
      Map<String, Object> ksqlMap = new HashMap<>();
      Set<Map.Entry> entrySet = valueMap.entrySet();
      for (Map.Entry avroMapEntry: entrySet) {
        ksqlMap.put(avroMapEntry.getKey().toString(),
                    enforceFieldType(fieldSchema.valueSchema(), avroMapEntry.getValue()));
      }
      return ksqlMap;
    default:
      throw new KsqlException("Type is not supported: " + fieldSchema.schema());

  }
}
 
開發者ID:confluentinc,項目名稱:ksql,代碼行數:41,代碼來源:KsqlGenericRowAvroDeserializer.java

示例11: shouldSerializeRowCorrectly

import org.apache.avro.generic.GenericData; //導入方法依賴的package包/類
@Test
public void shouldSerializeRowCorrectly() {
  SchemaRegistryClient schemaRegistryClient = new MockSchemaRegistryClient();
  KsqlGenericRowAvroSerializer ksqlGenericRowAvroSerializer = new KsqlGenericRowAvroSerializer
      (schema, schemaRegistryClient, new KsqlConfig(new HashMap<>()));

  List columns = Arrays.asList(1511897796092L, 1L, "item_1", 10.0, new Double[]{100.0},
                               Collections.singletonMap("key1", 100.0));

  GenericRow genericRow = new GenericRow(columns);
  byte[] serializedRow = ksqlGenericRowAvroSerializer.serialize("t1", genericRow);
  KafkaAvroDeserializer kafkaAvroDeserializer = new KafkaAvroDeserializer(schemaRegistryClient);
  GenericRecord genericRecord = (GenericRecord) kafkaAvroDeserializer.deserialize("t1", serializedRow);
  Assert.assertNotNull(genericRecord);
  assertThat("Incorrect serialization.", genericRecord.get("ordertime".toUpperCase()), equalTo
      (1511897796092L));
  assertThat("Incorrect serialization.", genericRecord.get("orderid".toUpperCase()), equalTo
      (1L));
  assertThat("Incorrect serialization.", genericRecord.get("itemid".toUpperCase()).toString(), equalTo("item_1"));
  assertThat("Incorrect serialization.", genericRecord.get("orderunits".toUpperCase()), equalTo
      (10.0));

  GenericData.Array array = (GenericData.Array) genericRecord.get("arraycol".toUpperCase());
  Map map = (Map) genericRecord.get("mapcol".toUpperCase());

  assertThat("Incorrect serialization.", array.size(), equalTo(1));
  assertThat("Incorrect serialization.", array.get(0), equalTo(100.0));
  assertThat("Incorrect serialization.", map.size(), equalTo(1));
  assertThat("Incorrect serialization.", map.get(new Utf8("key1")), equalTo(100.0));

}
 
開發者ID:confluentinc,項目名稱:ksql,代碼行數:32,代碼來源:KsqlGenericRowAvroSerializerTest.java

示例12: hslToASL

import org.apache.avro.generic.GenericData; //導入方法依賴的package包/類
static public AServerLoad hslToASL(HServerLoad hsl) throws IOException {
   AServerLoad asl = new AServerLoad();
   asl.load = hsl.getLoad();
   asl.maxHeapMB = hsl.getMaxHeapMB();
   asl.memStoreSizeInMB = hsl.getMemStoreSizeInMB();
   asl.numberOfRegions = hsl.getNumberOfRegions();
   asl.numberOfRequests = hsl.getNumberOfRequests();

   Collection<HServerLoad.RegionLoad> regionLoads = hsl.getRegionsLoad().values();
   Schema s = Schema.createArray(ARegionLoad.SCHEMA$);
   GenericData.Array<ARegionLoad> aregionLoads = null;
   if (regionLoads != null) {
     aregionLoads = new GenericData.Array<ARegionLoad>(regionLoads.size(), s);
     for (HServerLoad.RegionLoad rl : regionLoads) {
aregionLoads.add(hrlToARL(rl));
     }
   } else {
     aregionLoads = new GenericData.Array<ARegionLoad>(0, s);
   }
   asl.regionsLoad = aregionLoads;

   asl.storefileIndexSizeInMB = hsl.getStorefileIndexSizeInMB();
   asl.storefiles = hsl.getStorefiles();
   asl.storefileSizeInMB = hsl.getStorefileSizeInMB();
   asl.usedHeapMB = hsl.getUsedHeapMB();
   return asl;
 }
 
開發者ID:fengchen8086,項目名稱:LCIndex-HBase-0.94.16,代碼行數:28,代碼來源:AvroUtil.java

示例13: csToACS

import org.apache.avro.generic.GenericData; //導入方法依賴的package包/類
static public AClusterStatus csToACS(ClusterStatus cs) throws IOException {
   AClusterStatus acs = new AClusterStatus();
   acs.averageLoad = cs.getAverageLoad();
   Collection<ServerName> deadServerNames = cs.getDeadServerNames();
   Schema stringArraySchema = Schema.createArray(Schema.create(Schema.Type.STRING));
   GenericData.Array<CharSequence> adeadServerNames = null;
   if (deadServerNames != null) {
     adeadServerNames = new GenericData.Array<CharSequence>(deadServerNames.size(), stringArraySchema);
     for (ServerName deadServerName : deadServerNames) {
adeadServerNames.add(new Utf8(deadServerName.toString()));
     }
   } else {
     adeadServerNames = new GenericData.Array<CharSequence>(0, stringArraySchema);
   }
   acs.deadServerNames = adeadServerNames;
   acs.deadServers = cs.getDeadServers();
   acs.hbaseVersion = new Utf8(cs.getHBaseVersion());
   acs.regionsCount = cs.getRegionsCount();
   acs.requestsCount = cs.getRequestsCount();
   Collection<ServerName> hserverInfos = cs.getServers();
   Schema s = Schema.createArray(AServerInfo.SCHEMA$);
   GenericData.Array<AServerInfo> aserverInfos = null;
   if (hserverInfos != null) {
     aserverInfos = new GenericData.Array<AServerInfo>(hserverInfos.size(), s);
     for (ServerName hsi : hserverInfos) {
aserverInfos.add(hsiToASI(hsi, cs.getLoad(hsi)));
     }
   } else {
     aserverInfos = new GenericData.Array<AServerInfo>(0, s);
   }
   acs.serverInfos = aserverInfos;
   acs.servers = cs.getServers().size();
   return acs;
 }
 
開發者ID:fengchen8086,項目名稱:LCIndex-HBase-0.94.16,代碼行數:35,代碼來源:AvroUtil.java

示例14: resultsToAResults

import org.apache.avro.generic.GenericData; //導入方法依賴的package包/類
static public GenericArray<AResult> resultsToAResults(Result[] results) {
   Schema s = Schema.createArray(AResult.SCHEMA$);
   GenericData.Array<AResult> aresults = null;
   if (results != null && results.length > 0) {
     aresults = new GenericData.Array<AResult>(results.length, s);
     for (Result result : results) {
aresults.add(resultToAResult(result));
     }
   } else {
     aresults = new GenericData.Array<AResult>(0, s);
   }
   return aresults;
 }
 
開發者ID:fengchen8086,項目名稱:LCIndex-HBase-0.94.16,代碼行數:14,代碼來源:AvroUtil.java

示例15: testFamilyAdminAndMetadata

import org.apache.avro.generic.GenericData; //導入方法依賴的package包/類
/**
 * Tests for creating, modifying, and deleting column families.
 *
 * @throws Exception
 */
@Test
public void testFamilyAdminAndMetadata() throws Exception {
  AvroServer.HBaseImpl impl =
    new AvroServer.HBaseImpl(TEST_UTIL.getConfiguration());

  ATableDescriptor tableA = new ATableDescriptor();
  tableA.name = tableAname;
  AFamilyDescriptor familyA = new AFamilyDescriptor();
  familyA.name = familyAname;
  Schema familyArraySchema = Schema.createArray(AFamilyDescriptor.SCHEMA$);
  GenericArray<AFamilyDescriptor> families = new GenericData.Array<AFamilyDescriptor>(1, familyArraySchema);
  families.add(familyA);
  tableA.families = families;
  impl.createTable(tableA);
  assertEquals(impl.describeTable(tableAname).families.size(), 1);

  impl.disableTable(tableAname);
  assertFalse(impl.isTableEnabled(tableAname));

  familyA.maxVersions = 123456;
  impl.modifyFamily(tableAname, familyAname, familyA);
  assertEquals((int) impl.describeFamily(tableAname, familyAname).maxVersions, 123456);

  impl.deleteFamily(tableAname, familyAname);
  assertEquals(impl.describeTable(tableAname).families.size(), 0);

  impl.deleteTable(tableAname);
}
 
開發者ID:fengchen8086,項目名稱:LCIndex-HBase-0.94.16,代碼行數:34,代碼來源:TestAvroServer.java


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