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

Enable to specify set of conditional expression set in ScanAll #984

Merged
merged 4 commits into from
Aug 9, 2023

Conversation

jnmt
Copy link
Contributor

@jnmt jnmt commented Jul 27, 2023

This PR enables specifying a set of conditional expression sets in ScanAll. The main reason to add this interface is to easily build a where clause without calling builder methods several times (especially when we build ScanAll for an internal purpose, e.g., in ScalarDB SQL).

@jnmt jnmt self-assigned this Jul 27, 2023
@@ -349,6 +351,12 @@ public BuildableScanAllWithOngoingWhere where(ConditionalExpression condition) {
return new BuildableScanAllWithOngoingWhere(this, condition);
}

@Override
public BuildableScanAllWithWhere where(Set<Set<ConditionalExpression>> conditions) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This interface is mainly for internal purposes, but users can see the interface and might use it. So, I didn't use Conjunction here.

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!

* @param conditions an or-wise set of and-wise conditions.
* @return the operation builder
*/
T where(Set<Set<ConditionalExpression>> conditions);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please provide some examples to help us understand when this would be useful? I'm curious as to why the existing methods don't suffice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@brfrn169 Thank you for the question. When we have a set of conjunctions, we need to call where() and or() several times and change the behavior depending on the number of conjunctions. I just wanted to avoid managing an intermediate builder like the following.

BuildableScanAll buildableScanAll =
    Scan.newBuilder()
        .namespace(statement.namespaceName)
        .table(statement.tableName)
        .all();

BuildableScanAllWithOngoingWhereOr ongoing = null;
for (Conjunction conjunction : conjunctions) {
  // snip conversion of conjunction in the SQL layer -> conditional expression
  if (ongoing == null) {
     ongoing = builder.where(ConditionSetBuilder.andConditionSet(conditions).build());
  } else {
     ongoing.or(ConditionSetBuilder.andConditionSet(conditions).build());
  }
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jnmt Thank you! I understand.

I'm not sure this will works, but instead of introducing the new interface WhereConditions<T>, can we add alternative where() methods that accepts a set of AndConditionSet to WhereOr<T> as follows?

  interface WhereOr<T> {
    /**
     * Appends the specified set of and-wise conditions.
     *
     * @param conditions a set of conditions
     * @return the operation builder
     */
    T where(ScanBuilder.AndConditionSet conditions);

    // ADDED
    T where(Set<ScanBuilder.AndConditionSet> conditions);
  }

My concern is that the newly added method T where(Set<Set<ConditionalExpression>> conditions) is somewhat unclear, and users may struggle to predict the function of the method based on its signature. What do you think about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@brfrn169 That's the point that bothered me (since it's somewhat imbalanced in and/or set, how about adding a message like "internal purpose", and so on and so on...). Anyway, after reconsidering, I think your idea is better. Fixed in acd3be2. Thank you!

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! 👍

@jnmt jnmt requested a review from brfrn169 July 31, 2023 02:14
* @return the operation builder
*/
T where(ScanBuilder.OrConditionSet conditions);
T where(ScanBuilder.OrConditionSet orConditionSet);
Copy link
Collaborator

@brfrn169 brfrn169 Aug 1, 2023

Choose a reason for hiding this comment

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

BTW, can we also add where(Set<ScanBuilder.OrConditionSet> andConditionSets) to WhereAnd<T> as well for the sake of consistency, it could cause signature conflicts though?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, we cannot add it since it causes the signature conflict, as you guess.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay. In that case, how about changing the method name to address the signature conflict as follows?

  interface WhereAnd<T> {
    T where(ScanBuilder.OrConditionSet orConditionSet);

    T whereAnd(Set<ScanBuilder.OrConditionSet> orConditionSets);
  }

  interface WhereOr<T> {
    T where(ScanBuilder.AndConditionSet andConditionSet);

    T whereOr(Set<ScanBuilder.AndConditionSet> andConditionSets);
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the solution. Umm, it's a bit unstylish, but right, consistency is more important here, I think.

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 1b9ae6a. PTAL when you have time!

@jnmt jnmt requested a review from brfrn169 August 2, 2023 04:19
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.

LGTM! Thank you!

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!

@brfrn169 brfrn169 merged commit 9f45c79 into master Aug 9, 2023
13 checks passed
@brfrn169 brfrn169 deleted the scan-with-set-of-condition-set branch August 9, 2023 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants