5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-06 10:51:11 +08:00

SQOOP-1661: Sqoop2: Intermediate data format text null handling

(Abraham Elmahrek via Jarek Jarcec Cecho)
This commit is contained in:
Jarek Jarcec Cecho 2014-11-05 13:45:06 -08:00
parent 162cab8ecc
commit a63c9efe19
2 changed files with 33 additions and 0 deletions

View File

@ -45,6 +45,7 @@ public class CSVIntermediateDataFormat extends IntermediateDataFormat<String> {
public static final char SEPARATOR_CHARACTER = ',';
public static final char ESCAPE_CHARACTER = '\\';
public static final char QUOTE_CHARACTER = '\'';
public static final String NULL_STRING = "NULL";
private static final char[] originals = {
@ -326,6 +327,10 @@ private String getRegExp(String orig) {
}
private String escapeStrings(String orig) {
if (orig == null) {
return NULL_STRING;
}
int j = 0;
String replacement = orig;
try {

View File

@ -182,6 +182,34 @@ public void testObjectInObjectOut() {
assertTrue(Arrays.deepEquals(inCopy, data.getObjectData()));
}
@Test
public void testObjectWithNullInStringOut() {
Schema schema = new Schema("test");
schema.addColumn(new FixedPoint("1"))
.addColumn(new FixedPoint("2"))
.addColumn(new Text("3"))
.addColumn(new Text("4"))
.addColumn(new Binary("5"))
.addColumn(new Text("6"));
data.setSchema(schema);
byte[] byteFieldData = new byte[] { (byte) 0x0D, (byte) -112, (byte) 54};
Object[] in = new Object[6];
in[0] = new Long(10);
in[1] = new Long(34);
in[2] = null;
in[3] = "random data";
in[4] = byteFieldData;
in[5] = new String(new char[] { 0x0A });
data.setObjectData(in);
//byte[0] = \r byte[1] = -112, byte[1] = 54 - 2's complements
String testData = "10,34,NULL,'random data'," +
getByteFieldString(byteFieldData).replaceAll("\r", "\\\\r") + ",'\\n'";
assertEquals(testData, data.getTextData());
}
@Test
public void testStringFullRangeOfCharacters() {
Schema schema = new Schema("test");