You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by fh...@apache.org on 2016/03/23 17:30:51 UTC
[1/4] flink git commit: [FLINK-2445] Improve HadoopOutputFormatTests
Repository: flink
Updated Branches:
refs/heads/master f7a3c8104 -> b8299bf92
[FLINK-2445] Improve HadoopOutputFormatTests
This closes #1628
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/bcb34dd5
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/bcb34dd5
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/bcb34dd5
Branch: refs/heads/master
Commit: bcb34dd57fb4c9908cd8525db6fd7db3d4c6d254
Parents: 8e4a001
Author: Martin Liesenberg <ma...@gmail.com>
Authored: Thu Feb 11 15:59:01 2016 +0100
Committer: Fabian Hueske <fh...@apache.org>
Committed: Wed Mar 23 15:31:42 2016 +0100
----------------------------------------------------------------------
.../hadoop/mapred/HadoopOutputFormatTest.java | 229 ++++++++++++++++
.../mapreduce/HadoopOutputFormatTest.java | 265 ++++++++++++-------
2 files changed, 395 insertions(+), 99 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/bcb34dd5/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapred/HadoopOutputFormatTest.java
----------------------------------------------------------------------
diff --git a/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapred/HadoopOutputFormatTest.java b/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapred/HadoopOutputFormatTest.java
new file mode 100644
index 0000000..409feb4
--- /dev/null
+++ b/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapred/HadoopOutputFormatTest.java
@@ -0,0 +1,229 @@
+/*
+ * 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.hadoop.mapred;
+
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.hadoop.conf.Configurable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.JobConfigurable;
+import org.apache.hadoop.mapred.JobContext;
+import org.apache.hadoop.mapred.OutputCommitter;
+import org.apache.hadoop.mapred.OutputFormat;
+import org.apache.hadoop.mapred.RecordWriter;
+import org.apache.hadoop.mapred.Reporter;
+import org.apache.hadoop.mapred.TaskAttemptContext;
+import org.apache.hadoop.util.Progressable;
+import org.junit.Test;
+import org.mockito.Matchers;
+
+import java.io.IOException;
+
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyLong;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class HadoopOutputFormatTest {
+
+ @Test
+ public void testOpen() throws Exception {
+
+ OutputFormat<String, Long> dummyOutputFormat = mock(DummyOutputFormat.class);
+ DummyOutputCommitter outputCommitter = mock(DummyOutputCommitter.class);
+ JobConf jobConf = spy(new JobConf());
+ when(jobConf.getOutputCommitter()).thenReturn(outputCommitter);
+
+ HadoopOutputFormat<String, Long> outputFormat = new HadoopOutputFormat<>(dummyOutputFormat, jobConf);
+
+ outputFormat.open(1, 1);
+
+ verify(jobConf, times(2)).getOutputCommitter();
+ verify(outputCommitter, times(1)).setupJob(any(JobContext.class));
+ verify(dummyOutputFormat, times(1)).getRecordWriter(any(FileSystem.class), any(JobConf.class), anyString(), any(Progressable.class));
+ }
+
+ @Test
+ public void testConfigureWithConfigurable() {
+ ConfigurableDummyOutputFormat dummyOutputFormat = mock(ConfigurableDummyOutputFormat.class);
+ JobConf jobConf = mock(JobConf.class);
+
+ HadoopOutputFormat<String, Long> outputFormat = new HadoopOutputFormat<>(dummyOutputFormat, jobConf);
+
+ outputFormat.configure(Matchers.<org.apache.flink.configuration.Configuration>any());
+
+ verify(dummyOutputFormat, times(1)).setConf(any(Configuration.class));
+ }
+
+ @Test
+ public void testConfigureWithJobConfigurable() {
+ JobConfigurableDummyOutputFormat dummyOutputFormat = mock(JobConfigurableDummyOutputFormat.class);
+ JobConf jobConf = mock(JobConf.class);
+
+ HadoopOutputFormat<String, Long> outputFormat = new HadoopOutputFormat<>(dummyOutputFormat, jobConf);
+
+ outputFormat.configure(Matchers.<org.apache.flink.configuration.Configuration>any());
+
+ verify(dummyOutputFormat, times(1)).configure(any(JobConf.class));
+ }
+
+ @Test
+ public void testCloseWithTaskCommit() throws Exception {
+ OutputFormat<String, Long> dummyOutputFormat = mock(DummyOutputFormat.class);
+ DummyOutputCommitter outputCommitter = mock(DummyOutputCommitter.class);
+ when(outputCommitter.needsTaskCommit(any(TaskAttemptContext.class))).thenReturn(true);
+ DummyRecordWriter recordWriter = mock(DummyRecordWriter.class);
+ JobConf jobConf = mock(JobConf.class);
+
+ HadoopOutputFormat<String, Long> outputFormat = new HadoopOutputFormat<>(dummyOutputFormat, jobConf);
+ outputFormat.recordWriter = recordWriter;
+ outputFormat.outputCommitter = outputCommitter;
+
+ outputFormat.close();
+
+ verify(recordWriter, times(1)).close(any(Reporter.class));
+ verify(outputCommitter, times(1)).commitTask(any(TaskAttemptContext.class));
+ }
+
+ @Test
+ public void testCloseWithoutTaskCommit() throws Exception {
+ OutputFormat<String, Long> dummyOutputFormat = mock(DummyOutputFormat.class);
+ DummyOutputCommitter outputCommitter = mock(DummyOutputCommitter.class);
+ when(outputCommitter.needsTaskCommit(any(TaskAttemptContext.class))).thenReturn(false);
+ DummyRecordWriter recordWriter = mock(DummyRecordWriter.class);
+ JobConf jobConf = mock(JobConf.class);
+
+ HadoopOutputFormat<String, Long> outputFormat = new HadoopOutputFormat<>(dummyOutputFormat, jobConf);
+ outputFormat.recordWriter = recordWriter;
+ outputFormat.outputCommitter = outputCommitter;
+
+ outputFormat.close();
+
+ verify(recordWriter, times(1)).close(any(Reporter.class));
+ verify(outputCommitter, times(0)).commitTask(any(TaskAttemptContext.class));
+ }
+
+ @Test
+ public void testWriteRecord() throws Exception {
+ OutputFormat<String, Long> dummyOutputFormat = mock(DummyOutputFormat.class);
+ DummyRecordWriter recordWriter = mock(DummyRecordWriter.class);
+ JobConf jobConf = mock(JobConf.class);
+
+ HadoopOutputFormat<String, Long> outputFormat = new HadoopOutputFormat<>(dummyOutputFormat, jobConf);
+ outputFormat.recordWriter = recordWriter;
+
+ outputFormat.writeRecord(new Tuple2<>("key", 1L));
+
+ verify(recordWriter, times(1)).write(anyString(), anyLong());
+ }
+
+ @Test
+ public void testFinalizeGlobal() throws Exception {
+ OutputFormat<String, Long> dummyOutputFormat = mock(DummyOutputFormat.class);
+ DummyOutputCommitter outputCommitter = mock(DummyOutputCommitter.class);
+ JobConf jobConf = spy(new JobConf());
+ when(jobConf.getOutputCommitter()).thenReturn(outputCommitter);
+
+ HadoopOutputFormat<String, Long> outputFormat = new HadoopOutputFormat<>(dummyOutputFormat, jobConf);
+
+ outputFormat.finalizeGlobal(1);
+
+ verify(outputCommitter, times(1)).commitJob(any(JobContext.class));
+ }
+
+ public class DummyOutputFormat implements OutputFormat<String, Long> {
+
+ @Override
+ public RecordWriter<String, Long> getRecordWriter(FileSystem fileSystem, JobConf jobConf, String s, Progressable progressable) throws IOException {
+ return null;
+ }
+
+ @Override
+ public void checkOutputSpecs(FileSystem fileSystem, JobConf jobConf) throws IOException {
+
+ }
+ }
+
+ public class ConfigurableDummyOutputFormat extends DummyOutputFormat implements Configurable {
+
+ @Override
+ public void setConf(Configuration configuration) {
+
+ }
+
+ @Override
+ public Configuration getConf() {
+ return null;
+ }
+ }
+
+ public class JobConfigurableDummyOutputFormat extends DummyOutputFormat implements JobConfigurable {
+
+ @Override
+ public void configure(JobConf jobConf) {
+
+ }
+ }
+
+ public class DummyOutputCommitter extends OutputCommitter {
+
+ @Override
+ public void setupJob(JobContext jobContext) throws IOException {
+
+ }
+
+ @Override
+ public void setupTask(TaskAttemptContext taskAttemptContext) throws IOException {
+
+ }
+
+ @Override
+ public boolean needsTaskCommit(TaskAttemptContext taskAttemptContext) throws IOException {
+ return false;
+ }
+
+ @Override
+ public void commitTask(TaskAttemptContext taskAttemptContext) throws IOException {
+
+ }
+
+ @Override
+ public void abortTask(TaskAttemptContext taskAttemptContext) throws IOException {
+
+ }
+ }
+
+ public class DummyRecordWriter implements RecordWriter<String, Long> {
+
+ @Override
+ public void write(String s, Long aLong) throws IOException {
+
+ }
+
+ @Override
+ public void close(Reporter reporter) throws IOException {
+
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/bcb34dd5/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopOutputFormatTest.java
----------------------------------------------------------------------
diff --git a/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopOutputFormatTest.java b/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopOutputFormatTest.java
index 215ca95..7b126fc 100644
--- a/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopOutputFormatTest.java
+++ b/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopOutputFormatTest.java
@@ -19,112 +19,179 @@
package org.apache.flink.api.java.hadoop.mapreduce;
import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.mapreduce.*;
+import org.apache.hadoop.mapreduce.Job;
+import org.apache.hadoop.mapreduce.JobContext;
+import org.apache.hadoop.mapreduce.OutputCommitter;
+import org.apache.hadoop.mapreduce.OutputFormat;
+import org.apache.hadoop.mapreduce.RecordWriter;
+import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.junit.Test;
import org.mockito.Mockito;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.anyLong;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
public class HadoopOutputFormatTest {
- private static final String PATH = "an/ignored/file/";
- private Map<String, Long> map;
-
- @Test
- public void testWriteRecord() {
- OutputFormat<String, Long> dummyOutputFormat = new DummyOutputFormat();
- String key = "Test";
- Long value = 1L;
- map = new HashMap<>();
- map.put(key, 0L);
- try {
- Job job = Job.getInstance();
- Tuple2<String, Long> tuple = new Tuple2<>();
- tuple.setFields(key, value);
- HadoopOutputFormat<String, Long> hadoopOutputFormat = new HadoopOutputFormat<>(dummyOutputFormat, job);
-
- hadoopOutputFormat.recordWriter = new DummyRecordWriter();
- hadoopOutputFormat.writeRecord(tuple);
-
- Long expected = map.get(key);
- assertEquals(expected, value);
- } catch (IOException e) {
- fail();
- }
- }
-
- @Test
- public void testOpen() {
- OutputFormat<String, Long> dummyOutputFormat = new DummyOutputFormat();
- try {
- Job job = Job.getInstance();
- HadoopOutputFormat<String, Long> hadoopOutputFormat = new HadoopOutputFormat<>(dummyOutputFormat, job);
-
- hadoopOutputFormat.recordWriter = new DummyRecordWriter();
- hadoopOutputFormat.open(1, 4);
- } catch (IOException e) {
- fail();
- }
- }
-
- @Test
- public void testClose() {
- OutputFormat<String, Long> dummyOutputFormat = new DummyOutputFormat();
- try {
- Job job = Job.getInstance();
- HadoopOutputFormat<String, Long> hadoopOutputFormat = new HadoopOutputFormat<>(dummyOutputFormat, job);
-
- hadoopOutputFormat.recordWriter = new DummyRecordWriter();
-
- final OutputCommitter outputCommitter = Mockito.mock(OutputCommitter.class);
- Mockito.when(outputCommitter.needsTaskCommit(Mockito.any(TaskAttemptContext.class))).thenReturn(true);
- Mockito.doNothing().when(outputCommitter).commitTask(Mockito.any(TaskAttemptContext.class));
- hadoopOutputFormat.outputCommitter = outputCommitter;
- hadoopOutputFormat.configuration = new Configuration();
- hadoopOutputFormat.configuration.set("mapred.output.dir", PATH);
-
- hadoopOutputFormat.close();
- } catch (IOException e) {
- fail();
- }
- }
-
-
- class DummyRecordWriter extends RecordWriter<String, Long> {
- @Override
- public void write(String key, Long value) throws IOException, InterruptedException {
- map.put(key, value);
- }
-
- @Override
- public void close(TaskAttemptContext context) throws IOException, InterruptedException {
-
- }
- }
-
- class DummyOutputFormat extends OutputFormat<String, Long> {
- @Override
- public RecordWriter<String, Long> getRecordWriter(TaskAttemptContext context) throws IOException, InterruptedException {
- return null;
- }
-
- @Override
- public void checkOutputSpecs(JobContext context) throws IOException, InterruptedException {
-
- }
-
- @Override
- public OutputCommitter getOutputCommitter(TaskAttemptContext context) throws IOException, InterruptedException {
- final OutputCommitter outputCommitter = Mockito.mock(OutputCommitter.class);
- Mockito.doNothing().when(outputCommitter).setupJob(Mockito.any(JobContext.class));
-
- return outputCommitter;
- }
- }
+ private static final String MAPRED_OUTPUT_PATH = "an/ignored/file/";
+ private static final String MAPRED_OUTPUT_DIR_KEY = "mapred.output.dir";
+
+ @Test
+ public void testWriteRecord() throws Exception {
+
+ RecordWriter<String, Long> recordWriter = mock(DummyRecordWriter.class);
+ HadoopOutputFormat<String, Long> hadoopOutputFormat = setupHadoopOutputFormat(new DummyOutputFormat(),
+ Job.getInstance(), recordWriter, null, new Configuration());
+
+ hadoopOutputFormat.writeRecord(new Tuple2<String, Long>());
+
+ verify(recordWriter, times(1)).write(anyString(), anyLong());
+ }
+
+ @Test
+ public void testOpen() throws Exception {
+
+
+ OutputFormat<String, Long> dummyOutputFormat = mock(DummyOutputFormat.class);
+ OutputCommitter outputCommitter = setupOutputCommitter(true);
+ when(dummyOutputFormat.getOutputCommitter(any(TaskAttemptContext.class))).thenReturn(outputCommitter);
+
+ HadoopOutputFormat<String, Long> hadoopOutputFormat = setupHadoopOutputFormat(dummyOutputFormat,
+ Job.getInstance(), new DummyRecordWriter(), setupOutputCommitter(true), new Configuration());
+
+ hadoopOutputFormat.open(1, 4);
+
+ verify(hadoopOutputFormat.outputCommitter, times(1)).setupJob(any(JobContext.class));
+ verify(hadoopOutputFormat.mapreduceOutputFormat, times(1)).getRecordWriter(any(TaskAttemptContext.class));
+ }
+
+ @Test
+ public void testCloseWithNeedsTaskCommitTrue() throws Exception {
+
+ RecordWriter<String, Long> recordWriter = Mockito.mock(DummyRecordWriter.class);
+ OutputCommitter outputCommitter = setupOutputCommitter(true);
+
+ HadoopOutputFormat<String, Long> hadoopOutputFormat = setupHadoopOutputFormat(new DummyOutputFormat(),
+ Job.getInstance(), recordWriter, outputCommitter, new Configuration());
+
+ hadoopOutputFormat.close();
+
+ verify(outputCommitter, times(1)).commitTask(any(TaskAttemptContext.class));
+ verify(recordWriter, times(1)).close(any(TaskAttemptContext.class));
+ }
+
+ @Test
+ public void testCloseWithNeedsTaskCommitFalse() throws Exception {
+
+ RecordWriter<String, Long> recordWriter = Mockito.mock(DummyRecordWriter.class);
+ OutputCommitter outputCommitter = setupOutputCommitter(false);
+
+ HadoopOutputFormat<String, Long> hadoopOutputFormat = setupHadoopOutputFormat(new DummyOutputFormat(),
+ Job.getInstance(), recordWriter, outputCommitter, new Configuration());
+
+ hadoopOutputFormat.close();
+
+ verify(outputCommitter, times(0)).commitTask(any(TaskAttemptContext.class));
+ verify(recordWriter, times(1)).close(any(TaskAttemptContext.class));
+ }
+
+ @Test
+ public void testConfigure() throws Exception {
+
+ ConfigurableDummyOutputFormat outputFormat = mock(ConfigurableDummyOutputFormat.class);
+
+ HadoopOutputFormat<String, Long> hadoopOutputFormat = setupHadoopOutputFormat(outputFormat, Job.getInstance(),
+ null, null, new Configuration());
+
+ hadoopOutputFormat.configure(new org.apache.flink.configuration.Configuration());
+
+ verify(outputFormat, times(1)).setConf(any(Configuration.class));
+ }
+
+ @Test
+ public void testFinalizedGlobal() throws Exception {
+
+ HadoopOutputFormat<String, Long> hadoopOutputFormat = setupHadoopOutputFormat(new DummyOutputFormat(),
+ Job.getInstance(), null, null, new Configuration());
+
+ hadoopOutputFormat.finalizeGlobal(1);
+
+ verify(hadoopOutputFormat.outputCommitter, times(1)).commitJob(any(JobContext.class));
+ }
+
+ private OutputCommitter setupOutputCommitter(boolean needsTaskCommit) throws IOException {
+ OutputCommitter outputCommitter = Mockito.mock(OutputCommitter.class);
+ when(outputCommitter.needsTaskCommit(any(TaskAttemptContext.class))).thenReturn(needsTaskCommit);
+ doNothing().when(outputCommitter).commitTask(any(TaskAttemptContext.class));
+
+ return outputCommitter;
+ }
+
+ private HadoopOutputFormat<String, Long> setupHadoopOutputFormat(OutputFormat<String, Long> outputFormat,
+ Job job,
+ RecordWriter<String, Long> recordWriter,
+ OutputCommitter outputCommitter,
+ Configuration configuration) {
+
+ HadoopOutputFormat<String, Long> hadoopOutputFormat = new HadoopOutputFormat<>(outputFormat, job);
+ hadoopOutputFormat.recordWriter = recordWriter;
+ hadoopOutputFormat.outputCommitter = outputCommitter;
+ hadoopOutputFormat.configuration = configuration;
+ hadoopOutputFormat.configuration.set(MAPRED_OUTPUT_DIR_KEY, MAPRED_OUTPUT_PATH);
+
+ return hadoopOutputFormat;
+ }
+
+ class DummyRecordWriter extends RecordWriter<String, Long> {
+ @Override
+ public void write(String key, Long value) throws IOException, InterruptedException {
+ }
+
+ @Override
+ public void close(TaskAttemptContext context) throws IOException, InterruptedException {
+
+ }
+ }
+
+ class DummyOutputFormat extends OutputFormat<String, Long> {
+ @Override
+ public RecordWriter<String, Long> getRecordWriter(TaskAttemptContext context) throws IOException, InterruptedException {
+ return null;
+ }
+
+ @Override
+ public void checkOutputSpecs(JobContext context) throws IOException, InterruptedException {
+
+ }
+
+ @Override
+ public OutputCommitter getOutputCommitter(TaskAttemptContext context) throws IOException, InterruptedException {
+ final OutputCommitter outputCommitter = Mockito.mock(OutputCommitter.class);
+ doNothing().when(outputCommitter).setupJob(any(JobContext.class));
+
+ return outputCommitter;
+ }
+ }
+
+ class ConfigurableDummyOutputFormat extends DummyOutputFormat implements Configurable {
+
+ @Override
+ public void setConf(Configuration configuration) {}
+
+ @Override
+ public Configuration getConf() {
+ return null;
+ }
+ }
}
[2/4] flink git commit: [FLINK-2445] Add tests for HadoopOutputFormats
Posted by fh...@apache.org.
[FLINK-2445] Add tests for HadoopOutputFormats
This closes #1486
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/8e4a001b
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/8e4a001b
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/8e4a001b
Branch: refs/heads/master
Commit: 8e4a001b84c36827eb6168adac2724f76e30cc2c
Parents: f7a3c81
Author: Ajay Bhat <a....@gmail.com>
Authored: Wed Jan 6 16:12:03 2016 +0530
Committer: Fabian Hueske <fh...@apache.org>
Committed: Wed Mar 23 15:31:42 2016 +0100
----------------------------------------------------------------------
.../mapreduce/HadoopOutputFormatTest.java | 130 +++++++++++++++++++
1 file changed, 130 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/8e4a001b/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopOutputFormatTest.java
----------------------------------------------------------------------
diff --git a/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopOutputFormatTest.java b/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopOutputFormatTest.java
new file mode 100644
index 0000000..215ca95
--- /dev/null
+++ b/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopOutputFormatTest.java
@@ -0,0 +1,130 @@
+/*
+ * 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.hadoop.mapreduce;
+
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.mapreduce.*;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+public class HadoopOutputFormatTest {
+
+ private static final String PATH = "an/ignored/file/";
+ private Map<String, Long> map;
+
+ @Test
+ public void testWriteRecord() {
+ OutputFormat<String, Long> dummyOutputFormat = new DummyOutputFormat();
+ String key = "Test";
+ Long value = 1L;
+ map = new HashMap<>();
+ map.put(key, 0L);
+ try {
+ Job job = Job.getInstance();
+ Tuple2<String, Long> tuple = new Tuple2<>();
+ tuple.setFields(key, value);
+ HadoopOutputFormat<String, Long> hadoopOutputFormat = new HadoopOutputFormat<>(dummyOutputFormat, job);
+
+ hadoopOutputFormat.recordWriter = new DummyRecordWriter();
+ hadoopOutputFormat.writeRecord(tuple);
+
+ Long expected = map.get(key);
+ assertEquals(expected, value);
+ } catch (IOException e) {
+ fail();
+ }
+ }
+
+ @Test
+ public void testOpen() {
+ OutputFormat<String, Long> dummyOutputFormat = new DummyOutputFormat();
+ try {
+ Job job = Job.getInstance();
+ HadoopOutputFormat<String, Long> hadoopOutputFormat = new HadoopOutputFormat<>(dummyOutputFormat, job);
+
+ hadoopOutputFormat.recordWriter = new DummyRecordWriter();
+ hadoopOutputFormat.open(1, 4);
+ } catch (IOException e) {
+ fail();
+ }
+ }
+
+ @Test
+ public void testClose() {
+ OutputFormat<String, Long> dummyOutputFormat = new DummyOutputFormat();
+ try {
+ Job job = Job.getInstance();
+ HadoopOutputFormat<String, Long> hadoopOutputFormat = new HadoopOutputFormat<>(dummyOutputFormat, job);
+
+ hadoopOutputFormat.recordWriter = new DummyRecordWriter();
+
+ final OutputCommitter outputCommitter = Mockito.mock(OutputCommitter.class);
+ Mockito.when(outputCommitter.needsTaskCommit(Mockito.any(TaskAttemptContext.class))).thenReturn(true);
+ Mockito.doNothing().when(outputCommitter).commitTask(Mockito.any(TaskAttemptContext.class));
+ hadoopOutputFormat.outputCommitter = outputCommitter;
+ hadoopOutputFormat.configuration = new Configuration();
+ hadoopOutputFormat.configuration.set("mapred.output.dir", PATH);
+
+ hadoopOutputFormat.close();
+ } catch (IOException e) {
+ fail();
+ }
+ }
+
+
+ class DummyRecordWriter extends RecordWriter<String, Long> {
+ @Override
+ public void write(String key, Long value) throws IOException, InterruptedException {
+ map.put(key, value);
+ }
+
+ @Override
+ public void close(TaskAttemptContext context) throws IOException, InterruptedException {
+
+ }
+ }
+
+ class DummyOutputFormat extends OutputFormat<String, Long> {
+ @Override
+ public RecordWriter<String, Long> getRecordWriter(TaskAttemptContext context) throws IOException, InterruptedException {
+ return null;
+ }
+
+ @Override
+ public void checkOutputSpecs(JobContext context) throws IOException, InterruptedException {
+
+ }
+
+ @Override
+ public OutputCommitter getOutputCommitter(TaskAttemptContext context) throws IOException, InterruptedException {
+ final OutputCommitter outputCommitter = Mockito.mock(OutputCommitter.class);
+ Mockito.doNothing().when(outputCommitter).setupJob(Mockito.any(JobContext.class));
+
+ return outputCommitter;
+ }
+ }
+}
[4/4] flink git commit: [FLINK-2997] [dataSet] Add support for range
partitioning with custom data distribution.
Posted by fh...@apache.org.
[FLINK-2997] [dataSet] Add support for range partitioning with custom data distribution.
This closes #1776
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/b8299bf9
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/b8299bf9
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/b8299bf9
Branch: refs/heads/master
Commit: b8299bf92d8e3dbe140dd89602699394019b783d
Parents: a6c3778
Author: gallenvara <ga...@126.com>
Authored: Thu Jan 28 01:34:10 2016 +0800
Committer: Fabian Hueske <fh...@apache.org>
Committed: Wed Mar 23 15:32:13 2016 +0100
----------------------------------------------------------------------
.../common/distributions/DataDistribution.java | 7 +
.../apache/flink/api/common/operators/Keys.java | 6 +-
.../operators/base/PartitionOperatorBase.java | 11 +
.../api/java/operators/PartitionOperator.java | 38 ++-
.../flink/api/java/utils/DataSetUtils.java | 33 +++
.../flink/optimizer/dag/PartitionNode.java | 9 +-
.../dataproperties/GlobalProperties.java | 31 ++-
.../apache/flink/optimizer/plan/Channel.java | 2 +-
.../traversals/RangePartitionRewriter.java | 16 +-
.../dataproperties/MockDistribution.java | 7 +
.../apache/flink/api/scala/utils/package.scala | 60 +++++
.../CustomDistributionITCase.java | 266 +++++++++++++++++++
12 files changed, 460 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/b8299bf9/flink-core/src/main/java/org/apache/flink/api/common/distributions/DataDistribution.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/distributions/DataDistribution.java b/flink-core/src/main/java/org/apache/flink/api/common/distributions/DataDistribution.java
index 321948d..c0794d6 100644
--- a/flink-core/src/main/java/org/apache/flink/api/common/distributions/DataDistribution.java
+++ b/flink-core/src/main/java/org/apache/flink/api/common/distributions/DataDistribution.java
@@ -22,6 +22,7 @@ package org.apache.flink.api.common.distributions;
import java.io.Serializable;
import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.core.io.IOReadableWritable;
@PublicEvolving
@@ -57,4 +58,10 @@ public interface DataDistribution extends IOReadableWritable, Serializable {
* @return The number of fields in the (composite) key.
*/
int getNumberOfFields();
+
+ /**
+ * Gets the type of the key by which the dataSet is partitioned.
+ * @return The type of the key by which the dataSet is partitioned.
+ */
+ TypeInformation[] getKeyTypes();
}
http://git-wip-us.apache.org/repos/asf/flink/blob/b8299bf9/flink-core/src/main/java/org/apache/flink/api/common/operators/Keys.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/operators/Keys.java b/flink-core/src/main/java/org/apache/flink/api/common/operators/Keys.java
index ad21c47..abe41af 100644
--- a/flink-core/src/main/java/org/apache/flink/api/common/operators/Keys.java
+++ b/flink-core/src/main/java/org/apache/flink/api/common/operators/Keys.java
@@ -42,7 +42,7 @@ public abstract class Keys<T> {
public abstract int[] computeLogicalKeyPositions();
- protected abstract TypeInformation<?>[] getKeyFieldTypes();
+ public abstract TypeInformation<?>[] getKeyFieldTypes();
public abstract <E> void validateCustomPartitioner(Partitioner<E> partitioner, TypeInformation<E> typeInfo);
@@ -134,7 +134,7 @@ public abstract class Keys<T> {
}
@Override
- protected TypeInformation<?>[] getKeyFieldTypes() {
+ public TypeInformation<?>[] getKeyFieldTypes() {
TypeInformation<?>[] fieldTypes = new TypeInformation[keyFields.size()];
for (int i = 0; i < keyFields.size(); i++) {
fieldTypes[i] = keyFields.get(i).getType();
@@ -337,7 +337,7 @@ public abstract class Keys<T> {
}
@Override
- protected TypeInformation<?>[] getKeyFieldTypes() {
+ public TypeInformation<?>[] getKeyFieldTypes() {
TypeInformation<?>[] fieldTypes = new TypeInformation[keyFields.size()];
for (int i = 0; i < keyFields.size(); i++) {
fieldTypes[i] = keyFields.get(i).getType();
http://git-wip-us.apache.org/repos/asf/flink/blob/b8299bf9/flink-core/src/main/java/org/apache/flink/api/common/operators/base/PartitionOperatorBase.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/operators/base/PartitionOperatorBase.java b/flink-core/src/main/java/org/apache/flink/api/common/operators/base/PartitionOperatorBase.java
index fd71fac..4b802aa 100644
--- a/flink-core/src/main/java/org/apache/flink/api/common/operators/base/PartitionOperatorBase.java
+++ b/flink-core/src/main/java/org/apache/flink/api/common/operators/base/PartitionOperatorBase.java
@@ -22,6 +22,7 @@ import java.util.List;
import org.apache.flink.annotation.Internal;
import org.apache.flink.api.common.ExecutionConfig;
+import org.apache.flink.api.common.distributions.DataDistribution;
import org.apache.flink.api.common.functions.Partitioner;
import org.apache.flink.api.common.functions.RuntimeContext;
import org.apache.flink.api.common.functions.util.NoOpFunction;
@@ -49,6 +50,8 @@ public class PartitionOperatorBase<IN> extends SingleInputOperator<IN, IN, NoOpF
private Partitioner<?> customPartitioner;
+ private DataDistribution distribution;
+
public PartitionOperatorBase(UnaryOperatorInformation<IN, IN> operatorInfo, PartitionMethod pMethod, int[] keys, String name) {
super(new UserCodeObjectWrapper<NoOpFunction>(new NoOpFunction()), operatorInfo, keys, name);
@@ -70,6 +73,14 @@ public class PartitionOperatorBase<IN> extends SingleInputOperator<IN, IN, NoOpF
return customPartitioner;
}
+ public DataDistribution getDistribution() {
+ return this.distribution;
+ }
+
+ public void setDistribution(DataDistribution distribution) {
+ this.distribution = distribution;
+ }
+
public void setCustomPartitioner(Partitioner<?> customPartitioner) {
if (customPartitioner != null) {
int[] keys = getKeyColumns(0);
http://git-wip-us.apache.org/repos/asf/flink/blob/b8299bf9/flink-java/src/main/java/org/apache/flink/api/java/operators/PartitionOperator.java
----------------------------------------------------------------------
diff --git a/flink-java/src/main/java/org/apache/flink/api/java/operators/PartitionOperator.java b/flink-java/src/main/java/org/apache/flink/api/java/operators/PartitionOperator.java
index b2b9f6e..dc4a018 100644
--- a/flink-java/src/main/java/org/apache/flink/api/java/operators/PartitionOperator.java
+++ b/flink-java/src/main/java/org/apache/flink/api/java/operators/PartitionOperator.java
@@ -22,6 +22,7 @@ import com.google.common.base.Preconditions;
import org.apache.flink.annotation.Internal;
import org.apache.flink.annotation.Public;
+import org.apache.flink.api.common.distributions.DataDistribution;
import org.apache.flink.api.common.functions.Partitioner;
import org.apache.flink.api.common.operators.Keys;
import org.apache.flink.api.common.operators.Operator;
@@ -33,6 +34,8 @@ import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.common.operators.Keys.SelectorFunctionKeys;
import org.apache.flink.api.java.tuple.Tuple2;
+import java.util.Arrays;
+
/**
* This operator represents a partitioning.
*
@@ -45,35 +48,46 @@ public class PartitionOperator<T> extends SingleInputOperator<T, T, PartitionOpe
private final PartitionMethod pMethod;
private final String partitionLocationName;
private final Partitioner<?> customPartitioner;
-
-
+ private final DataDistribution distribution;
+
+
public PartitionOperator(DataSet<T> input, PartitionMethod pMethod, Keys<T> pKeys, String partitionLocationName) {
- this(input, pMethod, pKeys, null, null, partitionLocationName);
+ this(input, pMethod, pKeys, null, null, null, partitionLocationName);
}
-
+
+ public PartitionOperator(DataSet<T> input, PartitionMethod pMethod, Keys<T> pKeys, DataDistribution distribution, String partitionLocationName) {
+ this(input, pMethod, pKeys, null, null, distribution, partitionLocationName);
+ }
+
public PartitionOperator(DataSet<T> input, PartitionMethod pMethod, String partitionLocationName) {
- this(input, pMethod, null, null, null, partitionLocationName);
+ this(input, pMethod, null, null, null, null, partitionLocationName);
}
public PartitionOperator(DataSet<T> input, Keys<T> pKeys, Partitioner<?> customPartitioner, String partitionLocationName) {
- this(input, PartitionMethod.CUSTOM, pKeys, customPartitioner, null, partitionLocationName);
+ this(input, PartitionMethod.CUSTOM, pKeys, customPartitioner, null, null, partitionLocationName);
}
- public <P> PartitionOperator(DataSet<T> input, Keys<T> pKeys, Partitioner<P> customPartitioner,
+ public <P> PartitionOperator(DataSet<T> input, Keys<T> pKeys, Partitioner<P> customPartitioner,
TypeInformation<P> partitionerTypeInfo, String partitionLocationName)
{
- this(input, PartitionMethod.CUSTOM, pKeys, customPartitioner, partitionerTypeInfo, partitionLocationName);
+ this(input, PartitionMethod.CUSTOM, pKeys, customPartitioner, partitionerTypeInfo, null, partitionLocationName);
}
- private <P> PartitionOperator(DataSet<T> input, PartitionMethod pMethod, Keys<T> pKeys, Partitioner<P> customPartitioner,
- TypeInformation<P> partitionerTypeInfo, String partitionLocationName)
+ private <P> PartitionOperator(DataSet<T> input, PartitionMethod pMethod, Keys<T> pKeys, Partitioner<P> customPartitioner,
+ TypeInformation<P> partitionerTypeInfo, DataDistribution distribution, String partitionLocationName)
{
super(input, input.getType());
Preconditions.checkNotNull(pMethod);
Preconditions.checkArgument(pKeys != null || pMethod == PartitionMethod.REBALANCE, "Partitioning requires keys");
Preconditions.checkArgument(pMethod != PartitionMethod.CUSTOM || customPartitioner != null, "Custom partioning requires a partitioner.");
-
+ Preconditions.checkArgument(distribution == null || pMethod == PartitionMethod.RANGE, "Customized data distribution is only neccessary for range partition.");
+
+ if (distribution != null) {
+ Preconditions.checkArgument(distribution.getNumberOfFields() == pKeys.getNumberOfKeyFields(), "The number of key fields in the distribution and range partitioner should be the same.");
+ Preconditions.checkArgument(Arrays.equals(distribution.getKeyTypes(), pKeys.getKeyFieldTypes()), "The types of key from the distribution and range partitioner are not equal.");
+ }
+
if (customPartitioner != null) {
pKeys.validateCustomPartitioner(customPartitioner, partitionerTypeInfo);
}
@@ -82,6 +96,7 @@ public class PartitionOperator<T> extends SingleInputOperator<T, T, PartitionOpe
this.pKeys = pKeys;
this.partitionLocationName = partitionLocationName;
this.customPartitioner = customPartitioner;
+ this.distribution = distribution;
}
// --------------------------------------------------------------------------------------------
@@ -125,6 +140,7 @@ public class PartitionOperator<T> extends SingleInputOperator<T, T, PartitionOpe
PartitionOperatorBase<T> partitionedInput = new PartitionOperatorBase<>(operatorInfo, pMethod, logicalKeyPositions, name);
partitionedInput.setInput(input);
partitionedInput.setParallelism(getParallelism());
+ partitionedInput.setDistribution(distribution);
partitionedInput.setCustomPartitioner(customPartitioner);
return partitionedInput;
http://git-wip-us.apache.org/repos/asf/flink/blob/b8299bf9/flink-java/src/main/java/org/apache/flink/api/java/utils/DataSetUtils.java
----------------------------------------------------------------------
diff --git a/flink-java/src/main/java/org/apache/flink/api/java/utils/DataSetUtils.java b/flink-java/src/main/java/org/apache/flink/api/java/utils/DataSetUtils.java
index 78e5231..61a71aa 100644
--- a/flink-java/src/main/java/org/apache/flink/api/java/utils/DataSetUtils.java
+++ b/flink-java/src/main/java/org/apache/flink/api/java/utils/DataSetUtils.java
@@ -21,16 +21,23 @@ package org.apache.flink.api.java.utils;
import com.google.common.collect.Lists;
import org.apache.flink.annotation.PublicEvolving;
import org.apache.flink.api.common.JobExecutionResult;
+import org.apache.flink.api.common.distributions.DataDistribution;
import org.apache.flink.api.common.functions.BroadcastVariableInitializer;
import org.apache.flink.api.common.functions.RichMapPartitionFunction;
+import org.apache.flink.api.common.operators.Keys;
+import org.apache.flink.api.common.operators.base.PartitionOperatorBase;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.java.Utils;
+import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.api.java.functions.SampleInCoordinator;
import org.apache.flink.api.java.functions.SampleInPartition;
import org.apache.flink.api.java.functions.SampleWithFraction;
import org.apache.flink.api.java.operators.GroupReduceOperator;
import org.apache.flink.api.java.operators.MapPartitionOperator;
+import org.apache.flink.api.java.operators.PartitionOperator;
import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.api.java.typeutils.TypeExtractor;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.util.AbstractID;
import org.apache.flink.util.Collector;
@@ -251,6 +258,32 @@ public final class DataSetUtils {
}
// --------------------------------------------------------------------------------------------
+ // Partition
+ // --------------------------------------------------------------------------------------------
+
+ /**
+ * Range-partitions a DataSet on the specified tuple field positions.
+ */
+ public static <T> PartitionOperator<T> partitionByRange(DataSet<T> input, DataDistribution distribution, int... fields) {
+ return new PartitionOperator<>(input, PartitionOperatorBase.PartitionMethod.RANGE, new Keys.ExpressionKeys<>(fields, input.getType(), false), distribution, Utils.getCallLocationName());
+ }
+
+ /**
+ * Range-partitions a DataSet on the specified fields.
+ */
+ public static <T> PartitionOperator<T> partitionByRange(DataSet<T> input, DataDistribution distribution, String... fields) {
+ return new PartitionOperator<>(input, PartitionOperatorBase.PartitionMethod.RANGE, new Keys.ExpressionKeys<>(fields, input.getType()), distribution, Utils.getCallLocationName());
+ }
+
+ /**
+ * Range-partitions a DataSet using the specified key selector function.
+ */
+ public static <T, K extends Comparable<K>> PartitionOperator<T> partitionByRange(DataSet<T> input, DataDistribution distribution, KeySelector<T, K> keyExtractor) {
+ final TypeInformation<K> keyType = TypeExtractor.getKeySelectorTypes(keyExtractor, input.getType());
+ return new PartitionOperator<>(input, PartitionOperatorBase.PartitionMethod.RANGE, new Keys.SelectorFunctionKeys<>(input.clean(keyExtractor), input.getType(), keyType), distribution, Utils.getCallLocationName());
+ }
+
+ // --------------------------------------------------------------------------------------------
// Checksum
// --------------------------------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/b8299bf9/flink-optimizer/src/main/java/org/apache/flink/optimizer/dag/PartitionNode.java
----------------------------------------------------------------------
diff --git a/flink-optimizer/src/main/java/org/apache/flink/optimizer/dag/PartitionNode.java b/flink-optimizer/src/main/java/org/apache/flink/optimizer/dag/PartitionNode.java
index 65a6e02..9ecea6b 100644
--- a/flink-optimizer/src/main/java/org/apache/flink/optimizer/dag/PartitionNode.java
+++ b/flink-optimizer/src/main/java/org/apache/flink/optimizer/dag/PartitionNode.java
@@ -22,6 +22,7 @@ package org.apache.flink.optimizer.dag;
import java.util.Collections;
import java.util.List;
+import org.apache.flink.api.common.distributions.DataDistribution;
import org.apache.flink.api.common.functions.Partitioner;
import org.apache.flink.api.common.operators.Order;
import org.apache.flink.api.common.operators.Ordering;
@@ -51,7 +52,7 @@ public class PartitionNode extends SingleInputNode {
super(operator);
OperatorDescriptorSingle descr = new PartitionDescriptor(
- this.getOperator().getPartitionMethod(), this.keys, operator.getCustomPartitioner());
+ this.getOperator().getPartitionMethod(), this.keys, operator.getCustomPartitioner(), operator.getDistribution());
this.possibleProperties = Collections.singletonList(descr);
}
@@ -88,12 +89,14 @@ public class PartitionNode extends SingleInputNode {
private final PartitionMethod pMethod;
private final Partitioner<?> customPartitioner;
+ private final DataDistribution distribution;
- public PartitionDescriptor(PartitionMethod pMethod, FieldSet pKeys, Partitioner<?> customPartitioner) {
+ public PartitionDescriptor(PartitionMethod pMethod, FieldSet pKeys, Partitioner<?> customPartitioner, DataDistribution distribution) {
super(pKeys);
this.pMethod = pMethod;
this.customPartitioner = customPartitioner;
+ this.distribution = distribution;
}
@Override
@@ -127,7 +130,7 @@ public class PartitionNode extends SingleInputNode {
for (int field : this.keys) {
ordering.appendOrdering(field, null, Order.ASCENDING);
}
- rgps.setRangePartitioned(ordering);
+ rgps.setRangePartitioned(ordering, distribution);
break;
default:
throw new IllegalArgumentException("Invalid partition method");
http://git-wip-us.apache.org/repos/asf/flink/blob/b8299bf9/flink-optimizer/src/main/java/org/apache/flink/optimizer/dataproperties/GlobalProperties.java
----------------------------------------------------------------------
diff --git a/flink-optimizer/src/main/java/org/apache/flink/optimizer/dataproperties/GlobalProperties.java b/flink-optimizer/src/main/java/org/apache/flink/optimizer/dataproperties/GlobalProperties.java
index 57ba29d..ca17c2b 100644
--- a/flink-optimizer/src/main/java/org/apache/flink/optimizer/dataproperties/GlobalProperties.java
+++ b/flink-optimizer/src/main/java/org/apache/flink/optimizer/dataproperties/GlobalProperties.java
@@ -22,6 +22,7 @@ import java.util.HashSet;
import java.util.Set;
import org.apache.flink.api.common.ExecutionMode;
+import org.apache.flink.api.common.distributions.DataDistribution;
import org.apache.flink.api.common.functions.Partitioner;
import org.apache.flink.api.common.operators.Order;
import org.apache.flink.api.common.operators.Ordering;
@@ -55,6 +56,8 @@ public class GlobalProperties implements Cloneable {
private Partitioner<?> customPartitioner;
+ private DataDistribution distribution;
+
// --------------------------------------------------------------------------------------------
/**
@@ -80,16 +83,38 @@ public class GlobalProperties implements Cloneable {
this.partitioningFields = partitionedFields;
this.ordering = null;
}
-
+ /**
+ * Set the parameters for range partition.
+ *
+ * @param ordering Order of the partitioned fields
+ */
public void setRangePartitioned(Ordering ordering) {
if (ordering == null) {
throw new NullPointerException();
}
+
+ this.partitioning = PartitioningProperty.RANGE_PARTITIONED;
+ this.ordering = ordering;
+ this.partitioningFields = ordering.getInvolvedIndexes();
+ }
+
+ /**
+ * Set the parameters for range partition.
+ *
+ * @param ordering Order of the partitioned fields
+ * @param distribution The data distribution for range partition. User can supply a customized data distribution,
+ * also the data distribution can be null.
+ */
+ public void setRangePartitioned(Ordering ordering, DataDistribution distribution) {
+ if (ordering == null) {
+ throw new NullPointerException();
+ }
this.partitioning = PartitioningProperty.RANGE_PARTITIONED;
this.ordering = ordering;
this.partitioningFields = ordering.getInvolvedIndexes();
+ this.distribution = distribution;
}
public void setAnyPartitioning(FieldList partitionedFields) {
@@ -167,6 +192,10 @@ public class GlobalProperties implements Cloneable {
return this.customPartitioner;
}
+ public DataDistribution getDataDistribution() {
+ return this.distribution;
+ }
+
// --------------------------------------------------------------------------------------------
public boolean isPartitionedOnFields(FieldSet fields) {
http://git-wip-us.apache.org/repos/asf/flink/blob/b8299bf9/flink-optimizer/src/main/java/org/apache/flink/optimizer/plan/Channel.java
----------------------------------------------------------------------
diff --git a/flink-optimizer/src/main/java/org/apache/flink/optimizer/plan/Channel.java b/flink-optimizer/src/main/java/org/apache/flink/optimizer/plan/Channel.java
index 508cc95..bd2a594 100644
--- a/flink-optimizer/src/main/java/org/apache/flink/optimizer/plan/Channel.java
+++ b/flink-optimizer/src/main/java/org/apache/flink/optimizer/plan/Channel.java
@@ -427,7 +427,7 @@ public class Channel implements EstimateProvider, Cloneable, DumpableConnection<
this.globalProps.setHashPartitioned(this.shipKeys);
break;
case PARTITION_RANGE:
- this.globalProps.setRangePartitioned(Utils.createOrdering(this.shipKeys, this.shipSortOrder));
+ this.globalProps.setRangePartitioned(Utils.createOrdering(this.shipKeys, this.shipSortOrder), this.dataDistribution);
break;
case FORWARD:
break;
http://git-wip-us.apache.org/repos/asf/flink/blob/b8299bf9/flink-optimizer/src/main/java/org/apache/flink/optimizer/traversals/RangePartitionRewriter.java
----------------------------------------------------------------------
diff --git a/flink-optimizer/src/main/java/org/apache/flink/optimizer/traversals/RangePartitionRewriter.java b/flink-optimizer/src/main/java/org/apache/flink/optimizer/traversals/RangePartitionRewriter.java
index 7656dfd..b1c5dae 100644
--- a/flink-optimizer/src/main/java/org/apache/flink/optimizer/traversals/RangePartitionRewriter.java
+++ b/flink-optimizer/src/main/java/org/apache/flink/optimizer/traversals/RangePartitionRewriter.java
@@ -109,14 +109,16 @@ public class RangePartitionRewriter implements Visitor<PlanNode> {
// Make sure we only optimize the DAG for range partition, and do not optimize multi times.
if (shipStrategy == ShipStrategyType.PARTITION_RANGE) {
- if(node.isOnDynamicPath()) {
- throw new InvalidProgramException("Range Partitioning not supported within iterations.");
+ if(channel.getDataDistribution() == null) {
+ if (node.isOnDynamicPath()) {
+ throw new InvalidProgramException("Range Partitioning not supported within iterations if users do not supply the data distribution.");
+ }
+
+ PlanNode channelSource = channel.getSource();
+ List<Channel> newSourceOutputChannels = rewriteRangePartitionChannel(channel);
+ channelSource.getOutgoingChannels().remove(channel);
+ channelSource.getOutgoingChannels().addAll(newSourceOutputChannels);
}
-
- PlanNode channelSource = channel.getSource();
- List<Channel> newSourceOutputChannels = rewriteRangePartitionChannel(channel);
- channelSource.getOutgoingChannels().remove(channel);
- channelSource.getOutgoingChannels().addAll(newSourceOutputChannels);
}
}
}
http://git-wip-us.apache.org/repos/asf/flink/blob/b8299bf9/flink-optimizer/src/test/java/org/apache/flink/optimizer/dataproperties/MockDistribution.java
----------------------------------------------------------------------
diff --git a/flink-optimizer/src/test/java/org/apache/flink/optimizer/dataproperties/MockDistribution.java b/flink-optimizer/src/test/java/org/apache/flink/optimizer/dataproperties/MockDistribution.java
index 483bc51..a35f0d0 100644
--- a/flink-optimizer/src/test/java/org/apache/flink/optimizer/dataproperties/MockDistribution.java
+++ b/flink-optimizer/src/test/java/org/apache/flink/optimizer/dataproperties/MockDistribution.java
@@ -19,6 +19,8 @@
package org.apache.flink.optimizer.dataproperties;
import org.apache.flink.api.common.distributions.DataDistribution;
+import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.core.memory.DataInputView;
import org.apache.flink.core.memory.DataOutputView;
@@ -38,6 +40,11 @@ public class MockDistribution implements DataDistribution {
}
@Override
+ public TypeInformation[] getKeyTypes() {
+ return new TypeInformation[]{BasicTypeInfo.INT_TYPE_INFO};
+ }
+
+ @Override
public void write(DataOutputView out) throws IOException {
}
http://git-wip-us.apache.org/repos/asf/flink/blob/b8299bf9/flink-scala/src/main/scala/org/apache/flink/api/scala/utils/package.scala
----------------------------------------------------------------------
diff --git a/flink-scala/src/main/scala/org/apache/flink/api/scala/utils/package.scala b/flink-scala/src/main/scala/org/apache/flink/api/scala/utils/package.scala
index 6407093..adad9ab 100644
--- a/flink-scala/src/main/scala/org/apache/flink/api/scala/utils/package.scala
+++ b/flink-scala/src/main/scala/org/apache/flink/api/scala/utils/package.scala
@@ -19,9 +19,16 @@
package org.apache.flink.api.scala
import org.apache.flink.annotation.PublicEvolving
+import org.apache.flink.api.common.distributions.DataDistribution
+import org.apache.flink.api.common.operators.Keys
+import org.apache.flink.api.common.operators.base.PartitionOperatorBase
+import org.apache.flink.api.common.operators.base.PartitionOperatorBase.PartitionMethod
import org.apache.flink.api.common.typeinfo.{BasicTypeInfo, TypeInformation}
import org.apache.flink.api.java.Utils
import org.apache.flink.api.java.Utils.ChecksumHashCode
+import org.apache.flink.api.java.functions.KeySelector
+import org.apache.flink.api.java.operators.PartitionOperator
+import org.apache.flink.api.java.typeutils.TypeExtractor
import org.apache.flink.api.java.utils.{DataSetUtils => jutils}
import org.apache.flink.util.AbstractID
@@ -110,6 +117,59 @@ package object utils {
}
// --------------------------------------------------------------------------------------------
+ // Partitioning
+ // --------------------------------------------------------------------------------------------
+
+ /**
+ * Range-partitions a DataSet on the specified tuple field positions.
+ */
+ def partitionByRange(distribution: DataDistribution, fields: Int*): DataSet[T] = {
+ val op = new PartitionOperator[T](
+ self.javaSet,
+ PartitionMethod.RANGE,
+ new Keys.ExpressionKeys[T](fields.toArray, self.javaSet.getType),
+ distribution,
+ getCallLocationName())
+ wrap(op)
+ }
+
+ /**
+ * Range-partitions a DataSet on the specified fields.
+ */
+ def partitionByRange(distribution: DataDistribution,
+ firstField: String,
+ otherFields: String*): DataSet[T] = {
+ val op = new PartitionOperator[T](
+ self.javaSet,
+ PartitionMethod.RANGE,
+ new Keys.ExpressionKeys[T](firstField +: otherFields.toArray, self.javaSet.getType),
+ distribution,
+ getCallLocationName())
+ wrap(op)
+ }
+
+ /**
+ * Range-partitions a DataSet using the specified key selector function.
+ */
+ def partitionByRange[K: TypeInformation](distribution: DataDistribution,
+ fun: T => K): DataSet[T] = {
+ val keyExtractor = new KeySelector[T, K] {
+ val cleanFun = self.javaSet.clean(fun)
+ def getKey(in: T) = cleanFun(in)
+ }
+ val op = new PartitionOperator[T](
+ self.javaSet,
+ PartitionMethod.RANGE,
+ new Keys.SelectorFunctionKeys[T, K](
+ keyExtractor,
+ self.javaSet.getType,
+ implicitly[TypeInformation[K]]),
+ distribution,
+ getCallLocationName())
+ wrap(op)
+ }
+
+ // --------------------------------------------------------------------------------------------
// Checksum
// --------------------------------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/b8299bf9/flink-tests/src/test/java/org/apache/flink/test/javaApiOperators/CustomDistributionITCase.java
----------------------------------------------------------------------
diff --git a/flink-tests/src/test/java/org/apache/flink/test/javaApiOperators/CustomDistributionITCase.java b/flink-tests/src/test/java/org/apache/flink/test/javaApiOperators/CustomDistributionITCase.java
new file mode 100644
index 0000000..427e83e
--- /dev/null
+++ b/flink-tests/src/test/java/org/apache/flink/test/javaApiOperators/CustomDistributionITCase.java
@@ -0,0 +1,266 @@
+/*
+ * 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.test.javaApiOperators;
+
+import org.apache.flink.api.common.distributions.DataDistribution;
+import org.apache.flink.api.common.functions.RichMapPartitionFunction;
+import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.java.DataSet;
+import org.apache.flink.api.java.ExecutionEnvironment;
+import org.apache.flink.api.java.io.DiscardingOutputFormat;
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.api.java.utils.DataSetUtils;
+import org.apache.flink.core.memory.DataInputView;
+import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.test.javaApiOperators.util.CollectionDataSets;
+import org.apache.flink.util.Collector;
+import org.junit.Test;
+
+
+import java.io.IOException;
+
+import static org.junit.Assert.fail;
+
+
+public class CustomDistributionITCase {
+
+ @Test
+ public void testPartitionWithDistribution1() throws Exception{
+ /*
+ * Test the record partitioned rightly with one field according to the customized data distribution
+ */
+
+ ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment();
+
+ DataSet<Tuple3<Integer, Long, String>> input1 = CollectionDataSets.get3TupleDataSet(env);
+ final TestDataDist1 dist = new TestDataDist1();
+
+ env.setParallelism(dist.getParallelism());
+
+ DataSet<Boolean> result = DataSetUtils
+ .partitionByRange(input1, dist, 0)
+ .mapPartition(new RichMapPartitionFunction<Tuple3<Integer, Long, String>, Boolean>() {
+
+ @Override
+ public void mapPartition(Iterable<Tuple3<Integer, Long, String>> values, Collector<Boolean> out) throws Exception {
+ int pIdx = getRuntimeContext().getIndexOfThisSubtask();
+
+ for (Tuple3<Integer, Long, String> s : values) {
+ boolean correctlyPartitioned = true;
+ if (pIdx == 0) {
+ Integer[] upper = dist.boundaries[0];
+ if (s.f0.compareTo(upper[0]) > 0) {
+ correctlyPartitioned = false;
+ }
+ }
+ else if (pIdx > 0 && pIdx < dist.getParallelism() - 1) {
+ Integer[] lower = dist.boundaries[pIdx - 1];
+ Integer[] upper = dist.boundaries[pIdx];
+ if (s.f0.compareTo(upper[0]) > 0 || (s.f0.compareTo(lower[0]) <= 0)) {
+ correctlyPartitioned = false;
+ }
+ }
+ else {
+ Integer[] lower = dist.boundaries[pIdx - 1];
+ if ((s.f0.compareTo(lower[0]) <= 0)) {
+ correctlyPartitioned = false;
+ }
+ }
+
+ if (!correctlyPartitioned) {
+ fail("Record was not correctly partitioned: " + s.toString());
+ }
+ }
+ }
+ }
+ );
+
+ result.output(new DiscardingOutputFormat<Boolean>());
+ env.execute();
+ }
+
+ @Test
+ public void testRangeWithDistribution2() throws Exception{
+ /*
+ * Test the record partitioned rightly with two fields according to the customized data distribution
+ */
+
+ ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment();
+
+ DataSet<Tuple3<Integer, Integer, String>> input1 = env.fromElements(
+ new Tuple3<>(1, 5, "Hi"),
+ new Tuple3<>(1, 6, "Hi"),
+ new Tuple3<>(1, 7, "Hi"),
+ new Tuple3<>(1, 11, "Hello"),
+ new Tuple3<>(2, 3, "World"),
+ new Tuple3<>(2, 4, "World"),
+ new Tuple3<>(2, 5, "World"),
+ new Tuple3<>(2, 13, "Hello World"),
+ new Tuple3<>(3, 8, "Say"),
+ new Tuple3<>(4, 0, "Why"),
+ new Tuple3<>(4, 2, "Java"),
+ new Tuple3<>(4, 11, "Say Hello"),
+ new Tuple3<>(5, 1, "Hi Java!"),
+ new Tuple3<>(5, 2, "Hi Java?"),
+ new Tuple3<>(5, 3, "Hi Java again")
+ );
+
+ final TestDataDist2 dist = new TestDataDist2();
+
+ env.setParallelism(dist.getParallelism());
+
+ DataSet<Boolean> result = DataSetUtils
+ .partitionByRange(input1, dist, 0, 1)
+ .mapPartition(new RichMapPartitionFunction<Tuple3<Integer, Integer, String>, Boolean>() {
+
+ @Override
+ public void mapPartition(Iterable<Tuple3<Integer, Integer, String>> values, Collector<Boolean> out) throws Exception {
+ int pIdx = getRuntimeContext().getIndexOfThisSubtask();
+ boolean correctlyPartitioned = true;
+
+ for (Tuple3<Integer, Integer, String> s : values) {
+
+ if (pIdx == 0) {
+ Integer[] upper = dist.boundaries[0];
+ if (s.f0.compareTo(upper[0]) > 0 ||
+ (s.f0.compareTo(upper[0]) == 0 && s.f1.compareTo(upper[1]) > 0)) {
+ correctlyPartitioned = false;
+ }
+ }
+ else if (pIdx > 0 && pIdx < dist.getParallelism() - 1) {
+ Integer[] lower = dist.boundaries[pIdx - 1];
+ Integer[] upper = dist.boundaries[pIdx];
+
+ if (s.f0.compareTo(upper[0]) > 0 ||
+ (s.f0.compareTo(upper[0]) == 0 && s.f1.compareTo(upper[1]) > 0) ||
+ (s.f0.compareTo(lower[0]) < 0) ||
+ (s.f0.compareTo(lower[0]) == 0 && s.f1.compareTo(lower[1]) <= 0)) {
+ correctlyPartitioned = false;
+ }
+ }
+ else {
+ Integer[] lower = dist.boundaries[pIdx - 1];
+ if ((s.f0.compareTo(lower[0]) < 0) ||
+ (s.f0.compareTo(lower[0]) == 0 && s.f1.compareTo(lower[1]) <= 0)) {
+ correctlyPartitioned = false;
+ }
+ }
+
+ if (!correctlyPartitioned) {
+ fail("Record was not correctly partitioned: " + s.toString());
+ }
+ }
+ }
+ }
+ );
+
+ result.output(new DiscardingOutputFormat<Boolean>());
+ env.execute();
+ }
+
+ /**
+ * The class is used to do the tests of range partition with one key.
+ */
+ public static class TestDataDist1 implements DataDistribution {
+
+ public Integer boundaries[][] = new Integer[][]{
+ new Integer[]{4},
+ new Integer[]{9},
+ new Integer[]{13},
+ new Integer[]{18}
+ };
+
+ public TestDataDist1() {}
+
+ public int getParallelism() {
+ return boundaries.length;
+ }
+
+ @Override
+ public Object[] getBucketBoundary(int bucketNum, int totalNumBuckets) {
+ return boundaries[bucketNum];
+ }
+
+ @Override
+ public int getNumberOfFields() {
+ return 1;
+ }
+
+ @Override
+ public TypeInformation[] getKeyTypes() {
+ return new TypeInformation[]{BasicTypeInfo.INT_TYPE_INFO};
+ }
+
+ @Override
+ public void write(DataOutputView out) throws IOException {
+
+ }
+
+ @Override
+ public void read(DataInputView in) throws IOException {
+
+ }
+ }
+
+ /**
+ * The class is used to do the tests of range partition with two keys.
+ */
+ public static class TestDataDist2 implements DataDistribution {
+
+ public Integer boundaries[][] = new Integer[][]{
+ new Integer[]{1, 6},
+ new Integer[]{2, 4},
+ new Integer[]{3, 9},
+ new Integer[]{4, 1},
+ new Integer[]{5, 2}
+ };
+
+ public TestDataDist2() {}
+
+ public int getParallelism() {
+ return boundaries.length;
+ }
+
+ @Override
+ public Object[] getBucketBoundary(int bucketNum, int totalNumBuckets) {
+ return boundaries[bucketNum];
+ }
+
+ @Override
+ public int getNumberOfFields() {
+ return 2;
+ }
+
+ @Override
+ public TypeInformation[] getKeyTypes() {
+ return new TypeInformation[]{BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.INT_TYPE_INFO};
+ }
+
+ @Override
+ public void write(DataOutputView out) throws IOException {
+
+ }
+
+ @Override
+ public void read(DataInputView in) throws IOException {
+
+ }
+ }
+}
[3/4] flink git commit: [FLINK-2444] Add tests for HadoopInputFormats
Posted by fh...@apache.org.
[FLINK-2444] Add tests for HadoopInputFormats
This closes #1628
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/a6c3778f
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/a6c3778f
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/a6c3778f
Branch: refs/heads/master
Commit: a6c3778fd892398d2a6b9c4a02eee1613eda3f42
Parents: bcb34dd
Author: Martin Liesenberg <ma...@gmail.com>
Authored: Fri Feb 12 00:18:06 2016 +0100
Committer: Fabian Hueske <fh...@apache.org>
Committed: Wed Mar 23 15:31:54 2016 +0100
----------------------------------------------------------------------
.../hadoop/mapred/HadoopInputFormatBase.java | 4 +-
.../hadoop/mapreduce/HadoopInputFormat.java | 10 +-
.../hadoop/mapreduce/HadoopInputFormatBase.java | 12 +-
.../hadoop/mapred/HadoopInputFormatTest.java | 275 +++++++++++++++++--
.../hadoop/mapreduce/HadoopInputFormatTest.java | 202 ++++++++++++--
5 files changed, 443 insertions(+), 60 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/a6c3778f/flink-java/src/main/java/org/apache/flink/api/java/hadoop/mapred/HadoopInputFormatBase.java
----------------------------------------------------------------------
diff --git a/flink-java/src/main/java/org/apache/flink/api/java/hadoop/mapred/HadoopInputFormatBase.java b/flink-java/src/main/java/org/apache/flink/api/java/hadoop/mapred/HadoopInputFormatBase.java
index d80c80a..ef9999f 100644
--- a/flink-java/src/main/java/org/apache/flink/api/java/hadoop/mapred/HadoopInputFormatBase.java
+++ b/flink-java/src/main/java/org/apache/flink/api/java/hadoop/mapred/HadoopInputFormatBase.java
@@ -148,7 +148,7 @@ public abstract class HadoopInputFormatBase<K, V, T> extends HadoopInputFormatCo
throws IOException {
org.apache.hadoop.mapred.InputSplit[] splitArray = mapredInputFormat.getSplits(jobConf, minNumSplits);
HadoopInputSplit[] hiSplit = new HadoopInputSplit[splitArray.length];
- for(int i=0;i<splitArray.length;i++){
+ for (int i=0; i<splitArray.length; i++) {
hiSplit[i] = new HadoopInputSplit(i, splitArray[i], jobConf);
}
return hiSplit;
@@ -177,7 +177,7 @@ public abstract class HadoopInputFormatBase<K, V, T> extends HadoopInputFormatCo
@Override
public boolean reachedEnd() throws IOException {
- if(!fetched) {
+ if (!fetched) {
fetchNext();
}
return !hasNext;
http://git-wip-us.apache.org/repos/asf/flink/blob/a6c3778f/flink-java/src/main/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopInputFormat.java
----------------------------------------------------------------------
diff --git a/flink-java/src/main/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopInputFormat.java b/flink-java/src/main/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopInputFormat.java
index dadb954..abbcd25 100644
--- a/flink-java/src/main/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopInputFormat.java
+++ b/flink-java/src/main/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopInputFormat.java
@@ -18,15 +18,15 @@
package org.apache.flink.api.java.hadoop.mapreduce;
-import java.io.IOException;
-
import org.apache.flink.annotation.Public;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.api.java.typeutils.ResultTypeQueryable;
import org.apache.flink.api.java.typeutils.TupleTypeInfo;
-import org.apache.hadoop.mapreduce.Job;
import org.apache.flink.api.java.typeutils.TypeExtractor;
+import org.apache.hadoop.mapreduce.Job;
+
+import java.io.IOException;
/**
* InputFormat implementation allowing to use Hadoop (mapreduce) InputFormats with Flink.
@@ -49,10 +49,10 @@ public class HadoopInputFormat<K, V> extends HadoopInputFormatBase<K, V, Tuple2<
@Override
public Tuple2<K, V> nextRecord(Tuple2<K, V> record) throws IOException {
- if(!this.fetched) {
+ if (!this.fetched) {
fetchNext();
}
- if(!this.hasNext) {
+ if (!this.hasNext) {
return null;
}
try {
http://git-wip-us.apache.org/repos/asf/flink/blob/a6c3778f/flink-java/src/main/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopInputFormatBase.java
----------------------------------------------------------------------
diff --git a/flink-java/src/main/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopInputFormatBase.java b/flink-java/src/main/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopInputFormatBase.java
index 4829ce7..73b11eb 100644
--- a/flink-java/src/main/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopInputFormatBase.java
+++ b/flink-java/src/main/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopInputFormatBase.java
@@ -111,7 +111,7 @@ public abstract class HadoopInputFormatBase<K, V, T> extends HadoopInputFormatCo
@Override
public BaseStatistics getStatistics(BaseStatistics cachedStats) throws IOException {
// only gather base statistics for FileInputFormats
- if(!(mapreduceInputFormat instanceof FileInputFormat)) {
+ if (!(mapreduceInputFormat instanceof FileInputFormat)) {
return null;
}
@@ -158,7 +158,7 @@ public abstract class HadoopInputFormatBase<K, V, T> extends HadoopInputFormatCo
jobContext.getCredentials().addAll(this.credentials);
Credentials currentUserCreds = getCredentialsFromUGI(UserGroupInformation.getCurrentUser());
- if(currentUserCreds != null) {
+ if (currentUserCreds != null) {
jobContext.getCredentials().addAll(currentUserCreds);
}
@@ -170,7 +170,7 @@ public abstract class HadoopInputFormatBase<K, V, T> extends HadoopInputFormatCo
}
HadoopInputSplit[] hadoopInputSplits = new HadoopInputSplit[splits.size()];
- for(int i = 0; i < hadoopInputSplits.length; i++){
+ for (int i = 0; i < hadoopInputSplits.length; i++) {
hadoopInputSplits[i] = new HadoopInputSplit(i, splits.get(i), jobContext);
}
return hadoopInputSplits;
@@ -208,7 +208,7 @@ public abstract class HadoopInputFormatBase<K, V, T> extends HadoopInputFormatCo
@Override
public boolean reachedEnd() throws IOException {
- if(!this.fetched) {
+ if (!this.fetched) {
fetchNext();
}
return !this.hasNext;
@@ -243,7 +243,7 @@ public abstract class HadoopInputFormatBase<K, V, T> extends HadoopInputFormatCo
long latestModTime = 0L;
// get the file info and check whether the cached statistics are still valid.
- for(org.apache.hadoop.fs.Path hadoopPath : hadoopFilePaths) {
+ for (org.apache.hadoop.fs.Path hadoopPath : hadoopFilePaths) {
final Path filePath = new Path(hadoopPath.toUri());
final FileSystem fs = FileSystem.get(filePath.toUri());
@@ -308,7 +308,7 @@ public abstract class HadoopInputFormatBase<K, V, T> extends HadoopInputFormatCo
org.apache.hadoop.conf.Configuration configuration = new org.apache.hadoop.conf.Configuration();
configuration.readFields(in);
- if(this.configuration == null) {
+ if (this.configuration == null) {
this.configuration = configuration;
}
http://git-wip-us.apache.org/repos/asf/flink/blob/a6c3778f/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapred/HadoopInputFormatTest.java
----------------------------------------------------------------------
diff --git a/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapred/HadoopInputFormatTest.java b/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapred/HadoopInputFormatTest.java
index 63f8df4..3b8d227 100644
--- a/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapred/HadoopInputFormatTest.java
+++ b/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapred/HadoopInputFormatTest.java
@@ -20,21 +20,168 @@ package org.apache.flink.api.java.hadoop.mapred;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.java.hadoop.mapred.wrapper.HadoopInputSplit;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.api.java.typeutils.TupleTypeInfo;
-import org.apache.flink.api.java.hadoop.mapred.HadoopInputFormat;
+import org.apache.hadoop.conf.Configurable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileInputFormat;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.InputFormat;
+import org.apache.hadoop.mapred.InputSplit;
import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.JobConfigurable;
+import org.apache.hadoop.mapred.RecordReader;
import org.apache.hadoop.mapred.Reporter;
-import org.apache.hadoop.mapred.FileInputFormat;
import org.junit.Test;
import java.io.IOException;
-import static org.junit.Assert.fail;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyInt;
+import static org.mockito.Mockito.anyLong;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class HadoopInputFormatTest {
+ @Test
+ public void testConfigureWithConfigurableInstance() {
+ ConfigurableDummyInputFormat inputFormat = mock(ConfigurableDummyInputFormat.class);
+
+ HadoopInputFormat<String, Long> hadoopInputFormat = new HadoopInputFormat<>(inputFormat, String.class, Long.class, new JobConf());
+ verify(inputFormat, times(1)).setConf(any(JobConf.class));
+
+ hadoopInputFormat.configure(new org.apache.flink.configuration.Configuration());
+ verify(inputFormat, times(2)).setConf(any(JobConf.class));
+ }
+
+ @Test
+ public void testConfigureWithJobConfigurableInstance() {
+ JobConfigurableDummyInputFormat inputFormat = mock(JobConfigurableDummyInputFormat.class);
+
+ HadoopInputFormat<String, Long> hadoopInputFormat = new HadoopInputFormat<>(inputFormat, String.class, Long.class, new JobConf());
+ verify(inputFormat, times(1)).configure(any(JobConf.class));
+
+ hadoopInputFormat.configure(new org.apache.flink.configuration.Configuration());
+ verify(inputFormat, times(2)).configure(any(JobConf.class));
+ }
+
+ @Test
+ public void testOpenClose() throws Exception {
+ DummyRecordReader recordReader = mock(DummyRecordReader.class);
+ DummyInputFormat inputFormat = mock(DummyInputFormat.class);
+ when(inputFormat.getRecordReader(any(InputSplit.class), any(JobConf.class), any(Reporter.class))).thenReturn(recordReader);
+
+ HadoopInputFormat<String, Long> hadoopInputFormat = new HadoopInputFormat<>(inputFormat, String.class, Long.class, new JobConf());
+ hadoopInputFormat.open(getHadoopInputSplit());
+
+ verify(inputFormat, times(1)).getRecordReader(any(InputSplit.class), any(JobConf.class), any(Reporter.class));
+ verify(recordReader, times(1)).createKey();
+ verify(recordReader, times(1)).createValue();
+
+ assertThat(hadoopInputFormat.fetched, is(false));
+
+ hadoopInputFormat.close();
+ verify(recordReader, times(1)).close();
+ }
+
+ @Test
+ public void testOpenWithConfigurableReader() throws Exception {
+ ConfigurableDummyRecordReader recordReader = mock(ConfigurableDummyRecordReader.class);
+ DummyInputFormat inputFormat = mock(DummyInputFormat.class);
+ when(inputFormat.getRecordReader(any(InputSplit.class), any(JobConf.class), any(Reporter.class))).thenReturn(recordReader);
+
+ HadoopInputFormat<String, Long> hadoopInputFormat = new HadoopInputFormat<>(inputFormat, String.class, Long.class, new JobConf());
+ hadoopInputFormat.open(getHadoopInputSplit());
+
+ verify(inputFormat, times(1)).getRecordReader(any(InputSplit.class), any(JobConf.class), any(Reporter.class));
+ verify(recordReader, times(1)).setConf(any(JobConf.class));
+ verify(recordReader, times(1)).createKey();
+ verify(recordReader, times(1)).createValue();
+
+ assertThat(hadoopInputFormat.fetched, is(false));
+
+ }
+
+ @Test
+ public void testCreateInputSplits() throws Exception {
+
+ FileSplit[] result = new FileSplit[1];
+ result[0] = getFileSplit();
+ DummyInputFormat inputFormat = mock(DummyInputFormat.class);
+ when(inputFormat.getSplits(any(JobConf.class), anyInt())).thenReturn(result);
+
+ HadoopInputFormat<String, Long> hadoopInputFormat = new HadoopInputFormat<>(inputFormat, String.class, Long.class, new JobConf());
+ hadoopInputFormat.createInputSplits(2);
+
+ verify(inputFormat, times(1)).getSplits(any(JobConf.class), anyInt());
+ }
+
+ @Test
+ public void testReachedEndWithElementsRemaining() throws IOException {
+
+ HadoopInputFormat<String, Long> hadoopInputFormat = new HadoopInputFormat<>(new DummyInputFormat(), String.class, Long.class, new JobConf());
+ hadoopInputFormat.fetched = true;
+ hadoopInputFormat.hasNext = true;
+
+ assertThat(hadoopInputFormat.reachedEnd(), is(false));
+ }
+
+ @Test
+ public void testReachedEndWithNoElementsRemaining() throws IOException {
+ HadoopInputFormat<String, Long> hadoopInputFormat = new HadoopInputFormat<>(new DummyInputFormat(), String.class, Long.class, new JobConf());
+ hadoopInputFormat.fetched = true;
+ hadoopInputFormat.hasNext = false;
+
+ assertThat(hadoopInputFormat.reachedEnd(), is(true));
+ }
+
+ @Test
+ public void testFetchNext() throws IOException {
+ DummyRecordReader recordReader = mock(DummyRecordReader.class);
+ when(recordReader.next(anyString(), anyLong())).thenReturn(true);
+
+ DummyInputFormat inputFormat = mock(DummyInputFormat.class);
+ when(inputFormat.getRecordReader(any(InputSplit.class), any(JobConf.class), any(Reporter.class))).thenReturn(recordReader);
+
+ HadoopInputFormat<String, Long> hadoopInputFormat = new HadoopInputFormat<>(inputFormat, String.class, Long.class, new JobConf());
+ hadoopInputFormat.open(getHadoopInputSplit());
+ hadoopInputFormat.fetchNext();
+
+ verify(recordReader, times(1)).next(anyString(), anyLong());
+ assertThat(hadoopInputFormat.hasNext, is(true));
+ assertThat(hadoopInputFormat.fetched, is(true));
+ }
+
+ @Test
+ public void checkTypeInformation() throws Exception {
+ HadoopInputFormat<Void, Long> hadoopInputFormat = new HadoopInputFormat<>(
+ new DummyVoidKeyInputFormat<Long>(), Void.class, Long.class, new JobConf());
+
+ TypeInformation<Tuple2<Void,Long>> tupleType = hadoopInputFormat.getProducedType();
+ TypeInformation<Tuple2<Void,Long>> expectedType = new TupleTypeInfo<>(BasicTypeInfo.VOID_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO);
+
+ assertThat(tupleType.isTupleType(), is(true));
+ assertThat(tupleType, is(equalTo(expectedType)));
+ }
+
+ private HadoopInputSplit getHadoopInputSplit() {
+ return new HadoopInputSplit(1, getFileSplit(), new JobConf());
+ }
+
+ private FileSplit getFileSplit() {
+ return new FileSplit(new Path("path"), 1, 2, new String[]{});
+ }
+
public class DummyVoidKeyInputFormat<T> extends FileInputFormat<Void, T> {
public DummyVoidKeyInputFormat() {}
@@ -44,27 +191,107 @@ public class HadoopInputFormatTest {
return null;
}
}
-
- @Test
- public void checkTypeInformation() {
- try {
- HadoopInputFormat<Void, Long> hadoopInputFormat = new HadoopInputFormat<Void, Long>(
- new DummyVoidKeyInputFormat<Long>(), Void.class, Long.class, new JobConf());
-
- TypeInformation<Tuple2<Void,Long>> tupleType = hadoopInputFormat.getProducedType();
- TypeInformation<Tuple2<Void,Long>> testTupleType = new TupleTypeInfo<Tuple2<Void,Long>>(BasicTypeInfo.VOID_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO);
-
- if(tupleType.isTupleType()) {
- if(!((TupleTypeInfo<?>)tupleType).equals(testTupleType)) {
- fail("Tuple type information was not set correctly!");
- }
- } else {
- fail("Type information was not set to tuple type information!");
- }
-
- }
- catch (Exception ex) {
- fail("Test failed due to a " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
+
+ public class DummyRecordReader implements RecordReader<String, Long> {
+
+ @Override
+ public float getProgress() throws IOException {
+ return 0;
+ }
+
+ @Override
+ public boolean next(String s, Long aLong) throws IOException {
+ return false;
}
+
+ @Override
+ public String createKey() {
+ return null;
+ }
+
+ @Override
+ public Long createValue() {
+ return null;
+ }
+
+ @Override
+ public long getPos() throws IOException {
+ return 0;
+ }
+
+ @Override
+ public void close() throws IOException {
+
+ }
+ }
+
+ public class ConfigurableDummyRecordReader implements RecordReader<String, Long>, Configurable {
+
+ @Override
+ public void setConf(Configuration configuration) {}
+
+ @Override
+ public Configuration getConf() {
+ return null;
+ }
+
+ @Override
+ public boolean next(String s, Long aLong) throws IOException {
+ return false;
+ }
+
+ @Override
+ public String createKey() {
+ return null;
+ }
+
+ @Override
+ public Long createValue() {
+ return null;
+ }
+
+ @Override
+ public long getPos() throws IOException {
+ return 0;
+ }
+
+ @Override
+ public void close() throws IOException {
+
+ }
+
+ @Override
+ public float getProgress() throws IOException {
+ return 0;
+ }
+ }
+
+ public class DummyInputFormat implements InputFormat<String, Long> {
+
+ @Override
+ public InputSplit[] getSplits(JobConf jobConf, int i) throws IOException {
+ return new InputSplit[0];
+ }
+
+ @Override
+ public RecordReader<String, Long> getRecordReader(InputSplit inputSplit, JobConf jobConf, Reporter reporter) throws IOException {
+ return null;
+ }
+ }
+
+ public class ConfigurableDummyInputFormat extends DummyInputFormat implements Configurable {
+ @Override
+ public void setConf(Configuration configuration) {}
+
+ @Override
+ public Configuration getConf() {
+ return null;
+ }
+ }
+
+ public class JobConfigurableDummyInputFormat extends DummyInputFormat implements JobConfigurable {
+
+ @Override
+ public void configure(JobConf jobConf) {}
}
}
http://git-wip-us.apache.org/repos/asf/flink/blob/a6c3778f/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopInputFormatTest.java
----------------------------------------------------------------------
diff --git a/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopInputFormatTest.java b/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopInputFormatTest.java
index 919a286..d6ec484 100644
--- a/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopInputFormatTest.java
+++ b/flink-java/src/test/java/org/apache/flink/api/java/hadoop/mapreduce/HadoopInputFormatTest.java
@@ -20,22 +20,146 @@ package org.apache.flink.api.java.hadoop.mapreduce;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.java.hadoop.mapreduce.wrapper.HadoopInputSplit;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.api.java.typeutils.TupleTypeInfo;
-import org.apache.flink.api.java.hadoop.mapreduce.HadoopInputFormat;
+import org.apache.hadoop.conf.Configurable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.mapreduce.InputFormat;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.Job;
+import org.apache.hadoop.mapreduce.JobContext;
import org.apache.hadoop.mapreduce.RecordReader;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import java.io.IOException;
+import java.util.List;
-import static org.junit.Assert.fail;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class HadoopInputFormatTest {
+ @Rule
+ public final ExpectedException exception = ExpectedException.none();
+
+ @Test
+ public void testConfigure() throws Exception {
+
+ ConfigurableDummyInputFormat inputFormat = mock(ConfigurableDummyInputFormat.class);
+
+ HadoopInputFormat<String, Long> hadoopInputFormat = setupHadoopInputFormat(inputFormat, Job.getInstance(), null);
+ hadoopInputFormat.configure(new org.apache.flink.configuration.Configuration());
+
+ verify(inputFormat, times(1)).setConf(any(Configuration.class));
+ }
+
+ @Test
+ public void testCreateInputSplits() throws Exception {
+ DummyInputFormat inputFormat = mock(DummyInputFormat.class);
+
+ HadoopInputFormat<String, Long> hadoopInputFormat = setupHadoopInputFormat(inputFormat, Job.getInstance(), null);
+ hadoopInputFormat.createInputSplits(2);
+
+ verify(inputFormat, times(1)).getSplits(any(JobContext.class));
+ }
+
+ @Test
+ public void testOpen() throws Exception {
+ DummyInputFormat inputFormat = mock(DummyInputFormat.class);
+ when(inputFormat.createRecordReader(any(InputSplit.class), any(TaskAttemptContext.class))).thenReturn(new DummyRecordReader());
+ HadoopInputSplit inputSplit = mock(HadoopInputSplit.class);
+
+ HadoopInputFormat<String, Long> hadoopInputFormat = setupHadoopInputFormat(inputFormat, Job.getInstance(), null);
+ hadoopInputFormat.open(inputSplit);
+
+ verify(inputFormat, times(1)).createRecordReader(any(InputSplit.class), any(TaskAttemptContext.class));
+ assertThat(hadoopInputFormat.fetched, is(false));
+ }
+
+ @Test
+ public void testClose() throws Exception {
+
+ DummyRecordReader recordReader = mock(DummyRecordReader.class);
+
+ HadoopInputFormat<String, Long> hadoopInputFormat = setupHadoopInputFormat(new DummyInputFormat(), Job.getInstance(), recordReader);
+ hadoopInputFormat.close();
+
+ verify(recordReader, times(1)).close();
+ }
+
+ @Test
+ public void testFetchNextInitialState() throws Exception {
+ DummyRecordReader recordReader = new DummyRecordReader();
+
+ HadoopInputFormat<String, Long> hadoopInputFormat = setupHadoopInputFormat(new DummyInputFormat(), Job.getInstance(), recordReader);
+ hadoopInputFormat.fetchNext();
+
+ assertThat(hadoopInputFormat.fetched, is(true));
+ assertThat(hadoopInputFormat.hasNext, is(false));
+ }
+
+ @Test
+ public void testFetchNextRecordReaderHasNewValue() throws Exception {
+
+ DummyRecordReader recordReader = mock(DummyRecordReader.class);
+ when(recordReader.nextKeyValue()).thenReturn(true);
+
+ HadoopInputFormat<String, Long> hadoopInputFormat = setupHadoopInputFormat(new DummyInputFormat(), Job.getInstance(), recordReader);
+ hadoopInputFormat.fetchNext();
+
+ assertThat(hadoopInputFormat.fetched, is(true));
+ assertThat(hadoopInputFormat.hasNext, is(true));
+ }
+
+ @Test
+ public void testFetchNextRecordReaderThrowsException() throws Exception {
+
+ DummyRecordReader recordReader = mock(DummyRecordReader.class);
+ when(recordReader.nextKeyValue()).thenThrow(new InterruptedException());
+
+ HadoopInputFormat<String, Long> hadoopInputFormat = setupHadoopInputFormat(new DummyInputFormat(), Job.getInstance(), recordReader);
+
+ exception.expect(IOException.class);
+ hadoopInputFormat.fetchNext();
+
+ assertThat(hadoopInputFormat.hasNext, is(true));
+ }
+
+ @Test
+ public void checkTypeInformation() throws Exception {
+
+ HadoopInputFormat<Void, Long> hadoopInputFormat = new HadoopInputFormat<>(
+ new DummyVoidKeyInputFormat<Long>(), Void.class, Long.class, Job.getInstance());
+
+ TypeInformation<Tuple2<Void,Long>> tupleType = hadoopInputFormat.getProducedType();
+ TypeInformation<Tuple2<Void,Long>> expectedType = new TupleTypeInfo<>(BasicTypeInfo.VOID_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO);
+
+ assertThat(tupleType.isTupleType(), is(true));
+ assertThat(tupleType, is(equalTo(expectedType)));
+ }
+
+
+ private HadoopInputFormat<String, Long> setupHadoopInputFormat(InputFormat<String, Long> inputFormat, Job job,
+ RecordReader<String, Long> recordReader) {
+
+ HadoopInputFormat<String, Long> hadoopInputFormat = new HadoopInputFormat<>(inputFormat,
+ String.class, Long.class, job);
+ hadoopInputFormat.recordReader = recordReader;
+
+ return hadoopInputFormat;
+ }
+
public class DummyVoidKeyInputFormat<T> extends FileInputFormat<Void, T> {
public DummyVoidKeyInputFormat() {}
@@ -45,29 +169,61 @@ public class HadoopInputFormatTest {
return null;
}
}
-
- @Test
- public void checkTypeInformation() {
- try {
- // Set up the Hadoop Input Format
- Job job = Job.getInstance();
- HadoopInputFormat<Void, Long> hadoopInputFormat = new HadoopInputFormat<Void, Long>(
- new DummyVoidKeyInputFormat<Long>(), Void.class, Long.class, job);
-
- TypeInformation<Tuple2<Void,Long>> tupleType = hadoopInputFormat.getProducedType();
- TypeInformation<Tuple2<Void,Long>> testTupleType = new TupleTypeInfo<Tuple2<Void,Long>>(BasicTypeInfo.VOID_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO);
-
- if(tupleType.isTupleType()) {
- if(!((TupleTypeInfo<?>)tupleType).equals(testTupleType)) {
- fail("Tuple type information was not set correctly!");
- }
- } else {
- fail("Type information was not set to tuple type information!");
- }
+
+ public class DummyRecordReader extends RecordReader<String, Long> {
+
+ @Override
+ public void initialize(InputSplit inputSplit, TaskAttemptContext taskAttemptContext) throws IOException, InterruptedException {
}
- catch (Exception ex) {
- fail("Test failed due to a " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
+
+ @Override
+ public boolean nextKeyValue() throws IOException, InterruptedException {
+ return false;
+ }
+
+ @Override
+ public String getCurrentKey() throws IOException, InterruptedException {
+ return null;
+ }
+
+ @Override
+ public Long getCurrentValue() throws IOException, InterruptedException {
+ return null;
+ }
+
+ @Override
+ public float getProgress() throws IOException, InterruptedException {
+ return 0;
+ }
+
+ @Override
+ public void close() throws IOException {
+
+ }
+ }
+
+ public class DummyInputFormat extends InputFormat<String, Long> {
+
+ @Override
+ public List<InputSplit> getSplits(JobContext jobContext) throws IOException, InterruptedException {
+ return null;
+ }
+
+ @Override
+ public RecordReader<String, Long> createRecordReader(InputSplit inputSplit, TaskAttemptContext taskAttemptContext) throws IOException, InterruptedException {
+ return new DummyRecordReader();
+ }
+ }
+
+ public class ConfigurableDummyInputFormat extends DummyInputFormat implements Configurable {
+
+ @Override
+ public void setConf(Configuration configuration) {}
+
+ @Override
+ public Configuration getConf() {
+ return null;
}
}
}