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

[ESQL] Minor refactor for DataType #111016

Merged
merged 2 commits into from
Jul 18, 2024

Conversation

ioanatia
Copy link
Contributor

Minor refactor:

  • Removes 2 unused methods from DataType
  • Noticed that DataType and EsqlDataTypes had some duplicate methods so I removed the ones from EsqlDataTypes:

public static boolean isString(DataType t) {
return t == KEYWORD || t == TEXT;
}

public static DataType fromTypeName(String name) {
return NAME_TO_TYPE.get(name.toLowerCase(Locale.ROOT));
}

public static DataType fromTypeName(String name) {
return DataType.fromTypeName(name.toLowerCase(Locale.ROOT));
}
public static boolean isString(DataType t) {
return t == KEYWORD || t == TEXT;
}

@ioanatia ioanatia added >non-issue Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) :Analytics/ES|QL AKA ESQL v8.16.0 labels Jul 18, 2024
@ioanatia
Copy link
Contributor Author

@elasticmachine test this please

@ioanatia ioanatia marked this pull request as ready for review July 18, 2024 12:08
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@ioanatia ioanatia requested review from astefan and nik9000 July 18, 2024 12:09
@astefan astefan requested review from not-napoleon and bpintea and removed request for nik9000 and astefan July 18, 2024 12:22
Copy link
Member

@not-napoleon not-napoleon left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for cleaning this up!

@ioanatia ioanatia merged commit aca03a5 into elastic:main Jul 18, 2024
15 of 16 checks passed
@ioanatia ioanatia deleted the esql_data_types_refactor branch July 18, 2024 13:22
public static boolean isDateTime(DataType type) {
return type == DATETIME;
}

public static boolean areCompatible(DataType left, DataType right) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we'll want to keep this method here and remove the equivalent from EsqlDataTypes.java, which might be at some point removed entirely (similar to how isString() is kept here and has been removed from there). But this can be done at some subsequent refactor.
LGTM otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The implementation of the two is slightly different:

public static boolean areCompatible(DataType left, DataType right) {
if (left == right) {
return true;
} else {
return (left == NULL || right == NULL)
|| (DataType.isString(left) && DataType.isString(right))
|| (left.isNumeric() && right.isNumeric());
}
}

I did not know what are the consequences of having the extra || (isDateTime(left) && isDateTime(right)); condition.

Copy link
Contributor

Choose a reason for hiding this comment

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

I did not know what are the consequences of having the extra || (isDateTime(left) && isDateTime(right)); condition.

Right now, none. Since ESQL (unlike SQL, where that check was likely added) only has one datetime type (DATETIME), the check would be mostly superfluous, since for it to match, both types would have to be the same, so caught by the first equality check.

But once we'll have more than one type (like the upcoming nanos support, we'll likely need to add this check back. CC: @not-napoleon.

ioanatia added a commit to ioanatia/elasticsearch that referenced this pull request Jul 22, 2024
* Remove duplicate functions from EsqlDataTypes

* Remove unused methods from DataType
salvatore-campagna pushed a commit to salvatore-campagna/elasticsearch that referenced this pull request Jul 23, 2024
* Remove duplicate functions from EsqlDataTypes

* Remove unused methods from DataType
salvatore-campagna pushed a commit to salvatore-campagna/elasticsearch that referenced this pull request Jul 23, 2024
* Remove duplicate functions from EsqlDataTypes

* Remove unused methods from DataType
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL >non-issue Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.16.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants