-
Notifications
You must be signed in to change notification settings - Fork 7
Nested joins #145
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
Nested joins #145
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,8 +75,7 @@ public QueryResult read(byte[] rawQueryResult, int queryFormatVersion) { | |
| if (queryFormatVersion == QUERY_FORMAT_V2) { | ||
| long format = buffer.getVarUInt(); | ||
| if (format != QUERY_FORMAT_V2) { | ||
| String errorMessage = String.format("QueryResults format version='%d' is not supported", format); | ||
| throw new RuntimeException(errorMessage); | ||
| buffer.rewind(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут был бросок исключения, и он по смыслу был праввильным |
||
| } | ||
| } | ||
| QueryResult queryResult = getQueryResultWithFlags(buffer.getVarUInt()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,12 @@ public class Builtin implements Binding { | |
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(Builtin.class); | ||
|
|
||
| private static final int NESTED_JOIN_QUERIES_MIN_MAJOR = 5; | ||
|
|
||
| private static final int NESTED_JOIN_QUERIES_MIN_MINOR = 16; | ||
|
|
||
| private static final int NESTED_JOIN_QUERIES_MIN_PATCH = 0; | ||
|
|
||
| private final AtomicLong next = new AtomicLong(0L); | ||
|
|
||
| private final Gson gson = new GsonBuilder() | ||
|
|
@@ -57,6 +63,10 @@ public class Builtin implements Binding { | |
|
|
||
| private final Duration timeout; | ||
|
|
||
| private final boolean supportsNestedJoinQueries; | ||
|
|
||
| private final int queryFormatVersion; | ||
|
|
||
| /** | ||
| * Creates an instance. | ||
| * | ||
|
|
@@ -67,9 +77,11 @@ public Builtin(URI uri, Duration requestTimeout) { | |
| adapter = new BuiltinAdapter(); | ||
| timeout = requestTimeout; | ||
| rx = adapter.init(); | ||
| queryFormatVersion = QUERY_FORMAT_V2; | ||
| supportsNestedJoinQueries = isNestedJoinQueriesSupported(adapter.version()); | ||
| String path = uri.getPath(); | ||
| try { | ||
| ReindexerResponse response = adapter.connect(rx, path, REINDEXER_VERSION); | ||
| ReindexerResponse response = adapter.connect(rx, path, REINDEXER_VERSION, queryFormatVersion); | ||
| checkResponse(response); | ||
| } catch (Exception e) { | ||
| LOGGER.error("rx: connect error", e); | ||
|
|
@@ -89,6 +101,8 @@ public Builtin(BuiltinAdapter adapter, long rx, Duration timeout) { | |
| this.adapter = adapter; | ||
| this.rx = rx; | ||
| this.timeout = timeout; | ||
| queryFormatVersion = QUERY_FORMAT_V2; | ||
| supportsNestedJoinQueries = isNestedJoinQueriesSupported(adapter.version()); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -152,15 +166,15 @@ public RequestContext select(String query, boolean asJson, int fetchCount, long[ | |
| ReindexerResponse response = adapter.select(rx, next.getAndIncrement(), timeout.toMillis(), query, asJson, | ||
| ptVersions); | ||
| checkResponse(response); | ||
| return new BuiltinRequestContext(response); | ||
| return new BuiltinRequestContext(response, queryFormatVersion); | ||
| } | ||
|
|
||
| @Override | ||
| public RequestContext selectQuery(byte[] queryData, int fetchCount, long[] ptVersions, boolean asJson) { | ||
| ReindexerResponse response = adapter.selectQuery(rx, next.getAndIncrement(), timeout.toMillis(), queryData, | ||
| ptVersions, asJson); | ||
| checkResponse(response); | ||
| return new BuiltinRequestContext(response); | ||
| return new BuiltinRequestContext(response, queryFormatVersion); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -187,7 +201,7 @@ public TransactionContext beginTx(String namespaceName) { | |
| txId = (long) arg; | ||
| } | ||
| } | ||
| return new BuiltinTransactionContext(adapter, rx, txId, next::getAndIncrement, timeout); | ||
| return new BuiltinTransactionContext(adapter, rx, txId, next::getAndIncrement, timeout, queryFormatVersion); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -210,7 +224,35 @@ private void checkResponse(ReindexerResponse response) { | |
|
|
||
| @Override | ||
| public int queryFormatVersion() { | ||
| return QUERY_FORMAT_V2; | ||
| return queryFormatVersion; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean supportsNestedJoinQueries() { | ||
| return supportsNestedJoinQueries; | ||
| } | ||
|
|
||
| private boolean isNestedJoinQueriesSupported(String version) { | ||
| int[] parsedVersion = parseVersion(version); | ||
| if (parsedVersion[0] != NESTED_JOIN_QUERIES_MIN_MAJOR) { | ||
| return parsedVersion[0] > NESTED_JOIN_QUERIES_MIN_MAJOR; | ||
| } | ||
| if (parsedVersion[1] != NESTED_JOIN_QUERIES_MIN_MINOR) { | ||
| return parsedVersion[1] > NESTED_JOIN_QUERIES_MIN_MINOR; | ||
| } | ||
| return parsedVersion[2] >= NESTED_JOIN_QUERIES_MIN_PATCH; | ||
| } | ||
|
|
||
| private int[] parseVersion(String version) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вся логика с парсингом версии избыточна - у нас уже есть caps, который определяет поддержу nested join |
||
| String normalized = version.startsWith("v") ? version.substring(1) : version; | ||
| String[] parts = normalized.split("\\D+"); | ||
| int[] result = new int[3]; | ||
| for (int i = 0; i < result.length && i < parts.length; i++) { | ||
| if (!parts[i].isEmpty()) { | ||
| result[i] = Integer.parseInt(parts[i]); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -196,6 +196,11 @@ public int queryFormatVersion() { | |
| return builtin.queryFormatVersion(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean supportsNestedJoinQueries() { | ||
| return builtin.supportsNestedJoinQueries(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Флаг выглядит избыточным. Если используется QueryFormatV2, то мы гарантированно поддерживаем nested joins |
||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| ReindexerResponse response = adapter.stopServer(svc); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Builtin всегда работает по V2, логика лишняя