当前位置: 首页>>代码示例>>Java>>正文


Java DataFileReader.hasNext方法代码示例

本文整理汇总了Java中org.apache.avro.file.DataFileReader.hasNext方法的典型用法代码示例。如果您正苦于以下问题:Java DataFileReader.hasNext方法的具体用法?Java DataFileReader.hasNext怎么用?Java DataFileReader.hasNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.avro.file.DataFileReader的用法示例。


在下文中一共展示了DataFileReader.hasNext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readAvroFile

import org.apache.avro.file.DataFileReader; //导入方法依赖的package包/类
/**
 * Reads in binary Avro-encoded entities using the schema stored in the file
 * and prints them out.
 */
public static void readAvroFile(File file) throws IOException {
	GenericDatumReader datum = new GenericDatumReader();
	DataFileReader reader = new DataFileReader(file, datum);

	GenericData.Record record = new GenericData.Record(reader.getSchema());
	while (reader.hasNext()) {
		reader.next(record);
		System.out.println("Name " + record.get("name") + " on "
				+ record.get("Meetup_date") + " attending "
				+ record.get("going") + " organized by  "
				+ record.get("organizer") + " on  " + record.get("topics"));
	}

	reader.close();
}
 
开发者ID:airisdata,项目名称:avroparquet,代码行数:20,代码来源:StorageFormatUtils.java

示例2: testGenericRecord

import org.apache.avro.file.DataFileReader; //导入方法依赖的package包/类
@Test
public void testGenericRecord() throws IOException {
	final Path outputPath = new Path(File.createTempFile("avro-output-file", "generic.avro").getAbsolutePath());
	final AvroOutputFormat<GenericRecord> outputFormat = new AvroOutputFormat<>(outputPath, GenericRecord.class);
	Schema schema = new Schema.Parser().parse("{\"type\":\"record\", \"name\":\"user\", \"fields\": [{\"name\":\"user_name\", \"type\":\"string\"}, {\"name\":\"favorite_number\", \"type\":\"int\"}, {\"name\":\"favorite_color\", \"type\":\"string\"}]}");
	outputFormat.setWriteMode(FileSystem.WriteMode.OVERWRITE);
	outputFormat.setSchema(schema);
	output(outputFormat, schema);

	GenericDatumReader<GenericRecord> reader = new GenericDatumReader<>(schema);
	DataFileReader<GenericRecord> dataFileReader = new DataFileReader<>(new File(outputPath.getPath()), reader);

	while (dataFileReader.hasNext()) {
		GenericRecord record = dataFileReader.next();
		assertEquals(record.get("user_name").toString(), "testUser");
		assertEquals(record.get("favorite_number"), 1);
		assertEquals(record.get("favorite_color").toString(), "blue");
	}

	//cleanup
	FileSystem fs = FileSystem.getLocalFileSystem();
	fs.delete(outputPath, false);

}
 
开发者ID:axbaretto,项目名称:flink,代码行数:25,代码来源:AvroOutputFormatTest.java

示例3: deserUserCompile

import org.apache.avro.file.DataFileReader; //导入方法依赖的package包/类
public void deserUserCompile(){
	// Deserialize Users from disk
	DatumReader<User> userDatumReader = new SpecificDatumReader<User>(User.class);
	DataFileReader<User> dataFileReader = null;
	User user = null;
	try {
		dataFileReader = new DataFileReader<User>(
										new File("/Users/a/Desktop/tmp/users.avro"),
										userDatumReader);
		while (dataFileReader.hasNext()) {
			// Reuse user object by passing it to next(). This saves us from
			// allocating and garbage collecting many objects for files with
			// many items.
			user = dataFileReader.next(user);
			System.out.println(user);
		}
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:lrtdc,项目名称:book_ldrtc,代码行数:21,代码来源:TestAvro.java

示例4: MemberInfoDynDeser

import org.apache.avro.file.DataFileReader; //导入方法依赖的package包/类
/**
 * 动态反序列:通过Schema文件进行动态反序列化操作
 * 
 * @throws IOException
 */
public void MemberInfoDynDeser() throws IOException {
    // 1.schema文件解析
    Parser parser = new Parser();
    Schema mSchema = parser.parse(this.getClass().getResourceAsStream("/Members.avsc"));

    // 2.构建数据读对象
    DatumReader<GenericRecord> mGr = new SpecificDatumReader<GenericRecord>(mSchema);
    DataFileReader<GenericRecord> mDfr = new DataFileReader<GenericRecord>(new File("/Users/a/Desktop/tmp/members.avro"), mGr);
    // 3.从序列化文件中进行数据反序列化取出数据
    GenericRecord gr = null;
    while (mDfr.hasNext()) {
        gr = mDfr.next();
        System.err.println("deser data:" + gr.toString());
    }
    mDfr.close();
    System.out.println("Dyn Builder Ser Start Complete.");
}
 
开发者ID:lrtdc,项目名称:book_ldrtc,代码行数:23,代码来源:MemberServerConsumer.java

示例5: main

import org.apache.avro.file.DataFileReader; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException
{
    String filename = args[0] ;
    
    File file=new File(filename) ;
    DatumReader<GenericRecord> reader= new GenericDatumReader<GenericRecord>();
    DataFileReader<GenericRecord> dataFileReader=new DataFileReader<GenericRecord>(file,reader);
    
    while (dataFileReader.hasNext())
    {
        GenericRecord result=dataFileReader.next();
        String output = String.format("%s %s %s %f",
            result.get("sighting_date"), result.get("city"), result.get("shape"), result.get("duration")) ;
        System.out.println(output) ;
    }
}
 
开发者ID:PacktPublishing,项目名称:Data-Science-with-Hadoop,代码行数:17,代码来源:InputRead.java

示例6: main

import org.apache.avro.file.DataFileReader; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException
{
    String filename = args[0] ;
    
    File file=new File(filename) ;
    DatumReader<GenericRecord> reader= new GenericDatumReader<GenericRecord>();
    DataFileReader<GenericRecord> dataFileReader=new DataFileReader<GenericRecord>(file,reader);
    
    while (dataFileReader.hasNext())
    {
        GenericRecord result=dataFileReader.next();
        String output = String.format("%s %d",
            result.get("shape"), result.get("count")) ;
        System.out.println(output) ;
    }
}
 
开发者ID:PacktPublishing,项目名称:Data-Science-with-Hadoop,代码行数:17,代码来源:OutputRead.java

示例7: readWithDifferentSchema

import org.apache.avro.file.DataFileReader; //导入方法依赖的package包/类
/**
 * Reads in binary Avro-encoded entities using a schema that is different
 * from the writer's schema.
 * 
 */
public static void readWithDifferentSchema(File file, Schema newSchema)
		throws IOException {
	GenericDatumReader datum = new GenericDatumReader(newSchema);
	DataFileReader reader = new DataFileReader(file, datum);

	GenericData.Record record = new GenericData.Record(newSchema);
	while (reader.hasNext()) {
		reader.next(record);
		System.out.println("Name " + record.get("name") + " on "
				+ record.get("Meetup_date") + " attending "
				+ record.get("attendance") + " organized by  "
				+ record.get("organizer") 
				+ " at  " + record.get("location"));
	}

	reader.close();
}
 
开发者ID:airisdata,项目名称:avroparquet,代码行数:23,代码来源:StorageFormatUtils.java

示例8: deserializing

import org.apache.avro.file.DataFileReader; //导入方法依赖的package包/类
/**
 * Deserialize Users from disk
 */
private void deserializing() {
	long tiempoInicio = System.currentTimeMillis();
	// We create a SpecificDatumReader, analogous to the SpecificDatumWriter we used in serialization, which converts in-memory serialized items into instances of our generated class, in this case User.
	DatumReader<User> userDatumReader = new SpecificDatumReader<User>(User.class);
	// We pass the DatumReader and the previously created File to a DataFileReader, analogous to the DataFileWriter, which reads the data file on disk.
	try {
		File file = createFile();
		@SuppressWarnings("resource")
		DataFileReader<User> dataFileReader = new DataFileReader<User>(file, userDatumReader);
		User user = null;
		// Next we use the DataFileReader to iterate through the serialized Users and print the deserialized object to stdout.
		while (dataFileReader.hasNext()) {
			// Reuse user object by passing it to next(). This saves us from
			// allocating and garbage collecting many objects for files with
			// many items.
			user = dataFileReader.next(user);
			System.out.println(user);
		}
		// DataFileReader no cuenta con un metodo close()
		dataFileReader=null;
	} catch (IOException e) {
		e.printStackTrace();
	}
	terminaProceso("deserializing", tiempoInicio);
}
 
开发者ID:sphera5,项目名称:avro-example,代码行数:29,代码来源:Avro.java

示例9: readFile

import org.apache.avro.file.DataFileReader; //导入方法依赖的package包/类
/**
 *Reads the avro file
 * @throws IOException
 */
private void readFile() throws IOException {
    // Deserialize Activities from disk
    
    File file = new File(filename);
            
    DatumReader<Activity> activityDatumReader = new SpecificDatumReader<Activity>(Activity.class);
    DataFileReader<Activity> dataFileReader = new DataFileReader<Activity>(file, activityDatumReader);

    Activity activity = null;
    int i = 0;
    
    while (dataFileReader.hasNext() && i < numrecs) {
        i++;
        activity = dataFileReader.next(activity);
        System.out.println(activity);
    }
}
 
开发者ID:oracle,项目名称:big-data-lite,代码行数:22,代码来源:ReadActivityFile.java

示例10: computeAggregateFromRawData

import org.apache.avro.file.DataFileReader; //导入方法依赖的package包/类
private static Map<String, Number> computeAggregateFromRawData(File avroFile, Map<String, String> fixedValues) throws Exception {
  long m0Aggregate = 0;
  double m1Aggregate = 0.0;

  DatumReader<GenericRecord> reader = new GenericDatumReader<GenericRecord>();
  DataFileReader<GenericRecord> fileReader = new DataFileReader<GenericRecord>(avroFile, reader);
  GenericRecord record = null;
  while (fileReader.hasNext()) {
    record = fileReader.next(record);
    boolean matches = true;
    for (Map.Entry<String, String> entry : fixedValues.entrySet()) {
      String value = record.get(entry.getKey()).toString();
      if (!value.equals(entry.getValue())) {
        matches = false;
      }
    }

    if (matches) {
      m0Aggregate += (Long) record.get("M0");
      m1Aggregate += (Double) record.get("M1");
    }
  }

  return ImmutableMap.of("M0", m0Aggregate, "M1", m1Aggregate);
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:26,代码来源:StarTreeQueriesTest.java

示例11: deserializeFromByte

import org.apache.avro.file.DataFileReader; //导入方法依赖的package包/类
public static Object deserializeFromByte(byte[] byteArray)
		throws IOException {
	SeekableByteArrayInput sin = new SeekableByteArrayInput(byteArray);
	System.out.println("length of read input stream " + sin.length());
	DatumReader<?> reader2 = new ReflectDatumReader<>();
	DataFileReader<?> in = new DataFileReader<>(sin, reader2);
	System.out.println(in.getSchema());
	System.out.println(in.hasNext());
	Object returnObject = null;
	System.out.println(in.getSchema().getFullName() );
	while (in.hasNext()) {
		returnObject = in.next();
		
	}
	in.close();
	return returnObject;
}
 
开发者ID:QualiMaster,项目名称:Infrastructure,代码行数:18,代码来源:AvroSerializationHelper.java

示例12: extractRecords

import org.apache.avro.file.DataFileReader; //导入方法依赖的package包/类
/**
 * @param file
 *            where to read from
 * @param schema
 *            Avro records structure
 * @return all values from the file
 * @throws IOException
 */
public static <T extends SpecificRecord> List<T> extractRecords(File file, Schema schema) throws IOException {
    DatumReader<T> reader = new SpecificDatumReader<>(schema);
    DataFileReader<T> fileReader = new DataFileReader<>(file, reader);
    List<T> data = new ArrayList<T>();
    try {
     while (fileReader.hasNext()) {
         data.add(fileReader.next());
     }
    } finally {
    	if(fileReader != null) {
    		fileReader.close();
    	}
    }
    return data;
}
 
开发者ID:ch4mpy,项目名称:hadoop2,代码行数:24,代码来源:AvroTestUtil.java

示例13: getNextNonemptyReader

import org.apache.avro.file.DataFileReader; //导入方法依赖的package包/类
private DataFileReader<T> getNextNonemptyReader() throws IOException {
	while (fileIterator != null && fileIterator.hasNext()) {
		LocatedFileStatus currentFileStatus = fileIterator.next();
		if (isValidFile(currentFileStatus)) {
			FileSystemPath currPath = new FileSystemPath(
					path.getFileSystem(), currentFileStatus.getPath());
			DataFileReader<T> reader = 
					getSingleFileReader(currPath, readerSchema);
			/** Check if the file contains at least one record */
			if(reader.hasNext()){
				return reader;
			} else {
				reader.close();
			}
		}
	}
	/** fallback */
	return null;
}
 
开发者ID:openaire,项目名称:iis,代码行数:20,代码来源:AvroDataStoreReader.java

示例14: loadMembersToPurge

import org.apache.avro.file.DataFileReader; //导入方法依赖的package包/类
private void loadMembersToPurge(String filename) throws IOException
{
    // TODO: "memberId" column name should be configurable
    DataFileReader<GenericRecord> dataFileReader =
            createDataFileReader(filename, true);
    while (dataFileReader.hasNext())
    {
        GenericRecord record = dataFileReader.next();
        Integer memberId = (Integer) record.get("memberId");
        if (memberId == null)
        {
            throw new NullPointerException("memberId is null");
        }
        membersToPurge.add(((Number) record.get("memberId")).intValue());
    }
    dataFileReader.close();
}
 
开发者ID:linkedin,项目名称:Cubert,代码行数:18,代码来源:Purge.java

示例15: runOnPreview

import org.apache.avro.file.DataFileReader; //导入方法依赖的package包/类
static <T> T runOnPreview(byte[] bits, AvroPreviewProcessor<T> processor) throws IOException {
  DatumReader<GenericRecord> datumReader = new GenericDatumReader<GenericRecord>();
  SeekableByteArrayInput sbai = new SeekableByteArrayInput(bits);
  DataFileReader<GenericRecord> dataFileReader = null;

  try {
    dataFileReader = new DataFileReader<>(sbai, datumReader);
    int headerLen = (int) dataFileReader.previousSync();
    byte[] header = Arrays.copyOf(bits, headerLen);
    if (dataFileReader.hasNext()) {
      GenericRecord gr = dataFileReader.next();
      return processor.process(header, gr, dataFileReader.getBlockCount(), dataFileReader.getBlockSize());
    } else {
      throw new RuntimeException("Empty Avro file - cannot run preview! ");
    }
  } finally {
    try { if (dataFileReader!=null) dataFileReader.close(); } catch (IOException safeToIgnore) {}
  }
}
 
开发者ID:h2oai,项目名称:h2o-3,代码行数:20,代码来源:AvroParser.java


注:本文中的org.apache.avro.file.DataFileReader.hasNext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。