This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQOOP-2160: Sqoop2: Datatypes: Provide foundation for the exhaustive …
…type checks (Jarek Jarcec Cecho via Abraham Elmahrek)
- Loading branch information
1 parent
36663eb
commit 3ba01bc
Showing
11 changed files
with
574 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
common-test/src/main/java/org/apache/sqoop/common/test/db/types/DatabaseType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* 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. | ||
*/ | ||
package org.apache.sqoop.common.test.db.types; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
/** | ||
* Class describing type and example values that can be stored in the database. | ||
*/ | ||
public class DatabaseType { | ||
|
||
/** | ||
* Builder for simpler creation of the DatabaseType objects | ||
*/ | ||
public static class Builder { | ||
private String name; | ||
List<ExampleValue> values; | ||
|
||
public Builder(String name) { | ||
this.name = name; | ||
values = new LinkedList<ExampleValue>(); | ||
} | ||
|
||
public Builder addExample(String insertStatement, Object objectValue, String escapedStringValue) { | ||
values.add(new ExampleValue(insertStatement, objectValue, escapedStringValue)); | ||
return this; | ||
} | ||
|
||
public DatabaseType build() { | ||
return new DatabaseType(name, values); | ||
} | ||
} | ||
|
||
/** | ||
* Return new instance of builder. | ||
*/ | ||
public static Builder builder(String name) { | ||
return new Builder(name); | ||
} | ||
|
||
/** | ||
* Name of type as can appear in the CREATE TABLE statement. | ||
*/ | ||
public final String name; | ||
|
||
/** | ||
* Example values for given data type. | ||
* | ||
* Small number of the values, not exhaustive list. | ||
*/ | ||
public final List<ExampleValue> values; | ||
|
||
public DatabaseType(String name, List<ExampleValue> values) { | ||
this.name = name; | ||
this.values = values; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name; | ||
} | ||
|
||
/** | ||
* Returns escaped strings from all values in it's own array. | ||
* | ||
* The order is defined and will always be in the same order as | ||
* is present in the values array. | ||
* | ||
* @return Array where each item represents escapeStringValue field from the | ||
* corresponding values element | ||
*/ | ||
public String []escapedStringValues() { | ||
String [] ret = new String[values.size()]; | ||
int i = 0; | ||
for(ExampleValue value : values) { | ||
ret[i++] = value.escapedStringValue; | ||
} | ||
return ret; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
common-test/src/main/java/org/apache/sqoop/common/test/db/types/DatabaseTypeList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* 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. | ||
*/ | ||
package org.apache.sqoop.common.test.db.types; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
/** | ||
* List of all types provided by given database. | ||
*/ | ||
abstract public class DatabaseTypeList { | ||
|
||
/** | ||
* Internal list of all types. | ||
*/ | ||
List<DatabaseType> types; | ||
|
||
public DatabaseTypeList() { | ||
types = new LinkedList<DatabaseType>(); | ||
} | ||
|
||
protected void add(DatabaseType type) { | ||
types.add(type); | ||
} | ||
|
||
/** | ||
* Returns all types for given database. | ||
*/ | ||
public List<DatabaseType> getAllTypes() { | ||
return types; | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
common-test/src/main/java/org/apache/sqoop/common/test/db/types/DerbyTypeList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* 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. | ||
*/ | ||
package org.apache.sqoop.common.test.db.types; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.RoundingMode; | ||
|
||
/** | ||
* Source: https://db.apache.org/derby/docs/10.7/ref/crefsqlj31068.html | ||
*/ | ||
public class DerbyTypeList extends DatabaseTypeList { | ||
public DerbyTypeList() { | ||
super(); | ||
|
||
// Numeric types | ||
add(DatabaseType.builder("SMALLINT") | ||
.addExample("-32768", new Integer(-32768), "-32768") | ||
.addExample( "-1", new Integer(-1), "-1") | ||
.addExample( "0", new Integer(0), "0") | ||
.addExample( "1", new Integer(1), "1") | ||
.addExample( "32767", new Integer(32767), "32767") | ||
.build()); | ||
add(DatabaseType.builder("INT") | ||
.addExample("-2147483648", new Integer(-2147483648), "-2147483648") | ||
.addExample( "-1", new Integer(-1), "-1") | ||
.addExample( "0", new Integer(0), "0") | ||
.addExample( "1", new Integer(1), "1") | ||
.addExample( "2147483647", new Integer(2147483647), "2147483647") | ||
.build()); | ||
add(DatabaseType.builder("BIGINT") | ||
.addExample("-9223372036854775808", new Long(-9223372036854775808L), "-9223372036854775808") | ||
.addExample( "-1", new Long(-1L), "-1") | ||
.addExample( "0", new Long(0L), "0") | ||
.addExample( "1", new Long(1L), "1") | ||
.addExample( "9223372036854775807", new Long(9223372036854775807L), "9223372036854775807") | ||
.build()); | ||
|
||
// Floating points | ||
add(DatabaseType.builder("REAL") | ||
.addExample("CAST(-3.402E+38 AS REAL)", new Float(-3.402E+38), "-3.402E38") | ||
.addExample( "CAST(3.402E+38 AS REAL)", new Float(3.402E+38), "3.402E38") | ||
.addExample( "0", new Float(0), "0.0") | ||
.addExample( "CAST(1.175E-37 AS REAL)", new Float(1.175E-37), "1.175E-37") | ||
.addExample("CAST(-1.175E-37 AS REAL)", new Float(-1.175E-37), "-1.175E-37") | ||
.build()); | ||
add(DatabaseType.builder("DOUBLE") | ||
.addExample("-1.79769E+308", new Double(-1.79769E+308), "-1.79769E308") | ||
.addExample( "1.79769E+308", new Double(1.79769E+308), "1.79769E308") | ||
.addExample( "0", new Double(0), "0.0") | ||
.addExample( "2.225E-307", new Double(2.225E-307), "2.225E-307") | ||
.addExample( "-2.225E-307", new Double(-2.225E-307), "-2.225E-307") | ||
.build()); | ||
|
||
// Fixed point | ||
add(DatabaseType.builder("DECIMAL(5, 2)") | ||
.addExample("-999.99", new BigDecimal(-999.99).setScale(2, RoundingMode.CEILING), "-999.99") | ||
.addExample( "-999.9", new BigDecimal(-999.9).setScale(2, RoundingMode.FLOOR), "-999.90") | ||
.addExample( "-99.9", new BigDecimal(-99.9).setScale(2, RoundingMode.CEILING), "-99.90") | ||
.addExample( "-9.9", new BigDecimal(-9.9).setScale(2, RoundingMode.CEILING), "-9.90") | ||
.addExample( "-9", new BigDecimal(-9).setScale(2, RoundingMode.CEILING), "-9.00") | ||
.addExample( "0", new BigDecimal(0).setScale(2, RoundingMode.CEILING), "0.00") | ||
.addExample( "9", new BigDecimal(9).setScale(2, RoundingMode.CEILING), "9.00") | ||
.addExample( "9.9", new BigDecimal(9.9).setScale(2, RoundingMode.FLOOR), "9.90") | ||
.addExample( "99.9", new BigDecimal(99.9).setScale(2, RoundingMode.FLOOR), "99.90") | ||
.addExample( "999.9", new BigDecimal(999.9).setScale(2, RoundingMode.CEILING), "999.90") | ||
.addExample( "999.99", new BigDecimal(999.99).setScale(2, RoundingMode.FLOOR), "999.99") | ||
.build()); | ||
|
||
// BLOB | ||
// Boolean | ||
// Char | ||
// CLOB | ||
// Date | ||
// Time | ||
// Timestamp | ||
// XML? | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
common-test/src/main/java/org/apache/sqoop/common/test/db/types/EmptyTypeList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* 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. | ||
*/ | ||
package org.apache.sqoop.common.test.db.types; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
/** | ||
* Default implementation that don't have any types. | ||
*/ | ||
public class EmptyTypeList extends DatabaseTypeList { | ||
@Override | ||
public List<DatabaseType> getAllTypes() { | ||
return new LinkedList<DatabaseType>(); | ||
} | ||
} |
Oops, something went wrong.