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

SQOOP-1562: Sqoop2: BIT handling in CSV IDF

(Abraham Elmahrek via Jarek Jarcec Cecho)
This commit is contained in:
Jarek Jarcec Cecho 2014-10-06 06:46:46 -07:00 committed by Abraham Elmahrek
parent 1e9db0113f
commit c78b75a645
2 changed files with 26 additions and 2 deletions

View File

@ -223,7 +223,8 @@ public Object[] getObjectData() {
out[i] = LocalDateTime.parse(fields[i]);
break;
case BIT:
out[i] = fields[i];
out[i] = Boolean.valueOf(fields[i].equals("1")
|| fields[i].toLowerCase().equals("true"));
break;
default:
throw new SqoopException(IntermediateDataFormatError.INTERMEDIATE_DATA_FORMAT_0004, "Column type from schema was not recognized for " + colType);

View File

@ -19,6 +19,7 @@
package org.apache.sqoop.connector.idf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@ -28,6 +29,7 @@
import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.schema.Schema;
import org.apache.sqoop.schema.type.Binary;
import org.apache.sqoop.schema.type.Bit;
import org.apache.sqoop.schema.type.Date;
import org.apache.sqoop.schema.type.DateTime;
import org.apache.sqoop.schema.type.FixedPoint;
@ -195,7 +197,7 @@ public void testStringFullRangeOfCharacters() {
Object[] in = {strData};
Object[] inCopy = new Object[1];
System.arraycopy(in,0,inCopy,0,in.length);
System.arraycopy(in, 0, inCopy, 0, in.length);
// Modifies the input array, so we use the copy to confirm
data.setObjectData(in);
@ -249,6 +251,27 @@ public void testDateTime() {
}
}
@Test
public void testBit() {
Schema schema = new Schema("test");
schema.addColumn(new Bit("1"));
data.setSchema(schema);
for (String trueBit : new String[]{
"true", "TRUE", "1"
}) {
data.setTextData(trueBit);
assertTrue((Boolean) data.getObjectData()[0]);
}
for (String falseBit : new String[]{
"false", "FALSE", "0"
}) {
data.setTextData(falseBit);
assertFalse((Boolean) data.getObjectData()[0]);
}
}
@Test(expected=SqoopException.class)
public void testEmptySchema() {
String testData = "10,34,'54','random data'," + getByteFieldString(new byte[] { (byte) -112, (byte) 54})