sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mau...@apache.org
Subject sqoop git commit: SQOOP-3081: use OracleEscapeUtils.escapeIdentifier in OracleUpsertOutputFormat instead of inline appending quotes
Date Fri, 16 Dec 2016 11:31:07 GMT
Repository: sqoop
Updated Branches:
  refs/heads/trunk bde0ed1e7 -> d1e6c5f52


SQOOP-3081: use OracleEscapeUtils.escapeIdentifier
in OracleUpsertOutputFormat instead of inline
appending quotes

(Anna Szonyi via Attila Szabo)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/d1e6c5f5
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/d1e6c5f5
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/d1e6c5f5

Branch: refs/heads/trunk
Commit: d1e6c5f52f8913a619cfe77c87970d7938c84844
Parents: bde0ed1
Author: Attila Szabo <maugli@apache.org>
Authored: Fri Dec 16 12:29:09 2016 +0100
Committer: Attila Szabo <maugli@apache.org>
Committed: Fri Dec 16 12:29:09 2016 +0100

----------------------------------------------------------------------
 .../sqoop/mapreduce/OracleUpsertOutputFormat.java     | 11 +++++++++--
 .../com/cloudera/sqoop/manager/OracleExportTest.java  | 14 ++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/d1e6c5f5/src/java/org/apache/sqoop/mapreduce/OracleUpsertOutputFormat.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/sqoop/mapreduce/OracleUpsertOutputFormat.java b/src/java/org/apache/sqoop/mapreduce/OracleUpsertOutputFormat.java
index 88754e7..79a4efd 100644
--- a/src/java/org/apache/sqoop/mapreduce/OracleUpsertOutputFormat.java
+++ b/src/java/org/apache/sqoop/mapreduce/OracleUpsertOutputFormat.java
@@ -22,12 +22,14 @@ import java.io.IOException;
 import java.sql.SQLException;
 import java.util.LinkedHashSet;
 import java.util.Set;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.mapreduce.RecordWriter;
 import org.apache.hadoop.mapreduce.TaskAttemptContext;
 import com.cloudera.sqoop.lib.SqoopRecord;
 import com.cloudera.sqoop.mapreduce.UpdateOutputFormat;
+import org.apache.sqoop.manager.oracle.OracleUtils;
 
 /**
  * Update an existing table with new value if the table already
@@ -71,7 +73,7 @@ public class OracleUpsertOutputFormat<K extends SqoopRecord, V>
       // lookup table for update columns
       Set<String> updateKeyLookup = new LinkedHashSet<String>();
       for (String updateKey : updateCols) {
-        updateKeyLookup.add('"' + updateKey + '"');
+        updateKeyLookup.add(OracleUtils.escapeIdentifier(updateKey, isOracleEscapingDisabled()));
       }
 
       StringBuilder sb = new StringBuilder();
@@ -85,7 +87,8 @@ public class OracleUpsertOutputFormat<K extends SqoopRecord, V>
         } else {
           sb.append(" AND ");
         }
-        sb.append('"' + updateCols[i] + '"').append(" = ?");
+        sb.append(OracleUtils.escapeIdentifier(updateCols[i], isOracleEscapingDisabled()));
+        sb.append(" = ?");
       }
       sb.append(" )");
 
@@ -127,5 +130,9 @@ public class OracleUpsertOutputFormat<K extends SqoopRecord, V>
 
       return sb.toString();
     }
+
+    private boolean isOracleEscapingDisabled() {
+      return OracleUtils.isOracleEscapingDisabled(getConf());
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/d1e6c5f5/src/test/com/cloudera/sqoop/manager/OracleExportTest.java
----------------------------------------------------------------------
diff --git a/src/test/com/cloudera/sqoop/manager/OracleExportTest.java b/src/test/com/cloudera/sqoop/manager/OracleExportTest.java
index 382eb92..07d672f 100644
--- a/src/test/com/cloudera/sqoop/manager/OracleExportTest.java
+++ b/src/test/com/cloudera/sqoop/manager/OracleExportTest.java
@@ -277,4 +277,18 @@ public class OracleExportTest extends TestExport {
         "--update-key", "ID", "--update-mode", "allowinsert", "--oracle-escaping-disabled",
"false")));
     verifyExport(TOTAL_RECORDS);
   }
+
+  /** Make sure mixed update/insert export work correctly. */
+  public void testUpsertTextExportWithEscapingDisabled() throws IOException, SQLException
{
+    final int TOTAL_RECORDS = 10;
+    createTextFile(0, TOTAL_RECORDS, false);
+    createTable();
+    // first time will be insert.
+    runExport(getArgv(true, 10, 10, newStrArray(null,
+        "--update-key", "ID", "--update-mode", "allowinsert", "--oracle-escaping-disabled",
"true")));
+    // second time will be update.
+    runExport(getArgv(true, 10, 10, newStrArray(null,
+        "--update-key", "ID", "--update-mode", "allowinsert", "--oracle-escaping-disabled",
"true")));
+    verifyExport(TOTAL_RECORDS);
+  }
 }


Mime
View raw message