Index: src/docs/src/documentation/content/xdocs/inputoutput.xml =================================================================== --- src/docs/src/documentation/content/xdocs/inputoutput.xml (revision 1377597) +++ src/docs/src/documentation/content/xdocs/inputoutput.xml (working copy) @@ -33,21 +33,27 @@
HCatInputFormat -

The HCatInputFormat is used with MapReduce jobs to read data from HCatalog managed tables.

+

The HCatInputFormat is used with MapReduce jobs to read data from HCatalog-managed tables.

HCatInputFormat exposes a Hadoop 0.20 MapReduce API for reading data as if it had been published to a table.

API -

The API exposed by HCatInputFormat is shown below.

- -

To use HCatInputFormat to read data, first instantiate as InputJobInfo with the necessary information from the table being read +

The API exposed by HCatInputFormat is shown below. It includes:

+ + +

To use HCatInputFormat to read data, first instantiate an InputJobInfo + with the necessary information from the table being read and then call setInput with the InputJobInfo.

You can use the setOutputSchema method to include a projection schema, to -specify specific output fields. If a schema is not specified all the columns in the table +specify the output fields. If a schema is not specified, all the columns in the table will be returned.

-

You can use the getTableSchema methods to determine the table schema for a specified input table.

+

You can use the getTableSchema method to determine the table schema for a specified input table.

/** @@ -71,9 +77,9 @@ throws IOException; /** - * Gets the HCatTable schema for the table specified in the HCatInputFormat.setInput call - * on the specified job context. This information is available only after HCatInputFormat.setInput - * has been called for a JobContext. + * Get the HCatTable schema for the table specified in the HCatInputFormat.setInput + * call on the specified job context. This information is available only after + * HCatInputFormat.setInput has been called for a JobContext. * @param context the context * @return the table schema * @throws IOException if HCatInputFormat.setInput has not been called @@ -91,41 +97,50 @@
HCatOutputFormat -

HCatOutputFormat is used with MapReduce jobs to write data to HCatalog managed tables.

+

HCatOutputFormat is used with MapReduce jobs to write data to HCatalog-managed tables.

-

HCatOutputFormat exposes a Hadoop 20 MapReduce API for writing data to a table. +

HCatOutputFormat exposes a Hadoop 0.20 MapReduce API for writing data to a table. When a MapReduce job uses HCatOutputFormat to write output, the default OutputFormat configured for the table is used and the new partition is published to the table after the job completes.

API -

The API exposed by HCatOutputFormat is shown below.

-

The first call on the HCatOutputFormat must be setOutput; any other call will throw an exception saying the output format is not initialized. The schema for the data being written out is specified by the setSchema method. You must call this method, providing the schema of data you are writing. If your data has same schema as table schema, you can use HCatOutputFormat.getTableSchema() to get the table schema and then pass that along to setSchema().

+

The API exposed by HCatOutputFormat is shown below. It includes:

+
    +
  • setOutput
  • +
  • setSchema
  • +
  • getTableSchema
  • +
+ +

The first call on the HCatOutputFormat must be setOutput; any other call will throw an exception saying the output format is not initialized. The schema for the data being written out is specified by the setSchema method. You must call this method, providing the schema of data you are writing. If your data has the same schema as the table schema, you can use HCatOutputFormat.getTableSchema() to get the table schema and then pass that along to setSchema().

- /** - * Set the info about the output to write for the Job. This queries the metadata server - * to find the StorageDriver to use for the table. Throws error if partition is already published. - * @param job the job object - * @param outputJobInfo the table output info - * @throws IOException the exception in communicating with the metadata server - */ - @SuppressWarnings("unchecked") - public static void setOutput(Job job, OutputJobInfo outputJobInfo) throws IOException; + /** + * Set the information about the output to write for the job. This queries the metadata + * server to find the StorageHandler to use for the table. It throws an error if the + * partition is already published. + * @param job the job object + * @param outputJobInfo the table output information for the job + * @throws IOException the exception in communicating with the metadata server + */ + @SuppressWarnings("unchecked") + public static void setOutput(Job job, OutputJobInfo outputJobInfo) throws IOException; - /** - * Set the schema for the data being written out to the partition. The - * table schema is used by default for the partition if this is not called. - * @param job the job object - * @param schema the schema for the data - */ - public static void setSchema(final Job job, final HCatSchema schema) throws IOException; + /** + * Set the schema for the data being written out to the partition. The + * table schema is used by default for the partition if this is not called. + * @param job the job object + * @param schema the schema for the data + * @throws IOException + */ + public static void setSchema(final Job job, final HCatSchema schema) throws IOException; /** - * Gets the table schema for the table specified in the HCatOutputFormat.setOutput call + * Get the table schema for the table specified in the HCatOutputFormat.setOutput call * on the specified job context. * @param context the context * @return the table schema - * @throws IOException if HCatOutputFromat.setOutput has not been called for the passed context + * @throws IOException if HCatOutputFormat.setOutput has not been called + * for the passed context */ public static HCatSchema getTableSchema(JobContext context) throws IOException; @@ -135,19 +150,18 @@
-Examples - - -

Running MapReduce with HCatalog

+ Running MapReduce with HCatalog

-Your MapReduce program will need to know where the thrift server to connect to is. The -easiest way to do this is pass it as an argument to your Java program. You will need to -pass the Hive and HCatalog jars MapReduce as well, via the -libjars argument.

+Your MapReduce program needs to be told where the Thrift server is. +The easiest way to do this is to pass the location as an argument to your Java program. +You need to +pass the Hive and HCatalog jars to MapReduce as well, via the -libjars argument.

export HADOOP_HOME=<path_to_hadoop_install> export HCAT_HOME=<path_to_hcat_install> +export HIVE_HOME=<path_to_hive_install> export LIB_JARS=$HCAT_HOME/share/hcatalog/hcatalog-0.4.0.jar, $HIVE_HOME/lib/hive-metastore-0.9.0.jar, $HIVE_HOME/lib/libthrift-0.7.0.jar, @@ -169,6 +183,29 @@ <main_class> -libjars $LIB_JARS <program_arguments> +

This works but Hadoop will ship libjars every time you run the MapReduce program, treating the files as different cache entries, which is not efficient and may deplete the Hadoop distributed cache.

+

Instead, you can optimize to ship libjars using HDFS locations. By doing this, Hadoop will reuse the entries in the distributed cache.

+ + +bin/hadoop fs -copyFromLocal $HCAT_HOME/share/hcatalog/hcatalog-0.4.0.jar /tmp +bin/hadoop fs -copyFromLocal $HIVE_HOME/lib/hive-metastore-0.9.0.jar /tmp +bin/hadoop fs -copyFromLocal $HIVE_HOME/lib/libthrift-0.7.0.jar /tmp +bin/hadoop fs -copyFromLocal $HIVE_HOME/lib/hive-exec-0.9.0.jar /tmp +bin/hadoop fs -copyFromLocal $HIVE_HOME/lib/libfb303-0.7.0.jar /tmp +bin/hadoop fs -copyFromLocal $HIVE_HOME/lib/jdo2-api-2.3-ec.jar /tmp +bin/hadoop fs -copyFromLocal $HIVE_HOME/lib/slf4j-api-1.6.1.jar /tmp + +export LIB_JARS=hdfs:///tmp/hcatalog-0.4.0.jar, +hdfs:///tmp/hive-metastore-0.9.0.jar, +hdfs:///tmp/libthrift-0.7.0.jar, +hdfs:///tmp/hive-exec-0.9.0.jar, +hdfs:///tmp/libfb303-0.7.0.jar, +hdfs:///tmp/jdo2-api-2.3-ec.jar, +hdfs:///tmp/slf4j-api-1.6.1.jar + +# (Other statements remain the same.) + +

Authentication

@@ -176,12 +213,13 @@
-

Read Example

+
+ Read Example

The following very simple MapReduce program reads data from one table which it assumes to have an integer in the -second column, and counts how many different values it sees. That is, is does the -equivalent of select col1, count(*) from $table group by col1;. +second column, and counts how many different values it sees. That is, it does the +equivalent of "select col1, count(*) from $table group by col1;".

@@ -281,22 +319,28 @@

To scan just selected partitions of a table, a filter describing the desired partitions can be passed to -InputJobInfo.create. To scan a single filter, the filter string should look like: "datestamp=20120401" where -datestamp is the partition column name and 20120401 is the value you want to read.

+InputJobInfo.create. To scan a single partition, the filter string should look like: "ds=20120401" +where the datestamp "ds" is the partition column name and "20120401" is the value +you want to read (year, month, and day).

+
-

Filter Operators

+
+ Filter Operators -

A filter can contain the operators 'and', 'or', 'like', '()', '=', '<>' (not equal), '<', '>', '<=' -and '>='. For example:

+

A filter can contain the operators 'and', 'or', 'like', '()', '=', '<>' (not equal), '<', '>', '<=' and '>='.

+

For example:

+
    -
  • datestamp > "20110924"
  • -
  • datestamp < "20110925
  • -
  • datestamp <= "20110925" and datestamp >= "20110924"
  • +
  • ds > "20110924"
  • +
  • ds < "20110925"
  • +
  • ds <= "20110925" and ds >= "20110924"
+
-

Scan Filter

+
+ Scan Filter -

Assume for example you have a web_logs table that is partitioned by the column datestamp. You could select one partition of the table by changing

+

Assume for example you have a web_logs table that is partitioned by the column "ds". You could select one partition of the table by changing

HCatInputFormat.setInput(job, InputJobInfo.create(dbName, inputTableName, null)); @@ -305,23 +349,25 @@

HCatInputFormat.setInput(job, - InputJobInfo.create(dbName, inputTableName, "datestamp=\"20110924\"")); - + InputJobInfo.create(dbName, inputTableName, "ds=\"20110924\"")); +

This filter must reference only partition columns. Values from other columns will cause the job to fail.

+
-

Write Filter

+
+ Write Filter

To write to a single partition you can change the above example to have a Map of key value pairs that describe all of the partition keys and values for that partition. In our example web_logs table, there is only one partition -column (datestamp), so our Map will have only one entry. Change

+column (ds), so our Map will have only one entry. Change

HCatOutputFormat.setOutput(job, OutputJobInfo.create(dbName, outputTableName, null));

to

Map partitions = new HashMap<String, String>(1); -partitions.put("datestamp", "20110924"); +partitions.put("ds", "20110924"); HCatOutputFormat.setOutput(job, OutputJobInfo.create(dbName, outputTableName, partitions)); @@ -329,6 +375,7 @@

+