Skip to content

Commit 801e8ff

Browse files
authored
reverted VirtualScan simplification and added join-related info to VirtualScan (#145)
1 parent 98b4eeb commit 801e8ff

File tree

3 files changed

+174
-55
lines changed

3 files changed

+174
-55
lines changed

driver/src/main/java/oracle/nosql/driver/ops/serde/nson/NsonProtocol.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ public class NsonProtocol {
108108
public static String VIRTUAL_SCANS = "vssa";
109109
public static String VIRTUAL_SCAN_SID = "vssid";
110110
public static String VIRTUAL_SCAN_PID = "vspid";
111+
public static String VIRTUAL_SCAN_NUM_TABLES = "vsnt";
112+
public static String VIRTUAL_SCAN_CURRENT_INDEX_RANGE = "vscir";
111113
public static String VIRTUAL_SCAN_PRIM_KEY = "vspk";
112114
public static String VIRTUAL_SCAN_SEC_KEY = "vssk";
113115
public static String VIRTUAL_SCAN_MOVE_AFTER = "vsma";
@@ -276,6 +278,8 @@ public class NsonProtocol {
276278
{VIRTUAL_SCANS,"VIRTUAL_SCANS"},
277279
{VIRTUAL_SCAN_SID,"VIRTUAL_SCAN_SID"},
278280
{VIRTUAL_SCAN_PID,"VIRTUAL_SCAN_PID"},
281+
{VIRTUAL_SCAN_NUM_TABLES,"VIRTUAL_SCAN_NUM_TABLES"},
282+
{VIRTUAL_SCAN_CURRENT_INDEX_RANGE,"VIRTUAL_SCAN_CURRENT_INDEX_RANGE"},
279283
{VIRTUAL_SCAN_PRIM_KEY,"VIRTUAL_SCAN_PRIM_KEY"},
280284
{VIRTUAL_SCAN_SEC_KEY,"VIRTUAL_SCAN_SEC_KEY"},
281285
{VIRTUAL_SCAN_MOVE_AFTER,"VIRTUAL_SCAN_MOVE_AFTER"},

driver/src/main/java/oracle/nosql/driver/ops/serde/nson/NsonSerializerFactory.java

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
import oracle.nosql.driver.query.QueryDriver;
102102
import oracle.nosql.driver.query.TopologyInfo;
103103
import oracle.nosql.driver.query.VirtualScan;
104+
import oracle.nosql.driver.query.VirtualScan.TableResumeInfo;
104105
import oracle.nosql.driver.util.BinaryProtocol.OpCode;
105106
import oracle.nosql.driver.util.ByteInputStream;
106107
import oracle.nosql.driver.util.ByteOutputStream;
@@ -906,16 +907,32 @@ private static void writeVirtualScan(NsonSerializer ns,
906907
writeMapField(ns, VIRTUAL_SCAN_SID, vs.sid());
907908
writeMapField(ns, VIRTUAL_SCAN_PID, vs.pid());
908909

909-
if (queryVersion <= QueryDriver.QUERY_V4 && vs.isFirstBatch()) {
910-
writeMapField(ns, VIRTUAL_SCAN_PRIM_KEY, vs.primKey());
911-
writeMapField(ns, VIRTUAL_SCAN_SEC_KEY, vs.secKey());
912-
writeMapField(ns, VIRTUAL_SCAN_MOVE_AFTER, vs.moveAfterResumeKey());
913-
914-
writeMapField(ns, VIRTUAL_SCAN_JOIN_DESC_RESUME_KEY, vs.descResumeKey());
915-
writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_TABLES, vs.joinPathTables());
916-
writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_KEY, vs.joinPathKey());
917-
writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_SEC_KEY, vs.joinPathSecKey());
918-
writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_MATCHED, vs.joinPathMatched());
910+
if (vs.isFirstBatch()) {
911+
int numTables = 1;
912+
if (queryVersion >= QueryDriver.QUERY_V5) {
913+
numTables = vs.numTables();
914+
writeMapField(ns, VIRTUAL_SCAN_NUM_TABLES, numTables);
915+
}
916+
for (int t = 0; t < numTables; ++t) {
917+
writeMapField(ns, VIRTUAL_SCAN_CURRENT_INDEX_RANGE,
918+
vs.currentIndexRange(t));
919+
writeMapField(ns, VIRTUAL_SCAN_PRIM_KEY,
920+
vs.primKey(t));
921+
writeMapField(ns, VIRTUAL_SCAN_SEC_KEY,
922+
vs.secKey(t));
923+
writeMapField(ns, VIRTUAL_SCAN_MOVE_AFTER,
924+
vs.moveAfterResumeKey(t));
925+
writeMapField(ns, VIRTUAL_SCAN_JOIN_DESC_RESUME_KEY,
926+
vs.descResumeKey(t));
927+
writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_TABLES,
928+
vs.joinPathTables(t));
929+
writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_KEY,
930+
vs.joinPathKey(t));
931+
writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_SEC_KEY,
932+
vs.joinPathSecKey(t));
933+
writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_MATCHED,
934+
vs.joinPathMatched(t));
935+
}
919936
}
920937

921938
endMap(ns, VIRTUAL_SCAN);
@@ -1128,6 +1145,10 @@ private static VirtualScan readVirtualScan(ByteInputStream in)
11281145
byte[] joinPathKey = null;
11291146
byte[] joinPathSecKey = null;
11301147
boolean joinPathMatched = false;
1148+
int currentIndexRange = 0;
1149+
int numTables = 1;
1150+
int currTable = 0;
1151+
TableResumeInfo[] tableRIs = new TableResumeInfo[1];
11311152

11321153
MapWalker walker = getMapWalker(in);
11331154

@@ -1138,6 +1159,11 @@ private static VirtualScan readVirtualScan(ByteInputStream in)
11381159
sid = Nson.readNsonInt(in);
11391160
} else if (name.equals(VIRTUAL_SCAN_PID)) {
11401161
pid = Nson.readNsonInt(in);
1162+
} else if (name.equals(VIRTUAL_SCAN_NUM_TABLES)) {
1163+
numTables = Nson.readNsonInt(in);
1164+
tableRIs = new TableResumeInfo[numTables];
1165+
} else if (name.equals(VIRTUAL_SCAN_CURRENT_INDEX_RANGE)) {
1166+
currentIndexRange = Nson.readNsonInt(in);
11411167
} else if (name.equals(VIRTUAL_SCAN_PRIM_KEY)) {
11421168
primKey = Nson.readNsonBinary(in);
11431169
} else if (name.equals(VIRTUAL_SCAN_SEC_KEY)) {
@@ -1154,14 +1180,22 @@ private static VirtualScan readVirtualScan(ByteInputStream in)
11541180
joinPathSecKey = Nson.readNsonBinary(in);
11551181
} else if (name.equals(VIRTUAL_SCAN_JOIN_PATH_MATCHED)) {
11561182
joinPathMatched = Nson.readNsonBoolean(in);
1183+
tableRIs[currTable] = new TableResumeInfo(currentIndexRange,
1184+
primKey,
1185+
secKey,
1186+
moveAfter,
1187+
descResumeKey,
1188+
joinPathTables,
1189+
joinPathKey,
1190+
joinPathSecKey,
1191+
joinPathMatched);
1192+
++currTable;
11571193
} else {
11581194
skipUnknownField(walker, name);
11591195
}
11601196
}
11611197

1162-
return new VirtualScan(pid, sid, primKey, secKey, moveAfter,
1163-
descResumeKey, joinPathTables, joinPathKey,
1164-
joinPathSecKey, joinPathMatched);
1198+
return new VirtualScan(pid, sid, tableRIs);
11651199
}
11661200

11671201
private static void readPhase1Results(byte[] arr, QueryResult result)

driver/src/main/java/oracle/nosql/driver/query/VirtualScan.java

Lines changed: 123 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,110 @@
1010

1111
public class VirtualScan {
1212

13-
final private int theSID;
13+
public static class TableResumeInfo {
14+
15+
final private int theCurrentIndexRange;
16+
final private byte[] thePrimResumeKey;
17+
final private byte[] theSecResumeKey;
18+
final private boolean theMoveAfterResumeKey;
19+
20+
final private byte[] theDescResumeKey;
21+
final private int[] theJoinPathTables;
22+
final private byte[] theJoinPathKey;
23+
final private byte[] theJoinPathSecKey;
24+
final private boolean theJoinPathMatched;
25+
26+
public TableResumeInfo(
27+
int currentIndexRange,
28+
byte[] primKey,
29+
byte[] secKey,
30+
boolean moveAfterResumeKey,
31+
byte[] descResumeKey,
32+
int[] joinPathTables,
33+
byte[] joinPathKey,
34+
byte[] joinPathSecKey,
35+
boolean joinPathMatched) {
36+
37+
theCurrentIndexRange = currentIndexRange;
38+
thePrimResumeKey = primKey;
39+
theSecResumeKey = secKey;
40+
theMoveAfterResumeKey = moveAfterResumeKey;
41+
theDescResumeKey = descResumeKey;
42+
theJoinPathTables = joinPathTables;
43+
theJoinPathKey = joinPathKey;
44+
theJoinPathSecKey = joinPathSecKey;
45+
theJoinPathMatched = joinPathMatched;
46+
}
47+
48+
@Override
49+
public String toString() {
50+
51+
StringBuilder sb = new StringBuilder();
52+
53+
sb.append("theCurrentIndexRange = ").append(theCurrentIndexRange);
54+
sb.append("\n");
55+
56+
if (thePrimResumeKey != null) {
57+
sb.append("thePrimResumeKey = ");
58+
sb.append(PlanIter.printByteArray(thePrimResumeKey));
59+
sb.append("\n");
60+
}
61+
62+
if (theSecResumeKey != null) {
63+
sb.append("theSecResumeKey = ");
64+
sb.append(PlanIter.printByteArray(theSecResumeKey));
65+
sb.append("\n");
66+
}
67+
68+
sb.append("theMoveAfterResumeKey = ").append(theMoveAfterResumeKey);
69+
sb.append("\n");
70+
71+
if (theDescResumeKey != null) {
72+
sb.append("theDescResumeKey = ");
73+
sb.append(PlanIter.printByteArray(theDescResumeKey));
74+
sb.append("\n");
75+
}
76+
77+
if (theJoinPathTables != null) {
78+
sb.append("theJoinPathTables = ");
79+
sb.append(PlanIter.printIntArray(theJoinPathTables));
80+
sb.append("\n");
81+
}
82+
83+
if (theJoinPathKey != null) {
84+
sb.append("theJoinPathKey = ");
85+
sb.append(PlanIter.printByteArray(theJoinPathKey));
86+
sb.append("\n");
87+
}
88+
89+
if (theJoinPathSecKey != null) {
90+
sb.append("theJoinPathSecKey = ");
91+
sb.append(PlanIter.printByteArray(theJoinPathSecKey));
92+
sb.append("\n");
93+
}
94+
95+
sb.append("theJoinPathMatched = ").append(theJoinPathMatched);
96+
sb.append("\n");
97+
98+
return sb.toString();
99+
}
100+
}
14101

102+
final private int theSID;
15103
final private int thePID;
104+
final private TableResumeInfo[] theTableRIs;
16105

17-
final private byte[] thePrimResumeKey;
18-
final private byte[] theSecResumeKey;
19-
final private boolean theMoveAfterResumeKey;
20-
21-
final private byte[] theDescResumeKey;
22-
final private int[] theJoinPathTables;
23-
final private byte[] theJoinPathKey;
24-
final private byte[] theJoinPathSecKey;
25-
final private boolean theJoinPathMatched;
26106

27107
boolean theFirstBatch = true;
28108

29109
public VirtualScan(
30110
int pid,
31111
int sid,
32-
byte[] primKey,
33-
byte[] secKey,
34-
boolean moveAfterResumeKey,
35-
byte[] descResumeKey,
36-
int[] joinPathTables,
37-
byte[] joinPathKey,
38-
byte[] joinPathSecKey,
39-
boolean joinPathMatched) {
112+
TableResumeInfo[] tableRIs) {
113+
40114
theSID = sid;
41115
thePID = pid;
42-
thePrimResumeKey = primKey;
43-
theSecResumeKey = secKey;
44-
theMoveAfterResumeKey = moveAfterResumeKey;
45-
theDescResumeKey = descResumeKey;
46-
theJoinPathTables = joinPathTables;
47-
theJoinPathKey = joinPathKey;
48-
theJoinPathSecKey = joinPathSecKey;
49-
theJoinPathMatched = joinPathMatched;
116+
theTableRIs = tableRIs;
50117
}
51118

52119
public int sid() {
@@ -57,36 +124,44 @@ public int pid() {
57124
return thePID;
58125
}
59126

60-
public byte[] secKey() {
61-
return theSecResumeKey;
127+
public int numTables() {
128+
return theTableRIs.length;
62129
}
63130

64-
public byte[] primKey() {
65-
return thePrimResumeKey;
131+
public int currentIndexRange(int i) {
132+
return theTableRIs[i].theCurrentIndexRange;
66133
}
67134

68-
public boolean moveAfterResumeKey() {
69-
return theMoveAfterResumeKey;
135+
public byte[] secKey(int i) {
136+
return theTableRIs[i].theSecResumeKey;
70137
}
71138

72-
public byte[] descResumeKey() {
73-
return theDescResumeKey;
139+
public byte[] primKey(int i) {
140+
return theTableRIs[i].thePrimResumeKey;
141+
}
142+
143+
public boolean moveAfterResumeKey(int i) {
144+
return theTableRIs[i].theMoveAfterResumeKey;
145+
}
146+
147+
public byte[] descResumeKey(int i) {
148+
return theTableRIs[i].theDescResumeKey;
74149
}
75150

76-
public int[] joinPathTables() {
77-
return theJoinPathTables;
151+
public int[] joinPathTables(int i) {
152+
return theTableRIs[i].theJoinPathTables;
78153
}
79154

80-
public byte[] joinPathKey() {
81-
return theJoinPathKey;
155+
public byte[] joinPathKey(int i) {
156+
return theTableRIs[i].theJoinPathKey;
82157
}
83158

84-
public byte[] joinPathSecKey() {
85-
return theJoinPathSecKey;
159+
public byte[] joinPathSecKey(int i) {
160+
return theTableRIs[i].theJoinPathSecKey;
86161
}
87162

88-
public boolean joinPathMatched() {
89-
return theJoinPathMatched;
163+
public boolean joinPathMatched(int i) {
164+
return theTableRIs[i].theJoinPathMatched;
90165
}
91166

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

104179
sb.append("theFirstBatch = ").append(theFirstBatch);
105180
sb.append("\n");
181+
182+
for (int i = 0; i < theTableRIs.length; ++i) {
183+
sb.append("Table RI ").append(i).append(":\n");
184+
sb.append(theTableRIs[i]);
185+
}
186+
106187
return sb.toString();
107188
}
108189
}

0 commit comments

Comments
 (0)