Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] multiple-partition constraint #210

Merged
merged 1 commit into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 49 additions & 19 deletions voltdb/BatchRemoveINodes.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,63 @@
import org.voltdb.*;
import java.util.List;
import java.util.ArrayList;

public class BatchRemoveINodes extends VoltProcedure {

public final SQLStmt sql1 =
new SQLStmt(
"WITH RECURSIVE cte AS ("
+ " SELECT id, parent FROM inodes d WHERE id = ?"
+ " UNION ALL"
+ " SELECT d.id, d.parent FROM cte"
+ " JOIN inodes d ON cte.id = d.parent"
+ " )"
+ " SELECT id FROM cte;");
// public final SQLStmt sql1 =
// new SQLStmt(
// "WITH RECURSIVE cte AS ("
// + " SELECT id, parent FROM inodes d WHERE id = ?"
// + " UNION ALL"
// + " SELECT d.id, d.parent FROM cte"
// + " JOIN inodes d ON cte.id = d.parent"
// + " )"
// + " SELECT id FROM cte;");
// public final SQLStmt sql2 = new SQLStmt("DELETE FROM inodes WHERE id = ?;");

// public long run(long[] ids) throws VoltAbortException {
// for (int i = 0; i < ids.length; ++i) {
// voltQueueSQL(sql1, ids[i]);
// }
// VoltTable[] results = voltExecuteSQL();

// if (results[0].getRowCount() < 1) {
// return -1;
// }

// for (int j = 0; j < results.length; ++j) {
// for (int i = 0; i < results[j].getRowCount(); ++i) {
// voltQueueSQL(sql2, results[j].fetchRow(i).getLong(0));
// }
// }
// voltExecuteSQL();
// return 1;
// }

public final SQLStmt sql1 = new SQLStmt("SELECT id FROM inodes WHERE parent = ?");
public final SQLStmt sql2 = new SQLStmt("DELETE FROM inodes WHERE id = ?;");

public long run(long[] ids) throws VoltAbortException {
for (int i = 0; i < ids.length; ++i) {
voltQueueSQL(sql1, ids[i]);
}
VoltTable[] results = voltExecuteSQL();
List<Long> set = new ArrayList<Long>(Arrays.asList(ids));

if (results[0].getRowCount() < 1) {
return -1;
int i = 0;
while (i < set.size()) {
long cid = set.get(i);
i++;
voltQueueSQL(sql1, cid);
VoltTable[] results = voltExecuteSQL();
if (results[0].getRowCount() < 1) {
continue;
}
for (int j = 0; j < results[0].getRowCount(); ++j) {
set.add(results[0].fetchRow(j).getLong(0));
}
}

for (int j = 0; j < results.length; ++j) {
for (int i = 0; i < results[j].getRowCount(); ++i) {
voltQueueSQL(sql2, results[j].fetchRow(i).getLong(0));
}
for (Long id : set) {
voltQueueSQL(sql2, id);
}

voltExecuteSQL();
return 1;
}
Expand Down
63 changes: 48 additions & 15 deletions voltdb/RemoveChild.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,62 @@
import java.util.ArrayList;
import java.util.List;
import org.voltdb.*;

// https://docs.voltdb.com/tutorial/Part5.php
public class RemoveChild extends VoltProcedure {

public final SQLStmt sql1 =
new SQLStmt(
"WITH RECURSIVE cte AS ("
+ " SELECT id, parent FROM inodes d WHERE id = ?"
+ " UNION ALL"
+ " SELECT d.id, d.parent FROM cte"
+ " JOIN inodes d ON cte.id = d.parent"
+ " )"
+ " SELECT id FROM cte;");
// CTE only support single partition query
// public final SQLStmt sql1 =
// new SQLStmt(
// "WITH RECURSIVE cte AS ("
// + " SELECT id, parent FROM inodes d WHERE id = ?"
// + " UNION ALL"
// + " SELECT d.id, d.parent FROM cte"
// + " JOIN inodes d ON cte.id = d.parent"
// + " )"
// + " SELECT id FROM cte;");

// public final SQLStmt sql2 = new SQLStmt("DELETE FROM inodes WHERE id = ?;");

// public long run(long id) throws VoltAbortException {
// voltQueueSQL(sql1, id);
// VoltTable[] results = voltExecuteSQL();

// if (results[0].getRowCount() < 1) {
// return -1;
// }
// for (int i = 0; i < results[0].getRowCount(); ++i) {
// voltQueueSQL(sql2, results[0].fetchRow(i).getLong(0));
// }
// voltExecuteSQL();
// return 1;
// }

public final SQLStmt sql1 = new SQLStmt("SELECT id FROM inodes WHERE parent = ?");
public final SQLStmt sql2 = new SQLStmt("DELETE FROM inodes WHERE id = ?;");

public long run(long id) throws VoltAbortException {
voltQueueSQL(sql1, id);
VoltTable[] results = voltExecuteSQL();
List<Long> set = new ArrayList<>();
set.add(id);

if (results[0].getRowCount() < 1) {
return -1;
int i = 0;
while (i < set.size()) {
long cid = set.get(i);
i++;
voltQueueSQL(sql1, cid);
VoltTable[] results = voltExecuteSQL();
if (results[0].getRowCount() < 1) {
continue;
}
for (int j = 0; j < results[0].getRowCount(); ++j) {
set.add(results[0].fetchRow(j).getLong(0));
}
}
for (int i = 0; i < results[0].getRowCount(); ++i) {
voltQueueSQL(sql2, results[0].fetchRow(i).getLong(0));

for (Long id : set) {
voltQueueSQL(sql2, id);
}

voltExecuteSQL();
return 1;
}
Expand Down
16 changes: 10 additions & 6 deletions voltdb/UpdateModificationTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

// https://docs.voltdb.com/tutorial/Part5.php
public class UpdateModificationTime extends VoltProcedure {

public final SQLStmt sql =
new SQLStmt(
"UPDATE inodes SET modificationTime = ("
+ "SELECT modificationTime FROM inodes WHERE id = ?) WHERE id = ?;");
public final SQLStmt sql1 = new SQLStmt("SELECT modificationTime FROM inodes WHERE id = ?");
public final SQLStmt sql2 = new SQLStmt("UPDATE inodes SET modificationTime = ? WHERE id = ?;");

public long run(final long id, final long childId) throws VoltAbortException {
voltQueueSQL(sql, childId, id);
voltQueueSQL(sql1, childId);
VoltTable[] results = voltExecuteSQL();
if (results[0].getRowCount() < 1) {
return -1;
}

Long mtime = results[0].fetchRow(0).getLong(0);
voltQueueSQL(sql2, mtime, id);
voltExecuteSQL();
return 1;
}
Expand Down