You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by se...@apache.org on 2015/12/14 19:48:30 UTC
[1/7] flink git commit: [hotfix] Remove unused ValueUtil
Repository: flink
Updated Branches:
refs/heads/master 44eb58e08 -> 066913e23
[hotfix] Remove unused ValueUtil
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/4a26cced
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/4a26cced
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/4a26cced
Branch: refs/heads/master
Commit: 4a26cced238d276c2f9accc9ab226ddbdb3e895a
Parents: a8c4c48
Author: Stephan Ewen <se...@apache.org>
Authored: Sun Dec 13 17:47:24 2015 +0100
Committer: Stephan Ewen <se...@apache.org>
Committed: Mon Dec 14 17:44:19 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/flink/types/ValueUtil.java | 66 --------------------
1 file changed, 66 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/4a26cced/flink-core/src/main/java/org/apache/flink/types/ValueUtil.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/types/ValueUtil.java b/flink-core/src/main/java/org/apache/flink/types/ValueUtil.java
deleted file mode 100644
index 723906a..0000000
--- a/flink-core/src/main/java/org/apache/flink/types/ValueUtil.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.flink.types;
-
-/**
- * convert the java.lang type into a value type
- */
-public final class ValueUtil {
- public static Value toFlinkValueType(Object java) {
- if (java == null) {
- return NullValue.getInstance();
- }
- if (java.getClass() == java.lang.Boolean.class) {
- return new BooleanValue(((java.lang.Boolean)java).booleanValue());
- }
- if (java.getClass() == java.lang.Integer.class) {
- return new IntValue(((java.lang.Integer)java).intValue());
- }
- if (java.getClass() == java.lang.Byte.class) {
- return new ByteValue(((java.lang.Byte)java).byteValue());
- }
- if (java.getClass() == java.lang.Character.class) {
- return new CharValue(((java.lang.Character)java).charValue());
- }
- if (java.getClass() == java.lang.Double.class) {
- return new DoubleValue(((java.lang.Double)java).doubleValue());
- }
- if (java.getClass() == java.lang.Float.class) {
- return new FloatValue(((java.lang.Float)java).floatValue());
- }
- if (java.getClass() == java.lang.Long.class) {
- return new LongValue(((java.lang.Long)java).longValue());
- }
- if (java.getClass() == java.lang.Short.class) {
- return new ShortValue(((java.lang.Short)java).shortValue());
- }
- if (java.getClass() == java.lang.String.class) {
- return new StringValue(((java.lang.String)java).toString());
- }
- throw new IllegalArgumentException("unsupported Java value");
- }
-
- /**
- * Private constructor to prevent instantiation.
- */
- private ValueUtil() {
- throw new RuntimeException();
- }
-}
[2/7] flink git commit: [hotfix] Remove unused FileDataSourceBase and
FileDataSinkBase
Posted by se...@apache.org.
[hotfix] Remove unused FileDataSourceBase and FileDataSinkBase
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/a8c4c48d
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/a8c4c48d
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/a8c4c48d
Branch: refs/heads/master
Commit: a8c4c48d7ddc2d0fd880535d7c7d24bd4f63c0d8
Parents: bd657e6
Author: Stephan Ewen <se...@apache.org>
Authored: Sun Dec 13 18:57:26 2015 +0100
Committer: Stephan Ewen <se...@apache.org>
Committed: Mon Dec 14 17:44:19 2015 +0100
----------------------------------------------------------------------
.../common/operators/base/FileDataSinkBase.java | 83 --------------------
.../operators/base/FileDataSourceBase.java | 81 -------------------
.../examples/WordCountCompilerTest.java | 2 -
3 files changed, 166 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/a8c4c48d/flink-core/src/main/java/org/apache/flink/api/common/operators/base/FileDataSinkBase.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/operators/base/FileDataSinkBase.java b/flink-core/src/main/java/org/apache/flink/api/common/operators/base/FileDataSinkBase.java
deleted file mode 100644
index 8f5c4e3..0000000
--- a/flink-core/src/main/java/org/apache/flink/api/common/operators/base/FileDataSinkBase.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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.flink.api.common.operators.base;
-
-import org.apache.flink.api.common.io.FileOutputFormat;
-import org.apache.flink.api.common.operators.GenericDataSinkBase;
-import org.apache.flink.api.common.operators.UnaryOperatorInformation;
-import org.apache.flink.api.common.operators.util.UserCodeWrapper;
-import org.apache.flink.types.Nothing;
-
-/**
- * Operator for nodes which act as data sinks, storing the data they receive in a file instead of sending it to another
- * contract. The encoding of the data in the file is handled by the {@link org.apache.flink.api.common.io.FileOutputFormat}.
- *
- * @see org.apache.flink.api.common.io.FileOutputFormat
- */
-public class FileDataSinkBase<IN> extends GenericDataSinkBase<IN> {
-
- protected final String filePath;
-
- // --------------------------------------------------------------------------------------------
-
- /**
- * Creates a FileDataSink with the provided {@link org.apache.flink.api.common.io.FileOutputFormat} implementation
- * and the given name, writing to the file indicated by the given path.
- *
- * @param f The {@link org.apache.flink.api.common.io.FileOutputFormat} implementation used to encode the data.
- * @param filePath The path to the file to write the contents to.
- * @param name The given name for the sink, used in plans, logs and progress messages.
- */
- public FileDataSinkBase(FileOutputFormat<IN> f, UnaryOperatorInformation<IN, Nothing> operatorInfo, String filePath, String name) {
- super(f, operatorInfo, name);
- this.filePath = filePath;
- this.parameters.setString(FileOutputFormat.FILE_PARAMETER_KEY, filePath);
- }
-
- /**
- * Creates a FileDataSink with the provided {@link org.apache.flink.api.common.io.FileOutputFormat} implementation
- * and the given name, writing to the file indicated by the given path.
- *
- * @param f The {@link org.apache.flink.api.common.io.FileOutputFormat} implementation used to encode the data.
- * @param filePath The path to the file to write the contents to.
- * @param name The given name for the sink, used in plans, logs and progress messages.
- */
- public FileDataSinkBase(UserCodeWrapper<FileOutputFormat<IN>> f, UnaryOperatorInformation<IN, Nothing> operatorInfo, String filePath, String name) {
- super(f, operatorInfo, name);
- this.filePath = filePath;
- this.parameters.setString(FileOutputFormat.FILE_PARAMETER_KEY, filePath);
- }
-
- // --------------------------------------------------------------------------------------------
-
- /**
- * Returns the configured file path where the output is written to.
- *
- * @return The path to which the output shall be written.
- */
- public String getFilePath() {
- return this.filePath;
- }
-
-
- @Override
- public String toString() {
- return this.filePath;
- }
-}
http://git-wip-us.apache.org/repos/asf/flink/blob/a8c4c48d/flink-core/src/main/java/org/apache/flink/api/common/operators/base/FileDataSourceBase.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/operators/base/FileDataSourceBase.java b/flink-core/src/main/java/org/apache/flink/api/common/operators/base/FileDataSourceBase.java
deleted file mode 100644
index 907819f..0000000
--- a/flink-core/src/main/java/org/apache/flink/api/common/operators/base/FileDataSourceBase.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.flink.api.common.operators.base;
-
-import org.apache.flink.api.common.io.FileInputFormat;
-import org.apache.flink.api.common.operators.GenericDataSourceBase;
-import org.apache.flink.api.common.operators.OperatorInformation;
-
-import com.google.common.base.Preconditions;
-
-/**
- * Operator for input nodes which read data from files.
- */
-public class FileDataSourceBase<OUT> extends GenericDataSourceBase<OUT, FileInputFormat<OUT>> {
-
- protected final String filePath;
-
- // --------------------------------------------------------------------------------------------
-
- /**
- * Creates a new instance for the given file using the given file input format.
- *
- * @param f The {@link org.apache.flink.api.common.io.FileInputFormat} implementation used to read the data.
- * @param operatorInfo The type information for the output type.
- * @param filePath The file location. The file path must be a fully qualified URI, including the address schema.
- * @param name The given name for the Pact, used in plans, logs and progress messages.
- */
- public FileDataSourceBase(FileInputFormat<OUT> f, OperatorInformation<OUT> operatorInfo, String filePath, String name) {
- super(f, operatorInfo, name);
-
- Preconditions.checkNotNull(filePath, "The file path may not be null.");
-
- this.filePath = filePath;
- f.setFilePath(filePath);
- }
-
- /**
- * Creates a new instance for the given file using the given input format. The contract has the default name.
- *
- * @param f The {@link org.apache.flink.api.common.io.FileInputFormat} implementation used to read the data.
- * @param operatorInfo The type information for the output type.
- * @param filePath The file location. The file path must be a fully qualified URI, including the address schema.
- */
- public FileDataSourceBase(FileInputFormat<OUT> f, OperatorInformation<OUT> operatorInfo, String filePath) {
- this(f, operatorInfo, Preconditions.checkNotNull(filePath, "The file path may not be null."), "File " + filePath);
- }
-
- // --------------------------------------------------------------------------------------------
-
- /**
- * Returns the file path from which the input is read.
- *
- * @return The path from which the input shall be read.
- */
- public String getFilePath() {
- return this.filePath;
- }
-
- // --------------------------------------------------------------------------------------------
-
- public String toString() {
- return this.filePath;
- }
-}
http://git-wip-us.apache.org/repos/asf/flink/blob/a8c4c48d/flink-tests/src/test/java/org/apache/flink/test/optimizer/examples/WordCountCompilerTest.java
----------------------------------------------------------------------
diff --git a/flink-tests/src/test/java/org/apache/flink/test/optimizer/examples/WordCountCompilerTest.java b/flink-tests/src/test/java/org/apache/flink/test/optimizer/examples/WordCountCompilerTest.java
index 576717f..ab49282 100644
--- a/flink-tests/src/test/java/org/apache/flink/test/optimizer/examples/WordCountCompilerTest.java
+++ b/flink-tests/src/test/java/org/apache/flink/test/optimizer/examples/WordCountCompilerTest.java
@@ -24,8 +24,6 @@ import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.Plan;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.common.operators.GenericDataSourceBase;
-import org.apache.flink.api.common.operators.Order;
-import org.apache.flink.api.common.operators.base.FileDataSourceBase;
import org.apache.flink.api.common.operators.util.FieldList;
import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.java.ExecutionEnvironment;
[6/7] flink git commit: [FLINK-3169] Move Record Type Utils from
flink-java to flink-runtime/test
Posted by se...@apache.org.
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordComparatorFactory.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordComparatorFactory.java b/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordComparatorFactory.java
new file mode 100644
index 0000000..3ea7106
--- /dev/null
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordComparatorFactory.java
@@ -0,0 +1,152 @@
+/*
+ * 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.flink.runtime.testutils.recordutils;
+
+import java.util.Arrays;
+
+import org.apache.flink.api.common.typeutils.TypeComparatorFactory;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.IllegalConfigurationException;
+import org.apache.flink.types.Key;
+import org.apache.flink.types.Record;
+
+/**
+ * A factory for a {@link org.apache.flink.api.common.typeutils.TypeComparator} for {@link Record}. The comparator uses a subset of
+ * the fields for the comparison. That subset of fields (positions and types) is read from the
+ * supplied configuration.
+ */
+public class RecordComparatorFactory implements TypeComparatorFactory<Record> {
+
+ private static final String NUM_KEYS = "numkeys";
+
+ private static final String KEY_POS_PREFIX = "keypos.";
+
+ private static final String KEY_CLASS_PREFIX = "keyclass.";
+
+ private static final String KEY_SORT_DIRECTION_PREFIX = "key-direction.";
+
+ // --------------------------------------------------------------------------------------------
+
+ private int[] positions;
+
+ private Class<? extends Key<?>>[] types;
+
+ private boolean[] sortDirections;
+
+ // --------------------------------------------------------------------------------------------
+
+ public RecordComparatorFactory() {
+ // do nothing, allow to be configured via config
+ }
+
+ public RecordComparatorFactory(int[] positions, Class<? extends Key<?>>[] types) {
+ this(positions, types, null);
+ }
+
+ public RecordComparatorFactory(int[] positions, Class<? extends Key<?>>[] types, boolean[] sortDirections) {
+ if (positions == null || types == null) {
+ throw new NullPointerException();
+ }
+ if (positions.length != types.length) {
+ throw new IllegalArgumentException();
+ }
+
+ this.positions = positions;
+ this.types = types;
+
+ if (sortDirections == null) {
+ this.sortDirections = new boolean[positions.length];
+ Arrays.fill(this.sortDirections, true);
+ } else if (sortDirections.length != positions.length) {
+ throw new IllegalArgumentException();
+ } else {
+ this.sortDirections = sortDirections;
+ }
+ }
+
+
+ @Override
+ public void writeParametersToConfig(Configuration config) {
+ for (int i = 0; i < this.positions.length; i++) {
+ if (this.positions[i] < 0) {
+ throw new IllegalArgumentException("The key position " + i + " is invalid: " + this.positions[i]);
+ }
+ if (this.types[i] == null || !Key.class.isAssignableFrom(this.types[i])) {
+ throw new IllegalArgumentException("The key type " + i + " is null or not implenting the interface " +
+ Key.class.getName() + ".");
+ }
+ }
+
+ // write the config
+ config.setInteger(NUM_KEYS, this.positions.length);
+ for (int i = 0; i < this.positions.length; i++) {
+ config.setInteger(KEY_POS_PREFIX + i, this.positions[i]);
+ config.setString(KEY_CLASS_PREFIX + i, this.types[i].getName());
+ config.setBoolean(KEY_SORT_DIRECTION_PREFIX + i, this.sortDirections[i]);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void readParametersFromConfig(Configuration config, ClassLoader cl) throws ClassNotFoundException {
+ // figure out how many key fields there are
+ final int numKeyFields = config.getInteger(NUM_KEYS, -1);
+ if (numKeyFields < 0) {
+ throw new IllegalConfigurationException("The number of keys for the comparator is invalid: " + numKeyFields);
+ }
+
+ final int[] positions = new int[numKeyFields];
+ final Class<? extends Key<?>>[] types = new Class[numKeyFields];
+ final boolean[] direction = new boolean[numKeyFields];
+
+ // read the individual key positions and types
+ for (int i = 0; i < numKeyFields; i++) {
+ // next key position
+ final int p = config.getInteger(KEY_POS_PREFIX + i, -1);
+ if (p >= 0) {
+ positions[i] = p;
+ } else {
+ throw new IllegalConfigurationException("Contained invalid position for key no positions for keys.");
+ }
+
+ // next key type
+ final String name = config.getString(KEY_CLASS_PREFIX + i, null);
+ if (name != null) {
+ types[i] = (Class<? extends Key<?>>) Class.forName(name, true, cl).asSubclass(Key.class);
+ } else {
+ throw new IllegalConfigurationException("The key type (" + i +
+ ") for the comparator is null");
+ }
+
+ // next key sort direction
+ direction[i] = config.getBoolean(KEY_SORT_DIRECTION_PREFIX + i, true);
+ }
+
+ this.positions = positions;
+ this.types = types;
+ this.sortDirections = direction;
+ }
+
+
+ @Override
+ public RecordComparator createComparator() {
+ return new RecordComparator(this.positions, this.types, this.sortDirections);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordPairComparator.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordPairComparator.java b/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordPairComparator.java
new file mode 100644
index 0000000..fd51ce1
--- /dev/null
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordPairComparator.java
@@ -0,0 +1,106 @@
+/*
+ * 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.flink.runtime.testutils.recordutils;
+
+import org.apache.flink.api.common.typeutils.TypePairComparator;
+import org.apache.flink.types.Key;
+import org.apache.flink.types.NullKeyFieldException;
+import org.apache.flink.types.Record;
+import org.apache.flink.util.InstantiationUtil;
+
+
+/**
+ * Implementation of the {@link TypePairComparator} interface for Pact Records. The equality is established on a set of
+ * key fields. The indices of the key fields may be different on the reference and candidate side.
+ */
+public class RecordPairComparator extends TypePairComparator<Record, Record> {
+
+ private final int[] keyFields1, keyFields2; // arrays with the positions of the keys in the records
+
+ @SuppressWarnings("rawtypes")
+ private final Key[] keyHolders1, keyHolders2; // arrays with mutable objects for the key types
+
+
+ public RecordPairComparator(int[] keyFieldsReference, int[] keyFieldsCandidate, Class<? extends Key<?>>[] keyTypes) {
+ if (keyFieldsReference.length != keyFieldsCandidate.length || keyFieldsCandidate.length != keyTypes.length) {
+ throw new IllegalArgumentException(
+ "The arrays describing the key positions and types must be of the same length.");
+ }
+ this.keyFields1 = keyFieldsReference;
+ this.keyFields2 = keyFieldsCandidate;
+
+ // instantiate fields to extract keys into
+ this.keyHolders1 = new Key[keyTypes.length];
+ this.keyHolders2 = new Key[keyTypes.length];
+
+ for (int i = 0; i < keyTypes.length; i++) {
+ if (keyTypes[i] == null) {
+ throw new NullPointerException("Key type " + i + " is null.");
+ }
+ this.keyHolders1[i] = InstantiationUtil.instantiate(keyTypes[i], Key.class);
+ this.keyHolders2[i] = InstantiationUtil.instantiate(keyTypes[i], Key.class);
+ }
+ }
+
+ // --------------------------------------------------------------------------------------------
+
+
+ @Override
+ public void setReference(Record reference) {
+ for (int i = 0; i < this.keyFields1.length; i++) {
+ if (!reference.getFieldInto(this.keyFields1[i], this.keyHolders1[i])) {
+ throw new NullKeyFieldException(this.keyFields1[i]);
+ }
+ }
+ }
+
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public boolean equalToReference(Record candidate) {
+ for (int i = 0; i < this.keyFields2.length; i++) {
+ final Key k = candidate.getField(this.keyFields2[i], this.keyHolders2[i]);
+ if (k == null) {
+ throw new NullKeyFieldException(this.keyFields2[i]);
+ } else if (!k.equals(this.keyHolders1[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Override
+ public int compareToReference(Record candidate) {
+ for (int i = 0; i < this.keyFields2.length; i++) {
+ final Key k = candidate.getField(this.keyFields2[i], this.keyHolders2[i]);
+ if (k == null) {
+ throw new NullKeyFieldException(this.keyFields2[i]);
+ } else {
+ final int comp = k.compareTo(this.keyHolders1[i]);
+ if (comp != 0) {
+ return comp;
+ }
+ }
+ }
+ return 0;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordPairComparatorFactory.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordPairComparatorFactory.java b/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordPairComparatorFactory.java
new file mode 100644
index 0000000..c1741b0
--- /dev/null
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordPairComparatorFactory.java
@@ -0,0 +1,105 @@
+/*
+ * 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.flink.runtime.testutils.recordutils;
+
+import org.apache.flink.api.common.typeutils.TypeComparator;
+import org.apache.flink.api.common.typeutils.TypePairComparator;
+import org.apache.flink.api.common.typeutils.TypePairComparatorFactory;
+import org.apache.flink.types.Key;
+import org.apache.flink.types.Record;
+
+/**
+ * A factory for a {@link TypePairComparator} for {@link Record}. The comparator uses a subset of
+ * the fields for the comparison. That subset of fields (positions and types) is read from the
+ * supplied configuration.
+ */
+public class RecordPairComparatorFactory implements TypePairComparatorFactory<Record, Record> {
+
+ private static final RecordPairComparatorFactory INSTANCE = new RecordPairComparatorFactory();
+
+ /**
+ * Gets an instance of the comparator factory. The instance is shared, since the factory is a
+ * stateless class.
+ *
+ * @return An instance of the comparator factory.
+ */
+ public static final RecordPairComparatorFactory get() {
+ return INSTANCE;
+ }
+
+ @Override
+ public TypePairComparator<Record, Record> createComparator12(
+ TypeComparator<Record> comparator1, TypeComparator<Record> comparator2)
+ {
+ if (!(comparator1 instanceof RecordComparator && comparator2 instanceof RecordComparator)) {
+ throw new IllegalArgumentException("Cannot instantiate pair comparator from the given comparators.");
+ }
+ final RecordComparator prc1 = (RecordComparator) comparator1;
+ final RecordComparator prc2 = (RecordComparator) comparator2;
+
+ final int[] pos1 = prc1.getKeyPositions();
+ final int[] pos2 = prc2.getKeyPositions();
+
+ final Class<? extends Key<?>>[] types1 = prc1.getKeyTypes();
+ final Class<? extends Key<?>>[] types2 = prc2.getKeyTypes();
+
+ checkComparators(pos1, pos2, types1, types2);
+
+ return new RecordPairComparator(pos1, pos2, types1);
+ }
+
+ @Override
+ public TypePairComparator<Record, Record> createComparator21(
+ TypeComparator<Record> comparator1, TypeComparator<Record> comparator2)
+ {
+ if (!(comparator1 instanceof RecordComparator && comparator2 instanceof RecordComparator)) {
+ throw new IllegalArgumentException("Cannot instantiate pair comparator from the given comparators.");
+ }
+ final RecordComparator prc1 = (RecordComparator) comparator1;
+ final RecordComparator prc2 = (RecordComparator) comparator2;
+
+ final int[] pos1 = prc1.getKeyPositions();
+ final int[] pos2 = prc2.getKeyPositions();
+
+ final Class<? extends Key<?>>[] types1 = prc1.getKeyTypes();
+ final Class<? extends Key<?>>[] types2 = prc2.getKeyTypes();
+
+ checkComparators(pos1, pos2, types1, types2);
+
+ return new RecordPairComparator(pos2, pos1, types1);
+ }
+
+ // --------------------------------------------------------------------------------------------
+
+ private static final void checkComparators(int[] pos1, int[] pos2,
+ Class<? extends Key<?>>[] types1, Class<? extends Key<?>>[] types2)
+ {
+ if (pos1.length != pos2.length || types1.length != types2.length) {
+ throw new IllegalArgumentException(
+ "The given pair of RecordComparators does not operate on the same number of fields.");
+ }
+ for (int i = 0; i < types1.length; i++) {
+ if (!types1[i].equals(types2[i])) {
+ throw new IllegalArgumentException(
+ "The given pair of RecordComparators does not operates on different data types.");
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordSerializer.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordSerializer.java b/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordSerializer.java
new file mode 100644
index 0000000..146ccd0
--- /dev/null
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordSerializer.java
@@ -0,0 +1,144 @@
+/*
+ * 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.flink.runtime.testutils.recordutils;
+
+import java.io.IOException;
+
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.core.memory.DataInputView;
+import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.types.Record;
+
+
+/**
+ * Implementation of the (de)serialization and copying logic for the {@link Record}.
+ */
+public final class RecordSerializer extends TypeSerializer<Record> {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final RecordSerializer INSTANCE = new RecordSerializer(); // singleton instance
+
+ private static final int MAX_BIT = 0x80; // byte where only the most significant bit is set
+
+ // --------------------------------------------------------------------------------------------
+
+ public static RecordSerializer get() {
+ return INSTANCE;
+ }
+
+ /**
+ * Creates a new instance of the RecordSerializers. Private to prevent instantiation.
+ */
+ private RecordSerializer() {}
+
+ // --------------------------------------------------------------------------------------------
+
+ @Override
+ public boolean isImmutableType() {
+ return false;
+ }
+
+ @Override
+ public RecordSerializer duplicate() {
+ // does not hold state, so just return ourselves
+ return this;
+ }
+
+ @Override
+ public Record createInstance() {
+ return new Record();
+ }
+
+ @Override
+ public Record copy(Record from) {
+ return from.createCopy();
+ }
+
+ @Override
+ public Record copy(Record from, Record reuse) {
+ from.copyTo(reuse);
+ return reuse;
+ }
+
+ @Override
+ public int getLength() {
+ return -1;
+ }
+
+ // --------------------------------------------------------------------------------------------
+
+ @Override
+ public void serialize(Record record, DataOutputView target) throws IOException {
+ record.serialize(target);
+ }
+
+ @Override
+ public Record deserialize(DataInputView source) throws IOException {
+ return deserialize(new Record(), source);
+ }
+
+ @Override
+ public Record deserialize(Record target, DataInputView source) throws IOException {
+ target.deserialize(source);
+ return target;
+ }
+
+ @Override
+ public void copy(DataInputView source, DataOutputView target) throws IOException {
+ int val = source.readUnsignedByte();
+ target.writeByte(val);
+
+ if (val >= MAX_BIT) {
+ int shift = 7;
+ int curr;
+ val = val & 0x7f;
+ while ((curr = source.readUnsignedByte()) >= MAX_BIT) {
+ target.writeByte(curr);
+ val |= (curr & 0x7f) << shift;
+ shift += 7;
+ }
+ target.writeByte(curr);
+ val |= curr << shift;
+ }
+
+ target.write(source, val);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof RecordSerializer) {
+ RecordSerializer other = (RecordSerializer) obj;
+ return other.canEqual(this);
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean canEqual(Object obj) {
+ return obj instanceof RecordSerializer;
+ }
+
+ @Override
+ public int hashCode() {
+ return RecordSerializer.class.hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordSerializerFactory.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordSerializerFactory.java b/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordSerializerFactory.java
new file mode 100644
index 0000000..ea14591
--- /dev/null
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordSerializerFactory.java
@@ -0,0 +1,75 @@
+/*
+ * 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.flink.runtime.testutils.recordutils;
+
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.api.common.typeutils.TypeSerializerFactory;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.types.Record;
+
+/**
+ * A factory that create a serializer for the {@link Record} data type.
+ */
+public class RecordSerializerFactory implements TypeSerializerFactory<Record> {
+
+ private static final RecordSerializerFactory INSTANCE = new RecordSerializerFactory();
+
+ /**
+ * Gets an instance of the serializer factory. The instance is shared, since the factory is a
+ * stateless class.
+ *
+ * @return An instance of the serializer factory.
+ */
+ public static final RecordSerializerFactory get() {
+ return INSTANCE;
+ }
+
+ // --------------------------------------------------------------------------------------------
+
+
+ @Override
+ public void writeParametersToConfig(Configuration config) {}
+
+ @Override
+ public void readParametersFromConfig(Configuration config, ClassLoader cl) {}
+
+
+ @Override
+ public TypeSerializer<Record> getSerializer() {
+ return RecordSerializer.get();
+ }
+
+ @Override
+ public Class<Record> getDataType() {
+ return Record.class;
+ }
+
+ // --------------------------------------------------------------------------------------------
+
+ @Override
+ public int hashCode() {
+ return 31;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return obj != null && obj.getClass() == RecordSerializerFactory.class;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/util/NonReusingKeyGroupedIteratorTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/util/NonReusingKeyGroupedIteratorTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/util/NonReusingKeyGroupedIteratorTest.java
index b71fdb0..3cdf775 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/util/NonReusingKeyGroupedIteratorTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/util/NonReusingKeyGroupedIteratorTest.java
@@ -23,7 +23,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.NoSuchElementException;
-import org.apache.flink.api.common.typeutils.record.RecordComparator;
+import org.apache.flink.runtime.testutils.recordutils.RecordComparator;
import org.apache.flink.types.IntValue;
import org.apache.flink.types.Record;
import org.apache.flink.types.StringValue;
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/util/ReusingKeyGroupedIteratorTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/util/ReusingKeyGroupedIteratorTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/util/ReusingKeyGroupedIteratorTest.java
index 8a9f8ba..fae3767 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/util/ReusingKeyGroupedIteratorTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/util/ReusingKeyGroupedIteratorTest.java
@@ -23,8 +23,8 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.NoSuchElementException;
-import org.apache.flink.api.common.typeutils.record.RecordComparator;
-import org.apache.flink.api.common.typeutils.record.RecordSerializer;
+import org.apache.flink.runtime.testutils.recordutils.RecordComparator;
+import org.apache.flink.runtime.testutils.recordutils.RecordSerializer;
import org.apache.flink.types.IntValue;
import org.apache.flink.types.Record;
import org.apache.flink.types.StringValue;
[7/7] flink git commit: [FLINK-3169] Move Record Type Utils from
flink-java to flink-runtime/test
Posted by se...@apache.org.
[FLINK-3169] Move Record Type Utils from flink-java to flink-runtime/test
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/066913e2
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/066913e2
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/066913e2
Branch: refs/heads/master
Commit: 066913e2360db3c184e12f0104c87b91824b449b
Parents: 4a26cce
Author: Stephan Ewen <se...@apache.org>
Authored: Sun Dec 13 19:50:37 2015 +0100
Committer: Stephan Ewen <se...@apache.org>
Committed: Mon Dec 14 17:48:42 2015 +0100
----------------------------------------------------------------------
.../typeutils/record/RecordComparator.java | 423 -------------------
.../record/RecordComparatorFactory.java | 152 -------
.../typeutils/record/RecordPairComparator.java | 106 -----
.../record/RecordPairComparatorFactory.java | 105 -----
.../typeutils/record/RecordSerializer.java | 144 -------
.../record/RecordSerializerFactory.java | 75 ----
.../api/java/typeutils/RecordTypeInfo.java | 95 -----
.../api/java/typeutils/RecordTypeInfoTest.java | 44 --
.../runtime/operators/CachedMatchTaskTest.java | 4 +-
.../operators/CoGroupTaskExternalITCase.java | 4 +-
.../runtime/operators/CoGroupTaskTest.java | 4 +-
.../operators/CombineTaskExternalITCase.java | 2 +-
.../runtime/operators/DataSinkTaskTest.java | 2 +-
.../operators/JoinTaskExternalITCase.java | 4 +-
.../flink/runtime/operators/JoinTaskTest.java | 4 +-
.../operators/LeftOuterJoinTaskTest.java | 6 -
.../operators/ReduceTaskExternalITCase.java | 4 +-
.../flink/runtime/operators/ReduceTaskTest.java | 4 +-
.../operators/chaining/ChainTaskTest.java | 4 +-
.../runtime/operators/hash/HashTableITCase.java | 4 +-
...lockResettableMutableObjectIteratorTest.java | 2 +-
.../NonReusingBlockResettableIteratorTest.java | 2 +-
.../ReusingBlockResettableIteratorTest.java | 2 +-
...lingResettableMutableObjectIteratorTest.java | 2 +-
.../operators/testutils/DriverTestBase.java | 4 +-
.../operators/testutils/TaskTestBase.java | 2 +-
.../operators/util/OutputEmitterTest.java | 4 +-
.../testutils/recordutils/RecordComparator.java | 423 +++++++++++++++++++
.../recordutils/RecordComparatorFactory.java | 152 +++++++
.../recordutils/RecordPairComparator.java | 106 +++++
.../RecordPairComparatorFactory.java | 105 +++++
.../testutils/recordutils/RecordSerializer.java | 144 +++++++
.../recordutils/RecordSerializerFactory.java | 75 ++++
.../util/NonReusingKeyGroupedIteratorTest.java | 2 +-
.../util/ReusingKeyGroupedIteratorTest.java | 4 +-
35 files changed, 1037 insertions(+), 1182 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordComparator.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordComparator.java b/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordComparator.java
deleted file mode 100644
index 605d6a1..0000000
--- a/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordComparator.java
+++ /dev/null
@@ -1,423 +0,0 @@
-/*
- * 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.flink.api.common.typeutils.record;
-
-import java.io.IOException;
-
-import org.apache.flink.api.common.typeutils.TypeComparator;
-import org.apache.flink.core.memory.DataInputView;
-import org.apache.flink.core.memory.DataOutputView;
-import org.apache.flink.core.memory.MemorySegment;
-import org.apache.flink.types.Key;
-import org.apache.flink.types.KeyFieldOutOfBoundsException;
-import org.apache.flink.types.NormalizableKey;
-import org.apache.flink.types.NullKeyFieldException;
-import org.apache.flink.types.Record;
-import org.apache.flink.util.InstantiationUtil;
-
-
-/**
- * Implementation of the {@link TypeComparator} interface for the pact record. Instances of this class
- * are parameterized with which fields are relevant to the comparison.
- */
-public final class RecordComparator extends TypeComparator<Record> {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * A sequence of prime numbers to be used for salting the computed hash values.
- * Based on some empirical evidence, we are using a 32-element subsequence of the
- * OEIS sequence #A068652 (numbers such that every cyclic permutation is a prime).
- *
- * @see: http://en.wikipedia.org/wiki/List_of_prime_numbers
- * @see: http://oeis.org/A068652
- */
- private static final int[] HASH_SALT = new int[] {
- 73 , 79 , 97 , 113 , 131 , 197 , 199 , 311 ,
- 337 , 373 , 719 , 733 , 919 , 971 , 991 , 1193 ,
- 1931 , 3119 , 3779 , 7793 , 7937 , 9311 , 9377 , 11939 ,
- 19391, 19937, 37199, 39119, 71993, 91193, 93719, 93911 };
-
- private final int[] keyFields;
-
- @SuppressWarnings("rawtypes")
- private final Key[] keyHolders, transientKeyHolders;
-
- private final Record temp1, temp2;
-
- private final boolean[] ascending;
-
- private final int[] normalizedKeyLengths;
-
- private final int numLeadingNormalizableKeys;
-
- private final int normalizableKeyPrefixLen;
-
-
- /**
- * Creates a new comparator that compares Pact Records by the subset of fields as described
- * by the given key positions and types. All order comparisons will assume ascending order on all fields.
- *
- * @param keyFields The positions of the key fields.
- * @param keyTypes The types (classes) of the key fields.
- */
- public RecordComparator(int[] keyFields, Class<? extends Key<?>>[] keyTypes) {
- this(keyFields, keyTypes, null);
- }
-
- /**
- * Creates a new comparator that compares Pact Records by the subset of fields as described
- * by the given key positions and types.
- *
- * @param keyFields The positions of the key fields.
- * @param keyTypes The types (classes) of the key fields.
- * @param sortDirection The direction for sorting. A value of <i>true</i> indicates ascending for an attribute,
- * a value of <i>false</i> indicated descending. If the parameter is <i>null</i>, then
- * all order comparisons will assume ascending order on all fields.
- */
- public RecordComparator(int[] keyFields, Class<? extends Key<?>>[] keyTypes, boolean[] sortDirection) {
- this.keyFields = keyFields;
-
- // instantiate fields to extract keys into
- this.keyHolders = new Key[keyTypes.length];
- this.transientKeyHolders = new Key[keyTypes.length];
- for (int i = 0; i < keyTypes.length; i++) {
- if (keyTypes[i] == null) {
- throw new NullPointerException("Key type " + i + " is null.");
- }
- this.keyHolders[i] = InstantiationUtil.instantiate(keyTypes[i], Key.class);
- this.transientKeyHolders[i] = InstantiationUtil.instantiate(keyTypes[i], Key.class);
- }
-
- // set up auxiliary fields for normalized key support
- this.normalizedKeyLengths = new int[keyFields.length];
- int nKeys = 0;
- int nKeyLen = 0;
- boolean inverted = false;
- for (int i = 0; i < this.keyHolders.length; i++) {
- Key<?> k = this.keyHolders[i];
- if (k instanceof NormalizableKey) {
- if (sortDirection != null) {
- if (sortDirection[i] && inverted) {
- break;
- } else if (i == 0 && !sortDirection[0]) {
- inverted = true;
- }
- }
- nKeys++;
- final int len = ((NormalizableKey<?>) k).getMaxNormalizedKeyLen();
- if (len < 0) {
- throw new RuntimeException("Data type " + k.getClass().getName() +
- " specifies an invalid length for the normalized key: " + len);
- }
- this.normalizedKeyLengths[i] = len;
- nKeyLen += this.normalizedKeyLengths[i];
- if (nKeyLen < 0) {
- nKeyLen = Integer.MAX_VALUE;
- break;
- }
- } else {
- break;
- }
- }
- this.numLeadingNormalizableKeys = nKeys;
- this.normalizableKeyPrefixLen = nKeyLen;
-
- this.temp1 = new Record();
- this.temp2 = new Record();
-
- if (sortDirection != null) {
- this.ascending = sortDirection;
- } else {
- this.ascending = new boolean[keyFields.length];
- for (int i = 0; i < this.ascending.length; i++) {
- this.ascending[i] = true;
- }
- }
- }
-
- /**
- * Copy constructor.
- *
- * @param toCopy Comparator to copy.
- */
- private RecordComparator(RecordComparator toCopy) {
- this.keyFields = toCopy.keyFields;
- this.keyHolders = new Key[toCopy.keyHolders.length];
- this.transientKeyHolders = new Key[toCopy.keyHolders.length];
-
- try {
- for (int i = 0; i < this.keyHolders.length; i++) {
- this.keyHolders[i] = toCopy.keyHolders[i].getClass().newInstance();
- this.transientKeyHolders[i] = toCopy.keyHolders[i].getClass().newInstance();
- }
- } catch (Exception ex) {
- // this should never happen, because the classes have been instantiated before. Report for debugging.
- throw new RuntimeException("Could not instantiate key classes when duplicating RecordComparator.", ex);
- }
-
- this.normalizedKeyLengths = toCopy.normalizedKeyLengths;
- this.numLeadingNormalizableKeys = toCopy.numLeadingNormalizableKeys;
- this.normalizableKeyPrefixLen = toCopy.normalizableKeyPrefixLen;
- this.ascending = toCopy.ascending;
-
- this.temp1 = new Record();
- this.temp2 = new Record();
- }
-
- // --------------------------------------------------------------------------------------------
-
-
- @Override
- public int hash(Record object) {
- int i = 0;
- try {
- int code = 0;
- for (; i < this.keyFields.length; i++) {
- code ^= object.getField(this.keyFields[i], this.transientKeyHolders[i]).hashCode();
- code *= HASH_SALT[i & 0x1F]; // salt code with (i % HASH_SALT.length)-th salt component
- }
- return code;
- }
- catch (NullPointerException npex) {
- throw new NullKeyFieldException(this.keyFields[i]);
- }
- catch (IndexOutOfBoundsException iobex) {
- throw new KeyFieldOutOfBoundsException(this.keyFields[i]);
- }
- }
-
-
- @Override
- public void setReference(Record toCompare) {
- for (int i = 0; i < this.keyFields.length; i++) {
- if (!toCompare.getFieldInto(this.keyFields[i], this.keyHolders[i])) {
- throw new NullKeyFieldException(this.keyFields[i]);
- }
- }
- }
-
-
- @Override
- public boolean equalToReference(Record candidate) {
- for (int i = 0; i < this.keyFields.length; i++) {
- final Key<?> k = candidate.getField(this.keyFields[i], this.transientKeyHolders[i]);
- if (k == null) {
- throw new NullKeyFieldException(this.keyFields[i]);
- } else if (!k.equals(this.keyHolders[i])) {
- return false;
- }
- }
- return true;
- }
-
-
- @Override
- public int compareToReference(TypeComparator<Record> referencedAccessors) {
- final RecordComparator pra = (RecordComparator) referencedAccessors;
-
- for (int i = 0; i < this.keyFields.length; i++) {
- @SuppressWarnings("unchecked")
- final int comp = pra.keyHolders[i].compareTo(this.keyHolders[i]);
- if (comp != 0) {
- return this.ascending[i] ? comp : -comp;
- }
- }
- return 0;
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- @Override
- public int compare(Record first, Record second) {
- int i = 0;
- try {
- for (; i < this.keyFields.length; i++) {
- Key k1 = first.getField(this.keyFields[i], this.keyHolders[i]);
- Key k2 = second.getField(this.keyFields[i], this.transientKeyHolders[i]);
- int cmp = k1.compareTo(k2);
- if (cmp != 0) {
- return cmp;
- }
- }
- return 0;
- }
- catch (NullPointerException e) {
- throw new NullKeyFieldException(this.keyFields[i]);
- }
- }
-
- @Override
- public int compareSerialized(DataInputView source1, DataInputView source2) throws IOException {
- this.temp1.read(source1);
- this.temp2.read(source2);
-
- for (int i = 0; i < this.keyFields.length; i++) {
- @SuppressWarnings("rawtypes")
- final Key k1 = this.temp1.getField(this.keyFields[i], this.keyHolders[i]);
- @SuppressWarnings("rawtypes")
- final Key k2 = this.temp2.getField(this.keyFields[i], this.transientKeyHolders[i]);
-
- if (k1 == null || k2 == null) {
- throw new NullKeyFieldException(this.keyFields[i]);
- }
-
- @SuppressWarnings("unchecked")
- final int comp = k1.compareTo(k2);
- if (comp != 0) {
- return this.ascending[i] ? comp : -comp;
- }
- }
- return 0;
- }
-
- // --------------------------------------------------------------------------------------------
-
-
- @Override
- public boolean supportsNormalizedKey() {
- return this.numLeadingNormalizableKeys > 0;
- }
-
-
- @Override
- public int getNormalizeKeyLen() {
- return this.normalizableKeyPrefixLen;
- }
-
-
- @Override
- public boolean isNormalizedKeyPrefixOnly(int keyBytes) {
- return this.numLeadingNormalizableKeys < this.keyFields.length ||
- this.normalizableKeyPrefixLen == Integer.MAX_VALUE ||
- this.normalizableKeyPrefixLen > keyBytes;
- }
-
- @Override
- public void putNormalizedKey(Record record, MemorySegment target, int offset, int numBytes) {
- int i = 0;
- try {
- for (; i < this.numLeadingNormalizableKeys & numBytes > 0; i++)
- {
- int len = this.normalizedKeyLengths[i];
- len = numBytes >= len ? len : numBytes;
- ((NormalizableKey<?>) record.getField(this.keyFields[i], this.transientKeyHolders[i])).copyNormalizedKey(target, offset, len);
- numBytes -= len;
- offset += len;
- }
- }
- catch (NullPointerException npex) {
- throw new NullKeyFieldException(this.keyFields[i]);
- }
- }
-
-
- @Override
- public boolean invertNormalizedKey() {
- return !this.ascending[0];
- }
-
- // --------------------------------------------------------------------------------------------
-
- @Override
- public boolean supportsSerializationWithKeyNormalization() {
- return false;
- }
-
- @Override
- public void writeWithKeyNormalization(Record record, DataOutputView target) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Record readWithKeyDenormalization(Record reuse, DataInputView source) {
- throw new UnsupportedOperationException();
- }
-
- // --------------------------------------------------------------------------------------------
-
- @Override
- public RecordComparator duplicate() {
- return new RecordComparator(this);
- }
-
- // --------------------------------------------------------------------------------------------
- // Non Standard Comparator Methods
- // --------------------------------------------------------------------------------------------
-
- public final int[] getKeyPositions() {
- return this.keyFields;
- }
-
- @SuppressWarnings("unchecked")
- public final Class<? extends Key<?>>[] getKeyTypes() {
- final Class<? extends Key<?>>[] keyTypes = new Class[this.keyHolders.length];
- for (int i = 0; i < keyTypes.length; i++) {
- keyTypes[i] = (Class<? extends Key<?>>) this.keyHolders[i].getClass();
- }
- return keyTypes;
- }
-
- public final Key<?>[] getKeysAsCopy(Record record) {
- try {
- final Key<?>[] keys = new Key[this.keyFields.length];
- for (int i = 0; i < keys.length; i++) {
- keys[i] = this.keyHolders[i].getClass().newInstance();
- }
- if(!record.getFieldsInto(this.keyFields, keys)) {
- throw new RuntimeException("Could not extract keys from record.");
- }
- return keys;
- } catch (Exception ex) {
- // this should never happen, because the classes have been instantiated before. Report for debugging.
- throw new RuntimeException("Could not instantiate key classes when duplicating RecordComparator.", ex);
- }
- }
-
- @Override
- public int extractKeys(Object record, Object[] target, int index) {
- throw new UnsupportedOperationException("Record does not support extactKeys and " +
- "getComparators. This cannot be used with the GenericPairComparator.");
- }
-
-
- @Override
- public TypeComparator<?>[] getFlatComparators() {
- throw new UnsupportedOperationException("Record does not support extactKeys and " +
- "getComparators. This cannot be used with the GenericPairComparator.");
- }
-
- @Override
- public boolean supportsCompareAgainstReference() {
- return true;
- }
-
- @Override
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public final int compareAgainstReference(Comparable[] keys) {
- for (int i = 0; i < this.keyFields.length; i++)
- {
- final int comp = keys[i].compareTo(this.keyHolders[i]);
- if (comp != 0) {
- return this.ascending[i] ? comp : -comp;
- }
- }
- return 0;
- }
-}
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordComparatorFactory.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordComparatorFactory.java b/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordComparatorFactory.java
deleted file mode 100644
index 7de758b..0000000
--- a/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordComparatorFactory.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * 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.flink.api.common.typeutils.record;
-
-import java.util.Arrays;
-
-import org.apache.flink.api.common.typeutils.TypeComparatorFactory;
-import org.apache.flink.configuration.Configuration;
-import org.apache.flink.configuration.IllegalConfigurationException;
-import org.apache.flink.types.Key;
-import org.apache.flink.types.Record;
-
-/**
- * A factory for a {@link org.apache.flink.api.common.typeutils.TypeComparator} for {@link Record}. The comparator uses a subset of
- * the fields for the comparison. That subset of fields (positions and types) is read from the
- * supplied configuration.
- */
-public class RecordComparatorFactory implements TypeComparatorFactory<Record> {
-
- private static final String NUM_KEYS = "numkeys";
-
- private static final String KEY_POS_PREFIX = "keypos.";
-
- private static final String KEY_CLASS_PREFIX = "keyclass.";
-
- private static final String KEY_SORT_DIRECTION_PREFIX = "key-direction.";
-
- // --------------------------------------------------------------------------------------------
-
- private int[] positions;
-
- private Class<? extends Key<?>>[] types;
-
- private boolean[] sortDirections;
-
- // --------------------------------------------------------------------------------------------
-
- public RecordComparatorFactory() {
- // do nothing, allow to be configured via config
- }
-
- public RecordComparatorFactory(int[] positions, Class<? extends Key<?>>[] types) {
- this(positions, types, null);
- }
-
- public RecordComparatorFactory(int[] positions, Class<? extends Key<?>>[] types, boolean[] sortDirections) {
- if (positions == null || types == null) {
- throw new NullPointerException();
- }
- if (positions.length != types.length) {
- throw new IllegalArgumentException();
- }
-
- this.positions = positions;
- this.types = types;
-
- if (sortDirections == null) {
- this.sortDirections = new boolean[positions.length];
- Arrays.fill(this.sortDirections, true);
- } else if (sortDirections.length != positions.length) {
- throw new IllegalArgumentException();
- } else {
- this.sortDirections = sortDirections;
- }
- }
-
-
- @Override
- public void writeParametersToConfig(Configuration config) {
- for (int i = 0; i < this.positions.length; i++) {
- if (this.positions[i] < 0) {
- throw new IllegalArgumentException("The key position " + i + " is invalid: " + this.positions[i]);
- }
- if (this.types[i] == null || !Key.class.isAssignableFrom(this.types[i])) {
- throw new IllegalArgumentException("The key type " + i + " is null or not implenting the interface " +
- Key.class.getName() + ".");
- }
- }
-
- // write the config
- config.setInteger(NUM_KEYS, this.positions.length);
- for (int i = 0; i < this.positions.length; i++) {
- config.setInteger(KEY_POS_PREFIX + i, this.positions[i]);
- config.setString(KEY_CLASS_PREFIX + i, this.types[i].getName());
- config.setBoolean(KEY_SORT_DIRECTION_PREFIX + i, this.sortDirections[i]);
- }
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public void readParametersFromConfig(Configuration config, ClassLoader cl) throws ClassNotFoundException {
- // figure out how many key fields there are
- final int numKeyFields = config.getInteger(NUM_KEYS, -1);
- if (numKeyFields < 0) {
- throw new IllegalConfigurationException("The number of keys for the comparator is invalid: " + numKeyFields);
- }
-
- final int[] positions = new int[numKeyFields];
- final Class<? extends Key<?>>[] types = new Class[numKeyFields];
- final boolean[] direction = new boolean[numKeyFields];
-
- // read the individual key positions and types
- for (int i = 0; i < numKeyFields; i++) {
- // next key position
- final int p = config.getInteger(KEY_POS_PREFIX + i, -1);
- if (p >= 0) {
- positions[i] = p;
- } else {
- throw new IllegalConfigurationException("Contained invalid position for key no positions for keys.");
- }
-
- // next key type
- final String name = config.getString(KEY_CLASS_PREFIX + i, null);
- if (name != null) {
- types[i] = (Class<? extends Key<?>>) Class.forName(name, true, cl).asSubclass(Key.class);
- } else {
- throw new IllegalConfigurationException("The key type (" + i +
- ") for the comparator is null");
- }
-
- // next key sort direction
- direction[i] = config.getBoolean(KEY_SORT_DIRECTION_PREFIX + i, true);
- }
-
- this.positions = positions;
- this.types = types;
- this.sortDirections = direction;
- }
-
-
- @Override
- public RecordComparator createComparator() {
- return new RecordComparator(this.positions, this.types, this.sortDirections);
- }
-}
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordPairComparator.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordPairComparator.java b/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordPairComparator.java
deleted file mode 100644
index 7b95e55..0000000
--- a/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordPairComparator.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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.flink.api.common.typeutils.record;
-
-import org.apache.flink.api.common.typeutils.TypePairComparator;
-import org.apache.flink.types.Key;
-import org.apache.flink.types.NullKeyFieldException;
-import org.apache.flink.types.Record;
-import org.apache.flink.util.InstantiationUtil;
-
-
-/**
- * Implementation of the {@link TypePairComparator} interface for Pact Records. The equality is established on a set of
- * key fields. The indices of the key fields may be different on the reference and candidate side.
- */
-public class RecordPairComparator extends TypePairComparator<Record, Record> {
-
- private final int[] keyFields1, keyFields2; // arrays with the positions of the keys in the records
-
- @SuppressWarnings("rawtypes")
- private final Key[] keyHolders1, keyHolders2; // arrays with mutable objects for the key types
-
-
- public RecordPairComparator(int[] keyFieldsReference, int[] keyFieldsCandidate, Class<? extends Key<?>>[] keyTypes) {
- if (keyFieldsReference.length != keyFieldsCandidate.length || keyFieldsCandidate.length != keyTypes.length) {
- throw new IllegalArgumentException(
- "The arrays describing the key positions and types must be of the same length.");
- }
- this.keyFields1 = keyFieldsReference;
- this.keyFields2 = keyFieldsCandidate;
-
- // instantiate fields to extract keys into
- this.keyHolders1 = new Key[keyTypes.length];
- this.keyHolders2 = new Key[keyTypes.length];
-
- for (int i = 0; i < keyTypes.length; i++) {
- if (keyTypes[i] == null) {
- throw new NullPointerException("Key type " + i + " is null.");
- }
- this.keyHolders1[i] = InstantiationUtil.instantiate(keyTypes[i], Key.class);
- this.keyHolders2[i] = InstantiationUtil.instantiate(keyTypes[i], Key.class);
- }
- }
-
- // --------------------------------------------------------------------------------------------
-
-
- @Override
- public void setReference(Record reference) {
- for (int i = 0; i < this.keyFields1.length; i++) {
- if (!reference.getFieldInto(this.keyFields1[i], this.keyHolders1[i])) {
- throw new NullKeyFieldException(this.keyFields1[i]);
- }
- }
- }
-
-
- @SuppressWarnings("rawtypes")
- @Override
- public boolean equalToReference(Record candidate) {
- for (int i = 0; i < this.keyFields2.length; i++) {
- final Key k = candidate.getField(this.keyFields2[i], this.keyHolders2[i]);
- if (k == null) {
- throw new NullKeyFieldException(this.keyFields2[i]);
- } else if (!k.equals(this.keyHolders1[i])) {
- return false;
- }
- }
- return true;
- }
-
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- @Override
- public int compareToReference(Record candidate) {
- for (int i = 0; i < this.keyFields2.length; i++) {
- final Key k = candidate.getField(this.keyFields2[i], this.keyHolders2[i]);
- if (k == null) {
- throw new NullKeyFieldException(this.keyFields2[i]);
- } else {
- final int comp = k.compareTo(this.keyHolders1[i]);
- if (comp != 0) {
- return comp;
- }
- }
- }
- return 0;
- }
-}
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordPairComparatorFactory.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordPairComparatorFactory.java b/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordPairComparatorFactory.java
deleted file mode 100644
index 752540e..0000000
--- a/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordPairComparatorFactory.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * 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.flink.api.common.typeutils.record;
-
-import org.apache.flink.api.common.typeutils.TypeComparator;
-import org.apache.flink.api.common.typeutils.TypePairComparator;
-import org.apache.flink.api.common.typeutils.TypePairComparatorFactory;
-import org.apache.flink.types.Key;
-import org.apache.flink.types.Record;
-
-/**
- * A factory for a {@link TypePairComparator} for {@link Record}. The comparator uses a subset of
- * the fields for the comparison. That subset of fields (positions and types) is read from the
- * supplied configuration.
- */
-public class RecordPairComparatorFactory implements TypePairComparatorFactory<Record, Record> {
-
- private static final RecordPairComparatorFactory INSTANCE = new RecordPairComparatorFactory();
-
- /**
- * Gets an instance of the comparator factory. The instance is shared, since the factory is a
- * stateless class.
- *
- * @return An instance of the comparator factory.
- */
- public static final RecordPairComparatorFactory get() {
- return INSTANCE;
- }
-
- @Override
- public TypePairComparator<Record, Record> createComparator12(
- TypeComparator<Record> comparator1, TypeComparator<Record> comparator2)
- {
- if (!(comparator1 instanceof RecordComparator && comparator2 instanceof RecordComparator)) {
- throw new IllegalArgumentException("Cannot instantiate pair comparator from the given comparators.");
- }
- final RecordComparator prc1 = (RecordComparator) comparator1;
- final RecordComparator prc2 = (RecordComparator) comparator2;
-
- final int[] pos1 = prc1.getKeyPositions();
- final int[] pos2 = prc2.getKeyPositions();
-
- final Class<? extends Key<?>>[] types1 = prc1.getKeyTypes();
- final Class<? extends Key<?>>[] types2 = prc2.getKeyTypes();
-
- checkComparators(pos1, pos2, types1, types2);
-
- return new RecordPairComparator(pos1, pos2, types1);
- }
-
- @Override
- public TypePairComparator<Record, Record> createComparator21(
- TypeComparator<Record> comparator1, TypeComparator<Record> comparator2)
- {
- if (!(comparator1 instanceof RecordComparator && comparator2 instanceof RecordComparator)) {
- throw new IllegalArgumentException("Cannot instantiate pair comparator from the given comparators.");
- }
- final RecordComparator prc1 = (RecordComparator) comparator1;
- final RecordComparator prc2 = (RecordComparator) comparator2;
-
- final int[] pos1 = prc1.getKeyPositions();
- final int[] pos2 = prc2.getKeyPositions();
-
- final Class<? extends Key<?>>[] types1 = prc1.getKeyTypes();
- final Class<? extends Key<?>>[] types2 = prc2.getKeyTypes();
-
- checkComparators(pos1, pos2, types1, types2);
-
- return new RecordPairComparator(pos2, pos1, types1);
- }
-
- // --------------------------------------------------------------------------------------------
-
- private static final void checkComparators(int[] pos1, int[] pos2,
- Class<? extends Key<?>>[] types1, Class<? extends Key<?>>[] types2)
- {
- if (pos1.length != pos2.length || types1.length != types2.length) {
- throw new IllegalArgumentException(
- "The given pair of RecordComparators does not operate on the same number of fields.");
- }
- for (int i = 0; i < types1.length; i++) {
- if (!types1[i].equals(types2[i])) {
- throw new IllegalArgumentException(
- "The given pair of RecordComparators does not operates on different data types.");
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordSerializer.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordSerializer.java b/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordSerializer.java
deleted file mode 100644
index 6ffa0df..0000000
--- a/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordSerializer.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * 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.flink.api.common.typeutils.record;
-
-import java.io.IOException;
-
-import org.apache.flink.api.common.typeutils.TypeSerializer;
-import org.apache.flink.core.memory.DataInputView;
-import org.apache.flink.core.memory.DataOutputView;
-import org.apache.flink.types.Record;
-
-
-/**
- * Implementation of the (de)serialization and copying logic for the {@link Record}.
- */
-public final class RecordSerializer extends TypeSerializer<Record> {
-
- private static final long serialVersionUID = 1L;
-
- private static final RecordSerializer INSTANCE = new RecordSerializer(); // singleton instance
-
- private static final int MAX_BIT = 0x80; // byte where only the most significant bit is set
-
- // --------------------------------------------------------------------------------------------
-
- public static RecordSerializer get() {
- return INSTANCE;
- }
-
- /**
- * Creates a new instance of the RecordSerializers. Private to prevent instantiation.
- */
- private RecordSerializer() {}
-
- // --------------------------------------------------------------------------------------------
-
- @Override
- public boolean isImmutableType() {
- return false;
- }
-
- @Override
- public RecordSerializer duplicate() {
- // does not hold state, so just return ourselves
- return this;
- }
-
- @Override
- public Record createInstance() {
- return new Record();
- }
-
- @Override
- public Record copy(Record from) {
- return from.createCopy();
- }
-
- @Override
- public Record copy(Record from, Record reuse) {
- from.copyTo(reuse);
- return reuse;
- }
-
- @Override
- public int getLength() {
- return -1;
- }
-
- // --------------------------------------------------------------------------------------------
-
- @Override
- public void serialize(Record record, DataOutputView target) throws IOException {
- record.serialize(target);
- }
-
- @Override
- public Record deserialize(DataInputView source) throws IOException {
- return deserialize(new Record(), source);
- }
-
- @Override
- public Record deserialize(Record target, DataInputView source) throws IOException {
- target.deserialize(source);
- return target;
- }
-
- @Override
- public void copy(DataInputView source, DataOutputView target) throws IOException {
- int val = source.readUnsignedByte();
- target.writeByte(val);
-
- if (val >= MAX_BIT) {
- int shift = 7;
- int curr;
- val = val & 0x7f;
- while ((curr = source.readUnsignedByte()) >= MAX_BIT) {
- target.writeByte(curr);
- val |= (curr & 0x7f) << shift;
- shift += 7;
- }
- target.writeByte(curr);
- val |= curr << shift;
- }
-
- target.write(source, val);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof RecordSerializer) {
- RecordSerializer other = (RecordSerializer) obj;
- return other.canEqual(this);
- } else {
- return false;
- }
- }
-
- @Override
- public boolean canEqual(Object obj) {
- return obj instanceof RecordSerializer;
- }
-
- @Override
- public int hashCode() {
- return RecordSerializer.class.hashCode();
- }
-}
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordSerializerFactory.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordSerializerFactory.java b/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordSerializerFactory.java
deleted file mode 100644
index 306b063..0000000
--- a/flink-core/src/main/java/org/apache/flink/api/common/typeutils/record/RecordSerializerFactory.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.flink.api.common.typeutils.record;
-
-import org.apache.flink.api.common.typeutils.TypeSerializer;
-import org.apache.flink.api.common.typeutils.TypeSerializerFactory;
-import org.apache.flink.configuration.Configuration;
-import org.apache.flink.types.Record;
-
-/**
- * A factory that create a serializer for the {@link Record} data type.
- */
-public class RecordSerializerFactory implements TypeSerializerFactory<Record> {
-
- private static final RecordSerializerFactory INSTANCE = new RecordSerializerFactory();
-
- /**
- * Gets an instance of the serializer factory. The instance is shared, since the factory is a
- * stateless class.
- *
- * @return An instance of the serializer factory.
- */
- public static final RecordSerializerFactory get() {
- return INSTANCE;
- }
-
- // --------------------------------------------------------------------------------------------
-
-
- @Override
- public void writeParametersToConfig(Configuration config) {}
-
- @Override
- public void readParametersFromConfig(Configuration config, ClassLoader cl) {}
-
-
- @Override
- public TypeSerializer<Record> getSerializer() {
- return RecordSerializer.get();
- }
-
- @Override
- public Class<Record> getDataType() {
- return Record.class;
- }
-
- // --------------------------------------------------------------------------------------------
-
- @Override
- public int hashCode() {
- return 31;
- }
-
- @Override
- public boolean equals(Object obj) {
- return obj != null && obj.getClass() == RecordSerializerFactory.class;
- }
-}
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-java/src/main/java/org/apache/flink/api/java/typeutils/RecordTypeInfo.java
----------------------------------------------------------------------
diff --git a/flink-java/src/main/java/org/apache/flink/api/java/typeutils/RecordTypeInfo.java b/flink-java/src/main/java/org/apache/flink/api/java/typeutils/RecordTypeInfo.java
deleted file mode 100644
index e9ce102..0000000
--- a/flink-java/src/main/java/org/apache/flink/api/java/typeutils/RecordTypeInfo.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * 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.flink.api.java.typeutils;
-
-import org.apache.flink.api.common.ExecutionConfig;
-import org.apache.flink.api.common.typeinfo.TypeInformation;
-import org.apache.flink.api.common.typeutils.TypeSerializer;
-import org.apache.flink.api.common.typeutils.record.RecordSerializer;
-import org.apache.flink.types.Record;
-
-/**
- * Type information for the {@link Record} data type.
- */
-public class RecordTypeInfo extends TypeInformation<Record> {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public boolean isBasicType() {
- return false;
- }
-
- @Override
- public boolean isTupleType() {
- return false;
- }
-
- @Override
- public int getArity() {
- return 1;
- }
-
- @Override
- public int getTotalFields() {
- return 1;
- }
-
- @Override
- public Class<Record> getTypeClass() {
- return Record.class;
- }
-
- @Override
- public boolean isKeyType() {
- return false;
- }
-
- @Override
- public TypeSerializer<Record> createSerializer(ExecutionConfig config) {
- return RecordSerializer.get();
- }
-
- // --------------------------------------------------------------------------------------------
-
- @Override
- public int hashCode() {
- return Record.class.hashCode();
- }
-
- @Override
- public boolean canEqual(Object obj) {
- return obj instanceof RecordTypeInfo;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof RecordTypeInfo) {
- RecordTypeInfo recordTypeInfo = (RecordTypeInfo) obj;
- return recordTypeInfo.canEqual(this);
- } else {
- return false;
- }
- }
-
- @Override
- public String toString() {
- return "RecordType";
- }
-}
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-java/src/test/java/org/apache/flink/api/java/typeutils/RecordTypeInfoTest.java
----------------------------------------------------------------------
diff --git a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/RecordTypeInfoTest.java b/flink-java/src/test/java/org/apache/flink/api/java/typeutils/RecordTypeInfoTest.java
deleted file mode 100644
index 7aeb062..0000000
--- a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/RecordTypeInfoTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.flink.api.java.typeutils;
-
-import org.apache.flink.util.TestLogger;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-public class RecordTypeInfoTest extends TestLogger {
-
- @Test
- public void testRecordTypeInfoEquality() {
- RecordTypeInfo tpeInfo1 = new RecordTypeInfo();
- RecordTypeInfo tpeInfo2 = new RecordTypeInfo();
-
- assertEquals(tpeInfo1, tpeInfo2);
- assertEquals(tpeInfo1.hashCode(), tpeInfo2.hashCode());
- }
-
- @Test
- public void testRecordTypeInfoInequality() {
- RecordTypeInfo tpeInfo1 = new RecordTypeInfo();
- MissingTypeInfo tpeInfo2 = new MissingTypeInfo("foobar");
-
- assertNotEquals(tpeInfo1, tpeInfo2);
- }
-}
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CachedMatchTaskTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CachedMatchTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CachedMatchTaskTest.java
index c93c302..9ccb899 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CachedMatchTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CachedMatchTaskTest.java
@@ -25,8 +25,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.functions.FlatJoinFunction;
import org.apache.flink.api.common.functions.RichFlatJoinFunction;
-import org.apache.flink.api.common.typeutils.record.RecordComparator;
-import org.apache.flink.api.common.typeutils.record.RecordPairComparatorFactory;
+import org.apache.flink.runtime.testutils.recordutils.RecordComparator;
+import org.apache.flink.runtime.testutils.recordutils.RecordPairComparatorFactory;
import org.apache.flink.runtime.operators.testutils.DelayingInfinitiveInputIterator;
import org.apache.flink.runtime.operators.testutils.DriverTestBase;
import org.apache.flink.runtime.operators.testutils.ExpectedTestException;
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CoGroupTaskExternalITCase.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CoGroupTaskExternalITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CoGroupTaskExternalITCase.java
index 7f96954..a4e4fd5 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CoGroupTaskExternalITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CoGroupTaskExternalITCase.java
@@ -22,8 +22,8 @@ import org.apache.flink.api.common.ExecutionConfig;
import org.junit.Assert;
import org.apache.flink.api.common.functions.CoGroupFunction;
import org.apache.flink.api.common.functions.RichCoGroupFunction;
-import org.apache.flink.api.common.typeutils.record.RecordComparator;
-import org.apache.flink.api.common.typeutils.record.RecordPairComparatorFactory;
+import org.apache.flink.runtime.testutils.recordutils.RecordComparator;
+import org.apache.flink.runtime.testutils.recordutils.RecordPairComparatorFactory;
import org.apache.flink.runtime.operators.testutils.DriverTestBase;
import org.apache.flink.runtime.operators.testutils.UniformRecordGenerator;
import org.apache.flink.types.IntValue;
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CoGroupTaskTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CoGroupTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CoGroupTaskTest.java
index 9c0f075..bf7d467 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CoGroupTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CoGroupTaskTest.java
@@ -24,8 +24,8 @@ import org.apache.flink.api.common.ExecutionConfig;
import org.junit.Assert;
import org.apache.flink.api.common.functions.CoGroupFunction;
import org.apache.flink.api.common.functions.RichCoGroupFunction;
-import org.apache.flink.api.common.typeutils.record.RecordComparator;
-import org.apache.flink.api.common.typeutils.record.RecordPairComparatorFactory;
+import org.apache.flink.runtime.testutils.recordutils.RecordComparator;
+import org.apache.flink.runtime.testutils.recordutils.RecordPairComparatorFactory;
import org.apache.flink.runtime.operators.CoGroupTaskExternalITCase.MockCoGroupStub;
import org.apache.flink.runtime.operators.testutils.DelayingInfinitiveInputIterator;
import org.apache.flink.runtime.operators.testutils.DriverTestBase;
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CombineTaskExternalITCase.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CombineTaskExternalITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CombineTaskExternalITCase.java
index 800bca7..e162d7d 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CombineTaskExternalITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CombineTaskExternalITCase.java
@@ -27,7 +27,7 @@ import org.apache.flink.util.Collector;
import org.junit.Assert;
import org.apache.flink.api.common.functions.RichGroupReduceFunction;
import org.apache.flink.api.common.functions.RichGroupReduceFunction.Combinable;
-import org.apache.flink.api.common.typeutils.record.RecordComparator;
+import org.apache.flink.runtime.testutils.recordutils.RecordComparator;
import org.apache.flink.runtime.operators.testutils.DriverTestBase;
import org.apache.flink.runtime.operators.testutils.UniformRecordGenerator;
import org.apache.flink.types.IntValue;
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/operators/DataSinkTaskTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/DataSinkTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/DataSinkTaskTest.java
index 6221706..eb2c8a9 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/DataSinkTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/DataSinkTaskTest.java
@@ -19,7 +19,7 @@
package org.apache.flink.runtime.operators;
import org.apache.flink.api.common.io.FileOutputFormat;
-import org.apache.flink.api.common.typeutils.record.RecordComparatorFactory;
+import org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.runtime.io.network.partition.consumer.IteratorWrappingTestSingleInputGate;
import org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter;
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/operators/JoinTaskExternalITCase.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/JoinTaskExternalITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/JoinTaskExternalITCase.java
index 5b2e6eb..5dc3772 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/JoinTaskExternalITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/JoinTaskExternalITCase.java
@@ -22,8 +22,8 @@ package org.apache.flink.runtime.operators;
import org.apache.flink.api.common.ExecutionConfig;
import org.junit.Assert;
import org.apache.flink.api.common.functions.FlatJoinFunction;
-import org.apache.flink.api.common.typeutils.record.RecordComparator;
-import org.apache.flink.api.common.typeutils.record.RecordPairComparatorFactory;
+import org.apache.flink.runtime.testutils.recordutils.RecordComparator;
+import org.apache.flink.runtime.testutils.recordutils.RecordPairComparatorFactory;
import org.apache.flink.runtime.operators.testutils.DriverTestBase;
import org.apache.flink.runtime.operators.testutils.UniformRecordGenerator;
import org.apache.flink.types.IntValue;
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/operators/JoinTaskTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/JoinTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/JoinTaskTest.java
index ecde59e..4ce4fd1 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/JoinTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/JoinTaskTest.java
@@ -25,8 +25,8 @@ import java.util.concurrent.atomic.AtomicReference;
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.functions.FlatJoinFunction;
-import org.apache.flink.api.common.typeutils.record.RecordComparator;
-import org.apache.flink.api.common.typeutils.record.RecordPairComparatorFactory;
+import org.apache.flink.runtime.testutils.recordutils.RecordComparator;
+import org.apache.flink.runtime.testutils.recordutils.RecordPairComparatorFactory;
import org.apache.flink.runtime.operators.testutils.DelayingInfinitiveInputIterator;
import org.apache.flink.runtime.operators.testutils.DriverTestBase;
import org.apache.flink.runtime.operators.testutils.ExpectedTestException;
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/operators/LeftOuterJoinTaskTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/LeftOuterJoinTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/LeftOuterJoinTaskTest.java
index ad11768..266723a 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/LeftOuterJoinTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/LeftOuterJoinTaskTest.java
@@ -21,22 +21,16 @@ package org.apache.flink.runtime.operators;
import com.google.common.base.Throwables;
import org.apache.flink.api.common.ExecutionConfig;
-import org.apache.flink.api.common.typeutils.record.RecordPairComparatorFactory;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.api.java.typeutils.runtime.RuntimePairComparatorFactory;
-import org.apache.flink.runtime.operators.testutils.DelayingInfinitiveInputIterator;
import org.apache.flink.runtime.operators.testutils.DelayingIterator;
import org.apache.flink.runtime.operators.testutils.DiscardingOutputCollector;
import org.apache.flink.runtime.operators.testutils.ExpectedTestException;
import org.apache.flink.runtime.operators.testutils.InfiniteIntTupleIterator;
-import org.apache.flink.runtime.operators.testutils.NirvanaOutputList;
import org.apache.flink.runtime.operators.testutils.UniformIntTupleGenerator;
-import org.apache.flink.runtime.operators.testutils.UniformRecordGenerator;
-import org.apache.flink.types.Record;
import org.junit.Assert;
import org.junit.Test;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.assertFalse;
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/operators/ReduceTaskExternalITCase.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/ReduceTaskExternalITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/ReduceTaskExternalITCase.java
index 415b6bc..a00aea3 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/ReduceTaskExternalITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/ReduceTaskExternalITCase.java
@@ -27,8 +27,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.flink.api.common.functions.RichGroupReduceFunction;
import org.apache.flink.api.common.functions.RichGroupReduceFunction.Combinable;
-import org.apache.flink.api.common.typeutils.record.RecordComparator;
-import org.apache.flink.api.common.typeutils.record.RecordSerializerFactory;
+import org.apache.flink.runtime.testutils.recordutils.RecordComparator;
+import org.apache.flink.runtime.testutils.recordutils.RecordSerializerFactory;
import org.apache.flink.runtime.operators.sort.CombiningUnilateralSortMerger;
import org.apache.flink.runtime.operators.testutils.DriverTestBase;
import org.apache.flink.runtime.operators.testutils.UniformRecordGenerator;
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/operators/ReduceTaskTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/ReduceTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/ReduceTaskTest.java
index 8bc7fe5..531d8ba 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/ReduceTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/ReduceTaskTest.java
@@ -28,8 +28,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.flink.api.common.functions.RichGroupReduceFunction;
import org.apache.flink.api.common.functions.RichGroupReduceFunction.Combinable;
-import org.apache.flink.api.common.typeutils.record.RecordComparator;
-import org.apache.flink.api.common.typeutils.record.RecordSerializerFactory;
+import org.apache.flink.runtime.testutils.recordutils.RecordComparator;
+import org.apache.flink.runtime.testutils.recordutils.RecordSerializerFactory;
import org.apache.flink.runtime.operators.sort.CombiningUnilateralSortMerger;
import org.apache.flink.runtime.operators.testutils.DelayingInfinitiveInputIterator;
import org.apache.flink.runtime.operators.testutils.DriverTestBase;
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/operators/chaining/ChainTaskTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/chaining/ChainTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/chaining/ChainTaskTest.java
index 542812c..4d8e0de 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/chaining/ChainTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/chaining/ChainTaskTest.java
@@ -23,8 +23,8 @@ import java.util.List;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.common.operators.util.UserCodeClassWrapper;
-import org.apache.flink.api.common.typeutils.record.RecordComparatorFactory;
-import org.apache.flink.api.common.typeutils.record.RecordSerializerFactory;
+import org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory;
+import org.apache.flink.runtime.testutils.recordutils.RecordSerializerFactory;
import org.apache.flink.api.common.functions.RichGroupReduceFunction;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter;
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/HashTableITCase.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/HashTableITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/HashTableITCase.java
index d0a6fc6..4afa114 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/HashTableITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/HashTableITCase.java
@@ -30,8 +30,8 @@ import java.util.Map;
import org.apache.flink.api.common.typeutils.TypeComparator;
import org.apache.flink.api.common.typeutils.TypePairComparator;
import org.apache.flink.api.common.typeutils.TypeSerializer;
-import org.apache.flink.api.common.typeutils.record.RecordComparator;
-import org.apache.flink.api.common.typeutils.record.RecordSerializer;
+import org.apache.flink.runtime.testutils.recordutils.RecordComparator;
+import org.apache.flink.runtime.testutils.recordutils.RecordSerializer;
import org.apache.flink.core.memory.MemorySegment;
import org.apache.flink.runtime.io.disk.iomanager.IOManager;
import org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync;
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/BlockResettableMutableObjectIteratorTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/BlockResettableMutableObjectIteratorTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/BlockResettableMutableObjectIteratorTest.java
index bfb7cf2..00011ae 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/BlockResettableMutableObjectIteratorTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/BlockResettableMutableObjectIteratorTest.java
@@ -23,7 +23,7 @@ import java.util.List;
import org.junit.Assert;
import org.apache.flink.api.common.typeutils.TypeSerializer;
-import org.apache.flink.api.common.typeutils.record.RecordSerializer;
+import org.apache.flink.runtime.testutils.recordutils.RecordSerializer;
import org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable;
import org.apache.flink.runtime.memory.MemoryManager;
import org.apache.flink.runtime.operators.testutils.DummyInvokable;
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/NonReusingBlockResettableIteratorTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/NonReusingBlockResettableIteratorTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/NonReusingBlockResettableIteratorTest.java
index d5de75e..01dbe18 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/NonReusingBlockResettableIteratorTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/NonReusingBlockResettableIteratorTest.java
@@ -24,7 +24,7 @@ import java.util.List;
import org.junit.Assert;
import org.apache.flink.api.common.typeutils.TypeSerializer;
-import org.apache.flink.api.common.typeutils.record.RecordSerializer;
+import org.apache.flink.runtime.testutils.recordutils.RecordSerializer;
import org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable;
import org.apache.flink.runtime.memory.MemoryManager;
import org.apache.flink.runtime.operators.testutils.DummyInvokable;
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/ReusingBlockResettableIteratorTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/ReusingBlockResettableIteratorTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/ReusingBlockResettableIteratorTest.java
index 7dbd2fb..ea4b667 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/ReusingBlockResettableIteratorTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/ReusingBlockResettableIteratorTest.java
@@ -19,7 +19,7 @@
package org.apache.flink.runtime.operators.resettable;
import org.apache.flink.api.common.typeutils.TypeSerializer;
-import org.apache.flink.api.common.typeutils.record.RecordSerializer;
+import org.apache.flink.runtime.testutils.recordutils.RecordSerializer;
import org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable;
import org.apache.flink.runtime.memory.MemoryManager;
import org.apache.flink.runtime.operators.testutils.DummyInvokable;
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/SpillingResettableMutableObjectIteratorTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/SpillingResettableMutableObjectIteratorTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/SpillingResettableMutableObjectIteratorTest.java
index c64db54..ef48a1f 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/SpillingResettableMutableObjectIteratorTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/SpillingResettableMutableObjectIteratorTest.java
@@ -19,7 +19,7 @@
package org.apache.flink.runtime.operators.resettable;
import org.apache.flink.api.common.typeutils.TypeSerializer;
-import org.apache.flink.api.common.typeutils.record.RecordSerializer;
+import org.apache.flink.runtime.testutils.recordutils.RecordSerializer;
import org.apache.flink.runtime.io.disk.iomanager.IOManager;
import org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync;
import org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable;
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/operators/testutils/DriverTestBase.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/testutils/DriverTestBase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/testutils/DriverTestBase.java
index c442940..ab58cea 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/testutils/DriverTestBase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/testutils/DriverTestBase.java
@@ -32,8 +32,8 @@ import org.apache.flink.api.common.functions.Function;
import org.apache.flink.api.common.functions.util.FunctionUtils;
import org.apache.flink.api.common.typeutils.TypeComparator;
import org.apache.flink.api.common.typeutils.TypeSerializerFactory;
-import org.apache.flink.api.common.typeutils.record.RecordComparator;
-import org.apache.flink.api.common.typeutils.record.RecordSerializerFactory;
+import org.apache.flink.runtime.testutils.recordutils.RecordComparator;
+import org.apache.flink.runtime.testutils.recordutils.RecordSerializerFactory;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.runtime.io.disk.iomanager.IOManager;
import org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync;
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/operators/testutils/TaskTestBase.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/testutils/TaskTestBase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/testutils/TaskTestBase.java
index 63f54ea..458f0a8 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/testutils/TaskTestBase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/testutils/TaskTestBase.java
@@ -23,7 +23,7 @@ import org.apache.flink.api.common.io.DelimitedInputFormat;
import org.apache.flink.api.common.io.FileOutputFormat;
import org.apache.flink.api.common.operators.util.UserCodeClassWrapper;
import org.apache.flink.api.common.operators.util.UserCodeObjectWrapper;
-import org.apache.flink.api.common.typeutils.record.RecordSerializerFactory;
+import org.apache.flink.runtime.testutils.recordutils.RecordSerializerFactory;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.core.fs.FileSystem.WriteMode;
import org.apache.flink.core.fs.Path;
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/operators/util/OutputEmitterTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/util/OutputEmitterTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/util/OutputEmitterTest.java
index 6bf5dcc..4623646 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/util/OutputEmitterTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/util/OutputEmitterTest.java
@@ -28,8 +28,8 @@ import org.apache.flink.api.common.typeutils.base.IntComparator;
import org.junit.Assert;
import org.apache.flink.api.common.typeutils.TypeComparator;
import org.apache.flink.api.common.typeutils.base.IntSerializer;
-import org.apache.flink.api.common.typeutils.record.RecordComparatorFactory;
-import org.apache.flink.api.common.typeutils.record.RecordSerializerFactory;
+import org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory;
+import org.apache.flink.runtime.testutils.recordutils.RecordSerializerFactory;
import org.apache.flink.core.memory.DataInputView;
import org.apache.flink.core.memory.DataOutputView;
import org.apache.flink.core.memory.InputViewDataInputStreamWrapper;
http://git-wip-us.apache.org/repos/asf/flink/blob/066913e2/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordComparator.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordComparator.java b/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordComparator.java
new file mode 100644
index 0000000..41810bf
--- /dev/null
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/recordutils/RecordComparator.java
@@ -0,0 +1,423 @@
+/*
+ * 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.flink.runtime.testutils.recordutils;
+
+import java.io.IOException;
+
+import org.apache.flink.api.common.typeutils.TypeComparator;
+import org.apache.flink.core.memory.DataInputView;
+import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.core.memory.MemorySegment;
+import org.apache.flink.types.Key;
+import org.apache.flink.types.KeyFieldOutOfBoundsException;
+import org.apache.flink.types.NormalizableKey;
+import org.apache.flink.types.NullKeyFieldException;
+import org.apache.flink.types.Record;
+import org.apache.flink.util.InstantiationUtil;
+
+
+/**
+ * Implementation of the {@link TypeComparator} interface for the pact record. Instances of this class
+ * are parameterized with which fields are relevant to the comparison.
+ */
+public final class RecordComparator extends TypeComparator<Record> {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * A sequence of prime numbers to be used for salting the computed hash values.
+ * Based on some empirical evidence, we are using a 32-element subsequence of the
+ * OEIS sequence #A068652 (numbers such that every cyclic permutation is a prime).
+ *
+ * @see: http://en.wikipedia.org/wiki/List_of_prime_numbers
+ * @see: http://oeis.org/A068652
+ */
+ private static final int[] HASH_SALT = new int[] {
+ 73 , 79 , 97 , 113 , 131 , 197 , 199 , 311 ,
+ 337 , 373 , 719 , 733 , 919 , 971 , 991 , 1193 ,
+ 1931 , 3119 , 3779 , 7793 , 7937 , 9311 , 9377 , 11939 ,
+ 19391, 19937, 37199, 39119, 71993, 91193, 93719, 93911 };
+
+ private final int[] keyFields;
+
+ @SuppressWarnings("rawtypes")
+ private final Key[] keyHolders, transientKeyHolders;
+
+ private final Record temp1, temp2;
+
+ private final boolean[] ascending;
+
+ private final int[] normalizedKeyLengths;
+
+ private final int numLeadingNormalizableKeys;
+
+ private final int normalizableKeyPrefixLen;
+
+
+ /**
+ * Creates a new comparator that compares Pact Records by the subset of fields as described
+ * by the given key positions and types. All order comparisons will assume ascending order on all fields.
+ *
+ * @param keyFields The positions of the key fields.
+ * @param keyTypes The types (classes) of the key fields.
+ */
+ public RecordComparator(int[] keyFields, Class<? extends Key<?>>[] keyTypes) {
+ this(keyFields, keyTypes, null);
+ }
+
+ /**
+ * Creates a new comparator that compares Pact Records by the subset of fields as described
+ * by the given key positions and types.
+ *
+ * @param keyFields The positions of the key fields.
+ * @param keyTypes The types (classes) of the key fields.
+ * @param sortDirection The direction for sorting. A value of <i>true</i> indicates ascending for an attribute,
+ * a value of <i>false</i> indicated descending. If the parameter is <i>null</i>, then
+ * all order comparisons will assume ascending order on all fields.
+ */
+ public RecordComparator(int[] keyFields, Class<? extends Key<?>>[] keyTypes, boolean[] sortDirection) {
+ this.keyFields = keyFields;
+
+ // instantiate fields to extract keys into
+ this.keyHolders = new Key[keyTypes.length];
+ this.transientKeyHolders = new Key[keyTypes.length];
+ for (int i = 0; i < keyTypes.length; i++) {
+ if (keyTypes[i] == null) {
+ throw new NullPointerException("Key type " + i + " is null.");
+ }
+ this.keyHolders[i] = InstantiationUtil.instantiate(keyTypes[i], Key.class);
+ this.transientKeyHolders[i] = InstantiationUtil.instantiate(keyTypes[i], Key.class);
+ }
+
+ // set up auxiliary fields for normalized key support
+ this.normalizedKeyLengths = new int[keyFields.length];
+ int nKeys = 0;
+ int nKeyLen = 0;
+ boolean inverted = false;
+ for (int i = 0; i < this.keyHolders.length; i++) {
+ Key<?> k = this.keyHolders[i];
+ if (k instanceof NormalizableKey) {
+ if (sortDirection != null) {
+ if (sortDirection[i] && inverted) {
+ break;
+ } else if (i == 0 && !sortDirection[0]) {
+ inverted = true;
+ }
+ }
+ nKeys++;
+ final int len = ((NormalizableKey<?>) k).getMaxNormalizedKeyLen();
+ if (len < 0) {
+ throw new RuntimeException("Data type " + k.getClass().getName() +
+ " specifies an invalid length for the normalized key: " + len);
+ }
+ this.normalizedKeyLengths[i] = len;
+ nKeyLen += this.normalizedKeyLengths[i];
+ if (nKeyLen < 0) {
+ nKeyLen = Integer.MAX_VALUE;
+ break;
+ }
+ } else {
+ break;
+ }
+ }
+ this.numLeadingNormalizableKeys = nKeys;
+ this.normalizableKeyPrefixLen = nKeyLen;
+
+ this.temp1 = new Record();
+ this.temp2 = new Record();
+
+ if (sortDirection != null) {
+ this.ascending = sortDirection;
+ } else {
+ this.ascending = new boolean[keyFields.length];
+ for (int i = 0; i < this.ascending.length; i++) {
+ this.ascending[i] = true;
+ }
+ }
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param toCopy Comparator to copy.
+ */
+ private RecordComparator(RecordComparator toCopy) {
+ this.keyFields = toCopy.keyFields;
+ this.keyHolders = new Key[toCopy.keyHolders.length];
+ this.transientKeyHolders = new Key[toCopy.keyHolders.length];
+
+ try {
+ for (int i = 0; i < this.keyHolders.length; i++) {
+ this.keyHolders[i] = toCopy.keyHolders[i].getClass().newInstance();
+ this.transientKeyHolders[i] = toCopy.keyHolders[i].getClass().newInstance();
+ }
+ } catch (Exception ex) {
+ // this should never happen, because the classes have been instantiated before. Report for debugging.
+ throw new RuntimeException("Could not instantiate key classes when duplicating RecordComparator.", ex);
+ }
+
+ this.normalizedKeyLengths = toCopy.normalizedKeyLengths;
+ this.numLeadingNormalizableKeys = toCopy.numLeadingNormalizableKeys;
+ this.normalizableKeyPrefixLen = toCopy.normalizableKeyPrefixLen;
+ this.ascending = toCopy.ascending;
+
+ this.temp1 = new Record();
+ this.temp2 = new Record();
+ }
+
+ // --------------------------------------------------------------------------------------------
+
+
+ @Override
+ public int hash(Record object) {
+ int i = 0;
+ try {
+ int code = 0;
+ for (; i < this.keyFields.length; i++) {
+ code ^= object.getField(this.keyFields[i], this.transientKeyHolders[i]).hashCode();
+ code *= HASH_SALT[i & 0x1F]; // salt code with (i % HASH_SALT.length)-th salt component
+ }
+ return code;
+ }
+ catch (NullPointerException npex) {
+ throw new NullKeyFieldException(this.keyFields[i]);
+ }
+ catch (IndexOutOfBoundsException iobex) {
+ throw new KeyFieldOutOfBoundsException(this.keyFields[i]);
+ }
+ }
+
+
+ @Override
+ public void setReference(Record toCompare) {
+ for (int i = 0; i < this.keyFields.length; i++) {
+ if (!toCompare.getFieldInto(this.keyFields[i], this.keyHolders[i])) {
+ throw new NullKeyFieldException(this.keyFields[i]);
+ }
+ }
+ }
+
+
+ @Override
+ public boolean equalToReference(Record candidate) {
+ for (int i = 0; i < this.keyFields.length; i++) {
+ final Key<?> k = candidate.getField(this.keyFields[i], this.transientKeyHolders[i]);
+ if (k == null) {
+ throw new NullKeyFieldException(this.keyFields[i]);
+ } else if (!k.equals(this.keyHolders[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+ @Override
+ public int compareToReference(TypeComparator<Record> referencedAccessors) {
+ final RecordComparator pra = (RecordComparator) referencedAccessors;
+
+ for (int i = 0; i < this.keyFields.length; i++) {
+ @SuppressWarnings("unchecked")
+ final int comp = pra.keyHolders[i].compareTo(this.keyHolders[i]);
+ if (comp != 0) {
+ return this.ascending[i] ? comp : -comp;
+ }
+ }
+ return 0;
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Override
+ public int compare(Record first, Record second) {
+ int i = 0;
+ try {
+ for (; i < this.keyFields.length; i++) {
+ Key k1 = first.getField(this.keyFields[i], this.keyHolders[i]);
+ Key k2 = second.getField(this.keyFields[i], this.transientKeyHolders[i]);
+ int cmp = k1.compareTo(k2);
+ if (cmp != 0) {
+ return cmp;
+ }
+ }
+ return 0;
+ }
+ catch (NullPointerException e) {
+ throw new NullKeyFieldException(this.keyFields[i]);
+ }
+ }
+
+ @Override
+ public int compareSerialized(DataInputView source1, DataInputView source2) throws IOException {
+ this.temp1.read(source1);
+ this.temp2.read(source2);
+
+ for (int i = 0; i < this.keyFields.length; i++) {
+ @SuppressWarnings("rawtypes")
+ final Key k1 = this.temp1.getField(this.keyFields[i], this.keyHolders[i]);
+ @SuppressWarnings("rawtypes")
+ final Key k2 = this.temp2.getField(this.keyFields[i], this.transientKeyHolders[i]);
+
+ if (k1 == null || k2 == null) {
+ throw new NullKeyFieldException(this.keyFields[i]);
+ }
+
+ @SuppressWarnings("unchecked")
+ final int comp = k1.compareTo(k2);
+ if (comp != 0) {
+ return this.ascending[i] ? comp : -comp;
+ }
+ }
+ return 0;
+ }
+
+ // --------------------------------------------------------------------------------------------
+
+
+ @Override
+ public boolean supportsNormalizedKey() {
+ return this.numLeadingNormalizableKeys > 0;
+ }
+
+
+ @Override
+ public int getNormalizeKeyLen() {
+ return this.normalizableKeyPrefixLen;
+ }
+
+
+ @Override
+ public boolean isNormalizedKeyPrefixOnly(int keyBytes) {
+ return this.numLeadingNormalizableKeys < this.keyFields.length ||
+ this.normalizableKeyPrefixLen == Integer.MAX_VALUE ||
+ this.normalizableKeyPrefixLen > keyBytes;
+ }
+
+ @Override
+ public void putNormalizedKey(Record record, MemorySegment target, int offset, int numBytes) {
+ int i = 0;
+ try {
+ for (; i < this.numLeadingNormalizableKeys & numBytes > 0; i++)
+ {
+ int len = this.normalizedKeyLengths[i];
+ len = numBytes >= len ? len : numBytes;
+ ((NormalizableKey<?>) record.getField(this.keyFields[i], this.transientKeyHolders[i])).copyNormalizedKey(target, offset, len);
+ numBytes -= len;
+ offset += len;
+ }
+ }
+ catch (NullPointerException npex) {
+ throw new NullKeyFieldException(this.keyFields[i]);
+ }
+ }
+
+
+ @Override
+ public boolean invertNormalizedKey() {
+ return !this.ascending[0];
+ }
+
+ // --------------------------------------------------------------------------------------------
+
+ @Override
+ public boolean supportsSerializationWithKeyNormalization() {
+ return false;
+ }
+
+ @Override
+ public void writeWithKeyNormalization(Record record, DataOutputView target) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Record readWithKeyDenormalization(Record reuse, DataInputView source) {
+ throw new UnsupportedOperationException();
+ }
+
+ // --------------------------------------------------------------------------------------------
+
+ @Override
+ public RecordComparator duplicate() {
+ return new RecordComparator(this);
+ }
+
+ // --------------------------------------------------------------------------------------------
+ // Non Standard Comparator Methods
+ // --------------------------------------------------------------------------------------------
+
+ public final int[] getKeyPositions() {
+ return this.keyFields;
+ }
+
+ @SuppressWarnings("unchecked")
+ public final Class<? extends Key<?>>[] getKeyTypes() {
+ final Class<? extends Key<?>>[] keyTypes = new Class[this.keyHolders.length];
+ for (int i = 0; i < keyTypes.length; i++) {
+ keyTypes[i] = (Class<? extends Key<?>>) this.keyHolders[i].getClass();
+ }
+ return keyTypes;
+ }
+
+ public final Key<?>[] getKeysAsCopy(Record record) {
+ try {
+ final Key<?>[] keys = new Key[this.keyFields.length];
+ for (int i = 0; i < keys.length; i++) {
+ keys[i] = this.keyHolders[i].getClass().newInstance();
+ }
+ if(!record.getFieldsInto(this.keyFields, keys)) {
+ throw new RuntimeException("Could not extract keys from record.");
+ }
+ return keys;
+ } catch (Exception ex) {
+ // this should never happen, because the classes have been instantiated before. Report for debugging.
+ throw new RuntimeException("Could not instantiate key classes when duplicating RecordComparator.", ex);
+ }
+ }
+
+ @Override
+ public int extractKeys(Object record, Object[] target, int index) {
+ throw new UnsupportedOperationException("Record does not support extactKeys and " +
+ "getComparators. This cannot be used with the GenericPairComparator.");
+ }
+
+
+ @Override
+ public TypeComparator<?>[] getFlatComparators() {
+ throw new UnsupportedOperationException("Record does not support extactKeys and " +
+ "getComparators. This cannot be used with the GenericPairComparator.");
+ }
+
+ @Override
+ public boolean supportsCompareAgainstReference() {
+ return true;
+ }
+
+ @Override
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public final int compareAgainstReference(Comparable[] keys) {
+ for (int i = 0; i < this.keyFields.length; i++)
+ {
+ final int comp = keys[i].compareTo(this.keyHolders[i]);
+ if (comp != 0) {
+ return this.ascending[i] ? comp : -comp;
+ }
+ }
+ return 0;
+ }
+}
[3/7] flink git commit: [hotfix] Minor cleanups in classes FileSystem,
OperatingSystem, CopyableValue, GenericCsvInputFormat
Posted by se...@apache.org.
[hotfix] Minor cleanups in classes FileSystem, OperatingSystem, CopyableValue, GenericCsvInputFormat
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/f414e55e
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/f414e55e
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/f414e55e
Branch: refs/heads/master
Commit: f414e55e1c82b3238c0f2e994523e31b76cc1e26
Parents: 44eb58e
Author: Stephan Ewen <se...@apache.org>
Authored: Sun Dec 13 16:56:02 2015 +0100
Committer: Stephan Ewen <se...@apache.org>
Committed: Mon Dec 14 17:44:19 2015 +0100
----------------------------------------------------------------------
.../api/common/io/GenericCsvInputFormat.java | 17 ++-
.../org/apache/flink/core/fs/FileSystem.java | 76 ++------------
.../org/apache/flink/types/CopyableValue.java | 8 +-
.../java/org/apache/flink/util/ClassUtils.java | 105 -------------------
.../apache/flink/util/InstantiationUtil.java | 53 +++++-----
.../org/apache/flink/util/OperatingSystem.java | 12 +--
6 files changed, 48 insertions(+), 223 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/f414e55e/flink-core/src/main/java/org/apache/flink/api/common/io/GenericCsvInputFormat.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/io/GenericCsvInputFormat.java b/flink-core/src/main/java/org/apache/flink/api/common/io/GenericCsvInputFormat.java
index e68d271..89caf2f 100644
--- a/flink-core/src/main/java/org/apache/flink/api/common/io/GenericCsvInputFormat.java
+++ b/flink-core/src/main/java/org/apache/flink/api/common/io/GenericCsvInputFormat.java
@@ -46,7 +46,7 @@ public abstract class GenericCsvInputFormat<OT> extends DelimitedInputFormat<OT>
private static final long serialVersionUID = 1L;
- private static final Class<?>[] EMPTY_TYPES = new Class[0];
+ private static final Class<?>[] EMPTY_TYPES = new Class<?>[0];
private static final boolean[] EMPTY_INCLUDED = new boolean[0];
@@ -240,9 +240,8 @@ public abstract class GenericCsvInputFormat<OT> extends DelimitedInputFormat<OT>
fieldIncluded[i] = true;
}
}
-
- Class<?>[] denseTypeArray = (Class<?>[]) types.toArray(new Class[types.size()]);
- this.fieldTypes = denseTypeArray;
+
+ this.fieldTypes = types.toArray(new Class<?>[types.size()]);
}
protected void setFieldsGeneric(int[] sourceFieldIndices, Class<?>[] fieldTypes) {
@@ -275,8 +274,7 @@ public abstract class GenericCsvInputFormat<OT> extends DelimitedInputFormat<OT>
}
}
- Class<?>[] denseTypeArray = (Class<?>[]) types.toArray(new Class[types.size()]);
- this.fieldTypes = denseTypeArray;
+ this.fieldTypes = types.toArray(new Class<?>[types.size()]);
}
protected void setFieldsGeneric(boolean[] includedMask, Class<?>[] fieldTypes) {
@@ -307,8 +305,7 @@ public abstract class GenericCsvInputFormat<OT> extends DelimitedInputFormat<OT>
}
}
- Class<?>[] denseTypeArray = (Class<?>[]) types.toArray(new Class[types.size()]);
- this.fieldTypes = denseTypeArray;
+ this.fieldTypes = types.toArray(new Class<?>[types.size()]);
this.fieldIncluded = includedMask;
}
@@ -321,7 +318,7 @@ public abstract class GenericCsvInputFormat<OT> extends DelimitedInputFormat<OT>
super.open(split);
// instantiate the parsers
- FieldParser<?>[] parsers = new FieldParser[fieldTypes.length];
+ FieldParser<?>[] parsers = new FieldParser<?>[fieldTypes.length];
for (int i = 0; i < fieldTypes.length; i++) {
if (fieldTypes[i] != null) {
@@ -441,7 +438,7 @@ public abstract class GenericCsvInputFormat<OT> extends DelimitedInputFormat<OT>
final int delimLimit = limit - delim.length + 1;
- if(quotedStringParsing == true && bytes[i] == quoteCharacter) {
+ if (quotedStringParsing && bytes[i] == quoteCharacter) {
// quoted string parsing enabled and field is quoted
// search for ending quote character, continue when it is escaped
http://git-wip-us.apache.org/repos/asf/flink/blob/f414e55e/flink-core/src/main/java/org/apache/flink/core/fs/FileSystem.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/core/fs/FileSystem.java b/flink-core/src/main/java/org/apache/flink/core/fs/FileSystem.java
index 7dc92c6..03ca6a2 100644
--- a/flink-core/src/main/java/org/apache/flink/core/fs/FileSystem.java
+++ b/flink-core/src/main/java/org/apache/flink/core/fs/FileSystem.java
@@ -34,9 +34,7 @@ import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
-import org.apache.flink.util.ClassUtils;
import org.apache.flink.util.OperatingSystem;
-import org.apache.flink.util.StringUtils;
/**
* An abstract base class for a fairly generic file system. It
@@ -262,37 +260,26 @@ public abstract class FileSystem {
//Class must implement Hadoop FileSystem interface. The class is not avaiable in 'flink-core'.
private static FileSystem instantiateHadoopFileSystemWrapper(Class<?> wrappedFileSystem) throws IOException {
- FileSystem fs = null;
- Class<? extends FileSystem> fsClass;
try {
- fsClass = ClassUtils.getFileSystemByName(HADOOP_WRAPPER_FILESYSTEM_CLASS);
+ Class<? extends FileSystem> fsClass = getFileSystemByName(HADOOP_WRAPPER_FILESYSTEM_CLASS);
Constructor<? extends FileSystem> fsClassCtor = fsClass.getConstructor(Class.class);
- fs = fsClassCtor.newInstance(wrappedFileSystem);
+ return fsClassCtor.newInstance(wrappedFileSystem);
} catch (Throwable e) {
throw new IOException("Error loading Hadoop FS wrapper", e);
}
- return fs;
}
private static FileSystem instantiateFileSystem(String className) throws IOException {
- FileSystem fs = null;
- Class<? extends FileSystem> fsClass;
try {
- fsClass = ClassUtils.getFileSystemByName(className);
- } catch (ClassNotFoundException e1) {
- throw new IOException(StringUtils.stringifyException(e1));
+ Class<? extends FileSystem> fsClass = getFileSystemByName(className);
+ return fsClass.newInstance();
}
-
- try {
- fs = fsClass.newInstance();
+ catch (ClassNotFoundException e) {
+ throw new IOException("Could not load file system class '" + className + '\'', e);
}
- catch (InstantiationException e) {
+ catch (InstantiationException | IllegalAccessException e) {
throw new IOException("Could not instantiate file system class: " + e.getMessage(), e);
}
- catch (IllegalAccessException e) {
- throw new IOException("Could not instantiate file system class: " + e.getMessage(), e);
- }
- return fs;
}
private static HadoopFileSystemWrapper hadoopWrapper;
@@ -450,6 +437,7 @@ public abstract class FileSystem {
* @param replication
* required block replication for the file.
* @param blockSize
+ * the size of the file blocks
* @throws IOException
*/
public abstract FSDataOutputStream create(Path f, boolean overwrite, int bufferSize, short replication,
@@ -723,52 +711,8 @@ public abstract class FileSystem {
*/
public abstract boolean isDistributedFS();
- /**
- * Returns the number of blocks this file/directory consists of
- * assuming the file system's standard block size.
- *
- * @param file
- * the file
- * @return the number of block's the file/directory consists of
- * @throws IOException
- */
- public int getNumberOfBlocks(final FileStatus file) throws IOException {
-
- int numberOfBlocks = 0;
-
- if (file == null) {
- return 0;
- }
- // For a file, this is easy
- if (!file.isDir()) {
- return getNumberOfBlocks(file.getLen(), file.getBlockSize());
- }
-
- // file is a directory
- final FileStatus[] files = this.listStatus(file.getPath());
- for (FileStatus file1 : files) {
- if (!file1.isDir()) {
- numberOfBlocks += getNumberOfBlocks(file1.getLen(), file1.getBlockSize());
- }
- }
-
- return numberOfBlocks;
- }
-
- private int getNumberOfBlocks(final long length, final long blocksize) {
-
- if (blocksize != 0) {
- int numberOfBlocks;
- numberOfBlocks = (int) (length / blocksize);
-
- if ((length % blocksize) != 0) {
- numberOfBlocks++;
- }
-
- return numberOfBlocks;
- } else {
- return 1;
- }
+ private static Class<? extends FileSystem> getFileSystemByName(String className) throws ClassNotFoundException {
+ return Class.forName(className, true, FileSystem.class.getClassLoader()).asSubclass(FileSystem.class);
}
}
http://git-wip-us.apache.org/repos/asf/flink/blob/f414e55e/flink-core/src/main/java/org/apache/flink/types/CopyableValue.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/types/CopyableValue.java b/flink-core/src/main/java/org/apache/flink/types/CopyableValue.java
index 3974cb2..95498fe 100644
--- a/flink-core/src/main/java/org/apache/flink/types/CopyableValue.java
+++ b/flink-core/src/main/java/org/apache/flink/types/CopyableValue.java
@@ -44,10 +44,10 @@ public interface CopyableValue<T> extends Value {
/**
* Performs a deep copy of this object into a new instance.
- *
- * This method is useful for generic user-defined functions to clone a
- * {@link CopyableValue} when storing multiple objects. With object reuse
- * a deep copy must be created and type erasure prevents calling new.
+ *
+ * This method is useful for generic user-defined functions to clone a
+ * {@link CopyableValue} when storing multiple objects. With object reuse
+ * a deep copy must be created and type erasure prevents calling new.
*
* @return New object with copied fields.
*/
http://git-wip-us.apache.org/repos/asf/flink/blob/f414e55e/flink-core/src/main/java/org/apache/flink/util/ClassUtils.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/util/ClassUtils.java b/flink-core/src/main/java/org/apache/flink/util/ClassUtils.java
deleted file mode 100644
index a57e004..0000000
--- a/flink-core/src/main/java/org/apache/flink/util/ClassUtils.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * 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.flink.util;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.flink.core.fs.FileSystem;
-
-/**
- * Utility class which provides various methods for dynamic class loading.
- */
-public final class ClassUtils {
-
- /**
- * Private constructor used to overwrite public one.
- */
- private ClassUtils() {}
-
- /**
- * Searches for a file system class by its name and attempts to load it.
- *
- * @param className
- * the name of the file system class
- * @return an instance of the file system class
- * @throws ClassNotFoundException
- * thrown if no class with such a name can be found
- */
- public static Class<? extends FileSystem> getFileSystemByName(final String className) throws ClassNotFoundException {
- return Class.forName(className, true, getClassLoader()).asSubclass(FileSystem.class);
- }
-
-
- private static ClassLoader getClassLoader() {
- return ClassUtils.class.getClassLoader();
- }
-
- public static Class<?> resolveClassPrimitiveAware(String className) throws ClassNotFoundException {
- if (className == null) {
- throw new NullPointerException();
- }
-
- Class<?> primClass = PRIMITIVE_TYPES.get(className);
- if (primClass != null) {
- return primClass;
- } else {
- return Class.forName(className);
- }
- }
-
- public static boolean isPrimitiveOrBoxedOrString(Class<?> clazz) {
- return clazz != null && (clazz.isPrimitive() || ClassUtils.isBoxedTypeOrString(clazz));
- }
-
- public static boolean isBoxedTypeOrString(Class<?> clazz) {
- return BOXED_TYPES.contains(clazz);
- }
-
- // --------------------------------------------------------------------------------------------
-
- private static final Map<String, Class<?>> PRIMITIVE_TYPES = new HashMap<String, Class<?>>(9);
-
- private static final Set<Class<?>> BOXED_TYPES = new HashSet<Class<?>>();
-
- static {
- PRIMITIVE_TYPES.put("byte", byte.class);
- PRIMITIVE_TYPES.put("short", short.class);
- PRIMITIVE_TYPES.put("int", int.class);
- PRIMITIVE_TYPES.put("long", long.class);
- PRIMITIVE_TYPES.put("float", float.class);
- PRIMITIVE_TYPES.put("double", double.class);
- PRIMITIVE_TYPES.put("boolean", boolean.class);
- PRIMITIVE_TYPES.put("char", char.class);
- PRIMITIVE_TYPES.put("void", void.class);
-
- BOXED_TYPES.add(Byte.class);
- BOXED_TYPES.add(Short.class);
- BOXED_TYPES.add(Integer.class);
- BOXED_TYPES.add(Long.class);
- BOXED_TYPES.add(Float.class);
- BOXED_TYPES.add(Double.class);
- BOXED_TYPES.add(Boolean.class);
- BOXED_TYPES.add(Character.class);
- BOXED_TYPES.add(Void.class);
- BOXED_TYPES.add(String.class);
- }
-}
http://git-wip-us.apache.org/repos/asf/flink/blob/f414e55e/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java b/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java
index 4f6ee32..b1ef35d 100644
--- a/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java
+++ b/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java
@@ -47,20 +47,12 @@ public final class InstantiationUtil {
*
*/
public static class ClassLoaderObjectInputStream extends ObjectInputStream {
- private ClassLoader classLoader;
- private static final HashMap<String, Class<?>> primitiveClasses
- = new HashMap<String, Class<?>>(8, 1.0F);
- static {
- primitiveClasses.put("boolean", boolean.class);
- primitiveClasses.put("byte", byte.class);
- primitiveClasses.put("char", char.class);
- primitiveClasses.put("short", short.class);
- primitiveClasses.put("int", int.class);
- primitiveClasses.put("long", long.class);
- primitiveClasses.put("float", float.class);
- primitiveClasses.put("double", double.class);
- primitiveClasses.put("void", void.class);
+ private final ClassLoader classLoader;
+
+ public ClassLoaderObjectInputStream(InputStream in, ClassLoader classLoader) throws IOException {
+ super(in);
+ this.classLoader = classLoader;
}
@Override
@@ -84,10 +76,21 @@ public final class InstantiationUtil {
return super.resolveClass(desc);
}
+
+ // ------------------------------------------------
- public ClassLoaderObjectInputStream(InputStream in, ClassLoader classLoader) throws IOException {
- super(in);
- this.classLoader = classLoader;
+ private static final HashMap<String, Class<?>> primitiveClasses = new HashMap<>(9);
+
+ static {
+ primitiveClasses.put("boolean", boolean.class);
+ primitiveClasses.put("byte", byte.class);
+ primitiveClasses.put("char", char.class);
+ primitiveClasses.put("short", short.class);
+ primitiveClasses.put("int", int.class);
+ primitiveClasses.put("long", long.class);
+ primitiveClasses.put("float", float.class);
+ primitiveClasses.put("double", double.class);
+ primitiveClasses.put("void", void.class);
}
}
@@ -293,28 +296,22 @@ public final class InstantiationUtil {
@SuppressWarnings("unchecked")
public static <T> T deserializeObject(byte[] bytes, ClassLoader cl) throws IOException, ClassNotFoundException {
- ObjectInputStream oois = null;
final ClassLoader old = Thread.currentThread().getContextClassLoader();
- try {
+ try (ObjectInputStream oois = new ClassLoaderObjectInputStream(new ByteArrayInputStream(bytes), cl)) {
Thread.currentThread().setContextClassLoader(cl);
- oois = new ClassLoaderObjectInputStream(new ByteArrayInputStream(bytes), cl);
return (T) oois.readObject();
- } finally {
+ }
+ finally {
Thread.currentThread().setContextClassLoader(old);
- if (oois != null) {
- oois.close();
- }
}
}
public static byte[] serializeObject(Object o) throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(o);
+ return baos.toByteArray();
}
-
- return baos.toByteArray();
}
// --------------------------------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/f414e55e/flink-core/src/main/java/org/apache/flink/util/OperatingSystem.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/util/OperatingSystem.java b/flink-core/src/main/java/org/apache/flink/util/OperatingSystem.java
index 4aa4eed..eed1fc9 100644
--- a/flink-core/src/main/java/org/apache/flink/util/OperatingSystem.java
+++ b/flink-core/src/main/java/org/apache/flink/util/OperatingSystem.java
@@ -19,13 +19,9 @@
package org.apache.flink.util;
/**
- * An enumeration indicating the operating system that the engine runs on.
+ * An enumeration indicating the operating system that the JVM runs on.
*/
public enum OperatingSystem {
-
- // --------------------------------------------------------------------------------------------
- // Constants to extract the OS type from the java environment
- // --------------------------------------------------------------------------------------------
LINUX,
WINDOWS,
@@ -33,9 +29,7 @@ public enum OperatingSystem {
FREE_BSD,
UNKNOWN;
- // --------------------------------------------------------------------------------------------
- // Constants to extract the OS type from the java environment
- // --------------------------------------------------------------------------------------------
+ // ------------------------------------------------------------------------
/**
* Gets the operating system that the JVM runs on from the java system properties.
@@ -117,8 +111,6 @@ public enum OperatingSystem {
return UNKNOWN;
}
-
-
// --------------------------------------------------------------------------------------------
// Constants to extract the OS type from the java environment
// --------------------------------------------------------------------------------------------
[5/7] flink git commit: [hotfix] Add missing Override annotations to
RichFoldFunction and RichReduceFunction
Posted by se...@apache.org.
[hotfix] Add missing Override annotations to RichFoldFunction and RichReduceFunction
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/bd657e65
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/bd657e65
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/bd657e65
Branch: refs/heads/master
Commit: bd657e6503678654577c4679bcdff10530dd575f
Parents: daad577
Author: Stephan Ewen <se...@apache.org>
Authored: Sun Dec 13 18:51:32 2015 +0100
Committer: Stephan Ewen <se...@apache.org>
Committed: Mon Dec 14 17:44:19 2015 +0100
----------------------------------------------------------------------
.../org/apache/flink/api/common/functions/RichFoldFunction.java | 1 +
.../org/apache/flink/api/common/functions/RichReduceFunction.java | 1 +
2 files changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/bd657e65/flink-core/src/main/java/org/apache/flink/api/common/functions/RichFoldFunction.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/functions/RichFoldFunction.java b/flink-core/src/main/java/org/apache/flink/api/common/functions/RichFoldFunction.java
index 3663823..f4c2942 100644
--- a/flink-core/src/main/java/org/apache/flink/api/common/functions/RichFoldFunction.java
+++ b/flink-core/src/main/java/org/apache/flink/api/common/functions/RichFoldFunction.java
@@ -35,5 +35,6 @@ public abstract class RichFoldFunction<O, T> extends AbstractRichFunction implem
private static final long serialVersionUID = 1L;
+ @Override
public abstract T fold(T accumulator, O value) throws Exception;
}
http://git-wip-us.apache.org/repos/asf/flink/blob/bd657e65/flink-core/src/main/java/org/apache/flink/api/common/functions/RichReduceFunction.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/functions/RichReduceFunction.java b/flink-core/src/main/java/org/apache/flink/api/common/functions/RichReduceFunction.java
index 5380560..13e7e3f 100644
--- a/flink-core/src/main/java/org/apache/flink/api/common/functions/RichReduceFunction.java
+++ b/flink-core/src/main/java/org/apache/flink/api/common/functions/RichReduceFunction.java
@@ -34,5 +34,6 @@ public abstract class RichReduceFunction<T> extends AbstractRichFunction impleme
private static final long serialVersionUID = 1L;
+ @Override
public abstract T reduce(T value1, T value2) throws Exception;
}
[4/7] flink git commit: [hotfix] Add comments to
BroadcastVariableInitializer and SplittableIterator
Posted by se...@apache.org.
[hotfix] Add comments to BroadcastVariableInitializer and SplittableIterator
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/daad5778
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/daad5778
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/daad5778
Branch: refs/heads/master
Commit: daad5778e55a0f80e7b58382539113d87586acb2
Parents: f414e55
Author: Stephan Ewen <se...@apache.org>
Authored: Sun Dec 13 18:30:37 2015 +0100
Committer: Stephan Ewen <se...@apache.org>
Committed: Mon Dec 14 17:44:19 2015 +0100
----------------------------------------------------------------------
.../functions/BroadcastVariableInitializer.java | 61 +++++++++++++++++++-
.../flink/core/memory/MemorySegmentSource.java | 2 -
.../flink/util/NumberSequenceIterator.java | 5 +-
.../apache/flink/util/SplittableIterator.java | 27 ++++++++-
4 files changed, 90 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/daad5778/flink-core/src/main/java/org/apache/flink/api/common/functions/BroadcastVariableInitializer.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/functions/BroadcastVariableInitializer.java b/flink-core/src/main/java/org/apache/flink/api/common/functions/BroadcastVariableInitializer.java
index 7fc81e5..d38c1f8 100644
--- a/flink-core/src/main/java/org/apache/flink/api/common/functions/BroadcastVariableInitializer.java
+++ b/flink-core/src/main/java/org/apache/flink/api/common/functions/BroadcastVariableInitializer.java
@@ -18,7 +18,66 @@
package org.apache.flink.api.common.functions;
+/**
+ * A broadcast variable initializer can be used to transform a broadcast variable
+ * into another format during initialization. The transformed variable is shared
+ * among the parallel instances of a function inside one TaskManager, the
+ * same way as the plain broadcast variables (lists) are shared.
+ *
+ * <p>The broadcast variable initializer will in many cases only be executed by one
+ * parallel function instance per TaskManager, when acquiring the broadcast variable
+ * for the first time inside that particular TaskManager. It is possible that a
+ * broadcast variable is read and initialized multiple times, if the tasks that use
+ * the variables are not overlapping in their execution time; in such cases, it can
+ * happen that one function instance released the broadcast variable, and another
+ * function instance materializes it again.
+ *
+ * <p>This is an example of how to use a broadcast variable initializer, transforming
+ * the shared list of values into a shared map.
+ *
+ * <pre>{@code
+ * public class MyFunction extends RichMapFunction<Long, String> {
+ *
+ * private Map<Long, String> map;
+ *
+ * public void open(Configuration cfg) throws Exception {
+ * getRuntimeContext().getBroadcastVariableWithInitializer("mapvar",
+ * new BroadcastVariableInitializer<Tuple2<Long, String>, Map<Long, String>>() {
+ *
+ * public Map<Long, String> initializeBroadcastVariable(Iterable<Tuple2<Long, String>> data) {
+ * Map<Long, String> map = new HashMap<>();
+ *
+ * for (Tuple2<Long, String> t : data) {
+ * map.put(t.f0, t.f1);
+ * }
+ *
+ * return map;
+ * }
+ * });
+ * }
+ *
+ * public String map(Long value) {
+ * // replace the long by the String, based on the map
+ * return map.get(value);
+ * }
+ * }
+ *
+ * }</pre>
+ *
+ * @param <T> The type of the elements in the list of the original untransformed broadcast variable.
+ * @param <O> The type of the transformed broadcast variable.
+ */
public interface BroadcastVariableInitializer<T, O> {
-
+
+ /**
+ * The method that reads the data elements from the broadcast variable and
+ * creates the transformed data structure.
+ *
+ * <p>The iterable with the data elements can be traversed only once, i.e.,
+ * only the first call to {@code iterator()} will succeed.
+ *
+ * @param data The sequence of elements in the broadcast variable.
+ * @return The transformed broadcast variable.
+ */
O initializeBroadcastVariable(Iterable<T> data);
}
http://git-wip-us.apache.org/repos/asf/flink/blob/daad5778/flink-core/src/main/java/org/apache/flink/core/memory/MemorySegmentSource.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/core/memory/MemorySegmentSource.java b/flink-core/src/main/java/org/apache/flink/core/memory/MemorySegmentSource.java
index 1067e77..fc0805c 100644
--- a/flink-core/src/main/java/org/apache/flink/core/memory/MemorySegmentSource.java
+++ b/flink-core/src/main/java/org/apache/flink/core/memory/MemorySegmentSource.java
@@ -16,10 +16,8 @@
* limitations under the License.
*/
-
package org.apache.flink.core.memory;
-
/**
* Interface describing entities that can provide memory segments.
*/
http://git-wip-us.apache.org/repos/asf/flink/blob/daad5778/flink-core/src/main/java/org/apache/flink/util/NumberSequenceIterator.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/util/NumberSequenceIterator.java b/flink-core/src/main/java/org/apache/flink/util/NumberSequenceIterator.java
index 5cb992a..c536f44 100644
--- a/flink-core/src/main/java/org/apache/flink/util/NumberSequenceIterator.java
+++ b/flink-core/src/main/java/org/apache/flink/util/NumberSequenceIterator.java
@@ -29,13 +29,16 @@ public class NumberSequenceIterator extends SplittableIterator<Long> {
private static final long serialVersionUID = 1L;
+ /** The last number returned by the iterator */
private final long to;
+ /** The next number to be returned */
private long current;
/**
- * Internal constructor to allow for empty iterators.
+ * Creates a new splittable iterator, returning the range [from, to].
+ * Both boundaries of the interval are inclusive.
*
* @param from The first number returned by the iterator.
* @param to The last number returned by the iterator.
http://git-wip-us.apache.org/repos/asf/flink/blob/daad5778/flink-core/src/main/java/org/apache/flink/util/SplittableIterator.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/util/SplittableIterator.java b/flink-core/src/main/java/org/apache/flink/util/SplittableIterator.java
index 5518a50..3a585d7 100644
--- a/flink-core/src/main/java/org/apache/flink/util/SplittableIterator.java
+++ b/flink-core/src/main/java/org/apache/flink/util/SplittableIterator.java
@@ -21,13 +21,33 @@ package org.apache.flink.util;
import java.io.Serializable;
import java.util.Iterator;
-
+/**
+ * Abstract base class for iterators that can split themselves into multiple disjoint
+ * iterators. The union of these iterators returns the original iterator values.
+ *
+ * @param <T> The type of elements returned by the iterator.
+ */
public abstract class SplittableIterator<T> implements Iterator<T>, Serializable {
private static final long serialVersionUID = 200377674313072307L;
+ /**
+ * Splits this iterator into a number disjoint iterators.
+ * The union of these iterators returns the original iterator values.
+ *
+ * @param numPartitions The number of iterators to split into.
+ * @return An array with the split iterators.
+ */
public abstract Iterator<T>[] split(int numPartitions);
+ /**
+ * Splits this iterator into <i>n</i> partitions and returns the <i>i-th</i> partition
+ * out of those.
+ *
+ * @param num The partition to return (<i>i</i>).
+ * @param numPartitions The number of partitions to split into (<i>n</i>).
+ * @return The iterator for the partition.
+ */
public Iterator<T> getSplit(int num, int numPartitions) {
if (numPartitions < 1 || num < 0 || num >= numPartitions) {
throw new IllegalArgumentException();
@@ -36,5 +56,10 @@ public abstract class SplittableIterator<T> implements Iterator<T>, Serializable
return split(numPartitions)[num];
}
+ /**
+ * The maximum number of splits into which this iterator can be split up.
+ *
+ * @return The maximum number of splits into which this iterator can be split up.
+ */
public abstract int getMaximumNumberOfSplits();
}