You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by en...@apache.org on 2009/01/28 14:42:51 UTC
svn commit: r738483 - in /hadoop/core/branches/branch-0.20: CHANGES.txt
src/mapred/org/apache/hadoop/mapred/lib/db/DBOutputFormat.java
src/test/org/apache/hadoop/mapred/lib/db/TestConstructQuery.java
Author: enis
Date: Wed Jan 28 13:42:51 2009
New Revision: 738483
URL: http://svn.apache.org/viewvc?rev=738483&view=rev
Log:
Merge -r738476:738479 from trunk to 0.20 branch. Fixes Hadoop-4955.
Added:
hadoop/core/branches/branch-0.20/src/test/org/apache/hadoop/mapred/lib/db/TestConstructQuery.java
- copied unchanged from r738479, hadoop/core/trunk/src/test/org/apache/hadoop/mapred/lib/db/TestConstructQuery.java
Modified:
hadoop/core/branches/branch-0.20/CHANGES.txt
hadoop/core/branches/branch-0.20/src/mapred/org/apache/hadoop/mapred/lib/db/DBOutputFormat.java
Modified: hadoop/core/branches/branch-0.20/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.20/CHANGES.txt?rev=738483&r1=738482&r2=738483&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.20/CHANGES.txt (original)
+++ hadoop/core/branches/branch-0.20/CHANGES.txt Wed Jan 28 13:42:51 2009
@@ -637,6 +637,9 @@
verification log unclosed. (hairong)
HADOOP-5086. Use the appropriate FileSystem for trash URIs. (cdouglas)
+
+ HADOOP-4955. Make DBOutputFormat us column names from setOutput().
+ (Kevin Peterson via enis)
Release 0.19.0 - 2008-11-18
Modified: hadoop/core/branches/branch-0.20/src/mapred/org/apache/hadoop/mapred/lib/db/DBOutputFormat.java
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.20/src/mapred/org/apache/hadoop/mapred/lib/db/DBOutputFormat.java?rev=738483&r1=738482&r2=738483&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.20/src/mapred/org/apache/hadoop/mapred/lib/db/DBOutputFormat.java (original)
+++ hadoop/core/branches/branch-0.20/src/mapred/org/apache/hadoop/mapred/lib/db/DBOutputFormat.java Wed Jan 28 13:42:51 2009
@@ -99,10 +99,31 @@
/**
* Constructs the query used as the prepared statement to insert data.
+ *
+ * @param table
+ * the table to insert into
+ * @param fieldNames
+ * the fields to insert into. If field names are unknown, supply an
+ * array of nulls.
*/
protected String constructQuery(String table, String[] fieldNames) {
+ if(fieldNames == null) {
+ throw new IllegalArgumentException("Field names may not be null");
+ }
+
StringBuilder query = new StringBuilder();
- query.append("INSERT INTO ").append(table);
+ query.append("INSERT INTO ").append(table);
+
+ if (fieldNames.length > 0 && fieldNames[0] != null) {
+ query.append(" (");
+ for (int i = 0; i < fieldNames.length; i++) {
+ query.append(fieldNames[i]);
+ if (i != fieldNames.length - 1) {
+ query.append(",");
+ }
+ }
+ query.append(")");
+ }
query.append(" VALUES (");
for (int i = 0; i < fieldNames.length; i++) {
@@ -145,9 +166,13 @@
/**
* Initializes the reduce-part of the job with the appropriate output settings
*
- * @param job The job
- * @param tableName The table to insert data into
- * @param fieldNames The field names in the table
+ * @param job
+ * The job
+ * @param tableName
+ * The table to insert data into
+ * @param fieldNames
+ * The field names in the table. If unknown, supply the appropriate
+ * number of nulls.
*/
public static void setOutput(JobConf job, String tableName, String... fieldNames) {
job.setOutputFormat(DBOutputFormat.class);