Skip to content
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

Add arbitrary filtering for get operations #1834

Merged
merged 8 commits into from
Jun 14, 2024
Merged

Conversation

jnmt
Copy link
Contributor

@jnmt jnmt commented Jun 4, 2024

Description

This PR adds arbitrary filtering for get operations.

Related issues and/or PRs

Changes made

  • Support the where() clause in GetBuilder, as the same as ScanBuilder.
  • Revise the query builder for JDBC databases to push the where clause down. (Do nothing for NoSQL databases except for adding some tests since we already introduced get operations with dynamic filtering in Support dynamic arbitrary filtering on NoSQL databases #1682)
  • Change Snapshot to manage the issued Get operations so that it can re-read with the where clause in the extra read.
  • Fix a warning message, although it’s not directly related to this PR.

Checklist

  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation to reflect the changes. Will be updated in another PR.
  • Any remaining open issues linked to this PR are documented and up-to-date (Jira, GitHub, etc.).
  • Tests (unit, integration, etc.) have been added for the changes.
  • My changes generate no new warnings.
  • Any dependent changes in other PRs have been merged and published.

Additional notes (optional)

See inline comments.

Release notes

Added support for arbitrary filtering for get operations.

Comment on lines +3053 to +3054
DistributedTransaction transaction =
manager.begin(Isolation.SERIALIZABLE, SerializableStrategy.EXTRA_READ);
Copy link
Contributor Author

@jnmt jnmt Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I first created a bug regarding the extra read with get operations since I missed that integration tests are done with snapshot isolation by default, and this setting should be added in some cases.

Note that we might also be better to use SERIALIZABLE for some other tests (e.g., get_GetGivenForCommittedRecord_ShouldReturnRecord) because they are almost the same as the one in DistributedTransactionIntegrationTestBase if we run them with SNAPSHOT. However, I left it as is for now since it's a bit out of the scope of this PR.

@@ -51,6 +51,7 @@ public class Snapshot {
private final TransactionTableMetadataManager tableMetadataManager;
private final ParallelExecutor parallelExecutor;
private final ConcurrentMap<Key, Optional<TransactionResult>> readSet;
private final Map<Get, Key> getSet;
Copy link
Contributor Author

@jnmt jnmt Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we need to add the where clause into the Get operation for the extra read, as below, we start managing the issued Get operations similar to Scan.

@@ -1582,83 +1580,4 @@ public BuildableScanFromExistingWithOngoingWhereAnd and(OrConditionSet orConditi
return this;
}
}

private static class Where {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to SelectionBuilder to commonly use in both GetBuilder and ScanBuilder.

@@ -197,7 +197,7 @@ DistributedTransaction begin(String txId, Isolation isolation, SerializableStrat
if (!config.getIsolation().equals(isolation)
|| !config.getSerializableStrategy().equals(strategy)) {
logger.warn(
"Setting different isolation level or serializable strategy from the ones"
"Setting different isolation level or serializable strategy from the ones "
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's very minor, I fixed it in this PR.

@jnmt jnmt self-assigned this Jun 4, 2024
@jnmt jnmt added the enhancement New feature or request label Jun 4, 2024
Copy link
Contributor

@Torch3333 Torch3333 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you.


public static class BuildableGetWithWhere extends BuildableGet {

protected final SelectionBuilder.Where where;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] This exposes the package-private Where to classes that inherit this class. How about making this to package-private?

Suggested change
protected final SelectionBuilder.Where where;
final SelectionBuilder.Where where;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thank you! Fixed in 527d0b6.

BTW, I noticed that I can receive such warnings in IntelliJ by using a recent version. I'm using a bit old version due to some reasons, but I will migrate it : )

implements Consistency<BuildableGetWithIndexWhere>, Projection<BuildableGetWithIndexWhere> {

protected BuildableGetWithIndex buildableGetWithIndex;
protected final SelectionBuilder.Where where;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 527d0b6.

@jnmt jnmt requested a review from komamitsu June 7, 2024 02:59
Copy link
Contributor

@komamitsu komamitsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

@brfrn169 brfrn169 requested a review from josh-wong June 7, 2024 11:09
Copy link
Member

@josh-wong josh-wong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left some minor suggestions. Other than that, LGTM. Thank you!🙇🏻‍♂️

GET_BUILD_ERROR_OPERATION_SUPPORTED_ONLY_WHEN_NO_CONDITIONS_ARE_SPECIFIED(
Category.USER_ERROR,
"0141",
"This operation is supported only when no conditions are specified at all. "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"This operation is supported only when no conditions are specified at all. "
"This operation is supported only when no conditions are specified. "

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback. Fixed in e9840a9, including a similar message for the scan operation.

Category.USER_ERROR,
"0141",
"This operation is supported only when no conditions are specified at all. "
+ "If you want to modify the condition, please use clearConditions() to remove all existing conditions first",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
+ "If you want to modify the condition, please use clearConditions() to remove all existing conditions first",
+ "If you want to modify a condition, please use clearConditions() to remove all existing conditions first",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, fixed in e9840a9.

Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, looking good to me!
Left one minor comment. PTAL!

@@ -133,6 +133,11 @@ public Get withProjections(Collection<String> projections) {
return (Get) super.withProjections(projections);
}

@Override
Get withConjunctions(Collection<Conjunction> conjunctions) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add conjunctions to the toString() method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thank you! Fixed in e9840a9.

@jnmt jnmt requested a review from feeblefakie June 11, 2024 08:03
Copy link
Collaborator

@brfrn169 brfrn169 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a minor comment, but other than that, LGTM! Thank you!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this file is unnecessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my bad. Removed in d6d6475.

@jnmt
Copy link
Contributor Author

jnmt commented Jun 14, 2024

@feeblefakie PTAL again when you get a chance. I will submit the following two related PRs once this is merged. Thank you!

  1. exploiting partition scan/get filtering in ScalarDB SQL
  2. fixing a snapshot management issue in ScalarDB

Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

@feeblefakie feeblefakie merged commit 197ac95 into master Jun 14, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants