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

[feat] ppl #1770

Open
wants to merge 84 commits into
base: main
Choose a base branch
from
Open

[feat] ppl #1770

wants to merge 84 commits into from

Conversation

wu-hui
Copy link
Contributor

@wu-hui wu-hui commented Jul 30, 2024

No description provided.

@wu-hui wu-hui requested a review from a team as a code owner July 30, 2024 16:24
@product-auto-label product-auto-label bot added the size: xl Pull request size is extra large. label Jul 30, 2024
Copy link

generated-files-bot bot commented Jul 30, 2024

Warning: This pull request is touching the following templated files:

  • google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreAdminStubSettings.java
  • google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/FirestoreClient.java
  • google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/FirestoreSettings.java
  • google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/gapic_metadata.json
  • google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreStub.java
  • google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreStubSettings.java
  • google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/GrpcFirestoreStub.java
  • google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/FirestoreClientTest.java
  • google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/MockFirestoreImpl.java
  • grpc-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/FirestoreGrpc.java
  • proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/DocumentProto.java
  • proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/FirestoreProto.java
  • proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/Value.java
  • proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ValueOrBuilder.java
  • proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/document.proto
  • proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/firestore.proto

@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/java-firestore API. label Jul 30, 2024
@@ -29,6 +30,8 @@
import com.google.api.gax.rpc.StreamController;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.Timestamp;
import com.google.cloud.firestore.Transaction.AsyncFunction;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I am inclined not to import nested classes. In this case, the qualifier Transaction helps understand that this is not a lambda, such as java.util.function.Function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

* }</pre>
*/
@BetaApi
public final class Pipeline {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this class can be simplified. Here is a suggestion: #1786

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, that PR looks very helpful.

}
if (response.getResultsCount() > 0) {
numDocuments += response.getResultsCount();
if (numDocuments % 100 == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This condition seems wrong.

Maybe you should output trace when numDocuments > 100, and then reset numDocuments?

The trace message could add return numDocuments value instead of 100.

Also, text still says Firestore.Query and should be changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, copy/paste from query does not work for pipeline here.


public interface Stage {
String getName();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of StageUtils.toStageProto, I think Stage interface should be expanded:

Suggested change
}
com.google.firestore.v1.Pipeline.Stage toStageProto()
}

This is what polymorphism what invented to solve.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this was on my TODO list. I will address this later though, not urgent.

* @return A new {@code Expr} representing the addition operation.
*/
@BetaApi
default Add add(Object other) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ambiguous types in overloads cause problems. The danger is that an Expr is cast to Object causing wrong method to be called.

You could add:

Suggested change
default Add add(Object other) {
default Add add(Object other) {
if (other instanceof Expr) {
return add((Expr) other);
}

But can we instead come up with an API surface that doesn't require inspection of type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this is a problem. Constant.of should take care of the type inspection?

@BetaApi
public static Constant ofVector(double[] value) {
// Convert double array to List<Double>
return new Constant(Arrays.stream(value).boxed().collect(Collectors.toList()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Pull from main and use Marks work on VectorValues.


@BetaApi
public static <T> Constant of(T[] value) {
return new Constant(Arrays.asList(value)); // Convert array to list
Copy link
Contributor

Choose a reason for hiding this comment

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

We should make a copy of array, thereby preventing accidental mutation.

Suggested change
return new Constant(Arrays.asList(value)); // Convert array to list
return new Constant(Arrays.asList(value.clone())); // Convert array to list

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

private final String name;
private final List<Expr> params;

protected Function(String name, List<? extends Expr> params) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should prefer using ImmutableList instead of wrapping with unmodifiableList. Using ImmutableList prevents both upstream changes as well as downstream changes. Whereas, simply wrapping a list, still allows the caller to modify the list. Alternatively, we can always makes copies, but that seems wasteful.

The customer facing API can still use a mutable List as parameter, but we should always make a copy internally into a ImmutableList internally. Once we have an ImmutableList, we no longer need to make copies, and can safely pass them around by reference.

Suggested change
protected Function(String name, List<? extends Expr> params) {
protected Function(String name, ImmutableList<? extends Expr> params) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@tom-andersen tom-andersen assigned wu-hui and unassigned tom-andersen Aug 14, 2024
wu-hui and others added 9 commits August 21, 2024 12:45
# Conflicts:
#	README.md
#	google-cloud-firestore/pom.xml
#	google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java
#	google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java
#	proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/DocumentProto.java
Copy link
Contributor Author

@wu-hui wu-hui left a comment

Choose a reason for hiding this comment

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

Thanks for the suggestions!

@@ -29,6 +30,8 @@
import com.google.api.gax.rpc.StreamController;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.Timestamp;
import com.google.cloud.firestore.Transaction.AsyncFunction;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

* }</pre>
*/
@BetaApi
public final class Pipeline {
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, that PR looks very helpful.

}
if (response.getResultsCount() > 0) {
numDocuments += response.getResultsCount();
if (numDocuments % 100 == 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, copy/paste from query does not work for pipeline here.


@BetaApi
public static <T> Constant of(T[] value) {
return new Constant(Arrays.asList(value)); // Convert array to list
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

* @return A new {@code Expr} representing the addition operation.
*/
@BetaApi
default Add add(Object other) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this is a problem. Constant.of should take care of the type inspection?

private final String name;
private final List<Expr> params;

protected Function(String name, List<? extends Expr> params) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


public interface Stage {
String getName();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this was on my TODO list. I will address this later though, not urgent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/java-firestore API. size: xl Pull request size is extra large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants