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: Adds MONTHNAME, DAYNAME and QUARTER functions #33411

Merged
merged 9 commits into from
Sep 11, 2018

Conversation

astefan
Copy link
Contributor

@astefan astefan commented Sep 5, 2018

This PR adds three functions from those listed here.

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

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

Nice work! Left some comments.

@@ -123,6 +126,9 @@
def(MonthOfYear.class, MonthOfYear::new, "MONTH"),
def(Year.class, Year::new),
def(WeekOfYear.class, WeekOfYear::new, "WEEK"),
def(DayName.class, DayName::new, "DAYNAME"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need alias here and next line?

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, ignore this, Checked already. It's because DayName becomes day_name.

Copy link
Member

Choose a reason for hiding this comment

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

Should we make the class Dayname instead then? Do we want to support DAY_NAME as well as DAYNAME?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nik9000 I chose it like this because of consistency. There are other date/time functions that have aliases, even though the spec mentions only one name. For example WEEK (WEEK_OF_YEAR), HOUR (HOUR_OF_DAY) etc.

throw new SqlIllegalArgumentException("A string or a date is required; received {}", l);
}
public Object doProcess(long millis) {
ReadableDateTime dt = new DateTime(millis, DateTimeZone.forTimeZone(timeZone()));
Copy link
Contributor

Choose a reason for hiding this comment

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

With the introduction of the abstract class, in case of 6.3- we already have a ReadableDateTime which we now convert to millis and then back to ReadableDateTime. Could this be a perf issue?

Copy link
Member

Choose a reason for hiding this comment

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

Since this is operating on the data returned by the search it isn't as much of a problem as it could be. And it'll only come up during the rolling upgrade too. Since we're using the opportunity to switch from Joda time classes to Java 8 time classes I'm on board with it.

@@ -9,6 +9,9 @@
class org.elasticsearch.xpack.sql.expression.function.scalar.whitelist.InternalSqlScriptUtils {

Integer dateTimeChrono(long, String, String)
String dayName(long,String)
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: add a whitespace after comma here and below.

assertEquals(1, proc.process("0"));
assertEquals(3, proc.process("-64164233612338"));
assertEquals(2, proc.process("64164233612338"));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we add nonUTC tests here as well?

@matriv
Copy link
Contributor

matriv commented Sep 5, 2018

As discussed, maybe consider to add some tests with the functions used in ORDER BY clause.

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.

Left some minor comments. Can you please add more integration tests with the functions in ORDER BY and HAVING?


import java.util.TimeZone;

public abstract class BaseDateTimeFunction extends UnaryScalarFunction {
Copy link
Member

Choose a reason for hiding this comment

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

The class visibility could be package as the constructor.

import static org.elasticsearch.xpack.sql.expression.function.scalar.script.ParamsBuilder.paramsBuilder;
import static org.elasticsearch.xpack.sql.expression.function.scalar.script.ScriptTemplate.formatTemplate;

public abstract class NamedDateTimeFunction extends BaseDateTimeFunction {
Copy link
Member

Choose a reason for hiding this comment

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

Restrict class visibility to be inline with that of the constructor.
Plus javadocs.

return timeZone;
}

// add tz along the rest of the params
Copy link
Member

Choose a reason for hiding this comment

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

I find this comment confusing, like a TODO. The intent is clear - the name has been overwritten, the method is needed.

import static org.elasticsearch.xpack.sql.expression.function.scalar.script.ScriptTemplate.formatTemplate;

/*
* Base class for the two "naming" date/time functions: month_name and day_name
Copy link
Contributor

Choose a reason for hiding this comment

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

To make it more "future-proof" maybe:
Base class for "naming" data/time functions like: month_namd and day-name.

@astefan
Copy link
Contributor Author

astefan commented Sep 11, 2018

@matriv @costin I've incorporated your review in a follow up commit. Can you please, have another look?

Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

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

LGTM

@astefan astefan merged commit a3e1f1e into elastic:master Sep 11, 2018
astefan added a commit to astefan/elasticsearch that referenced this pull request Sep 11, 2018
* Added monthname, dayname and quarter functions
* Updated docs tests with the new functions
@astefan
Copy link
Contributor Author

astefan commented Sep 11, 2018

6.x commit: 6832248

@astefan astefan deleted the 33092_fix branch September 11, 2018 12:10
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Sep 11, 2018
* master:
  Preserve cluster settings on full restart tests (elastic#33590)
  Use IndexWriter.getFlushingBytes() rather than tracking it ourselves (elastic#33582)
  Fix upgrading of list settings (elastic#33589)
  Add read-only Engine (elastic#33563)
  HLRC: Add ML get categories API (elastic#33465)
  SQL: Adds MONTHNAME, DAYNAME and QUARTER functions (elastic#33411)
  Add predicate_token_filter (elastic#33431)
  Fix Replace function. Adds more tests to all string functions. (elastic#33478)
  [ML] Rename input_fields to column_names in file structure (elastic#33568)
jasontedor added a commit to martijnvg/elasticsearch that referenced this pull request Sep 11, 2018
* master: (91 commits)
  Preserve cluster settings on full restart tests (elastic#33590)
  Use IndexWriter.getFlushingBytes() rather than tracking it ourselves (elastic#33582)
  Fix upgrading of list settings (elastic#33589)
  Add read-only Engine (elastic#33563)
  HLRC: Add ML get categories API (elastic#33465)
  SQL: Adds MONTHNAME, DAYNAME and QUARTER functions (elastic#33411)
  Add predicate_token_filter (elastic#33431)
  Fix Replace function. Adds more tests to all string functions. (elastic#33478)
  [ML] Rename input_fields to column_names in file structure (elastic#33568)
  Add full cluster restart base class (elastic#33577)
  Validate list values for settings (elastic#33503)
  Copy and validatie soft-deletes setting on resize (elastic#33517)
  Test: Fix package name
  SQL: Fix result column names for arithmetic functions (elastic#33500)
  Upgrade to latest Lucene snapshot (elastic#33505)
  Enable not wiping cluster settings after REST test (elastic#33575)
  MINOR: Remove Dead Code in SearchScript (elastic#33569)
  [Test] Remove duplicate method in TestShardRouting (elastic#32815)
  mute test on windows
  Update beats template to include apm-server metrics (elastic#33286)
  ...
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.

6 participants