Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public class NsonProtocol {
public static String VIRTUAL_SCANS = "vssa";
public static String VIRTUAL_SCAN_SID = "vssid";
public static String VIRTUAL_SCAN_PID = "vspid";
public static String VIRTUAL_SCAN_NUM_TABLES = "vsnt";
public static String VIRTUAL_SCAN_CURRENT_INDEX_RANGE = "vscir";
public static String VIRTUAL_SCAN_PRIM_KEY = "vspk";
public static String VIRTUAL_SCAN_SEC_KEY = "vssk";
public static String VIRTUAL_SCAN_MOVE_AFTER = "vsma";
Expand Down Expand Up @@ -276,6 +278,8 @@ public class NsonProtocol {
{VIRTUAL_SCANS,"VIRTUAL_SCANS"},
{VIRTUAL_SCAN_SID,"VIRTUAL_SCAN_SID"},
{VIRTUAL_SCAN_PID,"VIRTUAL_SCAN_PID"},
{VIRTUAL_SCAN_NUM_TABLES,"VIRTUAL_SCAN_NUM_TABLES"},
{VIRTUAL_SCAN_CURRENT_INDEX_RANGE,"VIRTUAL_SCAN_CURRENT_INDEX_RANGE"},
{VIRTUAL_SCAN_PRIM_KEY,"VIRTUAL_SCAN_PRIM_KEY"},
{VIRTUAL_SCAN_SEC_KEY,"VIRTUAL_SCAN_SEC_KEY"},
{VIRTUAL_SCAN_MOVE_AFTER,"VIRTUAL_SCAN_MOVE_AFTER"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
import oracle.nosql.driver.query.QueryDriver;
import oracle.nosql.driver.query.TopologyInfo;
import oracle.nosql.driver.query.VirtualScan;
import oracle.nosql.driver.query.VirtualScan.TableResumeInfo;
import oracle.nosql.driver.util.BinaryProtocol.OpCode;
import oracle.nosql.driver.util.ByteInputStream;
import oracle.nosql.driver.util.ByteOutputStream;
Expand Down Expand Up @@ -906,16 +907,32 @@ private static void writeVirtualScan(NsonSerializer ns,
writeMapField(ns, VIRTUAL_SCAN_SID, vs.sid());
writeMapField(ns, VIRTUAL_SCAN_PID, vs.pid());

if (queryVersion <= QueryDriver.QUERY_V4 && vs.isFirstBatch()) {
writeMapField(ns, VIRTUAL_SCAN_PRIM_KEY, vs.primKey());
writeMapField(ns, VIRTUAL_SCAN_SEC_KEY, vs.secKey());
writeMapField(ns, VIRTUAL_SCAN_MOVE_AFTER, vs.moveAfterResumeKey());

writeMapField(ns, VIRTUAL_SCAN_JOIN_DESC_RESUME_KEY, vs.descResumeKey());
writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_TABLES, vs.joinPathTables());
writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_KEY, vs.joinPathKey());
writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_SEC_KEY, vs.joinPathSecKey());
writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_MATCHED, vs.joinPathMatched());
if (vs.isFirstBatch()) {
int numTables = 1;
if (queryVersion >= QueryDriver.QUERY_V5) {
numTables = vs.numTables();
writeMapField(ns, VIRTUAL_SCAN_NUM_TABLES, numTables);
}
for (int t = 0; t < numTables; ++t) {
writeMapField(ns, VIRTUAL_SCAN_CURRENT_INDEX_RANGE,
vs.currentIndexRange(t));
writeMapField(ns, VIRTUAL_SCAN_PRIM_KEY,
vs.primKey(t));
writeMapField(ns, VIRTUAL_SCAN_SEC_KEY,
vs.secKey(t));
writeMapField(ns, VIRTUAL_SCAN_MOVE_AFTER,
vs.moveAfterResumeKey(t));
writeMapField(ns, VIRTUAL_SCAN_JOIN_DESC_RESUME_KEY,
vs.descResumeKey(t));
writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_TABLES,
vs.joinPathTables(t));
writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_KEY,
vs.joinPathKey(t));
writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_SEC_KEY,
vs.joinPathSecKey(t));
writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_MATCHED,
vs.joinPathMatched(t));
}
}

endMap(ns, VIRTUAL_SCAN);
Expand Down Expand Up @@ -1128,6 +1145,10 @@ private static VirtualScan readVirtualScan(ByteInputStream in)
byte[] joinPathKey = null;
byte[] joinPathSecKey = null;
boolean joinPathMatched = false;
int currentIndexRange = 0;
int numTables = 1;
int currTable = 0;
TableResumeInfo[] tableRIs = new TableResumeInfo[1];

MapWalker walker = getMapWalker(in);

Expand All @@ -1138,6 +1159,11 @@ private static VirtualScan readVirtualScan(ByteInputStream in)
sid = Nson.readNsonInt(in);
} else if (name.equals(VIRTUAL_SCAN_PID)) {
pid = Nson.readNsonInt(in);
} else if (name.equals(VIRTUAL_SCAN_NUM_TABLES)) {
numTables = Nson.readNsonInt(in);
tableRIs = new TableResumeInfo[numTables];
} else if (name.equals(VIRTUAL_SCAN_CURRENT_INDEX_RANGE)) {
currentIndexRange = Nson.readNsonInt(in);
} else if (name.equals(VIRTUAL_SCAN_PRIM_KEY)) {
primKey = Nson.readNsonBinary(in);
} else if (name.equals(VIRTUAL_SCAN_SEC_KEY)) {
Expand All @@ -1154,14 +1180,22 @@ private static VirtualScan readVirtualScan(ByteInputStream in)
joinPathSecKey = Nson.readNsonBinary(in);
} else if (name.equals(VIRTUAL_SCAN_JOIN_PATH_MATCHED)) {
joinPathMatched = Nson.readNsonBoolean(in);
tableRIs[currTable] = new TableResumeInfo(currentIndexRange,
primKey,
secKey,
moveAfter,
descResumeKey,
joinPathTables,
joinPathKey,
joinPathSecKey,
joinPathMatched);
++currTable;
} else {
skipUnknownField(walker, name);
}
}

return new VirtualScan(pid, sid, primKey, secKey, moveAfter,
descResumeKey, joinPathTables, joinPathKey,
joinPathSecKey, joinPathMatched);
return new VirtualScan(pid, sid, tableRIs);
}

private static void readPhase1Results(byte[] arr, QueryResult result)
Expand Down
165 changes: 123 additions & 42 deletions driver/src/main/java/oracle/nosql/driver/query/VirtualScan.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,110 @@

public class VirtualScan {

final private int theSID;
public static class TableResumeInfo {

final private int theCurrentIndexRange;
final private byte[] thePrimResumeKey;
final private byte[] theSecResumeKey;
final private boolean theMoveAfterResumeKey;

final private byte[] theDescResumeKey;
final private int[] theJoinPathTables;
final private byte[] theJoinPathKey;
final private byte[] theJoinPathSecKey;
final private boolean theJoinPathMatched;

public TableResumeInfo(
int currentIndexRange,
byte[] primKey,
byte[] secKey,
boolean moveAfterResumeKey,
byte[] descResumeKey,
int[] joinPathTables,
byte[] joinPathKey,
byte[] joinPathSecKey,
boolean joinPathMatched) {

theCurrentIndexRange = currentIndexRange;
thePrimResumeKey = primKey;
theSecResumeKey = secKey;
theMoveAfterResumeKey = moveAfterResumeKey;
theDescResumeKey = descResumeKey;
theJoinPathTables = joinPathTables;
theJoinPathKey = joinPathKey;
theJoinPathSecKey = joinPathSecKey;
theJoinPathMatched = joinPathMatched;
}

@Override
public String toString() {

StringBuilder sb = new StringBuilder();

sb.append("theCurrentIndexRange = ").append(theCurrentIndexRange);
sb.append("\n");

if (thePrimResumeKey != null) {
sb.append("thePrimResumeKey = ");
sb.append(PlanIter.printByteArray(thePrimResumeKey));
sb.append("\n");
}

if (theSecResumeKey != null) {
sb.append("theSecResumeKey = ");
sb.append(PlanIter.printByteArray(theSecResumeKey));
sb.append("\n");
}

sb.append("theMoveAfterResumeKey = ").append(theMoveAfterResumeKey);
sb.append("\n");

if (theDescResumeKey != null) {
sb.append("theDescResumeKey = ");
sb.append(PlanIter.printByteArray(theDescResumeKey));
sb.append("\n");
}

if (theJoinPathTables != null) {
sb.append("theJoinPathTables = ");
sb.append(PlanIter.printIntArray(theJoinPathTables));
sb.append("\n");
}

if (theJoinPathKey != null) {
sb.append("theJoinPathKey = ");
sb.append(PlanIter.printByteArray(theJoinPathKey));
sb.append("\n");
}

if (theJoinPathSecKey != null) {
sb.append("theJoinPathSecKey = ");
sb.append(PlanIter.printByteArray(theJoinPathSecKey));
sb.append("\n");
}

sb.append("theJoinPathMatched = ").append(theJoinPathMatched);
sb.append("\n");

return sb.toString();
}
}

final private int theSID;
final private int thePID;
final private TableResumeInfo[] theTableRIs;

final private byte[] thePrimResumeKey;
final private byte[] theSecResumeKey;
final private boolean theMoveAfterResumeKey;

final private byte[] theDescResumeKey;
final private int[] theJoinPathTables;
final private byte[] theJoinPathKey;
final private byte[] theJoinPathSecKey;
final private boolean theJoinPathMatched;

boolean theFirstBatch = true;

public VirtualScan(
int pid,
int sid,
byte[] primKey,
byte[] secKey,
boolean moveAfterResumeKey,
byte[] descResumeKey,
int[] joinPathTables,
byte[] joinPathKey,
byte[] joinPathSecKey,
boolean joinPathMatched) {
TableResumeInfo[] tableRIs) {

theSID = sid;
thePID = pid;
thePrimResumeKey = primKey;
theSecResumeKey = secKey;
theMoveAfterResumeKey = moveAfterResumeKey;
theDescResumeKey = descResumeKey;
theJoinPathTables = joinPathTables;
theJoinPathKey = joinPathKey;
theJoinPathSecKey = joinPathSecKey;
theJoinPathMatched = joinPathMatched;
theTableRIs = tableRIs;
}

public int sid() {
Expand All @@ -57,36 +124,44 @@ public int pid() {
return thePID;
}

public byte[] secKey() {
return theSecResumeKey;
public int numTables() {
return theTableRIs.length;
}

public byte[] primKey() {
return thePrimResumeKey;
public int currentIndexRange(int i) {
return theTableRIs[i].theCurrentIndexRange;
}

public boolean moveAfterResumeKey() {
return theMoveAfterResumeKey;
public byte[] secKey(int i) {
return theTableRIs[i].theSecResumeKey;
}

public byte[] descResumeKey() {
return theDescResumeKey;
public byte[] primKey(int i) {
return theTableRIs[i].thePrimResumeKey;
}

public boolean moveAfterResumeKey(int i) {
return theTableRIs[i].theMoveAfterResumeKey;
}

public byte[] descResumeKey(int i) {
return theTableRIs[i].theDescResumeKey;
}

public int[] joinPathTables() {
return theJoinPathTables;
public int[] joinPathTables(int i) {
return theTableRIs[i].theJoinPathTables;
}

public byte[] joinPathKey() {
return theJoinPathKey;
public byte[] joinPathKey(int i) {
return theTableRIs[i].theJoinPathKey;
}

public byte[] joinPathSecKey() {
return theJoinPathSecKey;
public byte[] joinPathSecKey(int i) {
return theTableRIs[i].theJoinPathSecKey;
}

public boolean joinPathMatched() {
return theJoinPathMatched;
public boolean joinPathMatched(int i) {
return theTableRIs[i].theJoinPathMatched;
}

public boolean isFirstBatch() {
Expand All @@ -103,6 +178,12 @@ public String toString() {

sb.append("theFirstBatch = ").append(theFirstBatch);
sb.append("\n");

for (int i = 0; i < theTableRIs.length; ++i) {
sb.append("Table RI ").append(i).append(":\n");
sb.append(theTableRIs[i]);
}

return sb.toString();
}
}