• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java AvroFSInput类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.hadoop.fs.AvroFSInput的典型用法代码示例。如果您正苦于以下问题:Java AvroFSInput类的具体用法?Java AvroFSInput怎么用?Java AvroFSInput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AvroFSInput类属于org.apache.hadoop.fs包,在下文中一共展示了AvroFSInput类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: AvroFileInputStream

import org.apache.hadoop.fs.AvroFSInput; //导入依赖的package包/类
public AvroFileInputStream(FileStatus status) throws IOException {
  pos = 0;
  buffer = new byte[0];
  GenericDatumReader<Object> reader = new GenericDatumReader<Object>();
  FileContext fc = FileContext.getFileContext(new Configuration());
  fileReader =
    DataFileReader.openReader(new AvroFSInput(fc, status.getPath()),reader);
  Schema schema = fileReader.getSchema();
  writer = new GenericDatumWriter<Object>(schema);
  output = new ByteArrayOutputStream();
  JsonGenerator generator =
    new JsonFactory().createJsonGenerator(output, JsonEncoding.UTF8);
  MinimalPrettyPrinter prettyPrinter = new MinimalPrettyPrinter();
  prettyPrinter.setRootValueSeparator(System.getProperty("line.separator"));
  generator.setPrettyPrinter(prettyPrinter);
  encoder = EncoderFactory.get().jsonEncoder(schema, generator);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:18,代码来源:Display.java


示例2: getSingleFileReader

import org.apache.hadoop.fs.AvroFSInput; //导入依赖的package包/类
/**
 * Get a reader for the specified Avro file. A utility function. 
 * @param path path to the existing file
 * @param readerSchema optional reader schema. If you want to use the
 *		default option of using writer schema as the reader schema, pass the
 *		{@code null} value. 
 * @throws IOException
 */
private static <T> DataFileReader<T> getSingleFileReader(
		FileSystemPath path, Schema readerSchema) throws IOException{
	try{
	SpecificDatumReader<T> datumReader = new SpecificDatumReader<T>();
	if(readerSchema != null){
		datumReader.setExpected(readerSchema);
	}
	long len = path.getFileSystem().getFileStatus(path.getPath()).getLen();
	FSDataInputStream inputStream = path.getFileSystem().open(path.getPath());
	return new DataFileReader<T>(
			new AvroFSInput(inputStream, len), datumReader);
	} catch (IOException ex){
		throw new IOException("Problem with file \""+
				path.getPath().toString()+"\": "+ex.getMessage(), ex);
	}
}
 
开发者ID:openaire,项目名称:iis,代码行数:25,代码来源:AvroDataStoreReader.java


示例3: open

import org.apache.hadoop.fs.AvroFSInput; //导入依赖的package包/类
@Override
public void open() {
  Preconditions.checkState(state.equals(ReaderWriterState.NEW),
    "A reader may not be opened more than once - current state:%s", state);

  logger.debug("Opening reader on path:{}", path);

  try {
    reader = new DataFileReader<E>(new AvroFSInput(fileSystem.open(path),
      fileSystem.getFileStatus(path).getLen()), new ReflectDatumReader<E>(
      schema));
  } catch (IOException e) {
    throw new DatasetReaderException("Unable to create reader path:" + path, e);
  }

  state = ReaderWriterState.OPEN;
}
 
开发者ID:cloudera,项目名称:cdk,代码行数:18,代码来源:FileSystemDatasetReader.java


示例4: AvroFileReader

import org.apache.hadoop.fs.AvroFSInput; //导入依赖的package包/类
public AvroFileReader(FileSystem fs, Path filePath, Map<String, Object> config) throws IOException {
    super(fs, filePath, new GenericRecordToStruct(), config);

    AvroFSInput input = new AvroFSInput(FileContext.getFileContext(filePath.toUri()), filePath);
    this.reader = new DataFileReader<>(input, new SpecificDatumReader<>(this.schema));
    this.offset = new AvroOffset(0);
}
 
开发者ID:mmolimar,项目名称:kafka-connect-fs,代码行数:8,代码来源:AvroFileReader.java


示例5: open

import org.apache.hadoop.fs.AvroFSInput; //导入依赖的package包/类
@Override
public void open(String pathStr, String singleFileOffset) {
  LOG.info(String.format("%s: Open file [%s] with file offset [%s] for read", systemStreamPartition, pathStr, singleFileOffset));
  Path path = new Path(pathStr);
  try {
    AvroFSInput input = new AvroFSInput(FileContext.getFileContext(path.toUri()), path);
    fileReader = new DataFileReader<>(input, new GenericDatumReader<>());
    seek(singleFileOffset);
  } catch (IOException e) {
    throw new SamzaException(e);
  }
}
 
开发者ID:apache,项目名称:samza,代码行数:13,代码来源:AvroFileHdfsReader.java


示例6: main

import org.apache.hadoop.fs.AvroFSInput; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
  if (args.length == 0) {
    System.out.println("AvroReader {dataFile} {schemaFile} {max.lines.to.read.optional}");
  }
  
  
  String dataFile = args[0];
  String schemaFile = args[1];
  int recordsToRead = Integer.MAX_VALUE;
  if (args.length > 2) {
    recordsToRead = Integer.parseInt(args[2]);
  }
  
  Schema.Parser parser = new Schema.Parser();
  Configuration config = new Configuration();
  FileSystem fs = FileSystem.get(config);
  
  Schema schema = parser.parse(fs.open(new Path(schemaFile)));
  
  Path dataFilePath = new Path(dataFile);
  FileStatus fileStatus = fs.getFileStatus(dataFilePath);
  
  AvroFSInput input = new AvroFSInput(fs.open(dataFilePath), fileStatus.getLen());
  
  DatumReader<GenericRecord> datumReader = new GenericDatumReader<GenericRecord>(schema);
  DataFileReader<GenericRecord> dataFileReader = new DataFileReader<GenericRecord>(input, datumReader);
  System.out.println("Schema: " + dataFileReader.getSchema());
  System.out.println();
  int counter = 0;
  while (dataFileReader.hasNext() && counter++ < recordsToRead) {
    GenericRecord r = dataFileReader.next();
    System.out.println(counter + " : " + r);
  }
}
 
开发者ID:tmalaska,项目名称:HBase-ToHDFS,代码行数:35,代码来源:AvroReader.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TransformC14NWithComments类代码示例发布时间:2022-05-22
下一篇:
Java AuthenticationScheme类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap