Skip to content

Add 'fields' parameter to ProxySpace #263

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

Merged
merged 1 commit into from
Dec 22, 2022
Merged

Add 'fields' parameter to ProxySpace #263

merged 1 commit into from
Dec 22, 2022

Conversation

ArtDu
Copy link
Contributor

@ArtDu ArtDu commented Sep 15, 2022

Add fields option to crud proxy methods

  • Tests
  • Changelog
  • Documentation
  • Cleanup the code for review. See checklist

Closes #236

Copy link
Collaborator

@akudiyar akudiyar left a comment

Choose a reason for hiding this comment

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

I liked it overall, but I believe that there's a better way. Please take a look at the comments below.

I think that Options should be much like the Conditions class, which is actually a builder and it is convenient to call a select method like space.select(Conditions.any()), for example. We should have something like that for Options. Of course, in this case, we'll have to tell the user if any actual options aren't supported by the particular client instance (in the same way as we do in Conditions). Serialization of Options instances will happen internally, no need to force users to use additional builder instances and call build(), that's ugly. But the difference will be that we can have different Options classes for each operation. So for select it will be SelectOptions, for insertMany it will be InsertManyOptions etc.

An example of how the Options class can be used:

    space.select(
        Conditions.any(),
        SelectOptions.withTimeout(100500).withBatchSize(1000).withFields(Arrays.asList("id"))
    )

Here SelectOptions inherit some base class that provides withTimeout and withFields methods.

P.S. I think we further will replace the single Conditions class in the methods where it is passed with a hierarchy, like PrimaryIndexConditions (or just PrimaryIndex) for the methods that support only it and full Conditions (or IndexConditions?) for select.

/**
* Select tuples matching the specified query with specified conditions and options.
*
* @param conditions specified conditions
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's make the doc more descriptive. query with options or something better for conditions, and more words for options.

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


public T withTimeout(int timeout) {
this.timeout = timeout;
return self();
}

public T withOptions(Options options) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that timeout should be a part of Options. Therefore we'll be able to specify a custom timeout for each operation. This will be also useful for the box interface.

Copy link
Contributor Author

@ArtDu ArtDu Sep 19, 2022

Choose a reason for hiding this comment

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

In merged PR withTimeout is using as default parameter(to pass config.timeout) and withOptions -> timeout as custom timeout

* @author Alexey Kuzin
* @author Artyom Dubinin
*/
class CRUDFunctionOptions extends CRUDBaseOptions {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't like this name very much, it is confusing. And why do we have here a duplication of ProxyFunctionOptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In merged PR we've discussed to name CRUDReturnOptions

/**
* This class is not part of the public API.
*
* Represent options for cluster proxy operations which returns fields.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* Represent options for cluster proxy operations which returns fields.
* Represent options for cluster proxy operations that return fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It has been rewritten

/**
* @author Artyom Dubinin
*/
public class ProxyTarantoolSpaceIT extends SharedCartridgeContainer {
Copy link
Collaborator

@akudiyar akudiyar Sep 15, 2022

Choose a reason for hiding this comment

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

Why do we need a new test class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some classes in merged PR. I did this because the main class ProxyAPI is overloaded with many testcases, I wanted more precision test classes

@ArtDu
Copy link
Contributor Author

ArtDu commented Sep 16, 2022

An example of how the Options class can be used:

    space.select(
        Conditions.any(),
        SelectOptions.withTimeout(100500).withBatchSize(1000).withFields(Arrays.asList("id"))
    )

Here SelectOptions inherit some base class that provides withTimeout and withFields methods.

I see only one way how to implement this, we should have all abstract classes except leaf in inheritance hierarchy. Leaf implement self and also we should have one entrypoint in leaf, something like create.

SelectOptions.create().withTimeout(100500).withBatchSize(1000).withFields(Arrays.asList("id"))

@ArtDu ArtDu changed the base branch from refactor-crud-operation-options to master September 17, 2022 22:02
@ArtDu ArtDu changed the title Add 'fields' parameter to ProxySpace v2 Add 'fields' parameter to ProxySpace Sep 17, 2022
@ArtDu ArtDu marked this pull request as ready for review September 19, 2022 21:40
@ArtDu ArtDu requested review from akudiyar and Elishtar September 19, 2022 21:40
@ArtDu ArtDu force-pushed the crud/fields_v2 branch 2 times, most recently from 894e8a3 to 1618cfe Compare September 20, 2022 17:58
@ArtDu ArtDu marked this pull request as draft September 20, 2022 17:59
Copy link
Collaborator

@akudiyar akudiyar left a comment

Choose a reason for hiding this comment

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

Almost good, the questions are mostly about the docstrings.

/**
* Return list of fields.
*
* @return timeout, in milliseconds.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not timeout, fields

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

*/
public interface OperationWithFieldsOptions extends OperationWithTimeoutOptions {
/**
* Return list of fields.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be better to have a more full description (what is this list for?)

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


public static final String FIELDS = "fields";

/** TODO:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doc TODO?

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

}

@Override
public Optional<List> getFields() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we need List<String> here

Copy link
Contributor Author

@ArtDu ArtDu Sep 22, 2022

Choose a reason for hiding this comment

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

We can't have List<String> here, because we can't pass List<String>.class

Copy link
Contributor

Choose a reason for hiding this comment

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

Why we can't? Looks like we can change method interface methods signature

Copy link
Contributor Author

@ArtDu ArtDu Sep 23, 2022

Choose a reason for hiding this comment

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

Yeah we can change method signature, but in the inner implementation we need to do a hack to cast to List<String>.class. The problem is about we are storing any option types in a Map with generic Object type


public static final String BATCH_STOP_ON_ERROR = "stop_on_error";
public static final String BATCH_ROLLBACK_ON_ERROR = "rollback_on_error";

protected
<T extends AbstractBuilder<T>>
CRUDBatchOptions(AbstractBuilder<T> builder) {
<O extends CRUDBatchOptions, B extends AbstractBuilder<O, B>>
Copy link
Collaborator

Choose a reason for hiding this comment

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

CRUDBatchOptions is a final class, we don't need a generic for Options here

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

/**
* This class is not part of the public API.
* <p>
* Represent options for cluster proxy operations which returns fields
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's reformulate it. Something like operations for that the set of fields returned in the result tuples can be 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.

Has been rewritten to

 * Represent returned options for cluster proxy operations.
 * The return set of fields of the tuples can be specified.


public static final String SELECT_LIMIT = "first";
public static final String SELECT_AFTER = "after";
public static final String SELECT_BATCH_SIZE = "batch_size";

private <T extends AbstractBuilder<T>>
CRUDSelectOptions(AbstractBuilder<T> builder) {
private <O extends CRUDSelectOptions, B extends AbstractBuilder<O, B>>
Copy link
Collaborator

Choose a reason for hiding this comment

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

THis class is final, the generic for Options is redundant.

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

@ArtDu
Copy link
Contributor Author

ArtDu commented Sep 20, 2022

Almost good, the questions are mostly about the docstrings.

Yeah, that is reason why I've converted PR to Draft

<O extends CRUDBaseOptions, T extends AbstractBuilder<O, T>>
CRUDBaseOptions(AbstractBuilder<O, T> builder) {
<O extends CRUDBaseOptions, B extends AbstractBuilder<O, B>>
CRUDBaseOptions(AbstractBuilder<O, B> builder) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this case should be excluded from checkstyle only one line, current format looks not readable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added, please check and give your opinion how to do it correctly

class AbstractBuilder<O extends CRUDBaseOptions, T extends AbstractBuilder<O, T>>
extends CRUDAbstractOperationOptions.AbstractBuilder<O, T> {
class AbstractBuilder<O extends CRUDBaseOptions, B extends AbstractBuilder<O, B>>
extends CRUDAbstractOperationOptions.AbstractBuilder<O, B> {
Copy link
Contributor

@Elishtar Elishtar Sep 20, 2022

Choose a reason for hiding this comment

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

I think. looks better

    protected abstract static class AbstractBuilder<O extends CRUDBaseOptions, B extends AbstractBuilder<O, B>> 
            extends CRUDAbstractOperationOptions.AbstractBuilder<O, B> {
        
        protected Optional<Integer> timeout = Optional.empty();

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

protected <O extends CRUDReturnOptions, B extends AbstractBuilder<O, B>>
CRUDReturnOptions(CRUDReturnOptions.AbstractBuilder<O, B> builder) {
super(builder);

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove space

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

@ArtDu ArtDu marked this pull request as ready for review September 22, 2022 14:17
@ArtDu ArtDu requested review from akudiyar and Elishtar September 22, 2022 14:17
Elishtar
Elishtar previously approved these changes Sep 23, 2022
@ArtDu
Copy link
Contributor Author

ArtDu commented Sep 23, 2022

We have one problem with our approach we can't have multiple inheritances in java and especially in our ProxyOptions.
For example, we have InsertOptions and CountOption, both have bucket_id option, but only InsertOption has fields option

image

For these cases, we need to duplicate the code.

@ArtDu ArtDu marked this pull request as draft September 26, 2022 12:11
@ArtDu ArtDu added the blocked Not ready to be implemented label Sep 26, 2022
@ArtDu
Copy link
Contributor Author

ArtDu commented Sep 26, 2022

Blocked by #272 because driver should parse metadata from crud. We can't get field by field name if we don't know position and It will frustrate users
image

@ArtDu ArtDu force-pushed the crud/fields_v2 branch 2 times, most recently from 00857c2 to 77f358d Compare December 21, 2022 14:09
@ArtDu ArtDu removed the blocked Not ready to be implemented label Dec 21, 2022
@ArtDu ArtDu marked this pull request as ready for review December 21, 2022 14:23
@ArtDu ArtDu requested a review from Elishtar December 21, 2022 14:25
@ArtDu ArtDu merged commit 9ef0f47 into master Dec 22, 2022
@ArtDu ArtDu deleted the crud/fields_v2 branch December 22, 2022 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement API to pass 'fields' parameter to CRUD library
3 participants