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: Don't allow inexact fields for MIN/MAX #39563

Merged
merged 1 commit into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.util.List;

import static org.elasticsearch.xpack.sql.expression.TypeResolutions.isExact;
import static org.elasticsearch.xpack.sql.expression.TypeResolutions.isNumericOrDate;

/**
Expand Down Expand Up @@ -47,7 +48,7 @@ public String innerName() {
@Override
protected TypeResolution resolveType() {
if (field().dataType().isString()) {
return TypeResolution.TYPE_RESOLVED;
return isExact(field(), sourceText(), ParamOrdinal.DEFAULT);
} else {
return isNumericOrDate(field(), sourceText(), ParamOrdinal.DEFAULT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.util.List;

import static org.elasticsearch.xpack.sql.expression.TypeResolutions.isExact;
import static org.elasticsearch.xpack.sql.expression.TypeResolutions.isNumericOrDate;

/**
Expand Down Expand Up @@ -50,7 +51,7 @@ public String innerName() {
@Override
protected TypeResolution resolveType() {
if (field().dataType().isString()) {
return TypeResolution.TYPE_RESOLVED;
return isExact(field(), sourceText(), ParamOrdinal.DEFAULT);
} else {
return isNumericOrDate(field(), sourceText(), ParamOrdinal.DEFAULT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,18 @@ public void testTopHitsGroupByHavingUnsupported() {
error("SELECT FIRST(int) FROM test GROUP BY text HAVING FIRST(int) > 10"));
}

public void testMinOnInexactUnsupported() {
assertEquals("1:8: [MIN(text)] cannot operate on field of data type [text]: " +
"No keyword/multi-field defined exact matches for [text]; define one or use MATCH/QUERY instead",
error("SELECT MIN(text) FROM test"));
}

public void testMaxOnInexactUnsupported() {
assertEquals("1:8: [MAX(text)] cannot operate on field of data type [text]: " +
"No keyword/multi-field defined exact matches for [text]; define one or use MATCH/QUERY instead",
error("SELECT MAX(text) FROM test"));
}

public void testMinOnKeywordGroupByHavingUnsupported() {
assertEquals("1:52: HAVING filter is unsupported for function [MIN(keyword)]",
error("SELECT MIN(keyword) FROM test GROUP BY text HAVING MIN(keyword) > 10"));
Expand Down