use of org.knime.core.data.def.DefaultTable in project knime-core by knime.
the class AppendedRowsTableTest method testAppendedRowsTableDataTableArray.
/**
* Class under test for void AppendedRowsTable(DataTable[]).
*/
public void testAppendedRowsTableDataTableArray() {
DataTable firstTable = new DefaultTable(DATA, DATA_H, DATA_TYPES);
DataTable firstTableMissing = new DefaultTable(DATA_MISS_LAST, DATA_MISS_LAST_H, DATA_MISS_LAST_TYPES);
DataTable firstTableShuffle = new DefaultTable(DATA_SHUFFLE, DATA_SHUFFLE_H, DATA_SHUFFLE_TYPES);
DataTable secondTable = new DefaultTable(DATA_2, DATA_H, DATA_TYPES);
new AppendedRowsTable(firstTable, secondTable);
try {
new AppendedRowsTable(firstTable, null);
fail();
} catch (NullPointerException npe) {
// do nothing
}
try {
new AppendedRowsTable((DataTable) null, secondTable);
fail();
} catch (NullPointerException npe) {
// do nothing
}
new AppendedRowsTable(new DataTable[] { firstTableMissing, secondTable });
new AppendedRowsTable(new DataTable[] { firstTable, firstTableShuffle });
}
use of org.knime.core.data.def.DefaultTable in project knime-core by knime.
the class AppendedRowsTableTest method testGetDataTableSpec.
/**
* Test method for getDataTableSpec().
*/
public void testGetDataTableSpec() {
DataTable firstTable = new DefaultTable(DATA, DATA_H, DATA_TYPES);
DataTable firstTableShuffle = new DefaultTable(DATA_SHUFFLE, DATA_SHUFFLE_H, DATA_SHUFFLE_TYPES);
DataTable ap = new AppendedRowsTable(new DataTable[] { firstTable, firstTableShuffle });
assertTrue(ap.getDataTableSpec().equalStructure(firstTable.getDataTableSpec()));
}
use of org.knime.core.data.def.DefaultTable in project knime-core by knime.
the class JoinedTableTest method testMergedTable.
/**
* Test for constructor.
*/
public final void testMergedTable() {
DataColumnSpec[] leftCols = new DataColumnSpec[3];
DataColumnSpec[] rightCols = new DataColumnSpec[3];
System.arraycopy(COLS, 0, leftCols, 0, 3);
System.arraycopy(COLS, 3, rightCols, 0, 3);
DataTable leftTable = new DefaultTable(new DataRow[0], new DataTableSpec(leftCols));
DataTable rightTable = new DefaultTable(new DataRow[0], new DataTableSpec(rightCols));
new JoinedTable(leftTable, rightTable);
try {
new JoinedTable(null, rightTable);
fail();
} catch (NullPointerException ne) {
NodeLogger.getLogger(JoinedTableTest.class).debug("Got expected exception: " + ne.getClass(), ne);
}
try {
new JoinedTable(leftTable, null);
fail();
} catch (NullPointerException ne) {
NodeLogger.getLogger(JoinedTableTest.class).debug("Got expected exception: " + ne.getClass(), ne);
}
try {
new JoinedTable(leftTable, leftTable);
fail();
} catch (IllegalArgumentException iae) {
NodeLogger.getLogger(JoinedTableTest.class).debug("Got expected exception: " + iae.getClass(), iae);
}
try {
new JoinedTable(leftTable, leftTable);
fail();
} catch (IllegalArgumentException iae) {
NodeLogger.getLogger(JoinedTableTest.class).debug("Got expected exception: " + iae.getClass(), iae);
}
rightCols[1] = leftCols[2];
rightTable = new DefaultTable(new DataRow[0], new DataTableSpec(rightCols));
try {
new JoinedTable(leftTable, rightTable);
fail();
} catch (IllegalArgumentException iae) {
NodeLogger.getLogger(JoinedTableTest.class).debug("Got expected exception: " + iae.getClass(), iae);
}
}
use of org.knime.core.data.def.DefaultTable in project knime-core by knime.
the class JoinedTableTest method testGetRowIterator.
/**
* Test for RowIterator. That is the one that is most likely to fail ...
*/
public final void testGetRowIterator() {
DataColumnSpec[] leftCols = new DataColumnSpec[3];
DataColumnSpec[] rightCols = new DataColumnSpec[3];
System.arraycopy(COLS, 0, leftCols, 0, 3);
System.arraycopy(COLS, 3, rightCols, 0, 3);
final int allLength = 100;
DataRow[] leftRows = new DataRow[allLength];
DataRow[] rightRows = new DataRow[allLength];
Hashtable<RowKey, DataRow> rightHash = new Hashtable<RowKey, DataRow>();
for (int i = 0; i < allLength; i++) {
String id = "Id_" + i;
leftRows[i] = getRandomRow(id);
rightRows[i] = getRandomRow(id);
rightHash.put(rightRows[i].getKey(), rightRows[i]);
}
final DataTable leftTable = new DefaultTable(leftRows, new DataTableSpec(leftCols));
final DataTable rightTable = new DefaultTable(rightRows, new DataTableSpec(rightCols));
JoinedTable t = new JoinedTable(leftTable, rightTable);
// everything comes in order, shouldn't make a problem.
int count = checkForEquality(t, leftRows, rightHash);
assertEquals(count, allLength);
// shuffle the right table
DataRow[] shuffledRightRows = new DataRow[allLength];
System.arraycopy(rightRows, 0, shuffledRightRows, 0, allLength);
List<DataRow> c = Arrays.asList(shuffledRightRows);
Collections.shuffle(c, RAND);
shuffledRightRows = c.toArray(shuffledRightRows);
DataTable shuffleRightTable = new DefaultTable(shuffledRightRows, new DataTableSpec(rightCols));
t = new JoinedTable(leftTable, shuffleRightTable);
count = checkForEquality(t, leftRows, rightHash);
assertEquals(count, allLength);
// wow, it survived that.
// let's delete some of the rows in the right table.
// supposedly, the table will fill it with missing values ...
final int newLength = (int) (0.8 * allLength);
DataRow[] shuffledAndTruncRightRows = new DataRow[newLength];
System.arraycopy(shuffledRightRows, 0, shuffledAndTruncRightRows, 0, newLength);
Hashtable<RowKey, DataRow> newHash = new Hashtable<RowKey, DataRow>(rightHash);
for (int i = newLength; i < allLength; i++) {
RowKey removeMe = shuffledRightRows[i].getKey();
newHash.remove(removeMe);
}
DataTable shuffleAndTruncRightTable = new DefaultTable(shuffledAndTruncRightRows, new DataTableSpec(rightCols));
t = new JoinedTable(leftTable, shuffleAndTruncRightTable);
count = checkForEquality(t, leftRows, newHash);
assertEquals(count, allLength);
// now cut shorten the left table
DataRow[] truncLeftRows = new DataRow[newLength];
System.arraycopy(leftRows, 0, truncLeftRows, 0, newLength);
DataTable truncLeftTable = new DefaultTable(truncLeftRows, new DataTableSpec(leftCols));
t = new JoinedTable(truncLeftTable, rightTable);
count = checkForEquality(t, truncLeftRows, rightHash);
assertEquals(count, allLength);
// tables share no rows at all
final int halfLength = allLength / 2;
DataRow[] halfLeftRows = new DataRow[halfLength];
DataRow[] halfRightRows = new DataRow[halfLength];
System.arraycopy(leftRows, 0, halfLeftRows, 0, halfLength);
System.arraycopy(rightRows, halfLength, halfRightRows, 0, halfLength);
Hashtable<RowKey, DataRow> halfRightHash = new Hashtable<RowKey, DataRow>();
for (int i = 0; i < halfLength; i++) {
DataRow current = halfRightRows[i];
halfRightHash.put(current.getKey(), current);
}
DataTable halfLeftTable = new DefaultTable(halfLeftRows, new DataTableSpec(leftCols));
DataTable halfRightTable = new DefaultTable(halfRightRows, new DataTableSpec(rightCols));
t = new JoinedTable(halfLeftTable, halfRightTable);
count = checkForEquality(t, halfLeftRows, halfRightHash);
assertEquals(count, 2 * halfLength);
// left table is empty
DataTable emptyLeftTable = new DefaultTable(new DataRow[0], new DataTableSpec(leftCols));
t = new JoinedTable(emptyLeftTable, halfRightTable);
count = checkForEquality(t, new DataRow[0], halfRightHash);
assertEquals(count, halfLength);
// right table is empty
DataTable emptyRightTable = new DefaultTable(new DataRow[0], new DataTableSpec(rightCols));
t = new JoinedTable(halfLeftTable, emptyRightTable);
count = checkForEquality(t, halfLeftRows, new Hashtable<RowKey, DataRow>());
assertEquals(count, halfLength);
}
use of org.knime.core.data.def.DefaultTable in project knime-core by knime.
the class JoinedTableTest method testGetDataTableSpec.
/**
* Test for getDataTableSpec().
*/
public final void testGetDataTableSpec() {
DataColumnSpec[] leftCols = new DataColumnSpec[3];
DataColumnSpec[] rightCols = new DataColumnSpec[3];
System.arraycopy(COLS, 0, leftCols, 0, 3);
System.arraycopy(COLS, 3, rightCols, 0, 3);
DataTable leftTable = new DefaultTable(new DataRow[0], new DataTableSpec(leftCols));
DataTable rightTable = new DefaultTable(new DataRow[0], new DataTableSpec(rightCols));
JoinedTable t = new JoinedTable(leftTable, rightTable);
DataTableSpec s = t.getDataTableSpec();
assert (!t.iterator().hasNext());
assertEquals(s.getNumColumns(), COLS.length);
for (int i = 0; i < COLS.length; i++) {
assertEquals(s.getColumnSpec(i), COLS[i]);
}
}
Aggregations