-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add time extraction functions to project time as a dimension #1159
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,78 +1,156 @@ | ||
| --- | ||
| layout: doc_page | ||
| --- | ||
|
|
||
| # Transforming Dimension Values | ||
| The following JSON fields can be used in a query to operate on dimension values. | ||
|
|
||
| The following JSON fields can be used in a query to operate on dimension values. | ||
|
|
||
| ## DimensionSpec | ||
|
|
||
| `DimensionSpec`s define how dimension values get transformed prior to aggregation. | ||
|
|
||
| ### DefaultDimensionSpec | ||
| ### Default DimensionSpec | ||
|
|
||
| Returns dimension values as is and optionally renames the dimension. | ||
|
|
||
| ```json | ||
| { "type" : "default", "dimension" : <dimension>, "outputName": <output_name> } | ||
| ``` | ||
|
|
||
| ### ExtractionDimensionSpec | ||
| ### Extraction DimensionSpec | ||
|
|
||
| Returns dimension values transformed using the given [DimExtractionFn](#toc_3) | ||
| Returns dimension values transformed using the given [extraction function](#extraction-functions). | ||
|
|
||
| ```json | ||
| { | ||
| "type" : "extraction", | ||
| "dimension" : <dimension>, | ||
| "outputName" : <output_name>, | ||
| "dimExtractionFn" : <dim_extraction_fn> | ||
| "extractionFn" : <extraction_function> | ||
| } | ||
| ``` | ||
|
|
||
| ## <a id="toc_3"></a>DimExtractionFn | ||
| ## Extraction Functions | ||
|
|
||
| Extraction functions define the transformation applied to each dimension value. | ||
|
|
||
| `DimExtractionFn`s define the transformation applied to each dimension value | ||
| Transformations can be applied to both regular (string) dimensions, as well | ||
| as the special `__time` dimension, which represents the current time bucket | ||
| according to the query [aggregation granularity](Granularities.html). | ||
|
|
||
| ### RegexDimExtractionFn | ||
| **Note**: for functions taking string values (such as regular expressions), | ||
| `__time` dimension values will be formatted in [ISO-8601 format](https://en.wikipedia.org/wiki/ISO_8601) | ||
| before getting passed to the extraction function. | ||
|
|
||
| Returns the first group matched by the given regular expression. If there is no match it returns the dimension value as is. | ||
| ### Regular Expression Extraction Function | ||
|
|
||
| Returns the first matching group for the given regular expression. | ||
| If there is no match, it returns the dimension value as is. | ||
|
|
||
| ```json | ||
| { "type" : "regex", "expr", <regular_expression> } | ||
| { "type" : "regex", "expr" : <regular_expression> } | ||
| ``` | ||
|
|
||
| ### PartialDimExtractionFn | ||
| For example, using `"expr" : "(\\w\\w\\w).*"` will transform | ||
| `'Monday'`, `'Tuesday'`, `'Wednesday'` into `'Mon'`, `'Tue'`, `'Wed'`. | ||
|
|
||
| ### Partial Extraction Function | ||
|
|
||
| Returns the dimension value as is if there is a match, otherwise returns null. | ||
| Returns the dimension value unchanged if the regular expression matches, otherwise returns null. | ||
|
|
||
| ```json | ||
| { "type" : "partial", "expr", <regular_expression> } | ||
| { "type" : "partial", "expr" : <regular_expression> } | ||
| ``` | ||
|
|
||
| ### SearchQuerySpecDimExtractionFn | ||
| ### Search Query Extraction Function | ||
|
|
||
| Returns the dimension value as is if the given [SearchQuerySpec](SearchQuerySpec.html) matches, otherwise returns null. | ||
| Returns the dimension value unchanged if the given [`SearchQuerySpec`](SearchQuerySpec.html) | ||
| matches, otherwise returns null. | ||
|
|
||
| ```json | ||
| { "type" : "searchQuery", "query" : <search_query_spec> } | ||
| ``` | ||
|
|
||
| ### TimeDimExtractionFn | ||
| ### Time Format Extraction Function | ||
|
|
||
| Parses dimension values as timestamps using the given input format, and returns them formatted using the given output format. Time formats follow the [com.ibm.icu.text.SimpleDateFormat](http://icu-project.org/apiref/icu4j/com/ibm/icu/text/SimpleDateFormat.html) format | ||
| Returns the dimension value formatted according to the given format string, time zone, and locale. | ||
|
|
||
| For `__time` dimension values, this formats the time value bucketed by the | ||
| [aggregation granularity](Granularities.html) | ||
|
|
||
| For a regular dimension, it assumes the string is formatted in | ||
| [ISO-8601 date and time format](https://en.wikipedia.org/wiki/ISO_8601). | ||
|
|
||
| * `format` : date time format for the resulting dimension value, in [Joda Time DateTimeFormat](http://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html). | ||
| * `locale` : locale (language and country) to use, given as a [IETF BCP 47 language tag](http://www.oracle.com/technetwork/java/javase/java8locales-2095355.html#util-text), e.g. `en-US`, `en-GB`, `fr-FR`, `fr-CA`, etc. | ||
| * `timeZone` : time zone to use in [IANA tz database format](http://en.wikipedia.org/wiki/List_of_tz_database_time_zones), e.g. `Europe/Berlin` (this can possibly be different than the aggregation time-zone) | ||
|
|
||
| ```json | ||
| { "type" : "time", "timeFormat" : <input_format>, "resultFormat" : <output_format> } | ||
| { "type" : "timeFormat", | ||
| "format" : <output_format>, | ||
| "timeZone" : <time_zone> (optional), | ||
| "locale" : <locale> (optional) } | ||
| ``` | ||
|
|
||
| ### JavascriptDimExtractionFn | ||
| For example, the following dimension spec returns the day of the week for Montréal in French: | ||
|
|
||
| Returns the dimension value as transformed by the given JavaScript function. | ||
| ```json | ||
| { | ||
| "type" : "extraction", | ||
| "dimension" : "__time", | ||
| "outputName" : "dayOfWeek", | ||
| "extractionFn" : { | ||
| "type" : "timeFormat", | ||
| "format" : "EEEE", | ||
| "timeZone" : "America/Montreal", | ||
| "locale" : "fr" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Example | ||
| ### Time Parsing Extraction Function | ||
|
|
||
| Parses dimension values as timestamps using the given input format, | ||
| and returns them formatted using the given output format. | ||
|
|
||
| Note, if you are working with the `__time` dimension, you should consider using the | ||
| [time extraction function instead](#time-format-extraction-function) instead, | ||
| which works on time value directly as opposed to string values. | ||
|
|
||
| Time formats are described in the | ||
| [SimpleDateFormat documentation](http://icu-project.org/apiref/icu4j/com/ibm/icu/text/SimpleDateFormat.html) | ||
|
|
||
| ```json | ||
| { "type" : "time", | ||
| "timeFormat" : <input_format>, | ||
| "resultFormat" : <output_format> } | ||
| ``` | ||
|
|
||
|
|
||
| ### Javascript Extraction Function | ||
|
|
||
| Returns the dimension value, as transformed by the given JavaScript function. | ||
|
|
||
| For regular dimensions, the input value is passed as a string. | ||
|
|
||
| For the `__time` dimension, the input value is passed as a number | ||
| representing the number of milliseconds since January 1, 1970 UTC. | ||
|
|
||
| Example for a regular dimension | ||
|
|
||
| ```json | ||
| { | ||
| "type" : "javascript", | ||
| "function" : "function(str) { return str.substr(0, 3); }" | ||
| } | ||
| ``` | ||
|
|
||
| Example for the `__time` dimension: | ||
|
|
||
| ```json | ||
| { | ||
| "type" : "javascript", | ||
| "function" : "function(t) { return 'Second ' + Math.floor((t % 60000) / 1000); }" | ||
| } | ||
| ``` | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
was this hyperlink not used?
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.
links are created automatically now