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

QL: Eliminate internal type DATETIME_NANOS #68220

Merged
merged 19 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Address comments
  • Loading branch information
matriv committed Feb 10, 2021
commit 573cac4e56cdcfa3359cfa12f3e8c2ac2b55557f
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.elasticsearch.xpack.ql.type.DataType;

import static org.elasticsearch.xpack.ql.type.DataTypes.DATETIME;
import static org.elasticsearch.xpack.ql.type.DataTypes.KEYWORD;

// NB: this class is taken from SQL - it hasn't been ported over to QL
// since at this stage is unclear whether the whole FieldExtraction infrastructure
Expand Down Expand Up @@ -64,10 +63,6 @@ public String toString() {
return name;
}

private static boolean hasDocValues(DataType dataType) {
return dataType == KEYWORD || dataType == DATETIME;
}

private static String format(DataType dataType) {
// We need epoch_millis for the tiebreaker timestamp field, because parsing timestamp strings
// can have a negative performance impact
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,7 @@ private FieldExtraction topHitFieldRef(FieldAttribute fieldAttr) {
fullFieldName.insert(0, ".").insert(0, rootField.parent().field().getName());
rootField = rootField.parent();
}
return new SearchHitFieldRef(aliasName(actualField), fullFieldName.toString(), fieldAttr.field().getDataType(),
fieldAttr.field().isAggregatable(), fieldAttr.field().isAlias());
return new SearchHitFieldRef(aliasName(actualField), fieldAttr.field().getDataType());
}

private Tuple<QueryContainer, FieldExtraction> nestedHitFieldRef(FieldAttribute attr) {
Expand All @@ -347,8 +346,7 @@ private Tuple<QueryContainer, FieldExtraction> nestedHitFieldRef(FieldAttribute
SqlDataTypes.format(attr.field().getDataType()),
SqlDataTypes.isFromDocValuesOnly(attr.field().getDataType()));

SearchHitFieldRef nestedFieldRef = new SearchHitFieldRef(name, null, attr.field().getDataType(), attr.field().isAggregatable(),
false, attr.parent().name());
SearchHitFieldRef nestedFieldRef = new SearchHitFieldRef(name, attr.field().getDataType(), attr.parent().name());

return new Tuple<>(
new QueryContainer(q, aggs, fields, aliases, pseudoFunctions, scalarFunctions, sort, limit, trackHits, includeFrozen,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,16 @@

public class SearchHitFieldRef extends FieldReference {
private final String name;
private final String fullFieldName; // path included. If field full path is a.b.c, full field name is "a.b.c" and name is "c"
private final DataType dataType;
private final boolean docValue;
private final String hitName;

public SearchHitFieldRef(String name, String fullFieldName, DataType dataType, boolean useDocValueInsteadOfSource, boolean isAlias) {
this(name, fullFieldName, dataType, useDocValueInsteadOfSource, isAlias, null);
public SearchHitFieldRef(String name, DataType dataType) {
this(name, dataType, null);
}

public SearchHitFieldRef(String name, String fullFieldName, DataType dataType, boolean useDocValueInsteadOfSource, boolean isAlias,
String hitName) {
public SearchHitFieldRef(String name, DataType dataType, String hitName) {
this.name = name;
this.fullFieldName = fullFieldName;
this.dataType = dataType;
// these field types can only be extracted from docvalue_fields (ie, values already computed by Elasticsearch)
// because, for us to be able to extract them from _source, we would need the mapping of those fields (which we don't have)
this.docValue = isAlias ? useDocValueInsteadOfSource :
(SqlDataTypes.isFromDocValuesOnly(dataType) ? useDocValueInsteadOfSource : false);
this.hitName = hitName;
}

Expand All @@ -42,18 +34,10 @@ public String name() {
return name;
}

public String fullFieldName() {
return fullFieldName;
}

public DataType getDataType() {
return dataType;
}

public boolean useDocValue() {
return docValue;
}

@Override
public void collectFields(QlSourceBuilder sourceBuilder) {
// nested fields are handled by inner hits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,6 @@ public void testCastWithUnquotedDataType() {
assertEquals(INTEGER, mul.dataType());
}

public void testCastToDatetimeNanosNotSupported() {
ParsingException e = expectThrows(ParsingException.class, () -> parser.createExpression("CAST('foo' AS DATETIME_NANOS)"));
assertEquals("line 1:16: Does not recognize type [DATETIME_NANOS]", e.getMessage());
}

public void testCastWithQuotedDataType() {
Expression expr = parser.createExpression("CAST(10*2 AS \"LonG\")");
assertEquals(Cast.class, expr.getClass());
Expand Down