| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <!-- NewPage --> |
| <html lang="en"> |
| <head> |
| <!-- Generated by javadoc (1.8.0_161-google-v7) on Thu Oct 18 16:14:34 PDT 2018 --> |
| <title>HadoopInputFormatIO (Apache Beam 2.8.0-SNAPSHOT)</title> |
| <meta name="date" content="2018-10-18"> |
| <link rel="stylesheet" type="text/css" href="../../../../../../../stylesheet.css" title="Style"> |
| <script type="text/javascript" src="../../../../../../../script.js"></script> |
| </head> |
| <body> |
| <script type="text/javascript"><!-- |
| try { |
| if (location.href.indexOf('is-external=true') == -1) { |
| parent.document.title="HadoopInputFormatIO (Apache Beam 2.8.0-SNAPSHOT)"; |
| } |
| } |
| catch(err) { |
| } |
| //--> |
| var methods = {"i0":9}; |
| var tabs = {65535:["t0","All Methods"],1:["t1","Static Methods"],8:["t4","Concrete Methods"]}; |
| var altColor = "altColor"; |
| var rowColor = "rowColor"; |
| var tableTab = "tableTab"; |
| var activeTableTab = "activeTableTab"; |
| </script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| <!-- ========= START OF TOP NAVBAR ======= --> |
| <div class="topNav"><a name="navbar.top"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div> |
| <a name="navbar.top.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../../../../overview-summary.html">Overview</a></li> |
| <li><a href="package-summary.html">Package</a></li> |
| <li class="navBarCell1Rev">Class</li> |
| <li><a href="package-tree.html">Tree</a></li> |
| <li><a href="../../../../../../../deprecated-list.html">Deprecated</a></li> |
| <li><a href="../../../../../../../index-all.html">Index</a></li> |
| <li><a href="../../../../../../../help-doc.html">Help</a></li> |
| </ul> |
| </div> |
| <div class="subNav"> |
| <ul class="navList"> |
| <li>Prev Class</li> |
| <li><a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.HadoopInputFormatBoundedSource.html" title="class in org.apache.beam.sdk.io.hadoop.inputformat"><span class="typeNameLink">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../../../../../../index.html?org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.html" target="_top">Frames</a></li> |
| <li><a href="HadoopInputFormatIO.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_top"> |
| <li><a href="../../../../../../../allclasses-noframe.html">All Classes</a></li> |
| </ul> |
| <div> |
| <script type="text/javascript"><!-- |
| allClassesLink = document.getElementById("allclasses_navbar_top"); |
| if(window==top) { |
| allClassesLink.style.display = "block"; |
| } |
| else { |
| allClassesLink.style.display = "none"; |
| } |
| //--> |
| </script> |
| </div> |
| <div> |
| <ul class="subNavList"> |
| <li>Summary: </li> |
| <li><a href="#nested.class.summary">Nested</a> | </li> |
| <li>Field | </li> |
| <li><a href="#constructor.summary">Constr</a> | </li> |
| <li><a href="#method.summary">Method</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li><a href="#constructor.detail">Constr</a> | </li> |
| <li><a href="#method.detail">Method</a></li> |
| </ul> |
| </div> |
| <a name="skip.navbar.top"> |
| <!-- --> |
| </a></div> |
| <!-- ========= END OF TOP NAVBAR ========= --> |
| <!-- ======== START OF CLASS DATA ======== --> |
| <div class="header"> |
| <div class="subTitle">org.apache.beam.sdk.io.hadoop.inputformat</div> |
| <h2 title="Class HadoopInputFormatIO" class="title">Class HadoopInputFormatIO</h2> |
| </div> |
| <div class="contentContainer"> |
| <ul class="inheritance"> |
| <li>java.lang.Object</li> |
| <li> |
| <ul class="inheritance"> |
| <li>org.apache.beam.sdk.io.hadoop.inputformat.HadoopInputFormatIO</li> |
| </ul> |
| </li> |
| </ul> |
| <div class="description"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <hr> |
| <br> |
| <pre><a href="../../../../../../../org/apache/beam/sdk/annotations/Experimental.html" title="annotation in org.apache.beam.sdk.annotations">@Experimental</a>(<a href="../../../../../../../org/apache/beam/sdk/annotations/Experimental.html#value--">value</a>=<a href="../../../../../../../org/apache/beam/sdk/annotations/Experimental.Kind.html#SOURCE_SINK">SOURCE_SINK</a>) |
| public class <span class="typeNameLabel">HadoopInputFormatIO</span> |
| extends java.lang.Object</pre> |
| <div class="block">A <a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.html" title="class in org.apache.beam.sdk.io.hadoop.inputformat"><code>HadoopInputFormatIO</code></a> is a Transform for reading data from any source which implements |
| Hadoop <code>InputFormat</code>. For example- Cassandra, Elasticsearch, HBase, Redis, Postgres etc. |
| <a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.html" title="class in org.apache.beam.sdk.io.hadoop.inputformat"><code>HadoopInputFormatIO</code></a> has to make several performance trade-offs in connecting to <code>InputFormat</code>, so if there is another Beam IO Transform specifically for connecting to your data |
| source of choice, we would recommend using that one, but this IO Transform allows you to connect |
| to many data sources that do not yet have a Beam IO Transform. |
| |
| <p>You will need to pass a Hadoop <code>Configuration</code> with parameters specifying how the read |
| will occur. Many properties of the Configuration are optional, and some are required for certain |
| <code>InputFormat</code> classes, but the following properties must be set for all InputFormats: |
| |
| <ul> |
| <li><code>mapreduce.job.inputformat.class</code>: The <code>InputFormat</code> class used to connect to |
| your data source of choice. |
| <li><code>key.class</code>: The key class returned by the <code>InputFormat</code> in <code>mapreduce.job.inputformat.class</code>. |
| <li><code>value.class</code>: The value class returned by the <code>InputFormat</code> in <code>mapreduce.job.inputformat.class</code>. |
| </ul> |
| |
| For example: |
| |
| <pre> |
| { |
| Configuration myHadoopConfiguration = new Configuration(false); |
| // Set Hadoop InputFormat, key and value class in configuration |
| myHadoopConfiguration.setClass("mapreduce.job.inputformat.class", |
| MyDbInputFormatClass, InputFormat.class); |
| myHadoopConfiguration.setClass("key.class", MyDbInputFormatKeyClass, Object.class); |
| myHadoopConfiguration.setClass("value.class", |
| MyDbInputFormatValueClass, Object.class); |
| } |
| </pre> |
| |
| <p>You will need to check to see if the key and value classes output by the <code>InputFormat</code> |
| have a Beam <a href="../../../../../../../org/apache/beam/sdk/coders/Coder.html" title="class in org.apache.beam.sdk.coders"><code>Coder</code></a> available. If not, you can use withKeyTranslation/withValueTranslation |
| to specify a method transforming instances of those classes into another class that is supported |
| by a Beam <a href="../../../../../../../org/apache/beam/sdk/coders/Coder.html" title="class in org.apache.beam.sdk.coders"><code>Coder</code></a>. These settings are optional and you don't need to specify translation |
| for both key and value. If you specify a translation, you will need to make sure the K or V of |
| the read transform match the output type of the translation. |
| |
| <p>You will need to set appropriate InputFormat key and value class (i.e. "key.class" and |
| "value.class") in Hadoop <code>Configuration</code>. If you set different InputFormat key or value |
| class than InputFormat's actual key or value class then, it may result in an error like |
| "unexpected extra bytes after decoding" while the decoding process of key/value object happens. |
| Hence, it is important to set appropriate InputFormat key and value class. |
| |
| <h3>Reading using <a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.html" title="class in org.apache.beam.sdk.io.hadoop.inputformat"><code>HadoopInputFormatIO</code></a></h3> |
| |
| <pre><code> |
| Pipeline p = ...; // Create pipeline. |
| // Read data only with Hadoop configuration. |
| p.apply("read", |
| HadoopInputFormatIO.<InputFormatKeyClass, InputFormatKeyClass>read() |
| .withConfiguration(myHadoopConfiguration); |
| </code> |
| // Read data with configuration and key translation (Example scenario: Beam Coder is not |
| available for key class hence key translation is required.). |
| SimpleFunction<InputFormatKeyClass, MyKeyClass> myOutputKeyType = |
| new SimpleFunction<InputFormatKeyClass, MyKeyClass>() { |
| public MyKeyClass apply(InputFormatKeyClass input) { |
| // ...logic to transform InputFormatKeyClass to MyKeyClass |
| } |
| }; |
| </pre> |
| |
| <pre><code> |
| p.apply("read", |
| HadoopInputFormatIO.<MyKeyClass, InputFormatKeyClass>read() |
| .withConfiguration(myHadoopConfiguration) |
| .withKeyTranslation(myOutputKeyType); |
| </code></pre> |
| |
| <p>// Read data with configuration and value translation (Example scenario: Beam Coder is not |
| available for value class hence value translation is required.). |
| |
| <pre><code> |
| SimpleFunction&lt;InputFormatValueClass, MyValueClass&gt; myOutputValueType = |
| new SimpleFunction&lt;InputFormatValueClass, MyValueClass&gt;() { |
| public MyValueClass apply(InputFormatValueClass input) { |
| // ...logic to transform InputFormatValueClass to MyValueClass |
| } |
| }; |
| </code></pre> |
| |
| <pre><code> |
| p.apply("read", |
| HadoopInputFormatIO.<InputFormatKeyClass, MyValueClass>read() |
| .withConfiguration(myHadoopConfiguration) |
| .withValueTranslation(myOutputValueType); |
| </code></pre> |
| |
| <p>IMPORTANT! In case of using <code>DBInputFormat</code> to read data from RDBMS, Beam parallelizes |
| the process by using LIMIT and OFFSET clauses of SQL query to fetch different ranges of records |
| (as a split) by different workers. To guarantee the same order and proper split of results you |
| need to order them by one or more keys (either PRIMARY or UNIQUE). It can be done during |
| configuration step, for example: |
| |
| <pre><code> |
| Configuration conf = new Configuration(); |
| conf.set(DBConfiguration.INPUT_TABLE_NAME_PROPERTY, tableName); |
| conf.setStrings(DBConfiguration.INPUT_FIELD_NAMES_PROPERTY, "id", "name"); |
| conf.set(DBConfiguration.INPUT_ORDER_BY_PROPERTY, "id ASC"); |
| </code></pre></div> |
| </li> |
| </ul> |
| </div> |
| <div class="summary"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- ======== NESTED CLASS SUMMARY ======== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="nested.class.summary"> |
| <!-- --> |
| </a> |
| <h3>Nested Class Summary</h3> |
| <table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Nested Class Summary table, listing nested classes, and an explanation"> |
| <caption><span>Nested Classes</span><span class="tabEnd"> </span></caption> |
| <tr> |
| <th class="colFirst" scope="col">Modifier and Type</th> |
| <th class="colLast" scope="col">Class and Description</th> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code>static class </code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.HadoopInputFormatBoundedSource.html" title="class in org.apache.beam.sdk.io.hadoop.inputformat">HadoopInputFormatIO.HadoopInputFormatBoundedSource</a><<a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.HadoopInputFormatBoundedSource.html" title="type parameter in HadoopInputFormatIO.HadoopInputFormatBoundedSource">K</a>,<a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.HadoopInputFormatBoundedSource.html" title="type parameter in HadoopInputFormatIO.HadoopInputFormatBoundedSource">V</a>></span></code> |
| <div class="block">Bounded source implementation for <a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.html" title="class in org.apache.beam.sdk.io.hadoop.inputformat"><code>HadoopInputFormatIO</code></a>.</div> |
| </td> |
| </tr> |
| <tr class="rowColor"> |
| <td class="colFirst"><code>static class </code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.Read.html" title="class in org.apache.beam.sdk.io.hadoop.inputformat">HadoopInputFormatIO.Read</a><<a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.Read.html" title="type parameter in HadoopInputFormatIO.Read">K</a>,<a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.Read.html" title="type parameter in HadoopInputFormatIO.Read">V</a>></span></code> |
| <div class="block">A <a href="../../../../../../../org/apache/beam/sdk/transforms/PTransform.html" title="class in org.apache.beam.sdk.transforms"><code>PTransform</code></a> that reads from any data source which implements Hadoop InputFormat.</div> |
| </td> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code>static class </code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.SerializableSplit.html" title="class in org.apache.beam.sdk.io.hadoop.inputformat">HadoopInputFormatIO.SerializableSplit</a></span></code> |
| <div class="block">A wrapper to allow Hadoop <code>InputSplit</code> to be serialized using |
| Java's standard serialization mechanisms.</div> |
| </td> |
| </tr> |
| </table> |
| </li> |
| </ul> |
| <!-- ======== CONSTRUCTOR SUMMARY ======== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="constructor.summary"> |
| <!-- --> |
| </a> |
| <h3>Constructor Summary</h3> |
| <table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation"> |
| <caption><span>Constructors</span><span class="tabEnd"> </span></caption> |
| <tr> |
| <th class="colOne" scope="col">Constructor and Description</th> |
| </tr> |
| <tr class="altColor"> |
| <td class="colOne"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.html#HadoopInputFormatIO--">HadoopInputFormatIO</a></span>()</code> </td> |
| </tr> |
| </table> |
| </li> |
| </ul> |
| <!-- ========== METHOD SUMMARY =========== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="method.summary"> |
| <!-- --> |
| </a> |
| <h3>Method Summary</h3> |
| <table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation"> |
| <caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd"> </span></span><span id="t1" class="tableTab"><span><a href="javascript:show(1);">Static Methods</a></span><span class="tabEnd"> </span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd"> </span></span></caption> |
| <tr> |
| <th class="colFirst" scope="col">Modifier and Type</th> |
| <th class="colLast" scope="col">Method and Description</th> |
| </tr> |
| <tr id="i0" class="altColor"> |
| <td class="colFirst"><code>static <K,V> <a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.Read.html" title="class in org.apache.beam.sdk.io.hadoop.inputformat">HadoopInputFormatIO.Read</a><K,V></code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.html#read--">read</a></span>()</code> |
| <div class="block">Creates an uninitialized <a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.Read.html" title="class in org.apache.beam.sdk.io.hadoop.inputformat"><code>HadoopInputFormatIO.Read</code></a>.</div> |
| </td> |
| </tr> |
| </table> |
| <ul class="blockList"> |
| <li class="blockList"><a name="methods.inherited.from.class.java.lang.Object"> |
| <!-- --> |
| </a> |
| <h3>Methods inherited from class java.lang.Object</h3> |
| <code>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| <div class="details"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- ========= CONSTRUCTOR DETAIL ======== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="constructor.detail"> |
| <!-- --> |
| </a> |
| <h3>Constructor Detail</h3> |
| <a name="HadoopInputFormatIO--"> |
| <!-- --> |
| </a> |
| <ul class="blockListLast"> |
| <li class="blockList"> |
| <h4>HadoopInputFormatIO</h4> |
| <pre>public HadoopInputFormatIO()</pre> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| <!-- ============ METHOD DETAIL ========== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="method.detail"> |
| <!-- --> |
| </a> |
| <h3>Method Detail</h3> |
| <a name="read--"> |
| <!-- --> |
| </a> |
| <ul class="blockListLast"> |
| <li class="blockList"> |
| <h4>read</h4> |
| <pre>public static <K,V> <a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.Read.html" title="class in org.apache.beam.sdk.io.hadoop.inputformat">HadoopInputFormatIO.Read</a><K,V> read()</pre> |
| <div class="block">Creates an uninitialized <a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.Read.html" title="class in org.apache.beam.sdk.io.hadoop.inputformat"><code>HadoopInputFormatIO.Read</code></a>. Before use, the <code>Read</code> must be |
| initialized with a HadoopInputFormatIO.Read#withConfiguration(HadoopConfiguration) that |
| specifies the source. A key/value translation may also optionally be specified using <a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.Read.html#withKeyTranslation-org.apache.beam.sdk.transforms.SimpleFunction-"><code>HadoopInputFormatIO.Read.withKeyTranslation(org.apache.beam.sdk.transforms.SimpleFunction<?, K>)</code></a>/ <a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.Read.html#withValueTranslation-org.apache.beam.sdk.transforms.SimpleFunction-"><code>HadoopInputFormatIO.Read.withValueTranslation(org.apache.beam.sdk.transforms.SimpleFunction<?, V>)</code></a>.</div> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| </div> |
| <!-- ========= END OF CLASS DATA ========= --> |
| <!-- ======= START OF BOTTOM NAVBAR ====== --> |
| <div class="bottomNav"><a name="navbar.bottom"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div> |
| <a name="navbar.bottom.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../../../../overview-summary.html">Overview</a></li> |
| <li><a href="package-summary.html">Package</a></li> |
| <li class="navBarCell1Rev">Class</li> |
| <li><a href="package-tree.html">Tree</a></li> |
| <li><a href="../../../../../../../deprecated-list.html">Deprecated</a></li> |
| <li><a href="../../../../../../../index-all.html">Index</a></li> |
| <li><a href="../../../../../../../help-doc.html">Help</a></li> |
| </ul> |
| </div> |
| <div class="subNav"> |
| <ul class="navList"> |
| <li>Prev Class</li> |
| <li><a href="../../../../../../../org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.HadoopInputFormatBoundedSource.html" title="class in org.apache.beam.sdk.io.hadoop.inputformat"><span class="typeNameLink">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../../../../../../index.html?org/apache/beam/sdk/io/hadoop/inputformat/HadoopInputFormatIO.html" target="_top">Frames</a></li> |
| <li><a href="HadoopInputFormatIO.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_bottom"> |
| <li><a href="../../../../../../../allclasses-noframe.html">All Classes</a></li> |
| </ul> |
| <div> |
| <script type="text/javascript"><!-- |
| allClassesLink = document.getElementById("allclasses_navbar_bottom"); |
| if(window==top) { |
| allClassesLink.style.display = "block"; |
| } |
| else { |
| allClassesLink.style.display = "none"; |
| } |
| //--> |
| </script> |
| </div> |
| <div> |
| <ul class="subNavList"> |
| <li>Summary: </li> |
| <li><a href="#nested.class.summary">Nested</a> | </li> |
| <li>Field | </li> |
| <li><a href="#constructor.summary">Constr</a> | </li> |
| <li><a href="#method.summary">Method</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li><a href="#constructor.detail">Constr</a> | </li> |
| <li><a href="#method.detail">Method</a></li> |
| </ul> |
| </div> |
| <a name="skip.navbar.bottom"> |
| <!-- --> |
| </a></div> |
| <!-- ======== END OF BOTTOM NAVBAR ======= --> |
| </body> |
| </html> |