I am getting a run time error when I run a select query in Volt DB stored procedure. When I run the select query in volt DB web studio everything is fine. The error is as follows:
Error: VOLTDB ERROR: UNEXPECTED FAILURE: java.lang.RuntimeException: VoltTableRow is in an invalid state. Consider calling advanceRow(). at org.voltdb.VoltTableRow.validateColumnType(VoltTableRow.java:752) at org.voltdb.VoltTableRow.getDouble(VoltTableRow.java:384) at procedures.testPrcUpdateConstraint.run(testPrcUpdateConstraint.java:93) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.voltdb.ProcedureRunner.call(ProcedureRunner.java:316) at org.voltdb.iv2.ProcedureTask.processInitiateTask(ProcedureTask.java:111) at org.voltdb.iv2.MpProcedureTask.run(MpProcedureTask.java:157) at org.voltdb.iv2.MpRoSite.run(MpRoSite.java:278) at org.voltcore.utils.CoreUtils$6$1.run(CoreUtils.java:644) at java.lang.Thread.run(Thread.java:744)
Any pointers as to what might have went wrong would be very helpful.
from this it appears that the SQL in the stored procedure is fine but you are trying to access some values from a particular row of the VoltTable without first advancing it to the first row. A VoltTable has an internal pointer to the "current row" which is initially not pointed to any row at all.
For example, if you know that the VoltTable has only one row, you could do any of the following:
// most efficient, moves the pointer to the next row
table.advanceRow();
String col1 = table.getString(0);
or
// moves the pointer to an arbitrary row, less efficient for iterating
table.advanceToRow(0);
String col1 = table.getString(0);
or
// least efficient - makes a new copy of the row
VoltTableRow row = table.fetchRow(0);
String col1 = row.getString(0);
There is an example on the Javadoc page for VoltTable. It's the most common idiom for iterating through the rows of a VoltTable:
while (table.advanceRow()) {
System.out.println(table.getLong(7));
}
The advanceRow() and advanceToRow(int rownumber) methods are from VoltTableRow, which VoltTable extends. VoltTable's fetchRow(int rownumber) method returns a copy of that row as a new VoltTableRow object, which contains only one row of data that it is already pointed to.