Skip to content

Commit

Permalink
This closes #2717
Browse files Browse the repository at this point in the history
  • Loading branch information
tgroh committed Apr 27, 2017
2 parents 14a90d7 + d3b399f commit c493695
Show file tree
Hide file tree
Showing 54 changed files with 6 additions and 671 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,6 @@ public void verifyDeterministic() {
public boolean consistentWithEquals() {
return true;
}

@Override
public String getEncodingId() {
return "";
}
}

/**
Expand Down Expand Up @@ -694,11 +689,6 @@ public long getEncodedElementByteSize(KeyPrefix value, Coder.Context context)
return VarInt.getLength(value.getSharedKeySize())
+ VarInt.getLength(value.getUnsharedKeySize());
}

@Override
public String getEncodingId() {
return "";
}
}

/**
Expand Down Expand Up @@ -779,10 +769,5 @@ public long getEncodedElementByteSize(Footer value, Coder.Context context)
throws Exception {
return Footer.FIXED_LENGTH;
}

@Override
public String getEncodingId() {
return "";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ protected long getEncodedElementByteSize(RandomAccessData value, Coder.Context c
}
return size + value.size;
}

@Override
public String getEncodingId() {
return "";
}
}

public static final UnsignedLexicographicalComparator UNSIGNED_LEXICOGRAPHICAL_COMPARATOR =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,39 +239,6 @@ public DatumWriter<T> initialValue() {
};
}

/**
* The encoding identifier is designed to support evolution as per the design of Avro
* In order to use this class effectively, carefully read the Avro
* documentation at
* <a href="https://avro.apache.org/docs/1.7.7/spec.html#Schema+Resolution">Schema Resolution</a>
* to ensure that the old and new schema <i>match</i>.
*
* <p>In particular, this encoding identifier is guaranteed to be the same for {@code AvroCoder}
* instances of the same principal class, and otherwise distinct. The schema is not included
* in the identifier.
*
* <p>When modifying a class to be encoded as Avro, here are some guidelines; see the above link
* for greater detail.
*
* <ul>
* <li>Avoid changing field names.
* <li>Never remove a <code>required</code> field.
* <li>Only add <code>optional</code> fields, with sensible defaults.
* <li>When changing the type of a field, consult the Avro documentation to ensure the new and
* old types are interchangeable.
* </ul>
*
* <p>Code consuming this message class should be prepared to support <i>all</i> versions of
* the class until it is certain that no remaining serialized instances exist.
*
* <p>If backwards incompatible changes must be made, the best recourse is to change the name
* of your class.
*/
@Override
public String getEncodingId() {
return type.getName();
}

/**
* Returns the type this coder encodes/decodes.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ public boolean consistentWithEquals() {
return true;
}

@Override
public String getEncodingId() {
return "";
}

/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ public boolean consistentWithEquals() {
return true;
}

@Override
public String getEncodingId() {
return "";
}

/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ public boolean consistentWithEquals() {
return true;
}

@Override
public String getEncodingId() {
return "";
}

/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ public boolean consistentWithEquals() {
return true;
}

@Override
public String getEncodingId() {
return "";
}

/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ public boolean consistentWithEquals() {
return true;
}

@Override
public String getEncodingId() {
return "";
}

/**
* {@inheritDoc}
*
Expand Down
34 changes: 0 additions & 34 deletions sdks/java/core/src/main/java/org/apache/beam/sdk/coders/Coder.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nullable;
import org.apache.beam.sdk.annotations.Experimental;
Expand Down Expand Up @@ -55,9 +54,6 @@
* inferred. See {@link KvCoder} for an example of a simple compound {@link Coder} that supports
* automatic composition in the {@link CoderRegistry}.
*
* <p>The binary format of a {@link Coder} is identified by {@link #getEncodingId()}; be sure to
* understand the requirements for evolving coder formats.
*
* <p>All methods of a {@link Coder} are required to be thread safe.
*
* @param <T> the type of the values being transcoded
Expand Down Expand Up @@ -225,36 +221,6 @@ void registerByteSizeObserver(
T value, ElementByteSizeObserver observer, Context context)
throws Exception;

/**
* An identifier for the binary format written by {@link #encode}.
*
* <p>This value, along with the fully qualified class name, forms an identifier for the
* binary format of this coder. Whenever this value changes, the new encoding is considered
* incompatible with the prior format: It is presumed that the prior version of the coder will
* be unable to correctly read the new format and the new version of the coder will be unable to
* correctly read the old format.
*
* <p>If the format is changed in a backwards-compatible way (the Coder can still accept data from
* the prior format), such as by adding optional fields to a Protocol Buffer or Avro definition,
* and you want a Beam runner to understand that the new coder is compatible with the prior coder,
* this value must remain unchanged. It is then the responsibility of {@link #decode} to correctly
* read data from the prior format.
*/
@Experimental(Kind.CODER_ENCODING_ID)
String getEncodingId();

/**
* A collection of encodings supported by {@link #decode} in addition to the encoding
* from {@link #getEncodingId()} (which is assumed supported).
*
* <p><i>This information is not currently used for any purpose</i>. It is descriptive only,
* and this method is subject to change.
*
* @see #getEncodingId()
*/
@Experimental(Kind.CODER_ENCODING_ID)
Collection<String> getAllowedEncodings();

/**
* Returns the {@link TypeDescriptor} for the type encoded.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
* serialization.
*
* <p>To complete an implementation, subclasses must implement {@link Coder#encode}
* and {@link Coder#decode} methods. Anonymous subclasses must furthermore override
* {@link #getEncodingId}.
* and {@link Coder#decode} methods.
*
* <p>Not to be confused with {@link SerializableCoder} that encodes objects that implement the
* {@link Serializable} interface.
Expand All @@ -43,6 +42,7 @@
*/
public abstract class CustomCoder<T> extends StandardCoder<T>
implements Serializable {

@JsonCreator
@Deprecated
public static CustomCoder<?> of(
Expand Down Expand Up @@ -114,27 +114,6 @@ public void verifyDeterministic() throws NonDeterministicException {
+ " or they are presumed nondeterministic.");
}

/**
* {@inheritDoc}
*
* @return The canonical class name for this coder. For stable data formats that are independent
* of class name, it is recommended to override this method.
*
* @throws UnsupportedOperationException when an anonymous class is used, since they do not have
* a stable canonical class name.
*/
@Override
public String getEncodingId() {
if (getClass().isAnonymousClass()) {
throw new UnsupportedOperationException(
String.format("Anonymous CustomCoder subclass %s must override getEncodingId()."
+ " Otherwise, convert to a named class and getEncodingId() will be automatically"
+ " generated from the fully qualified class name.",
getClass()));
}
return getClass().getCanonicalName();
}

// This coder inherits isRegisterByteSizeObserverCheap,
// getEncodedElementByteSize and registerByteSizeObserver
// from StandardCoder. Override if we can do better.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.collect.Lists;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nullable;
import org.apache.beam.sdk.values.TypeDescriptor;

Expand Down Expand Up @@ -142,34 +139,6 @@ public String toString() {
.toString();
}

/**
* {@inheritDoc}
*
* @return a {@link String} composed from the underlying coder class name and its encoding id.
* Note that this omits any description of the coding functions. These should be modified
* with care.
*/
@Override
public String getEncodingId() {
return delegateEncodingId(coder.getClass(), coder.getEncodingId());
}

/**
* {@inheritDoc}
*
* @return allowed encodings which are composed from the underlying coder class and its allowed
* encoding ids. Note that this omits any description of the coding functions. These
* should be modified with care.
*/
@Override
public Collection<String> getAllowedEncodings() {
List<String> allowedEncodings = Lists.newArrayList();
for (String allowedEncoding : coder.getAllowedEncodings()) {
allowedEncodings.add(delegateEncodingId(coder.getClass(), allowedEncoding));
}
return allowedEncodings;
}

@Override
public TypeDescriptor<T> getEncodedTypeDescriptor() {
if (typeDescriptor == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ public boolean consistentWithEquals() {
return true;
}

@Override
public String getEncodingId() {
return "";
}

/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ public boolean consistentWithEquals() {
return true;
}

@Override
public String getEncodingId() {
return "";
}

/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -182,14 +181,4 @@ public TypeDescriptor<Map<K, V>> getEncodedTypeDescriptor() {
new TypeParameter<K>() {}, keyCoder.getEncodedTypeDescriptor())
.where(new TypeParameter<V>() {}, valueCoder.getEncodedTypeDescriptor());
}

@Override
public String getEncodingId() {
return "";
}

@Override
public Collection<String> getAllowedEncodings() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
import org.apache.beam.sdk.util.common.ElementByteSizeObserver;
Expand Down Expand Up @@ -178,14 +176,4 @@ public boolean isRegisterByteSizeObserverCheap(@Nullable T value, Context contex
public TypeDescriptor<T> getEncodedTypeDescriptor() {
return valueCoder.getEncodedTypeDescriptor();
}

@Override
public String getEncodingId() {
return "";
}

@Override
public Collection<String> getAllowedEncodings() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
import java.io.OutputStream;
import java.io.Serializable;
import org.apache.beam.sdk.values.TypeDescriptor;
Expand Down Expand Up @@ -123,13 +122,6 @@ public T decode(InputStream inStream, Context context)
}
}

@Override
public String getEncodingId() {
return String.format("%s:%s",
type.getName(),
ObjectStreamClass.lookup(type).getSerialVersionUID());
}

/**
* {@inheritDoc}
*
Expand Down
Loading

0 comments on commit c493695

Please sign in to comment.