Skip to content

Commit 89908e7

Browse files
authored
Feature/joins (#133)
* simplified VirtualScan * added PrepareQueryException * reverted simplifications to VirtualScan in order to handle case of new driver with old proxy * updated decrementQueryVersion() method * added changelog entry for PrepareQueryException
1 parent f11f779 commit 89908e7

File tree

9 files changed

+59
-53
lines changed

9 files changed

+59
-53
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
2525
(~/.oci/regions-config.json) or environment variable (OCI_REGION_METADATA)
2626

2727
### Added
28+
- Cloud only: added new OCI regions (RKT, SHJ, RUH, EBB, EBL)
29+
- PrepareQueryException. This exception is thrown if a prepared query is
30+
executed after (a) the index used by the query has been dropped and then
31+
re-created with a different schema, or (b) one or more of the referenced
32+
tables has been altered (via the alter table statement).
2833
- Cloud only: added new OCI regions (RKT, SHJ, RUH, EBB, EBL, JJT, DLN, DTZ)
2934
- Cloud only: refactored how the Region class is managed, allowing dynamic
3035
addition of regions not yet known to the system
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*-
2+
* Copyright (c) 2011, 2024 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* Licensed under the Universal Permissive License v 1.0 as shown at
5+
* https://oss.oracle.com/licenses/upl/
6+
*/
7+
8+
package oracle.nosql.driver;
9+
10+
/**
11+
* The query must be recompiled after DDL changes on the tables and/or
12+
* indexes that are accessed by the query.
13+
*/
14+
public class PrepareQueryException extends NoSQLException {
15+
16+
private static final long serialVersionUID = 1L;
17+
18+
/**
19+
* @hidden
20+
* @param msg the exception message
21+
*/
22+
public PrepareQueryException(String msg) {
23+
super(msg);
24+
}
25+
}

driver/src/main/java/oracle/nosql/driver/http/Client.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ public Result execute(Request kvRequest) {
633633
*/
634634
kvRequest.setTimeoutInternal(thisIterationTimeoutMs);
635635
serialVersionUsed = writeContent(buffer, kvRequest,
636-
queryVersionUsed);
636+
queryVersionUsed);
637637
kvRequest.setTimeoutInternal(timeoutMs);
638638

639639
/*
@@ -1628,14 +1628,17 @@ private synchronized boolean decrementSerialVersion(short versionUsed) {
16281628
* false: already at lowest version number.
16291629
*/
16301630
private synchronized boolean decrementQueryVersion(short versionUsed) {
1631+
16311632
if (queryVersion != versionUsed) {
16321633
return true;
16331634
}
1634-
if (queryVersion == QueryDriver.QUERY_V4) {
1635-
queryVersion = QueryDriver.QUERY_V3;
1636-
return true;
1635+
1636+
if (queryVersion == QueryDriver.QUERY_V3) {
1637+
return false;
16371638
}
1638-
return false;
1639+
1640+
--queryVersion;
1641+
return true;
16391642
}
16401643

16411644
/**

driver/src/main/java/oracle/nosql/driver/ops/serde/BinaryProtocol.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import static oracle.nosql.driver.util.BinaryProtocol.OPERATION_NOT_SUPPORTED;
4040
import static oracle.nosql.driver.util.BinaryProtocol.PROVISIONED;
4141
import static oracle.nosql.driver.util.BinaryProtocol.READ_LIMIT_EXCEEDED;
42+
import static oracle.nosql.driver.util.BinaryProtocol.RECOMPILE_QUERY;
4243
import static oracle.nosql.driver.util.BinaryProtocol.REQUEST_SIZE_LIMIT;
4344
import static oracle.nosql.driver.util.BinaryProtocol.REQUEST_SIZE_LIMIT_EXCEEDED;
4445
import static oracle.nosql.driver.util.BinaryProtocol.REQUEST_TIMEOUT;
@@ -85,6 +86,7 @@
8586
import oracle.nosql.driver.Nson;
8687
import oracle.nosql.driver.OperationNotSupportedException;
8788
import oracle.nosql.driver.OperationThrottlingException;
89+
import oracle.nosql.driver.PrepareQueryException;
8890
import oracle.nosql.driver.ReadThrottlingException;
8991
import oracle.nosql.driver.RequestSizeLimitException;
9092
import oracle.nosql.driver.RequestTimeoutException;
@@ -492,6 +494,8 @@ public static RuntimeException mapException(int code, String msg) {
492494
return new TableNotReadyException(msg);
493495
case ETAG_MISMATCH:
494496
return new IllegalArgumentException(msg);
497+
case RECOMPILE_QUERY:
498+
return new PrepareQueryException(msg);
495499
default:
496500
return new NoSQLException("Unknown error code " + code + ": " +
497501
msg);

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ public void serialize(Request request,
889889
writeMapField(ns, QUERY_NAME, rq.getQueryName());
890890
}
891891
if (rq.getVirtualScan() != null) {
892-
writeVirtualScan(ns, rq.getVirtualScan());
892+
writeVirtualScan(ns, rq.getVirtualScan(), queryVersion);
893893
}
894894
}
895895

@@ -898,13 +898,15 @@ public void serialize(Request request,
898898
}
899899

900900
private static void writeVirtualScan(NsonSerializer ns,
901-
VirtualScan vs)
901+
VirtualScan vs,
902+
short queryVersion)
902903
throws IOException {
904+
903905
startMap(ns, VIRTUAL_SCAN);
904906
writeMapField(ns, VIRTUAL_SCAN_SID, vs.sid());
905907
writeMapField(ns, VIRTUAL_SCAN_PID, vs.pid());
906908

907-
if (vs.isFirstBatch()) {
909+
if (queryVersion <= QueryDriver.QUERY_V4 && vs.isFirstBatch()) {
908910
writeMapField(ns, VIRTUAL_SCAN_PRIM_KEY, vs.primKey());
909911
writeMapField(ns, VIRTUAL_SCAN_SEC_KEY, vs.secKey());
910912
writeMapField(ns, VIRTUAL_SCAN_MOVE_AFTER, vs.moveAfterResumeKey());
@@ -915,6 +917,7 @@ private static void writeVirtualScan(NsonSerializer ns,
915917
writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_SEC_KEY, vs.joinPathSecKey());
916918
writeMapField(ns, VIRTUAL_SCAN_JOIN_PATH_MATCHED, vs.joinPathMatched());
917919
}
920+
918921
endMap(ns, VIRTUAL_SCAN);
919922
}
920923

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ public class QueryDriver {
3535
/* added query name in QueryRequest */
3636
public static short QUERY_V4 = 4;
3737

38-
public static short QUERY_VERSION = QUERY_V4;
38+
/* Changed VirtualScan info exchanged between sdk and proxy */
39+
public static final short QUERY_V5 = 5;
40+
41+
public static final short QUERY_VERSION = QUERY_V5;
3942

4043
private static final int BATCH_SIZE = 100;
4144

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,8 @@ private void initPartitionSort(
429429
rcb.trace("ReceiveIter.initPartitionSort() : got result.\n" +
430430
"reached limit = " + result.reachedLimit() +
431431
" in phase 1 = " + result.isInPhase1());
432+
433+
origRequest.addQueryTraces(result.getQueryTraces());
432434
}
433435

434436
/*

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

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
public class VirtualScan {
1212

1313
final private int theSID;
14+
1415
final private int thePID;
16+
1517
final private byte[] thePrimResumeKey;
1618
final private byte[] theSecResumeKey;
1719
final private boolean theMoveAfterResumeKey;
@@ -62,7 +64,7 @@ public byte[] secKey() {
6264
public byte[] primKey() {
6365
return thePrimResumeKey;
6466
}
65-
67+
6668
public boolean moveAfterResumeKey() {
6769
return theMoveAfterResumeKey;
6870
}
@@ -99,51 +101,8 @@ public String toString() {
99101
sb.append("sid/pid = ").append(theSID).append("/").append(thePID);
100102
sb.append("\n");
101103

102-
if (thePrimResumeKey != null) {
103-
sb.append("thePrimResumeKey = ");
104-
sb.append(PlanIter.printByteArray(thePrimResumeKey));
105-
sb.append("\n");
106-
}
107-
108-
if (theSecResumeKey != null) {
109-
sb.append("theSecResumeKey = ");
110-
sb.append(PlanIter.printByteArray(theSecResumeKey));
111-
sb.append("\n");
112-
}
113-
114-
sb.append("theMoveAfterResumeKey = ").append(theMoveAfterResumeKey);
115-
sb.append("\n");
116-
117-
if (theDescResumeKey != null) {
118-
sb.append("theDescResumeKey = ");
119-
sb.append(PlanIter.printByteArray(theDescResumeKey));
120-
sb.append("\n");
121-
}
122-
123-
if (theJoinPathTables != null) {
124-
sb.append("theJoinPathTables = ");
125-
sb.append(PlanIter.printIntArray(theJoinPathTables));
126-
sb.append("\n");
127-
}
128-
129-
if (theJoinPathKey != null) {
130-
sb.append("theJoinPathKey = ");
131-
sb.append(PlanIter.printByteArray(theJoinPathKey));
132-
sb.append("\n");
133-
}
134-
135-
if (theJoinPathSecKey != null) {
136-
sb.append("theJoinPathSecKey = ");
137-
sb.append(PlanIter.printByteArray(theJoinPathSecKey));
138-
sb.append("\n");
139-
}
140-
141-
sb.append("theJoinPathMatched = ").append(theJoinPathMatched);
142-
sb.append("\n");
143-
144104
sb.append("theFirstBatch = ").append(theFirstBatch);
145105
sb.append("\n");
146-
147106
return sb.toString();
148107
}
149108
}

driver/src/main/java/oracle/nosql/driver/util/BinaryProtocol.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ public static boolean isTenantOperation(OpCode op) {
187187
/* added in V4 */
188188
public static final int TABLE_NOT_READY = 26;
189189
public static final int UNSUPPORTED_QUERY_VERSION = 27;
190+
/* added in V5 */
191+
public static final int RECOMPILE_QUERY = 28;
190192

191193
/*
192194
* Error codes for user throttling, range from 50 to 100(exclusive).

0 commit comments

Comments
 (0)