Skip to content

Commit

Permalink
added missing test cases consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
suarezgpablo committed Dec 16, 2024
1 parent 3e548e4 commit 20ad0e3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,15 @@ public void csvCassandra(String tableName, String keyspace, String properties, S
}

/**
* Auxiliary method of csvCassandra that processes each row and returns
* Auxiliary method of csvCassandra that processes each row and returns
* its content in a string formatted as a CSV.
*/
private String rowProcessing(Row row, String[][] results, boolean[] numeric, int rowNumber, int columnNumber) {
StringBuilder stringRow = new StringBuilder("\"");
for (int i = 0; i < columnNumber; i++) {
String result = row.getString(i);
if (result == null) { //When there is no value stored in the db, skip the iteration
stringRow.append(",\"\"");
continue;
}
if (i==0) {
Expand Down Expand Up @@ -119,8 +120,8 @@ private String[][] sortMatrix(String[][] matrixResultSet, int columnNumber, List
matrixResultSet = sortMatrix(matrixResultSet, columnNumber + 1, cassandraRows, 0,
matrixResultSet.length - 1, numericArray);
return matrixResultSet;
}
//For the rest of columns it sorts them when the values of the first column are the same. This also applies
}
//For the rest of columns it sorts them when the values of the first column are the same. This also applies
//for the following of columns
else {
List<Integer> border = equalRanges(beggining, end, columnNumber - 1, matrixResultSet,
Expand Down Expand Up @@ -161,8 +162,8 @@ private void sortIteration (boolean numeric, String[][] matrixResultSet, List<St
String next = matrixResultSet[row2][numberColumn];
boolean sort = false;
if (numeric) {
Long currentNumber = Long.valueOf(current);
Long nextNumber = Long.valueOf(next);
long currentNumber = Long.parseLong(current);
long nextNumber = Long.parseLong(next);
if (currentNumber < nextNumber) {
sort = true;
}
Expand Down Expand Up @@ -263,7 +264,7 @@ public void convertToCsv(java.sql.ResultSet rs, String path) {

/**
* Returns the names of the tables of a keyspace
* @param tableProjection
* @param tableProjection
*/
public Map<String, List<String>> namesTablesColumnsKeyspace(String keyspace, CassandraConnection connection, Map<String, String> tableProjection) {
Map<String, List<String>> tableColumns = new HashMap<>();
Expand All @@ -288,7 +289,7 @@ public Map<String, List<String>> namesTablesColumnsKeyspace(String keyspace, Cas
List<String> columnNamesList = new ArrayList<>();
BoundStatement bsColumns = columnNamesPreparedStatement.bind(keyspace, tableName);
ResultSet resultColumnNames = connection.executeStatement(bsColumns);
Row rowColumnNames = resultColumnNames.one();
Row rowColumnNames = resultColumnNames.one();
while (rowColumnNames != null) {
String columnName = rowColumnNames.getString("column_name");
if (projectionStatementTable.matches(".*\\b" + columnName + "\\b.*")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,30 @@ public void testCustomV7SplitTable() throws IOException {
testConsistency(name.getMethodName(), projectionAfterEvo, "custom", projectionBeforeEvo);
}
@Test
public void testCustomV8JoinColumn() throws IOException {
Map<String, String> projectionAfterEvo = new HashMap<String, String>();
Map<String, String> projectionBeforeEvo = new HashMap<String, String>();
projectionBeforeEvo.put("table1", "SELECT author.id AS idauthor, book.id AS idbook, book.title as title, book.subtitle AS subtitle FROM author INNER JOIN authorbook ON author.id = authorbook.idauthor INNER JOIN book ON book.id = authorbook.idbook;");
projectionAfterEvo.put("table1", "SELECT author.id AS idauthor, book.id AS idbook, CONCAT(book.title, book.subtitle) AS completetitle, book.subtitle AS subtitle, book.title as title FROM author INNER JOIN authorbook ON author.id = authorbook.idauthor INNER JOIN book ON book.id = authorbook.idbook ORDER BY author.id DESC, book.id DESC;");
testConsistency(name.getMethodName(), projectionAfterEvo, "custom", projectionBeforeEvo);
}
@Test
public void testCustomV9RemovePK() throws IOException {
Map<String, String> projectionAfterEvo = new HashMap<String, String>();
Map<String, String> projectionBeforeEvo = new HashMap<String, String>();
projectionBeforeEvo.put("table1beforechange", "SELECT author.id AS idauthor, book.id AS idbook, book.title as title FROM author INNER JOIN authorbook ON author.id = authorbook.idauthor INNER JOIN book ON book.id = authorbook.idbook;");
projectionAfterEvo.put("table1", "SELECT author.id AS idauthor, book.id AS idbook FROM author INNER JOIN authorbook ON author.id = authorbook.idauthor INNER JOIN book ON book.id = authorbook.idbook ORDER BY author.id DESC, book.id DESC;");
testConsistency(name.getMethodName(), projectionAfterEvo, "custom", projectionBeforeEvo);
}
@Test
public void testMindsV3SplitColumn() throws IOException {
Map<String, String> projectionAfterEvo = new HashMap<String, String>();
Map<String, String> projectionBeforeEvo = new HashMap<String, String>();
projectionBeforeEvo.put("comments", "SELECT id, parent_guid FROM comments;");
projectionAfterEvo.put("comments", "SELECT id,parent_guid, CASE WHEN parent_guid < 'F' THEN parent_guid ELSE NULL END AS parent_guid_c1, CASE WHEN parent_guid < 'P' THEN parent_guid ELSE NULL END AS parent_guid_c2, CASE WHEN parent_guid > 'P' THEN parent_guid ELSE NULL END AS parent_guid_c3 FROM comments ORDER BY id DESC;");
testConsistency(name.getMethodName(), projectionAfterEvo, "minds", projectionBeforeEvo);
}
@Test
public void testMindsV10NewTableMigrationFromOneTable() throws IOException {
Map<String, String> projectionAfterEvo = new HashMap<String, String>();
Map<String, String> projectionBeforeEvo = new HashMap<String, String>();
Expand Down
12 changes: 6 additions & 6 deletions modevo-transform/dat/inp/testMindsV3SplitColumn-schemaChange.xmi
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
<CriteriaSplit
xmi:id="cs1"
column="c1"
value="f"
operator="g"/>
value="F"
operator="l"/>
<CriteriaSplit
xmi:id="cs2"
column="c2"
value="p"
operator="g"/>
value="P"
operator="l"/>
<CriteriaSplit
xmi:id="cs3"
column="c3"
value="p"
operator="l"/>
value="P"
operator="g"/>
</xmi:XMI>
Loading

0 comments on commit 20ad0e3

Please sign in to comment.