Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.avro.io.parsing;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.avro.AvroTypeException;
import org.apache.avro.Resolver;
import org.apache.avro.Schema;
import org.apache.avro.Schema.Field;
import org.apache.avro.io.Encoder;
import org.apache.avro.io.EncoderFactory;
import org.apache.avro.util.internal.Accessor;
import org.apache.avro.util.internal.Accessor.ResolvingGrammarGeneratorAccessor;
import io.prestosql.hive.$internal.com.fasterxml.jackson.databind.JsonNode;
/**
* The class that generates a resolving grammar to resolve between two schemas.
*/
public class ResolvingGrammarGenerator extends ValidatingGrammarGenerator {
static {
Accessor.setAccessor(new ResolvingGrammarGeneratorAccessor() {
@Override
protected void encode(Encoder e, Schema s, JsonNode n) throws IOException {
ResolvingGrammarGenerator.encode(e, s, n);
}
});
}
/**
* Resolves the writer schema writer and the reader schema
* reader and returns the start symbol for the grammar generated.
*
* @param writer The schema used by the writer
* @param reader The schema used by the reader
* @return The start symbol for the resolving grammar
* @throws IOException
*/
public final Symbol generate(Schema writer, Schema reader) throws IOException {
Resolver.Action r = Resolver.resolve(writer, reader);
return Symbol.root(generate(r, new HashMap<>()));
}
/**
* Takes a {@link Resolver.Action} for resolving two schemas and returns the
* start symbol for a grammar that implements that resolution. If the action is
* for a record and there's already a symbol for that record in seen,
* then that symbol is returned. Otherwise a new symbol is generated and
* returned.
*
* @param action The resolver to be implemented
* @param seen The <Action> to symbol map of start symbols of resolving
* grammars so far.
* @return The start symbol for the resolving grammar
* @throws IOException
*/
private Symbol generate(Resolver.Action action, Map