5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-17 09:20:43 +08:00

SQOOP-459 Remove redundant steps in compatibility tests: verifyReadback() method

git-svn-id: https://svn.apache.org/repos/asf/incubator/sqoop/trunk@1299056 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bilung Lee 2012-03-09 21:30:23 +00:00
parent 166b12965d
commit 8b39345360
6 changed files with 60 additions and 370 deletions

View File

@ -72,11 +72,6 @@ protected boolean supportsBlob() {
return false; return false;
} }
@Override
protected String getVarBinaryDbOutput(String asInserted) {
return asInserted.toLowerCase();
}
@Override @Override
protected String getVarBinarySeqOutput(String asInserted) { protected String getVarBinarySeqOutput(String asInserted) {
return toLowerHexString(asInserted); return toLowerHexString(asInserted);

View File

@ -47,21 +47,14 @@ public class TestMultiCols extends ImportJobTestCase {
* @param importColumns The list of columns to import * @param importColumns The list of columns to import
*/ */
private void verifyTypes(String [] types , String [] insertVals, private void verifyTypes(String [] types , String [] insertVals,
String [] validateVals, String validateLine) { String validateLine) {
verifyTypes(types, insertVals, validateVals, validateLine, null); verifyTypes(types, insertVals, validateLine, null);
} }
private void verifyTypes(String [] types , String [] insertVals, private void verifyTypes(String [] types , String [] insertVals,
String [] validateVals, String validateLine, String [] importColumns) { String validateLine, String [] importColumns) {
createTableWithColTypes(types, insertVals); createTableWithColTypes(types, insertVals);
int i = 0;
for (String val : validateVals) {
verifyReadback(++i, val);
LOG.debug("Verified column " + i + " as value: " + val);
}
verifyImport(validateLine, importColumns); verifyImport(validateLine, importColumns);
LOG.debug("Verified input line as " + validateLine + " -- ok!"); LOG.debug("Verified input line as " + validateLine + " -- ok!");
} }
@ -69,109 +62,97 @@ private void verifyTypes(String [] types , String [] insertVals,
public void testThreeStrings() { public void testThreeStrings() {
String [] types = { "VARCHAR(32)", "VARCHAR(32)", "VARCHAR(32)" }; String [] types = { "VARCHAR(32)", "VARCHAR(32)", "VARCHAR(32)" };
String [] insertVals = { "'foo'", "'bar'", "'baz'" }; String [] insertVals = { "'foo'", "'bar'", "'baz'" };
String [] validateVals = { "foo", "bar", "baz" };
String validateLine = "foo,bar,baz"; String validateLine = "foo,bar,baz";
verifyTypes(types, insertVals, validateVals, validateLine); verifyTypes(types, insertVals, validateLine);
} }
public void testStringsWithNull1() { public void testStringsWithNull1() {
String [] types = { "VARCHAR(32)", "VARCHAR(32)", "VARCHAR(32)" }; String [] types = { "VARCHAR(32)", "VARCHAR(32)", "VARCHAR(32)" };
String [] insertVals = { "'foo'", "null", "'baz'" }; String [] insertVals = { "'foo'", "null", "'baz'" };
String [] validateVals = { "foo", null, "baz" };
String validateLine = "foo,null,baz"; String validateLine = "foo,null,baz";
verifyTypes(types, insertVals, validateVals, validateLine); verifyTypes(types, insertVals, validateLine);
} }
public void testStringsWithNull2() { public void testStringsWithNull2() {
String [] types = { "VARCHAR(32)", "VARCHAR(32)", "VARCHAR(32)" }; String [] types = { "VARCHAR(32)", "VARCHAR(32)", "VARCHAR(32)" };
String [] insertVals = { "null", "'foo'", "'baz'" }; String [] insertVals = { "null", "'foo'", "'baz'" };
String [] validateVals = { null, "foo", "baz" };
String validateLine = "null,foo,baz"; String validateLine = "null,foo,baz";
verifyTypes(types, insertVals, validateVals, validateLine); verifyTypes(types, insertVals, validateLine);
} }
public void testStringsWithNull3() { public void testStringsWithNull3() {
String [] types = { "VARCHAR(32)", "VARCHAR(32)", "VARCHAR(32)" }; String [] types = { "VARCHAR(32)", "VARCHAR(32)", "VARCHAR(32)" };
String [] insertVals = { "'foo'", "'baz'", "null"}; String [] insertVals = { "'foo'", "'baz'", "null"};
String [] validateVals = { "foo", "baz", null };
String validateLine = "foo,baz,null"; String validateLine = "foo,baz,null";
verifyTypes(types, insertVals, validateVals, validateLine); verifyTypes(types, insertVals, validateLine);
} }
public void testThreeInts() { public void testThreeInts() {
String [] types = { "INTEGER", "INTEGER", "INTEGER" }; String [] types = { "INTEGER", "INTEGER", "INTEGER" };
String [] insertVals = { "1", "2", "3" }; String [] insertVals = { "1", "2", "3" };
String [] validateVals = { "1", "2", "3" };
String validateLine = "1,2,3"; String validateLine = "1,2,3";
verifyTypes(types, insertVals, validateVals, validateLine); verifyTypes(types, insertVals, validateLine);
} }
public void testIntsWithNulls() { public void testIntsWithNulls() {
String [] types = { "INTEGER", "INTEGER", "INTEGER" }; String [] types = { "INTEGER", "INTEGER", "INTEGER" };
String [] insertVals = { "1", "null", "3" }; String [] insertVals = { "1", "null", "3" };
String [] validateVals = { "1", null, "3" };
String validateLine = "1,null,3"; String validateLine = "1,null,3";
verifyTypes(types, insertVals, validateVals, validateLine); verifyTypes(types, insertVals, validateLine);
} }
public void testMixed1() { public void testMixed1() {
String [] types = { "INTEGER", "VARCHAR(32)", "DATE" }; String [] types = { "INTEGER", "VARCHAR(32)", "DATE" };
String [] insertVals = { "1", "'meep'", "'2009-12-31'" }; String [] insertVals = { "1", "'meep'", "'2009-12-31'" };
String [] validateVals = { "1", "meep", "2009-12-31" };
String validateLine = "1,meep,2009-12-31"; String validateLine = "1,meep,2009-12-31";
verifyTypes(types, insertVals, validateVals, validateLine); verifyTypes(types, insertVals, validateLine);
} }
public void testMixed2() { public void testMixed2() {
String [] types = { "INTEGER", "VARCHAR(32)", "DATE" }; String [] types = { "INTEGER", "VARCHAR(32)", "DATE" };
String [] insertVals = { "null", "'meep'", "'2009-12-31'" }; String [] insertVals = { "null", "'meep'", "'2009-12-31'" };
String [] validateVals = { null, "meep", "2009-12-31" };
String validateLine = "null,meep,2009-12-31"; String validateLine = "null,meep,2009-12-31";
verifyTypes(types, insertVals, validateVals, validateLine); verifyTypes(types, insertVals, validateLine);
} }
public void testMixed3() { public void testMixed3() {
String [] types = { "INTEGER", "VARCHAR(32)", "DATE" }; String [] types = { "INTEGER", "VARCHAR(32)", "DATE" };
String [] insertVals = { "1", "'meep'", "null" }; String [] insertVals = { "1", "'meep'", "null" };
String [] validateVals = { "1", "meep", null };
String validateLine = "1,meep,null"; String validateLine = "1,meep,null";
verifyTypes(types, insertVals, validateVals, validateLine); verifyTypes(types, insertVals, validateLine);
} }
public void testMixed4() { public void testMixed4() {
String [] types = { "NUMERIC", "INTEGER", "NUMERIC" }; String [] types = { "NUMERIC", "INTEGER", "NUMERIC" };
String [] insertVals = { "-42", "17", "33333333333333333333333.1714" }; String [] insertVals = { "-42", "17", "33333333333333333333333.1714" };
String [] validateVals = { "-42", "17", "33333333333333333333333.1714" };
String validateLine = "-42,17,33333333333333333333333.1714"; String validateLine = "-42,17,33333333333333333333333.1714";
verifyTypes(types, insertVals, validateVals, validateLine); verifyTypes(types, insertVals, validateLine);
} }
public void testMixed5() { public void testMixed5() {
String [] types = { "NUMERIC", "INTEGER", "NUMERIC" }; String [] types = { "NUMERIC", "INTEGER", "NUMERIC" };
String [] insertVals = { "null", "17", "33333333333333333333333.0" }; String [] insertVals = { "null", "17", "33333333333333333333333.0" };
String [] validateVals = { null, "17", "33333333333333333333333.0" };
String validateLine = "null,17,33333333333333333333333.0"; String validateLine = "null,17,33333333333333333333333.0";
verifyTypes(types, insertVals, validateVals, validateLine); verifyTypes(types, insertVals, validateLine);
} }
public void testMixed6() { public void testMixed6() {
String [] types = { "NUMERIC", "INTEGER", "NUMERIC" }; String [] types = { "NUMERIC", "INTEGER", "NUMERIC" };
String [] insertVals = { "33333333333333333333333", "17", "-42"}; String [] insertVals = { "33333333333333333333333", "17", "-42"};
String [] validateVals = { "33333333333333333333333", "17", "-42" };
String validateLine = "33333333333333333333333,17,-42"; String validateLine = "33333333333333333333333,17,-42";
verifyTypes(types, insertVals, validateVals, validateLine); verifyTypes(types, insertVals, validateLine);
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -182,34 +163,31 @@ public void testMixed6() {
public void testSkipFirstCol() { public void testSkipFirstCol() {
String [] types = { "NUMERIC", "INTEGER", "NUMERIC" }; String [] types = { "NUMERIC", "INTEGER", "NUMERIC" };
String [] insertVals = { "33333333333333333333333", "17", "-42"}; String [] insertVals = { "33333333333333333333333", "17", "-42"};
String [] validateVals = { "33333333333333333333333", "17", "-42" };
String validateLine = "17,-42"; String validateLine = "17,-42";
String [] loadCols = {"DATA_COL1", "DATA_COL2"}; String [] loadCols = {"DATA_COL1", "DATA_COL2"};
verifyTypes(types, insertVals, validateVals, validateLine, loadCols); verifyTypes(types, insertVals, validateLine, loadCols);
} }
public void testSkipSecondCol() { public void testSkipSecondCol() {
String [] types = { "NUMERIC", "INTEGER", "NUMERIC" }; String [] types = { "NUMERIC", "INTEGER", "NUMERIC" };
String [] insertVals = { "33333333333333333333333", "17", "-42"}; String [] insertVals = { "33333333333333333333333", "17", "-42"};
String [] validateVals = { "33333333333333333333333", "17", "-42" };
String validateLine = "33333333333333333333333,-42"; String validateLine = "33333333333333333333333,-42";
String [] loadCols = {"DATA_COL0", "DATA_COL2"}; String [] loadCols = {"DATA_COL0", "DATA_COL2"};
verifyTypes(types, insertVals, validateVals, validateLine, loadCols); verifyTypes(types, insertVals, validateLine, loadCols);
} }
public void testSkipThirdCol() { public void testSkipThirdCol() {
String [] types = { "NUMERIC", "INTEGER", "NUMERIC" }; String [] types = { "NUMERIC", "INTEGER", "NUMERIC" };
String [] insertVals = { "33333333333333333333333", "17", "-42"}; String [] insertVals = { "33333333333333333333333", "17", "-42"};
String [] validateVals = { "33333333333333333333333", "17", "-42" };
String validateLine = "33333333333333333333333,17"; String validateLine = "33333333333333333333333,17";
String [] loadCols = {"DATA_COL0", "DATA_COL1"}; String [] loadCols = {"DATA_COL0", "DATA_COL1"};
verifyTypes(types, insertVals, validateVals, validateLine, loadCols); verifyTypes(types, insertVals, validateLine, loadCols);
} }
/** /**
@ -223,11 +201,10 @@ public void testSkipThirdCol() {
public void testSingleColumnsArg() throws IOException { public void testSingleColumnsArg() throws IOException {
String [] types = { "VARCHAR(32)", "VARCHAR(32)", "VARCHAR(32)" }; String [] types = { "VARCHAR(32)", "VARCHAR(32)", "VARCHAR(32)" };
String [] insertVals = { "'foo'", "'bar'", "'baz'" }; String [] insertVals = { "'foo'", "'bar'", "'baz'" };
String [] validateVals = { "foo", "bar", "baz" };
String validateLine = "foo,bar,baz"; String validateLine = "foo,bar,baz";
String [] loadCols = {"DATA_COL0,DATA_COL1,DATA_COL2"}; String [] loadCols = {"DATA_COL0,DATA_COL1,DATA_COL2"};
verifyTypes(types, insertVals, validateVals, validateLine, loadCols); verifyTypes(types, insertVals, validateLine, loadCols);
} }
/** /**
@ -241,10 +218,9 @@ public void testSingleColumnsArg() throws IOException {
public void testColumnsWithSpaces() throws IOException { public void testColumnsWithSpaces() throws IOException {
String [] types = { "VARCHAR(32)", "VARCHAR(32)", "VARCHAR(32)" }; String [] types = { "VARCHAR(32)", "VARCHAR(32)", "VARCHAR(32)" };
String [] insertVals = { "'foo'", "'bar'", "'baz'" }; String [] insertVals = { "'foo'", "'bar'", "'baz'" };
String [] validateVals = { "foo", "bar", "baz" };
String validateLine = "foo,bar,baz"; String validateLine = "foo,bar,baz";
String [] loadCols = {"DATA_COL0, DATA_COL1, DATA_COL2"}; String [] loadCols = {"DATA_COL0, DATA_COL1, DATA_COL2"};
verifyTypes(types, insertVals, validateVals, validateLine, loadCols); verifyTypes(types, insertVals, validateLine, loadCols);
} }
} }

View File

@ -98,48 +98,23 @@ protected String getBlobType() {
return "MEDIUMBLOB"; return "MEDIUMBLOB";
} }
@Override
protected String getTrueBoolDbOutput() {
return "1";
}
@Override
protected String getFalseBoolDbOutput() {
return "0";
}
@Override
protected String getRealDbOutput(String realAsInserted) {
return realAsInserted;
}
@Override @Override
protected String getRealSeqOutput(String realAsInserted) { protected String getRealSeqOutput(String realAsInserted) {
return withDecimalZero(realAsInserted); return withDecimalZero(realAsInserted);
} }
@Override
protected String getFloatDbOutput(String floatAsInserted) {
return floatAsInserted;
}
@Override @Override
protected String getFloatSeqOutput(String floatAsInserted) { protected String getFloatSeqOutput(String floatAsInserted) {
return withDecimalZero(floatAsInserted); return withDecimalZero(floatAsInserted);
} }
@Override
protected String getDoubleDbOutput(String doubleAsInserted) {
return doubleAsInserted;
}
@Override @Override
protected String getDoubleSeqOutput(String doubleAsInserted) { protected String getDoubleSeqOutput(String doubleAsInserted) {
return withDecimalZero(doubleAsInserted); return withDecimalZero(doubleAsInserted);
} }
@Override @Override
protected String getTimestampDbOutput(String tsAsInserted) { protected String getTimestampSeqOutput(String tsAsInserted) {
// We trim timestamps to exactly one tenth of a second. // We trim timestamps to exactly one tenth of a second.
if ("null".equals(tsAsInserted)) { if ("null".equals(tsAsInserted)) {
return tsAsInserted; return tsAsInserted;
@ -154,12 +129,7 @@ protected String getTimestampDbOutput(String tsAsInserted) {
} }
@Override @Override
protected String getTimestampSeqOutput(String tsAsInserted) { protected String getNumericSeqOutput(String numAsInserted) {
return getTimestampDbOutput(tsAsInserted);
}
@Override
protected String getNumericDbOutput(String numAsInserted) {
// We always pad to exactly the number of digits in // We always pad to exactly the number of digits in
// getNumericDecPartDigits(). // getNumericDecPartDigits().
@ -188,13 +158,13 @@ protected String getNumericDbOutput(String numAsInserted) {
} }
@Override @Override
protected String getDecimalDbOutput(String numAsInserted) { protected String getDecimalSeqOutput(String numAsInserted) {
return getNumericDbOutput(numAsInserted); return getNumericSeqOutput(numAsInserted);
} }
@Test @Test
public void testYear() { public void testYear() {
verifyType("YEAR", "2012", "2012-01-01", "2012"); verifyType("YEAR", "2012", "2012");
} }
} }

View File

@ -29,8 +29,6 @@
import com.cloudera.sqoop.SqoopOptions; import com.cloudera.sqoop.SqoopOptions;
import com.cloudera.sqoop.testutil.ManagerCompatTestCase; import com.cloudera.sqoop.testutil.ManagerCompatTestCase;
import junit.framework.AssertionFailedError;
/** /**
* Test the basic Oracle connection manager with the various column types. * Test the basic Oracle connection manager with the various column types.
*/ */
@ -135,51 +133,26 @@ protected String getTimestampInsertStr(String tsStr) {
} }
@Override @Override
protected String getDateDbOutput(String asInserted) { protected String getDateSeqOutput(String asInserted) {
// DATE is actually a TIMESTAMP in Oracle; add a time component. // DATE is actually a TIMESTAMP in Oracle; add a time component.
return asInserted + " 00:00:00.0"; return asInserted + " 00:00:00.0";
} }
@Override
protected String getDateSeqOutput(String asInserted) {
return getDateDbOutput(asInserted);
}
@Override
protected String getFixedCharDbOut(int fieldWidth, String asInserted) {
return padString(fieldWidth, asInserted);
}
@Override @Override
protected String getFixedCharSeqOut(int fieldWidth, String asInserted) { protected String getFixedCharSeqOut(int fieldWidth, String asInserted) {
return padString(fieldWidth, asInserted); return padString(fieldWidth, asInserted);
} }
@Override
protected String getRealDbOutput(String realAsInserted) {
return realAsInserted;
}
@Override @Override
protected String getRealSeqOutput(String realAsInserted) { protected String getRealSeqOutput(String realAsInserted) {
return realAsInserted; return realAsInserted;
} }
@Override
protected String getFloatDbOutput(String floatAsInserted) {
return floatAsInserted;
}
@Override @Override
protected String getFloatSeqOutput(String floatAsInserted) { protected String getFloatSeqOutput(String floatAsInserted) {
return floatAsInserted; return floatAsInserted;
} }
@Override
protected String getDoubleDbOutput(String doubleAsInserted) {
return doubleAsInserted;
}
@Override @Override
protected String getDoubleSeqOutput(String doubleAsInserted) { protected String getDoubleSeqOutput(String doubleAsInserted) {
return doubleAsInserted; return doubleAsInserted;
@ -219,84 +192,34 @@ public void testEmptyStringCol() {
"Oracle treats empty strings as null (non-ANSI compliant). Skipping."); "Oracle treats empty strings as null (non-ANSI compliant). Skipping.");
} }
// Date and timestamp output values seem to be formatted in multiple
// different ways depending on which Oracle JDBC driver subversion is used.
// We override the test to control the expected output. We actually accept
// one of multiple different output results -- if it fails one output
// format, we check the other. Success on either is success for the whole
// test. Because of this, we can't just use a single getTimestampDbOutput()
// method.
@Override @Override
public void testTimestamp1() { public void testTimestamp1() {
try { verifyType(getTimestampType(),
// Older ojdbc6_g jars succeed with this format. getTimestampInsertStr("'2009-04-24 18:24:00'"),
verifyType(getTimestampType(), "2009-04-24 18:24:00.0");
getTimestampInsertStr("'2009-04-24 18:24:00'"),
"2009-4-24 18:24:0. 0",
"2009-04-24 18:24:00.0");
} catch (AssertionFailedError afe) {
// Try the test again with a different timestamp format.
verifyType(getTimestampType(),
getTimestampInsertStr("'2009-04-24 18:24:00'"),
"2009-04-24 18:24:00",
"2009-04-24 18:24:00.0");
}
} }
@Override @Override
public void testTimestamp2() { public void testTimestamp2() {
try { verifyType(getTimestampType(),
LOG.debug("Beginning testTimestamp2"); getTimestampInsertStr("'2009-04-24 18:24:00.0002'"),
verifyType(getTimestampType(), "2009-04-24 18:24:00.0002");
getTimestampInsertStr("'2009-04-24 18:24:00.0002'"),
"2009-4-24 18:24:0. 200000",
"2009-04-24 18:24:00.0002");
} catch (AssertionFailedError afe) {
// Try again with the newer version of the timestamp format.
// The in-db format (third argument) looks weird to me, like it's losing
// precision. But the final argument (the to-string version of what we
// extract) is correct, which is what is most important.
verifyType(getTimestampType(),
getTimestampInsertStr("'2009-04-24 18:24:00.0002'"),
"2009-04-24 18:24:00.2",
"2009-04-24 18:24:00.0002");
} finally {
LOG.debug("End testTimestamp2");
}
} }
@Override @Override
public void testDate1() { public void testDate1() {
try { verifyType("DATE", getDateInsertStr("'2009-01-12'"),
verifyType("DATE", getDateInsertStr("'2009-01-12'"), getDateSeqOutput("2009-01-12"));
"2009-01-12 00:00:00.0",
getDateSeqOutput("2009-01-12"));
} catch (AssertionFailedError afe) {
// If the above format doesn't work, it might be a newer ojdbc jar,
// which does not append the ".0" on the end.
verifyType("DATE", getDateInsertStr("'2009-01-12'"),
"2009-01-12 00:00:00",
getDateSeqOutput("2009-01-12"));
}
} }
@Override @Override
public void testDate2() { public void testDate2() {
try { verifyType("DATE", getDateInsertStr("'2009-04-24'"),
verifyType("DATE", getDateInsertStr("'2009-04-24'"), getDateSeqOutput("2009-04-24"));
"2009-04-24 00:00:00.0",
getDateSeqOutput("2009-04-24"));
} catch (AssertionFailedError afe) {
verifyType("DATE", getDateInsertStr("'2009-04-24'"),
"2009-04-24 00:00:00",
getDateSeqOutput("2009-04-24"));
}
} }
public void testRawVal() { public void testRawVal() {
verifyType("RAW(8)", "'12ABCD'", "12ABCD", verifyType("RAW(8)", "'12ABCD'", getVarBinarySeqOutput("12ABCD"), true);
getVarBinarySeqOutput("12ABCD"), true);
} }
} }

View File

@ -416,44 +416,6 @@ protected void removeTableDir() {
} }
} }
/**
* Verify that the single-column single-row result can be read back from the
* db.
*/
protected void verifyReadback(int colNum, String expectedVal) {
ResultSet results = null;
try {
results = getManager().readTable(getTableName(), getColNames());
assertNotNull("Null results from readTable()!", results);
assertTrue("Expected at least one row returned", results.next());
String resultVal = results.getString(colNum);
LOG.info("Verifying readback from " + getTableName()
+ ": got value [" + resultVal + "]");
LOG.info("Expected value is: [" + expectedVal + "]");
if (null != expectedVal) {
assertNotNull("Expected non-null result value", resultVal);
}
assertEquals("Error reading inserted value back from db", expectedVal,
resultVal);
assertFalse("Expected at most one row returned", results.next());
} catch (SQLException sqlE) {
fail("Got SQLException: " + StringUtils.stringifyException(sqlE));
} finally {
if (null != results) {
try {
results.close();
} catch (SQLException sqlE) {
fail("Got SQLException in resultset.close(): "
+ StringUtils.stringifyException(sqlE));
}
}
// Free internal resources after the readTable.
getManager().release();
}
}
/** /**
* Create a new string array with 'moreEntries' appended to the 'entries' * Create a new string array with 'moreEntries' appended to the 'entries'
* array. * array.

View File

@ -274,22 +274,12 @@ protected String getFalseBoolLiteralSqlInput() {
return "false"; return "false";
} }
/** @return How a BOOLEAN column with value TRUE is communicated over JDBC */
protected String getTrueBoolDbOutput() {
return "true";
}
/** @return How a BOOLEAN column with value TRUE is represented in a seq-file /** @return How a BOOLEAN column with value TRUE is represented in a seq-file
* import. */ * import. */
protected String getTrueBoolSeqOutput() { protected String getTrueBoolSeqOutput() {
return "true"; return "true";
} }
/** @return How a BOOLEAN column with value FALSE is communicated over JDBC */
protected String getFalseBoolDbOutput() {
return "false";
}
/** @return How a BOOLEAN column with value FALSE is represented in a seq-file /** @return How a BOOLEAN column with value FALSE is represented in a seq-file
* import. */ * import. */
protected String getFalseBoolSeqOutput() { protected String getFalseBoolSeqOutput() {
@ -317,59 +307,28 @@ protected String withDecimalZero(String floatingPointStr) {
} }
} }
/**
* A real value inserted as '40' may be returned as '40', '40.', or '40.0',
* etc. Given a string that defines how a real value is inserted, determine
* how it is returned.
*
* @param realAsInserted the string we used in the SQL INSERT statement
* @return how the string version of this as returned by the database is
* represented.
*/
protected String getRealDbOutput(String realAsInserted) {
return withDecimalZero(realAsInserted);
}
/** /**
* @return how a given real value is represented in an imported sequence * @return how a given real value is represented in an imported sequence
* file * file
*/ */
protected String getRealSeqOutput(String realAsInserted) { protected String getRealSeqOutput(String realAsInserted) {
return getRealDbOutput(realAsInserted); return withDecimalZero(realAsInserted);
} }
/** /**
* A float value inserted as '40' may be returned as '40', '40.', or '40.0', * @return how a given float value is represented in an imported sequence
* etc. Given a string that defines how a float value is inserted, determine * file
* how it is returned.
*
* @param floatAsInserted the string we used in the SQL INSERT statement
* @return how the string version of this as returned by the database is
* represented.
*/ */
protected String getFloatDbOutput(String floatAsInserted) { protected String getFloatSeqOutput(String floatAsInserted) {
return withDecimalZero(floatAsInserted); return withDecimalZero(floatAsInserted);
} }
protected String getFloatSeqOutput(String floatAsInserted) {
return getFloatDbOutput(floatAsInserted);
}
/** /**
* A double value inserted as '40' may be returned as '40', '40.', or '40.0', * @return how a given double value is represented in an imported sequence
* etc. Given a string that defines how a double value is inserted, determine * file
* how it is returned.
*
* @param doubleAsInserted the string we used in the SQL INSERT statement
* @return how the string version of this as returned by the database is
* represented.
*/ */
protected String getDoubleDbOutput(String doubleAsInserted) {
return withDecimalZero(doubleAsInserted);
}
protected String getDoubleSeqOutput(String doubleAsInserted) { protected String getDoubleSeqOutput(String doubleAsInserted) {
return getDoubleDbOutput(doubleAsInserted); return withDecimalZero(doubleAsInserted);
} }
/** /**
@ -402,43 +361,10 @@ protected String getTimestampInsertStr(String insertStr) {
return insertStr; return insertStr;
} }
protected String getDateDbOutput(String dateAsInserted) {
return dateAsInserted;
}
protected String getDateSeqOutput(String dateAsInserted) { protected String getDateSeqOutput(String dateAsInserted) {
return dateAsInserted; return dateAsInserted;
} }
/**
* Convert an input timestamp to the string representation of the timestamp
* returned by a database select query.
*
* @param tsAsInserted the input timestamp
* @return the string version of this as returned by the database is
* represented.
*/
protected String getTimestampDbOutput(String tsAsInserted) {
if ("null".equals(tsAsInserted)) {
return tsAsInserted;
}
int dotPos = tsAsInserted.indexOf(".");
if (-1 == dotPos) {
// No dot in the original string; expand to 9 places.
return tsAsInserted + ".000000000";
} else {
// Default with a dot is to pad the nanoseconds column to 9 places.
int numZerosNeeded = tsAsInserted.length() - dotPos;
String zeros = "";
for (int i = 0; i < numZerosNeeded; i++) {
zeros = zeros + "0";
}
return tsAsInserted + zeros;
}
}
/** /**
* Convert an input timestamp to the string representation of the timestamp * Convert an input timestamp to the string representation of the timestamp
* returned by a sequencefile-based import. * returned by a sequencefile-based import.
@ -463,30 +389,18 @@ protected String getTimestampSeqOutput(String tsAsInserted) {
} }
} }
protected String getNumericDbOutput(String numAsInserted) {
return numAsInserted;
}
protected String getNumericSeqOutput(String numAsInserted) { protected String getNumericSeqOutput(String numAsInserted) {
return getNumericDbOutput(numAsInserted);
}
protected String getDecimalDbOutput(String numAsInserted) {
return numAsInserted; return numAsInserted;
} }
protected String getDecimalSeqOutput(String numAsInserted) { protected String getDecimalSeqOutput(String numAsInserted) {
return getDecimalDbOutput(numAsInserted); return numAsInserted;
} }
/** /**
* @return how a CHAR(fieldWidth) field is returned by the database * @return how a CHAR(fieldWidth) field is represented in an imported
* for a given input. * sequence file
*/ */
protected String getFixedCharDbOut(int fieldWidth, String asInserted) {
return asInserted;
}
protected String getFixedCharSeqOut(int fieldWidth, String asInserted) { protected String getFixedCharSeqOut(int fieldWidth, String asInserted) {
return asInserted; return asInserted;
} }
@ -523,14 +437,6 @@ protected String getBlobSeqOutput(String asInserted) {
return new BytesWritable(getBlobDbOutput(asInserted)).toString(); return new BytesWritable(getBlobDbOutput(asInserted)).toString();
} }
/**
* @return A String declaring how an inserted VARBINARY will be
* returned to us via the database.
*/
protected String getVarBinaryDbOutput(String asInserted) {
return asInserted;
}
/** /**
* @return A String declaring how an inserted VARBINARY will be * @return A String declaring how an inserted VARBINARY will be
* returned to us via the sequencefile. * returned to us via the sequencefile.
@ -572,49 +478,31 @@ protected String toLowerHexString(String str) {
* Do a full verification test on the singleton value of a given type. * Do a full verification test on the singleton value of a given type.
* @param colType The SQL type to instantiate the column. * @param colType The SQL type to instantiate the column.
* @param insertVal The SQL text to insert a value into the database. * @param insertVal The SQL text to insert a value into the database.
* @param returnVal The string representation of the value as extracted
* from the db.
*/
protected void verifyType(String colType, String insertVal,
String returnVal) {
verifyType(colType, insertVal, returnVal, returnVal);
}
/**
* Do a full verification test on the singleton value of a given type.
* @param colType The SQL type to instantiate the column.
* @param insertVal The SQL text to insert a value into the database.
* @param returnVal The string representation of the value as extracted from
* the db.
* @param seqFileVal The string representation of the value as extracted * @param seqFileVal The string representation of the value as extracted
* through the DBInputFormat, serialized, and injected into a * through the DBInputFormat, serialized, and injected into a
* SequenceFile and put through toString(). This may be slightly * SequenceFile and put through toString(). This may be slightly
* different than what ResultSet.getString() returns, which is used * different than what ResultSet.getString() returns, which is used
* by returnVal. * by returnVal.
*/ */
protected void verifyType(String colType, String insertVal, String returnVal, protected void verifyType(String colType, String insertVal,
String seqFileVal) { String seqFileVal) {
verifyType(colType, insertVal, returnVal, seqFileVal, false); verifyType(colType, insertVal, seqFileVal, false);
} }
protected void verifyType(String colType, String insertVal, String returnVal, protected void verifyType(String colType, String insertVal, String seqFileVal,
String seqFileVal, boolean useIntPrimaryKey) { boolean useIntPrimaryKey) {
int readBackCol;
String readbackPrepend = ""; String readbackPrepend = "";
if (useIntPrimaryKey) { if (useIntPrimaryKey) {
String [] types = { "INTEGER", colType }; String [] types = { "INTEGER", colType };
String [] vals = { "0", insertVal }; String [] vals = { "0", insertVal };
createTableWithColTypes(types, vals); createTableWithColTypes(types, vals);
readBackCol = 2;
readbackPrepend = "0,"; // verifyImport will verify the entire row. readbackPrepend = "0,"; // verifyImport will verify the entire row.
} else { } else {
createTableForColType(colType, insertVal); createTableForColType(colType, insertVal);
readBackCol = 1;
} }
verifyReadback(readBackCol, returnVal);
verifyImport(readbackPrepend + seqFileVal, null); verifyImport(readbackPrepend + seqFileVal, null);
} }
@ -629,7 +517,6 @@ public void testStringCol1() {
@Test @Test
public void testStringCol2() { public void testStringCol2() {
verifyType("CHAR(32)", STRING_VAL_IN, verifyType("CHAR(32)", STRING_VAL_IN,
getFixedCharDbOut(32, STRING_VAL_OUT),
getFixedCharSeqOut(32, STRING_VAL_OUT)); getFixedCharSeqOut(32, STRING_VAL_OUT));
} }
@ -661,7 +548,7 @@ public void testBoolean() {
return; return;
} }
verifyType("BOOLEAN", getTrueBoolNumericSqlInput(), verifyType("BOOLEAN", getTrueBoolNumericSqlInput(),
getTrueBoolDbOutput(), getTrueBoolSeqOutput()); getTrueBoolSeqOutput());
} }
@Test @Test
@ -672,7 +559,7 @@ public void testBoolean2() {
return; return;
} }
verifyType("BOOLEAN", getFalseBoolNumericSqlInput(), verifyType("BOOLEAN", getFalseBoolNumericSqlInput(),
getFalseBoolDbOutput(), getFalseBoolSeqOutput()); getFalseBoolSeqOutput());
} }
@Test @Test
@ -682,7 +569,7 @@ public void testBoolean3() {
skipped = true; skipped = true;
return; return;
} }
verifyType("BOOLEAN", getFalseBoolLiteralSqlInput(), getFalseBoolDbOutput(), verifyType("BOOLEAN", getFalseBoolLiteralSqlInput(),
getFalseBoolSeqOutput()); getFalseBoolSeqOutput());
} }
@ -729,50 +616,43 @@ public void testBigInt1() {
@Test @Test
public void testReal1() { public void testReal1() {
verifyType("REAL", "256", getRealDbOutput("256"), getRealSeqOutput("256")); verifyType("REAL", "256", getRealSeqOutput("256"));
} }
@Test @Test
public void testReal2() { public void testReal2() {
verifyType("REAL", "256.45", getRealDbOutput("256.45"), verifyType("REAL", "256.45", getRealSeqOutput("256.45"));
getRealSeqOutput("256.45"));
} }
@Test @Test
public void testFloat1() { public void testFloat1() {
verifyType("FLOAT", "256", getFloatDbOutput("256"), verifyType("FLOAT", "256", getFloatSeqOutput("256"));
getFloatSeqOutput("256"));
} }
@Test @Test
public void testFloat2() { public void testFloat2() {
verifyType("FLOAT", "256.5", getFloatDbOutput("256.5"), verifyType("FLOAT", "256.5", getFloatSeqOutput("256.5"));
getFloatSeqOutput("256.5"));
} }
@Test @Test
public void testDouble1() { public void testDouble1() {
verifyType(getDoubleType(), "-256", getDoubleDbOutput("-256"), verifyType(getDoubleType(), "-256", getDoubleSeqOutput("-256"));
getDoubleSeqOutput("-256"));
} }
@Test @Test
public void testDouble2() { public void testDouble2() {
verifyType(getDoubleType(), "256.45", getDoubleDbOutput("256.45"), verifyType(getDoubleType(), "256.45", getDoubleSeqOutput("256.45"));
getDoubleSeqOutput("256.45"));
} }
@Test @Test
public void testDate1() { public void testDate1() {
verifyType("DATE", getDateInsertStr("'2009-01-12'"), verifyType("DATE", getDateInsertStr("'2009-01-12'"),
getDateDbOutput("2009-01-12"),
getDateSeqOutput("2009-01-12")); getDateSeqOutput("2009-01-12"));
} }
@Test @Test
public void testDate2() { public void testDate2() {
verifyType("DATE", getDateInsertStr("'2009-04-24'"), verifyType("DATE", getDateInsertStr("'2009-04-24'"),
getDateDbOutput("2009-04-24"),
getDateSeqOutput("2009-04-24")); getDateSeqOutput("2009-04-24"));
} }
@ -820,7 +700,6 @@ public void testTime4() {
public void testTimestamp1() { public void testTimestamp1() {
verifyType(getTimestampType(), verifyType(getTimestampType(),
getTimestampInsertStr("'2009-04-24 18:24:00'"), getTimestampInsertStr("'2009-04-24 18:24:00'"),
getTimestampDbOutput("2009-04-24 18:24:00"),
getTimestampSeqOutput("2009-04-24 18:24:00")); getTimestampSeqOutput("2009-04-24 18:24:00"));
} }
@ -830,7 +709,6 @@ public void testTimestamp2() {
log.debug("Beginning testTimestamp2"); log.debug("Beginning testTimestamp2");
verifyType(getTimestampType(), verifyType(getTimestampType(),
getTimestampInsertStr("'2009-04-24 18:24:00.0002'"), getTimestampInsertStr("'2009-04-24 18:24:00.0002'"),
getTimestampDbOutput("2009-04-24 18:24:00.0002"),
getTimestampSeqOutput("2009-04-24 18:24:00.0002")); getTimestampSeqOutput("2009-04-24 18:24:00.0002"));
} finally { } finally {
log.debug("End testTimestamp2"); log.debug("End testTimestamp2");
@ -850,21 +728,18 @@ public void testTimestamp3() {
@Test @Test
public void testNumeric1() { public void testNumeric1() {
verifyType(getNumericType(), "1", verifyType(getNumericType(), "1",
getNumericDbOutput("1"),
getNumericSeqOutput("1")); getNumericSeqOutput("1"));
} }
@Test @Test
public void testNumeric2() { public void testNumeric2() {
verifyType(getNumericType(), "-10", verifyType(getNumericType(), "-10",
getNumericDbOutput("-10"),
getNumericSeqOutput("-10")); getNumericSeqOutput("-10"));
} }
@Test @Test
public void testNumeric3() { public void testNumeric3() {
verifyType(getNumericType(), "3.14159", verifyType(getNumericType(), "3.14159",
getNumericDbOutput("3.14159"),
getNumericSeqOutput("3.14159")); getNumericSeqOutput("3.14159"));
} }
@ -872,7 +747,6 @@ public void testNumeric3() {
public void testNumeric4() { public void testNumeric4() {
verifyType(getNumericType(), verifyType(getNumericType(),
"3000000000000000000.14159", "3000000000000000000.14159",
getNumericDbOutput("3000000000000000000.14159"),
getNumericSeqOutput("3000000000000000000.14159")); getNumericSeqOutput("3000000000000000000.14159"));
} }
@ -880,7 +754,6 @@ public void testNumeric4() {
public void testNumeric5() { public void testNumeric5() {
verifyType(getNumericType(), verifyType(getNumericType(),
"99999999999999999999.14159", "99999999999999999999.14159",
getNumericDbOutput("99999999999999999999.14159"),
getNumericSeqOutput("99999999999999999999.14159")); getNumericSeqOutput("99999999999999999999.14159"));
} }
@ -889,28 +762,24 @@ public void testNumeric5() {
public void testNumeric6() { public void testNumeric6() {
verifyType(getNumericType(), verifyType(getNumericType(),
"-99999999999999999999.14159", "-99999999999999999999.14159",
getNumericDbOutput("-99999999999999999999.14159"),
getNumericSeqOutput("-99999999999999999999.14159")); getNumericSeqOutput("-99999999999999999999.14159"));
} }
@Test @Test
public void testDecimal1() { public void testDecimal1() {
verifyType(getDecimalType(), "1", verifyType(getDecimalType(), "1",
getDecimalDbOutput("1"),
getDecimalSeqOutput("1")); getDecimalSeqOutput("1"));
} }
@Test @Test
public void testDecimal2() { public void testDecimal2() {
verifyType(getDecimalType(), "-10", verifyType(getDecimalType(), "-10",
getDecimalDbOutput("-10"),
getDecimalSeqOutput("-10")); getDecimalSeqOutput("-10"));
} }
@Test @Test
public void testDecimal3() { public void testDecimal3() {
verifyType(getDecimalType(), "3.14159", verifyType(getDecimalType(), "3.14159",
getDecimalDbOutput("3.14159"),
getDecimalSeqOutput("3.14159")); getDecimalSeqOutput("3.14159"));
} }
@ -918,7 +787,6 @@ public void testDecimal3() {
public void testDecimal4() { public void testDecimal4() {
verifyType(getDecimalType(), verifyType(getDecimalType(),
"3000000000000000000.14159", "3000000000000000000.14159",
getDecimalDbOutput("3000000000000000000.14159"),
getDecimalSeqOutput("3000000000000000000.14159")); getDecimalSeqOutput("3000000000000000000.14159"));
} }
@ -926,7 +794,6 @@ public void testDecimal4() {
public void testDecimal5() { public void testDecimal5() {
verifyType(getDecimalType(), verifyType(getDecimalType(),
"99999999999999999999.14159", "99999999999999999999.14159",
getDecimalDbOutput("99999999999999999999.14159"),
getDecimalSeqOutput("99999999999999999999.14159")); getDecimalSeqOutput("99999999999999999999.14159"));
} }
@ -934,7 +801,6 @@ public void testDecimal5() {
public void testDecimal6() { public void testDecimal6() {
verifyType(getDecimalType(), verifyType(getDecimalType(),
"-99999999999999999999.14159", "-99999999999999999999.14159",
getDecimalDbOutput("-99999999999999999999.14159"),
getDecimalSeqOutput("-99999999999999999999.14159")); getDecimalSeqOutput("-99999999999999999999.14159"));
} }
@ -958,7 +824,6 @@ protected void verifyClob(String insertVal, String returnVal,
String [] checkCol = { "DATA_COL0", "DATA_COL1" }; String [] checkCol = { "DATA_COL0", "DATA_COL1" };
createTableWithColTypes(types, vals); createTableWithColTypes(types, vals);
verifyReadback(2, returnVal);
verifyImport("1," + seqFileVal, checkCol); verifyImport("1," + seqFileVal, checkCol);
} }
@ -1042,7 +907,6 @@ public void testVarBinary() {
} }
verifyType(getVarBinaryType(), "'F00FABCD'", verifyType(getVarBinaryType(), "'F00FABCD'",
getVarBinaryDbOutput("F00FABCD"),
getVarBinarySeqOutput("F00FABCD"), true); getVarBinarySeqOutput("F00FABCD"), true);
} }
} }