本文整理汇总了Java中org.apache.avro.SchemaParseException类的典型用法代码示例。如果您正苦于以下问题:Java SchemaParseException类的具体用法?Java SchemaParseException怎么用?Java SchemaParseException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SchemaParseException类属于org.apache.avro包,在下文中一共展示了SchemaParseException类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createNewSchema
import org.apache.avro.SchemaParseException; //导入依赖的package包/类
private Schema createNewSchema(Schema currentSchema, SchemaField newField) {
List<Schema.Field> avroFields = currentSchema.getFields().stream()
.filter(field -> field.schema().getType() != Schema.Type.NULL)
.map(field -> new Schema.Field(field.name(), field.schema(), field.doc(), field.defaultValue()))
.collect(toList());
try {
avroFields.add(AvroUtil.generateAvroField(newField));
} catch (SchemaParseException e) {
throw new RakamException("Couldn't create new column: " + e.getMessage(), BAD_REQUEST);
}
conditionalMagicFields.keySet().stream()
.filter(s -> !avroFields.stream().anyMatch(af -> af.name().equals(s)))
.map(n -> new Schema.Field(n, Schema.create(NULL), "", null))
.forEach(x -> avroFields.add(x));
Schema avroSchema = Schema.createRecord("collection", null, null, false);
avroSchema.setFields(avroFields);
return avroSchema;
}
示例2: readerWithUnparseableSchema
import org.apache.avro.SchemaParseException; //导入依赖的package包/类
@Test(expected = SchemaParseException.class)
public void readerWithUnparseableSchema() throws Throwable {
Map<String, Object> cfg = new HashMap<String, Object>() {{
put(ParquetFileReader.FILE_READER_PARQUET_SCHEMA, "invalid schema");
put(AgnosticFileReader.FILE_READER_AGNOSTIC_EXTENSIONS_PARQUET, getFileExtension());
}};
getReader(FileSystem.newInstance(fsUri, new Configuration()), dataFile, cfg);
}
示例3: readerWithUnparseableSchema
import org.apache.avro.SchemaParseException; //导入依赖的package包/类
@Test(expected = SchemaParseException.class)
public void readerWithUnparseableSchema() throws Throwable {
Map<String, Object> cfg = new HashMap<String, Object>() {{
put(AvroFileReader.FILE_READER_AVRO_SCHEMA, "invalid schema");
put(AgnosticFileReader.FILE_READER_AGNOSTIC_EXTENSIONS_AVRO, getFileExtension());
}};
getReader(fs, dataFile, cfg);
}
示例4: readerWithUnparseableSchema
import org.apache.avro.SchemaParseException; //导入依赖的package包/类
@Test(expected = SchemaParseException.class)
public void readerWithUnparseableSchema() throws Throwable {
Map<String, Object> cfg = new HashMap<String, Object>() {{
put(ParquetFileReader.FILE_READER_PARQUET_SCHEMA, "invalid schema");
}};
getReader(FileSystem.newInstance(fsUri, new Configuration()), dataFile, cfg);
}
示例5: readerWithUnparseableSchema
import org.apache.avro.SchemaParseException; //导入依赖的package包/类
@Test(expected = SchemaParseException.class)
public void readerWithUnparseableSchema() throws Throwable {
Map<String, Object> cfg = new HashMap<String, Object>() {{
put(AvroFileReader.FILE_READER_AVRO_SCHEMA, "invalid schema");
}};
getReader(fs, dataFile, cfg);
}
示例6: parseSchema
import org.apache.avro.SchemaParseException; //导入依赖的package包/类
private static Schema parseSchema(String schemaString) {
try {
Schema.Parser parser1 = new Schema.Parser();
Schema schema = parser1.parse(schemaString);
return schema;
} catch (SchemaParseException e) {
return null;
}
}
示例7: parseSchema
import org.apache.avro.SchemaParseException; //导入依赖的package包/类
public static Schema parseSchema(String schemaString) {
try {
Schema.Parser parser1 = new Schema.Parser();
return parser1.parse(schemaString);
} catch (SchemaParseException e) {
return null;
}
}
示例8: schemaBackwardCompatibility
import org.apache.avro.SchemaParseException; //导入依赖的package包/类
public SchemaCompatiblityCheck schemaBackwardCompatibility(SchemaDTO schemaDto) {
String schemaContent = schemaDto.getContents();
SchemaCompatibility.SchemaPairCompatibility schemaCompatibility;
Schema writer;
TypedQuery<SchemaTopics> query = em.createNamedQuery(
"SchemaTopics.findByName", SchemaTopics.class);
query.setParameter("name", schemaDto.getName());
try {
Schema reader = new Schema.Parser().parse(schemaContent);
for (SchemaTopics schemaTopic : query.getResultList()) {
writer = new Schema.Parser().parse(schemaTopic.getContents());
schemaCompatibility = SchemaCompatibility.
checkReaderWriterCompatibility(reader, writer);
switch (schemaCompatibility.getType()) {
case COMPATIBLE:
break;
case INCOMPATIBLE:
return SchemaCompatiblityCheck.INCOMPATIBLE;
case RECURSION_IN_PROGRESS:
break;
}
}
} catch (SchemaParseException ex) {
return SchemaCompatiblityCheck.INVALID;
}
return SchemaCompatiblityCheck.COMPATIBLE;
}
示例9: isValid
import org.apache.avro.SchemaParseException; //导入依赖的package包/类
@Override
public boolean isValid(String definition) {
boolean result = true;
try {
new org.apache.avro.Schema.Parser().parse(definition);
}
catch (SchemaParseException ex) {
result = false;
}
return result;
}
示例10: compile
import org.apache.avro.SchemaParseException; //导入依赖的package包/类
protected void compile() throws IOException {
File sourceDirectory = getSourcesDirectory();
File outputDirectory = getOutputDirectory();
if (!outputDirectory.exists()) {
outputDirectory.mkdirs();
}
Scanner fileScanner = context.newScanner(sourceDirectory, true);
fileScanner.setIncludes(includes);
fileScanner.setExcludes(excludes);
fileScanner.scan();
File basedir = fileScanner.getBasedir();
List<File> changedFiles = new ArrayList<File>();
for (String fileName : fileScanner.getIncludedFiles()) {
File file = new File(basedir, fileName);
changedFiles.add(file);
context.removeMessages(file);
}
if (!changedFiles.isEmpty()) {
try {
File[] schemaFile = changedFiles.toArray(new File[changedFiles.size()]);
GoraCompiler.compileSchema(schemaFile, outputDirectory);
} catch (SchemaParseException e) {
if (e.getCause() != null && e.getCause() instanceof JsonParseException) {
attachErrorMessage((JsonParseException) e.getCause());
} else {
throw e;
}
}
}
context.refresh(outputDirectory);
}
示例11: compile
import org.apache.avro.SchemaParseException; //导入依赖的package包/类
protected void compile() throws IOException {
File sourceDirectory = getSourcesDirectory();
File outputDirectory = getOutputDirectory();
if (!outputDirectory.exists()) {
outputDirectory.mkdirs();
}
Scanner fileScanner = context.newScanner(sourceDirectory, true);
fileScanner.setIncludes(includes);
fileScanner.setExcludes(excludes);
fileScanner.scan();
File basedir = fileScanner.getBasedir();
List<File> changedFiles = new ArrayList<File>();
for (String fileName : fileScanner.getIncludedFiles()) {
File file = new File(basedir, fileName);
changedFiles.add(file);
context.removeMessages(file);
}
if (!changedFiles.isEmpty()) {
try {
File[] schemaFile = changedFiles.toArray(new File[changedFiles.size()]);
GoraCompiler.compileSchema(schemaFile, outputDirectory);
} catch (SchemaParseException e) {
if (e.getCause() != null && e.getCause() instanceof JsonParseException) {
attachErrorMessage((JsonParseException) e.getCause());
} else {
throw e;
}
}
}
context.refresh(outputDirectory);
}