mirror of
https://github.com/apache/sqoop.git
synced 2025-05-04 05:51:17 +08:00
SQOOP-1561: Sqoop2: Date and DateTime handling in CSV IDF
(Abraham Elmahrek via Jarek Jarcec Cecho)
This commit is contained in:
parent
8362c73cc0
commit
1e9db0113f
@ -33,6 +33,10 @@ limitations under the License.
|
||||
<name>Sqoop Connector SDK</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
@ -27,6 +27,8 @@
|
||||
import org.apache.sqoop.schema.type.FixedPoint;
|
||||
import org.apache.sqoop.schema.type.FloatingPoint;
|
||||
import org.apache.sqoop.schema.type.Type;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.LocalDateTime;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
@ -215,7 +217,11 @@ public Object[] getObjectData() {
|
||||
out[i] = new BigDecimal(fields[i]);
|
||||
break;
|
||||
case DATE:
|
||||
out[i] = LocalDate.parse(fields[i]);
|
||||
break;
|
||||
case DATE_TIME:
|
||||
out[i] = LocalDateTime.parse(fields[i]);
|
||||
break;
|
||||
case BIT:
|
||||
out[i] = fields[i];
|
||||
break;
|
||||
|
@ -28,6 +28,8 @@
|
||||
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.Date;
|
||||
import org.apache.sqoop.schema.type.DateTime;
|
||||
import org.apache.sqoop.schema.type.FixedPoint;
|
||||
import org.apache.sqoop.schema.type.Text;
|
||||
import org.junit.Before;
|
||||
@ -222,6 +224,31 @@ public void testByteArrayFullRangeOfCharacters() {
|
||||
assertTrue(Arrays.deepEquals(inCopy, data.getObjectData()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDate() {
|
||||
Schema schema = new Schema("test");
|
||||
schema.addColumn(new Date("1"));
|
||||
data.setSchema(schema);
|
||||
|
||||
data.setTextData("2014-10-01");
|
||||
assertEquals("2014-10-01", data.getObjectData()[0].toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDateTime() {
|
||||
Schema schema = new Schema("test");
|
||||
schema.addColumn(new DateTime("1"));
|
||||
data.setSchema(schema);
|
||||
|
||||
for (String dateTime : new String[]{
|
||||
"2014-10-01T12:00:00",
|
||||
"2014-10-01T12:00:00.000"
|
||||
}) {
|
||||
data.setTextData(dateTime);
|
||||
assertEquals("2014-10-01T12:00:00.000", data.getObjectData()[0].toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected=SqoopException.class)
|
||||
public void testEmptySchema() {
|
||||
String testData = "10,34,'54','random data'," + getByteFieldString(new byte[] { (byte) -112, (byte) 54})
|
||||
|
9
pom.xml
9
pom.xml
@ -14,7 +14,8 @@ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache</groupId>
|
||||
@ -111,6 +112,7 @@ limitations under the License.
|
||||
<jdbc.sqlserver.version>4.0</jdbc.sqlserver.version>
|
||||
<jdbc.teradata.version>14.00.00.21</jdbc.teradata.version>
|
||||
<jdbc.netezza.version>6.0</jdbc.netezza.version>
|
||||
<joda.version>2.4</joda.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -440,6 +442,11 @@ limitations under the License.
|
||||
<artifactId>nzjdbc3</artifactId>
|
||||
<version>${jdbc.netezza.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>${joda.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
|
Loading…
Reference in New Issue
Block a user