-
Notifications
You must be signed in to change notification settings - Fork 80
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(api): dataset fields statistics #1360
Open
MFori
wants to merge
8
commits into
master
Choose a base branch
from
feat/dataset-field-statistics-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f8342c2
feat(api): dataset fields statistics
MFori a8237f4
update link in description
MFori 060b245
remove redundant fields
MFori fb34858
update endpoint description
MFori 425bbbc
update response description
MFori 4cc52db
use /v2/datasets/{datasetId}/statistics approach
MFori 2fb2806
fix indent
MFori c431a15
fieldStatistics nullable
MFori File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
apify-api/openapi/components/schemas/datasets/DatasetFieldStatistics.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
title: DatasetFieldStatistics | ||
type: object | ||
properties: | ||
min: | ||
type: number | ||
description: 'Minimum value of the field. For numbers, this is calculated directly. For strings, this is the length of the shortest string. For arrays, this is the length of the shortest array. For objects, this is the number of keys in the smallest object.' | ||
nullable: true | ||
max: | ||
type: number | ||
description: 'Maximum value of the field. For numbers, this is calculated directly. For strings, this is the length of the longest string. For arrays, this is the length of the longest array. For objects, this is the number of keys in the largest object.' | ||
nullable: true | ||
nullCount: | ||
type: number | ||
description: 'How many items in the dataset have a null value for this field.' | ||
nullable: true | ||
emptyCount: | ||
type: number | ||
description: 'How many items in the dataset are `undefined`, meaning that for example empty string is not considered empty.' | ||
nullable: true |
21 changes: 21 additions & 0 deletions
21
apify-api/openapi/components/schemas/datasets/GetDatasetFieldStatisticsResponse.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
title: GetDatasetFieldStatisticsResponse | ||
required: | ||
- data | ||
type: object | ||
properties: | ||
data: | ||
type: object | ||
required: | ||
- fields | ||
- statistics | ||
properties: | ||
fields: | ||
type: array | ||
items: | ||
type: string | ||
description: 'Keys of the fields for which the statistics are provided.' | ||
statistics: | ||
type: object | ||
additionalProperties: | ||
$ref: ./DatasetFieldStatistics.yaml | ||
description: 'Statistics for each field. The keys are the same as in the `fields` array.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
apify-api/openapi/paths/datasets/datasets@{datasetId}@field-statistics.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
get: | ||
tags: | ||
- Datasets/Field statistics | ||
summary: Get field statistics | ||
description: | | ||
Returns field statistics for given dataset. | ||
When you configure the dataset [fields schema](https://docs.apify.com/platform/actors/development/actor-definition/dataset-schema/validation), we generate a field list and measure the statistics such as `min`, `max`, `nullCount` and `emptyCount`. | ||
|
||
See dataset fields schema [documentation](https://docs.apify.com/platform/actors/development/actor-definition/dataset-schema/validation#dataset-field-statistics) for more information. | ||
|
||
operationId: dataset_field_statistics_get | ||
parameters: | ||
- name: datasetId | ||
in: path | ||
description: Dataset ID or `username~dataset-name`. | ||
required: true | ||
style: simple | ||
schema: | ||
type: string | ||
example: WkzbQMuFYuamGv3YF | ||
- name: token | ||
in: query | ||
description: | | ||
API authentication token. It is required only when using the `username~dataset-name` format for `datasetId`. | ||
style: form | ||
explode: true | ||
schema: | ||
type: string | ||
example: soSkq9ekdmfOslopH | ||
responses: | ||
'200': | ||
description: '' | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "../../components/schemas/datasets/GetDatasetFieldStatisticsResponse.yaml" | ||
example: | ||
data: | ||
fields: ["name", "price"] | ||
statistics: { | ||
name: { | ||
nullCount: 122 | ||
}, | ||
price: { | ||
min: 59, | ||
max: 89 | ||
} | ||
} | ||
# TODO: add clients methods | ||
# x-js-parent: DatasetClient | ||
# x-js-name: fieldStatistics | ||
# x-js-doc-url: https://docs.apify.com/api/client/js/reference/class/DatasetClient#fieldStatistics | ||
# x-py-parent: DatasetClientAsync | ||
# x-py-name: field_statistics | ||
# x-py-doc-url: https://docs.apify.com/api/client/python/reference/class/DatasetClientAsync#field_statistics |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the list of all fields from
dataset.fields
in DB or really the list of fields for which we have statistics? If the latter one then the question is if we need to be returning this redundant information asThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the list of all fields defined in
dataset.schema.fields
.I was thinking the same but because we store it separately and in docs there is this sentence:
When you configure the dataset fields schema, we generate a field list and measure the following statistics
, I though it has some reason.But from implementation it looks like there will be always all fields in
statistics
, which meansIf some field defined in dataset schema is never in dataset itself, it will have
emptyCount=number_of_items
.And if some field is in dataset but isn't defined in dataset schema, it won't be in statistics.
So I assume you are right and it's redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In such case, I'd remove it; we can always add new properties later, but we can't ever remove them as that would break existing integrations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already updated it, but now I wonder, whether it would be better like this having the fields right under
data
object. E.g.{ "data": { "name": { "emptyCount": 100 } } }
Or keep the
data.statistics
object having the place to add other things underdata
in the future 🤔 such as{ "data": { "statistics": { "name": { "emptyCount": 100 } } } }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@netmilk and @fnesveda , what do you think?
vs simply
The former one is extensible and the latter one is simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this?
That way, if we want to add more statistics about datasets later on, we can do it in the same endpoint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the ticket https://github.com/apify/apify-core/issues/18807 was note about this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking about what is better. We could split it but then we will have a few more endpoints in the docs. Or we can go with
/stats
and have this properties. Considering we don't plan to add much anytime soon, I'd go with a single endpoint for stats for simplicity.What would you prefer @netmilk ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer @fnesveda's proposal: The uri
.../statistics
+fieldStatistics
objects underfieldStatistics
property, especially if you foresee additional types of statistics in the future returned in the response.Naming the key just
statistics
doesn't provide any additional semantic meaning, it would now introduce just an additional nesting and it would lead to an overload of the term in the future.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I used @fnesveda's approach, please take a look @mtrunkat @netmilk