> Java > java지도 시간 > 본문

아브로 파일

WBOY
풀어 주다: 2024-08-30 16:17:32
원래의
981명이 탐색했습니다.

Avro는 Apache Hadoop에서 개발한 데이터 직렬화 프레임워크를 사용할 수 있는 행 기반 소셜 시스템입니다. Avro 파일은 압축 바이너리 형식으로 데이터를 직렬화하기 위해 데이터 직렬화를 전달할 수 있는 데이터 파일입니다. Apache MapReduce로 시도하면 스키마는 JSON 형식이 됩니다. 그런 다음 하위 집합으로 배포해야 하는 대규모 데이터 세트가 있는 경우 이러한 파일은 마커를 예약할 수 있습니다. 또한 쉽게 읽고 쓸 수 있는 신중한 데이터를 보관하기 위한 컨테이너 파일도 있습니다. 추가 구성이 필요하지 않습니다.

무료 소프트웨어 개발 과정 시작

웹 개발, 프로그래밍 언어, 소프트웨어 테스팅 등

Avro 파일 개요

Avro 파일은 대규모 데이터 구조와 작고 빠른 바이너리 데이터 형식을 제공할 수 있는 데이터 직렬화 시스템입니다. 또한 지속적인 데이터를 운반하고 RPC 절차를 사용할 수 있는 컨테이너 파일을 가질 수도 있습니다. 또한, 간단한 통합으로 다양한 언어로 사용이 가능하므로 코드 생성이 필수가 아닌 데이터 파일을 읽거나 쓸 때 새로운 코드 생성이 필요하지 않습니다. 엄격한 유형의 언어로만 배포할 수 있습니다.

일반적으로 두 개의 세그먼트가 있습니다. 첫 번째는 자발적일 수 있는 스키마이고 두 번째는 바이너리 데이터입니다. 예를 들어 텍스트 편집기를 사용하여 avro 파일을 보고 싶다고 가정해 보겠습니다. 이 경우 첫 번째 세그먼트에는 객체로 시작하는 데이터가 포함되고 두 번째 세그먼트에는 읽을 수 있는 데이터와 필요한 파일 형식이 포함되는 두 개의 세그먼트를 볼 수 있습니다. 어떤 Bhoomi가 읽고 쓸 수 있는지 확인하세요.

Avro 파일 구성

다양한 구조적 매개변수를 사용하여 Avro 데이터 파일의 작업을 변환할 수 있는 Avro 파일의 구성을 살펴보겠습니다.

Hadoop을 사용하는 경우

  • avro 파일을 구성하고 싶다면 '. 그런 다음 파일을 읽을 때 Avro의 확장 프로그램을 사용하면 기본값이 false인 'avro.mapred.ignore.inputs.without.extension'을 사용하여 매개변수를 조정할 수 있습니다.

아브로 파일

  • 위의 경우 먼저 Spark에 도달한 다음 Spark 콘텐츠, Hadoop 구성에 도달한 다음 (“avro.mapred.ignore.inputs.without.extension”, “true”)를 설정해야 합니다.

압축을 구성하려면 다음 속성을 설정해야 합니다.

  • 압축 코덱인 Spark.sql.avro.compression.codec에는 snappy가 기본 코덱인 snappy 및 deflate 코덱이 있습니다.
  • 압축 코덱을 deflate로 설정하려면 압축 수준을 "spark.sql.avro.deflate.level"로 조정해야 하며 기본 수준은 '-1'입니다.
  • 다음과 같은 스파크 클러스터의 항목을 조정할 수도 있습니다.

spark.conf.set(“spark.sql.avro.compression.codec”, “deflate”)

spark.conf.set(“spark.sql.avro.deflate.level”, “4”).

아브로 파일

Avro 파일 종류

Avro 파일에는 두 가지 유형이 있습니다.

1. 기본 유형

null, Boolean, int, long, double, bytes, string이 포함됩니다.

Schema: {"type": "null"}
로그인 후 복사

2. 복합 유형

  • 배열:
{
"kind": "array"
"objects": "long"
}
로그인 후 복사
  • 맵: 키는 문자열입니다
{
"kind": "map"
"values": "long"
}
로그인 후 복사
  • 기록:
{
"kind": "record",
"name": "---",
"doc": "---",
"area": [
{"name": "--", "type": "int"},
---
]
}
로그인 후 복사
  • 열거형:
{
"kind": "enum",
"name": "---",
"doc": "---",
"symbols": ["--", "--"]
}
로그인 후 복사
  • 수정됨: 8비트 부호 없는 바이트가 있습니다
{
"kind": "fixed",
"name": "---",
"size": in bytes
}
로그인 후 복사
  • union: 데이터는 스키마와 동일합니다
[
"null",
"string",
--
]
로그인 후 복사

Avro 파일 예시

스키마가 있는 avro 파일과 스키마가 없는 avro 파일의 예를 살펴보겠습니다.

예시 #1

스키마를 사용하는 Avro 파일:

import java.util.Properties
import java.io.InputStream
import com.boomi.execution.ExecutionUtil
import org.apache.avro.Schema;
import org.apache.avro.file.DataFileStream;
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.io.DatumReader;
logger = ExecutionUtil.getBaseLogger();
for (int j = 0; j < dataContext.getDataCount(); j++) {
InputStream istm = dataContext.getStream(j)
Properties prop = dataContext.getProperties(j)
DatumReader<GenericRecord> datumReader = new GenericDatumReader<GenericRecord>();
DataFileStream<GenericRecord> dataFileStream = new DataFileStream<GenericRecord>(istm, datumReader);
Schema sche = dataFileStream.getSchema();
logger.info("Schema utilize for: " + sche);
GenericRecord rec = null;
while (dataFileStream.hasNext()) {
rec = dataFileStream.next(rec);
System.out.println(rec);
istm = new ByteArrayInputStream(rec.toString().getBytes('UTF-8'))
dataContext.storeStream(istm, prop)
}
}
로그인 후 복사

avro 파일과 함께 스키마가 사용된 위의 예에서는 이것이 avro 파일을 읽을 수 있는 스크립트라고 할 수 있으며, 여기서는 하나 이상의 JSON 문서를 생성했습니다. 위 스크립트에서 주어진 코드를 이용하여 관련 패키지를 import하고, 스키마를 설정하고, 객체를 생성하고 데이터를 JSON으로 작성하여 호출해보았습니다.

예시 #2

스키마가 없는 Avro 파일:

import java.util.Properties
import java.io.InputStream
import com.boomi.execution.ExecutionUtil
import org.apache.avro.Schema;
import org.apache.avro.file.DataFileStream;
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.io.DatumReader;
logger = ExecutionUtil.getBaseLogger();
String schemaString = '{"type":"record","name":"college","namespace":"student.avro",' +
'"fields":[{"name":"title","type":"string","doc":"college title"},{"name":"exam_date","type":"string","sub":"start date"},{"name":"teacher","type":"int","sub":"main charactor is the teacher in college"}]}'
for (int k = 0; k < dataContext.getDataCount(); k++) {
InputStream istm = dataContext.getStream(k)
Properties prop = dataContext.getProperties(k)
DatumReader<GenericRecord> datumReader = new GenericDatumReader<GenericRecord>();
DataFileStream<GenericRecord> dataFileStre= new DataFileStream<GenericRecord>(istm, datumReader);
Schema sche = Schema.parse(scheString)
logger.info("Schema used: " + sche);
GenericRecord rec = null;
while (dataFileStre.hasNext()) {
rec = dataFileStre.next(rec);
System.out.println(rec);
is = new ByteArrayInputStream(rec.toString().getBytes('UTF-8'))
dataContext.storeStream(is, prop)
}
}
로그인 후 복사

In the above example, we have written an example of reading files without schema in which we have to understand that if we have not included the schema under the avro file, then we have to perform some steps for informing the interpreter how to explain binary avro data, we also need to generate the schema which has been utilizing, in which this example can avro schema with a different name. We can also set it on another path.

Conclusion

In this article, we have concluded that the avro file is a data file that can work with the data serialized system utilized by Apache Hadoop. It has an open-source platform; we have also seen the configuration of the data files and examples, which helps to understand the concept.

위 내용은 아브로 파일의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!