zhoufek commented on a change in pull request #16762: URL: https://github.com/apache/beam/pull/16762#discussion_r814026896
########## File path: sdks/java/extensions/sbe/src/main/java/org/apache/beam/sdk/extensions/sbe/SbeSchema.java ########## @@ -0,0 +1,252 @@ +/* + * 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 + * + * http://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.beam.sdk.extensions.sbe; + +import static org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkState; + +import com.google.auto.value.AutoValue; +import java.io.Serializable; +import org.apache.beam.sdk.annotations.Experimental; +import org.apache.beam.sdk.annotations.Experimental.Kind; +import org.apache.beam.sdk.schemas.Schema; +import org.apache.beam.sdk.schemas.io.payloads.PayloadSerializerProvider; +import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting; +import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList; +import org.checkerframework.checker.nullness.qual.Nullable; +import uk.co.real_logic.sbe.ir.Ir; + +/** + * Represents an SBE schema that can be translated to a Beam {@link Schema} and {@link + * PayloadSerializerProvider}. + * + * <p>The schema represents a single SBE message. If the XML schema contains more than one message, + * then a new instance must be created for each message that the pipeline will work with. + * + * <p>The currently supported ways of generating a schema are: + * + * <ul> + * <li>Through an intermediate representation ({@link Ir}). + * </ul> + * + * <h3>Intermediate Representation</h3> + * + * <p>An {@link Ir} allows for a reflection-less way of getting a very accurate representation of + * the SBE schema, since it is a tokenized form of the original XML schema. To help deal with some + * ambiguities, such as which message to base the schema around, passing {@link IrOptions} is + * required. See the Javadoc for the options for more details. + * + * <p>At this time, we cannot support serialization to an SBE message through IR. As a result, the + * {@code byte[]} output from the {@link PayloadSerializerProvider} serializer will be from a JSON Review comment: > Could you clarify what you mean by run our own serialzation? The IR contains all the necessary information that we could use for serializing a `Row` (or equivalent) into a `byte[]`. Real Logic uses this to generate stubs that know how to serialize and deserialize the `byte[]`. We'd basically do the same but focused on how to serialize a `Row`. It'll allow us to support writing SBE messages to a sink with IR, but it means implementing that serialization ourselves. Converting to JSON would probably cover many use cases, including the one we have in Dataflow Templates, but I'd imagine that, sooner or later, someone would have a need to write SBE messages to a sink. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
