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>
|
<name>Sqoop Connector SDK</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>joda-time</groupId>
|
||||||
|
<artifactId>joda-time</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
import org.apache.sqoop.schema.type.FixedPoint;
|
import org.apache.sqoop.schema.type.FixedPoint;
|
||||||
import org.apache.sqoop.schema.type.FloatingPoint;
|
import org.apache.sqoop.schema.type.FloatingPoint;
|
||||||
import org.apache.sqoop.schema.type.Type;
|
import org.apache.sqoop.schema.type.Type;
|
||||||
|
import org.joda.time.LocalDate;
|
||||||
|
import org.joda.time.LocalDateTime;
|
||||||
|
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.DataOutput;
|
import java.io.DataOutput;
|
||||||
@ -215,7 +217,11 @@ public Object[] getObjectData() {
|
|||||||
out[i] = new BigDecimal(fields[i]);
|
out[i] = new BigDecimal(fields[i]);
|
||||||
break;
|
break;
|
||||||
case DATE:
|
case DATE:
|
||||||
|
out[i] = LocalDate.parse(fields[i]);
|
||||||
|
break;
|
||||||
case DATE_TIME:
|
case DATE_TIME:
|
||||||
|
out[i] = LocalDateTime.parse(fields[i]);
|
||||||
|
break;
|
||||||
case BIT:
|
case BIT:
|
||||||
out[i] = fields[i];
|
out[i] = fields[i];
|
||||||
break;
|
break;
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
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.Date;
|
||||||
|
import org.apache.sqoop.schema.type.DateTime;
|
||||||
import org.apache.sqoop.schema.type.FixedPoint;
|
import org.apache.sqoop.schema.type.FixedPoint;
|
||||||
import org.apache.sqoop.schema.type.Text;
|
import org.apache.sqoop.schema.type.Text;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -222,6 +224,31 @@ public void testByteArrayFullRangeOfCharacters() {
|
|||||||
assertTrue(Arrays.deepEquals(inCopy, data.getObjectData()));
|
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)
|
@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})
|
||||||
|
33
pom.xml
33
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.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.apache</groupId>
|
<groupId>org.apache</groupId>
|
||||||
@ -111,6 +112,7 @@ limitations under the License.
|
|||||||
<jdbc.sqlserver.version>4.0</jdbc.sqlserver.version>
|
<jdbc.sqlserver.version>4.0</jdbc.sqlserver.version>
|
||||||
<jdbc.teradata.version>14.00.00.21</jdbc.teradata.version>
|
<jdbc.teradata.version>14.00.00.21</jdbc.teradata.version>
|
||||||
<jdbc.netezza.version>6.0</jdbc.netezza.version>
|
<jdbc.netezza.version>6.0</jdbc.netezza.version>
|
||||||
|
<joda.version>2.4</joda.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -440,18 +442,23 @@ limitations under the License.
|
|||||||
<artifactId>nzjdbc3</artifactId>
|
<artifactId>nzjdbc3</artifactId>
|
||||||
<version>${jdbc.netezza.version}</version>
|
<version>${jdbc.netezza.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>joda-time</groupId>
|
||||||
<artifactId>mockito-all</artifactId>
|
<artifactId>joda-time</artifactId>
|
||||||
<version>${mockito.version}</version>
|
<version>${joda.version}</version>
|
||||||
<scope>test</scope>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>org.mockito</groupId>
|
||||||
<groupId>org.apache.tomcat</groupId>
|
<artifactId>mockito-all</artifactId>
|
||||||
<artifactId>catalina</artifactId>
|
<version>${mockito.version}</version>
|
||||||
<version>${tomcat.version}</version>
|
<scope>test</scope>
|
||||||
<scope>provided</scope>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
|
<groupId>org.apache.tomcat</groupId>
|
||||||
|
<artifactId>catalina</artifactId>
|
||||||
|
<version>${tomcat.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user