mirror of
https://github.com/apache/sqoop.git
synced 2025-05-03 22:34:30 +08:00
SQOOP-1562: Sqoop2: BIT handling in CSV IDF
(Abraham Elmahrek via Jarek Jarcec Cecho)
This commit is contained in:
parent
1e9db0113f
commit
c78b75a645
@ -223,7 +223,8 @@ public Object[] getObjectData() {
|
|||||||
out[i] = LocalDateTime.parse(fields[i]);
|
out[i] = LocalDateTime.parse(fields[i]);
|
||||||
break;
|
break;
|
||||||
case BIT:
|
case BIT:
|
||||||
out[i] = fields[i];
|
out[i] = Boolean.valueOf(fields[i].equals("1")
|
||||||
|
|| fields[i].toLowerCase().equals("true"));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new SqoopException(IntermediateDataFormatError.INTERMEDIATE_DATA_FORMAT_0004, "Column type from schema was not recognized for " + colType);
|
throw new SqoopException(IntermediateDataFormatError.INTERMEDIATE_DATA_FORMAT_0004, "Column type from schema was not recognized for " + colType);
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
package org.apache.sqoop.connector.idf;
|
package org.apache.sqoop.connector.idf;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
@ -28,6 +29,7 @@
|
|||||||
import org.apache.sqoop.common.SqoopException;
|
import org.apache.sqoop.common.SqoopException;
|
||||||
import org.apache.sqoop.schema.Schema;
|
import org.apache.sqoop.schema.Schema;
|
||||||
import org.apache.sqoop.schema.type.Binary;
|
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.Date;
|
||||||
import org.apache.sqoop.schema.type.DateTime;
|
import org.apache.sqoop.schema.type.DateTime;
|
||||||
import org.apache.sqoop.schema.type.FixedPoint;
|
import org.apache.sqoop.schema.type.FixedPoint;
|
||||||
@ -195,7 +197,7 @@ public void testStringFullRangeOfCharacters() {
|
|||||||
|
|
||||||
Object[] in = {strData};
|
Object[] in = {strData};
|
||||||
Object[] inCopy = new Object[1];
|
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
|
// Modifies the input array, so we use the copy to confirm
|
||||||
data.setObjectData(in);
|
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)
|
@Test(expected=SqoopException.class)
|
||||||
public void testEmptySchema() {
|
public void testEmptySchema() {
|
||||||
String testData = "10,34,'54','random data'," + getByteFieldString(new byte[] { (byte) -112, (byte) 54})
|
String testData = "10,34,'54','random data'," + getByteFieldString(new byte[] { (byte) -112, (byte) 54})
|
||||||
|
Loading…
Reference in New Issue
Block a user