Skip to content

feat(firestore): add samples for sum and average #37

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 7 commits into from
Oct 9, 2024

Conversation

Lyokone
Copy link
Contributor

@Lyokone Lyokone commented Aug 14, 2024

Description of what this PR is changing or adding:

_Issues fixed by this PR (if any): firebase/flutterfire#13062

Risk Level

  • No risk
  • Somewhat Risky
  • High risk

Pre-submit checklist

Copy link
Member

@thatfiredev thatfiredev left a comment

Choose a reason for hiding this comment

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

Thanks @Lyokone ! Two comments:

  1. The current examples in the docs use the cities example, can we use that same collection for consistency? (I have added suggested edits below)
  2. Can you please also add a snippet for multiple aggregations in a query?

Comment on lines 870 to 873
db.collection("users").aggregate(sum("age")).get().then(
(res) => print(res.getAverage("age")),
onError: (e) => print("Error completing: $e"),
);
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
db.collection("users").aggregate(sum("age")).get().then(
(res) => print(res.getAverage("age")),
onError: (e) => print("Error completing: $e"),
);
db.collection("cities").aggregate(sum("population")).get().then(
(res) => print(res.getAverage("population")),
onError: (e) => print("Error completing: $e"),
);

Comment on lines 880 to 885
.collection("users")
.where("age", isGreaterThan: 10)
.aggregate(sum("age"))
.get()
.then(
(res) => print(res.getAverage("age")),
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
.collection("users")
.where("age", isGreaterThan: 10)
.aggregate(sum("age"))
.get()
.then(
(res) => print(res.getAverage("age")),
.collection("cities")
.where("capital", isEqualTo: true)
.aggregate(sum("population"))
.get()
.then(
(res) => print(res.getAverage("population")),

Comment on lines 893 to 894
db.collection("users").aggregate(average("age")).get().then(
(res) => print(res.getAverage("age")),
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
db.collection("users").aggregate(average("age")).get().then(
(res) => print(res.getAverage("age")),
db.collection("cities").aggregate(average("population")).get().then(
(res) => print(res.getAverage("population")),

Comment on lines 903 to 908
.collection("users")
.where("age", isGreaterThan: 10)
.aggregate(average("age"))
.get()
.then(
(res) => print(res.getAverage("age")),
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
.collection("users")
.where("age", isGreaterThan: 10)
.aggregate(average("age"))
.get()
.then(
(res) => print(res.getAverage("age")),
.collection("cities")
.where("capital", isEqualTo: true)
.aggregate(average("population"))
.get()
.then(
(res) => print(res.getAverage("population")),

@cynthiajoan
Copy link
Contributor

Thanks @Lyokone ! Two comments:

  1. The current examples in the docs use the cities example, can we use that same collection for consistency? (I have added suggested edits below)
  2. Can you please also add a snippet for multiple aggregations in a query?

Thanks @thatfiredev for the review. In this case, should we also update the count snippets to use cities example?

@thatfiredev
Copy link
Member

@cynthiajoan Oh, I hadn't noticed that one was using a different example. Yes, let's use cities there too please. :)

@thatfiredev
Copy link
Member

thatfiredev commented Oct 3, 2024

Hmmm, not sure why CI is failing (both here and in #36), but some posts suggest upgrading packages. Can we try that @Lyokone ?

Error log for reference:

../../../../../.pub-cache/hosted/pub.dev/win32-5.0.6/lib/src/guid.dart:32:9: Error: Type 'UnmodifiableUint8ListView' not found.
  final UnmodifiableUint8ListView bytes;
        ^^^^^^^^^^^^^^^^^^^^^^^^^
../../../../../.pub-cache/hosted/pub.dev/win32-5.0.6/lib/src/guid.dart:32:9: Error: 'UnmodifiableUint8ListView' isn't a type.
  final UnmodifiableUint8ListView bytes;
        ^^^^^^^^^^^^^^^^^^^^^^^^^
../../../../../.pub-cache/hosted/pub.dev/win32-5.0.6/lib/src/guid.dart:52:17: Error: Method not found: 'UnmodifiableUint8ListView'.
    return Guid(UnmodifiableUint8ListView(guid));
                ^^^^^^^^^^^^^^^^^^^^^^^^^
../../../../../.pub-cache/hosted/pub.dev/win32-5.0.6/lib/src/guid.dart:56:31: Error: Method not found: 'UnmodifiableUint8ListView'.
  factory Guid.zero() => Guid(UnmodifiableUint8ListView(Uint8List(16)));
                              ^^^^^^^^^^^^^^^^^^^^^^^^^
../../../../../.pub-cache/hosted/pub.dev/win32-5.0.6/lib/src/guid.dart:100:17: Error: Method not found: 'UnmodifiableUint8ListView'.
    return Guid(UnmodifiableUint8ListView(Uint8List.fromList(guidAsBytes)));
                ^^^^^^^^^^^^^^^^^^^^^^^^^
Target kernel_snapshot_program failed: Exception


FAILURE: Build failed with an exception.

* Where:
Script '/home/runner/work/snippets-flutter/snippets-flutter/_flutter/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy' line: 1687

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/home/runner/work/snippets-flutter/snippets-flutter/_flutter/bin/flutter'' finished with non-zero exit value 1

@cynthiajoan
Copy link
Contributor

Hmmm, not sure why CI is failing (both here and in #36), but some posts suggest upgrading packages. Can we try that @Lyokone ?

Error log for reference:

../../../../../.pub-cache/hosted/pub.dev/win32-5.0.6/lib/src/guid.dart:32:9: Error: Type 'UnmodifiableUint8ListView' not found.
  final UnmodifiableUint8ListView bytes;
        ^^^^^^^^^^^^^^^^^^^^^^^^^
../../../../../.pub-cache/hosted/pub.dev/win32-5.0.6/lib/src/guid.dart:32:9: Error: 'UnmodifiableUint8ListView' isn't a type.
  final UnmodifiableUint8ListView bytes;
        ^^^^^^^^^^^^^^^^^^^^^^^^^
../../../../../.pub-cache/hosted/pub.dev/win32-5.0.6/lib/src/guid.dart:52:17: Error: Method not found: 'UnmodifiableUint8ListView'.
    return Guid(UnmodifiableUint8ListView(guid));
                ^^^^^^^^^^^^^^^^^^^^^^^^^
../../../../../.pub-cache/hosted/pub.dev/win32-5.0.6/lib/src/guid.dart:56:31: Error: Method not found: 'UnmodifiableUint8ListView'.
  factory Guid.zero() => Guid(UnmodifiableUint8ListView(Uint8List(16)));
                              ^^^^^^^^^^^^^^^^^^^^^^^^^
../../../../../.pub-cache/hosted/pub.dev/win32-5.0.6/lib/src/guid.dart:100:17: Error: Method not found: 'UnmodifiableUint8ListView'.
    return Guid(UnmodifiableUint8ListView(Uint8List.fromList(guidAsBytes)));
                ^^^^^^^^^^^^^^^^^^^^^^^^^
Target kernel_snapshot_program failed: Exception


FAILURE: Build failed with an exception.

* Where:
Script '/home/runner/work/snippets-flutter/snippets-flutter/_flutter/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy' line: 1687

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/home/runner/work/snippets-flutter/snippets-flutter/_flutter/bin/flutter'' finished with non-zero exit value 1

#38 to try fixing the CI

Copy link
Member

@thatfiredev thatfiredev left a comment

Choose a reason for hiding this comment

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

@thatfiredev thatfiredev merged commit 2b96a4c into firebase:main Oct 9, 2024
2 checks passed
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.

3 participants