Navigation Menu

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

SQL: Fix metric aggs on date/time to not return double #40377

Merged
merged 2 commits into from Mar 23, 2019

Conversation

matriv
Copy link
Contributor

@matriv matriv commented Mar 22, 2019

Previously metric aggregations on date fields would return a double
which caused errors when trying to apply scalar functions on top, e.g.:

SELECT YEAR(MAX(date)) FROM test

Fixes: #40376
Fixes: #39492

Previously metric aggregations on date fields would return a double
which caused errors when trying to apply scalar functions on top, e.g.:
```
SELECT YEAR(MAX(date)) FROM test
```

Fixes: elastic#40376
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

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

Good catch. LGTM!
Yet another instance of session information...

return tryExtractDateTime(innerKey != null && v instanceof Map ? ((Map<?, ?>) v).get(innerKey) : v);
}

private Object tryExtractDateTime(Object object) {
Copy link
Member

Choose a reason for hiding this comment

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

handleDateTime/maybeDateTime sounds better.

@matriv matriv merged commit 41d0a03 into elastic:master Mar 23, 2019
@matriv matriv deleted the mt/fix-40376 branch March 23, 2019 13:11
matriv added a commit that referenced this pull request Mar 23, 2019
Previously metric aggregations on date fields would return a double
which caused errors when trying to apply scalar functions on top, e.g.:
```
SELECT YEAR(MAX(date)) FROM test
```

Fixes: #40376

(cherry-picked from commit 41d0a03)
matriv added a commit that referenced this pull request Mar 23, 2019
Previously metric aggregations on date fields would return a double
which caused errors when trying to apply scalar functions on top, e.g.:
```
SELECT YEAR(MAX(date)) FROM test
```

Fixes: #40376

(cherry picked from commit 41d0a03)
Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

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

I know it's merged already, but left two comments.

this.name = name;
this.property = property;
this.innerKey = innerKey;
this. isDateTimeBased =isDateTimeBased;
Copy link
Contributor

Choose a reason for hiding this comment

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

Weird spacing.

@@ -279,6 +279,8 @@ aggMinWithAlias
SELECT gender g, MIN(emp_no) m FROM "test_emp" GROUP BY g ORDER BY gender;
aggMinOnDateTime
SELECT gender, MIN(birth_date) m FROM "test_emp" GROUP BY gender ORDER BY gender;
Copy link
Contributor

Choose a reason for hiding this comment

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

If this test here wasn't complaining before, this means that our SQL spec test case infrastructure isn't actually comparing an actual date type of data, right? Otherwise, the test would have failed.
If so, I would like to see a test with MIN(date_field) in CSV spec test case infra, if possible. I have seen the unit test that compares the metric agg key with an actual date (assertEquals(DateUtils.asDateTime((long) innerValue , zoneId), extractor.extract(bucket));) but I believe our tests would be more complete if there would be an integration test as well (CSV-spec in this case).

matriv added a commit that referenced this pull request Mar 23, 2019
Previously metric aggregations on date fields would return a double
which caused errors when trying to apply scalar functions on top, e.g.:
```
SELECT YEAR(MAX(date)) FROM test
```

Fixes: #40376

(cherry picked from commit 41d0a03)
matriv added a commit that referenced this pull request Mar 23, 2019
Previously metric aggregations on date fields would return a double
which caused errors when trying to apply scalar functions on top, e.g.:
```
SELECT YEAR(MAX(date)) FROM test
```

Fixes: #40376

(cherry picked from commit 41d0a03)
pgomulka pushed a commit to pgomulka/elasticsearch that referenced this pull request Mar 25, 2019
Previously metric aggregations on date fields would return a double
which caused errors when trying to apply scalar functions on top, e.g.:
```
SELECT YEAR(MAX(date)) FROM test
```

Fixes: elastic#40376
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SQL: Metric aggs on date fields return double SQL: MIN and MAX could work better with date fields
6 participants