-
Notifications
You must be signed in to change notification settings - Fork 25.7k
ESQL: Time_zone tests #136748
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: Time_zone tests #136748
Changes from 14 commits
f95c2a8
569d9e5
cc15c9f
449abe6
5dec7c3
fedbf4f
b088abf
ee1316c
13d8b4b
d794329
2713280
f76f5ec
9005c78
fad189f
4f62f23
4c5adc0
d81729b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,9 +13,6 @@ | |
| import java.util.function.Function; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| public final class CsvSpecReader { | ||
|
|
||
| private CsvSpecReader() {} | ||
|
|
@@ -25,9 +22,6 @@ public static SpecReader.Parser specParser() { | |
| } | ||
|
|
||
| public static class CsvSpecParser implements SpecReader.Parser { | ||
| private static final String SCHEMA_PREFIX = "schema::"; | ||
|
|
||
| private final StringBuilder earlySchema = new StringBuilder(); | ||
| private final StringBuilder query = new StringBuilder(); | ||
| private final StringBuilder data = new StringBuilder(); | ||
| private final List<String> requiredCapabilities = new ArrayList<>(); | ||
|
|
@@ -39,21 +33,22 @@ private CsvSpecParser() {} | |
| public Object parse(String line) { | ||
| // read the query | ||
| if (testCase == null) { | ||
| if (line.startsWith(SCHEMA_PREFIX)) { | ||
| assertThat("Early schema already declared " + earlySchema, earlySchema.length(), is(0)); | ||
| earlySchema.append(line.substring(SCHEMA_PREFIX.length()).trim()); | ||
| } else if (line.toLowerCase(Locale.ROOT).startsWith("required_capability:")) { | ||
| if (line.toLowerCase(Locale.ROOT).startsWith("required_capability:")) { | ||
| requiredCapabilities.add(line.substring("required_capability:".length()).trim()); | ||
| } else { | ||
| if (line.endsWith(";")) { | ||
| if (line.endsWith("\\;")) { | ||
| // SET statement with escaped ";" | ||
|
Comment on lines
+39
to
+40
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could use other mechanism; I just chose a typical one here. Listening for opinions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we have plenty of queries that end with a
In conclusion, your solution seems reasonable |
||
| var updatedLine = line.substring(0, line.length() - 2); | ||
| query.append(updatedLine); | ||
| query.append(";"); | ||
| query.append("\r\n"); | ||
| } else if (line.endsWith(";")) { | ||
| // pick up the query | ||
| testCase = new CsvTestCase(); | ||
| query.append(line.substring(0, line.length() - 1).trim()); | ||
| testCase.query = query.toString(); | ||
| testCase.earlySchema = earlySchema.toString(); | ||
| testCase.requiredCapabilities = List.copyOf(requiredCapabilities); | ||
| requiredCapabilities.clear(); | ||
| earlySchema.setLength(0); | ||
| query.setLength(0); | ||
| } | ||
| // keep reading the query | ||
|
|
@@ -109,7 +104,6 @@ private static Pattern warningRegexToPattern(String regex) { | |
|
|
||
| public static class CsvTestCase { | ||
| public String query; | ||
| public String earlySchema; | ||
| public String expectedResults; | ||
| private final List<String> expectedWarnings = new ArrayList<>(); | ||
| private final List<String> expectedWarningsRegexString = new ArrayList<>(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| set | ||
| required_capability: global_timezone_parameter | ||
|
|
||
| set time_zone="+02:00"\; | ||
| from employees | ||
| | sort emp_no | ||
| | keep emp_no, hire_date | ||
| | eval hour = date_extract("hour_of_day", hire_date) | ||
| | limit 1; | ||
|
|
||
| emp_no:integer | hire_date:date | hour:long | ||
| 10001 | 1986-06-26T00:00:00.000Z | 2 | ||
| ; | ||
|
|
||
| set with foldable | ||
| required_capability: global_timezone_parameter | ||
|
|
||
| set time_zone="+02:00"\; | ||
| ROW date = "1986-06-26T00:00:00.000Z"::date | ||
| | eval hour = date_extract("hour_of_day", date) | ||
| ; | ||
|
|
||
| date:date | hour:long | ||
| 1986-06-26T00:00:00.000Z | 2 | ||
| ; | ||
|
|
||
| last set prevails | ||
| required_capability: global_timezone_parameter | ||
|
|
||
| set time_zone="+02:00"\; | ||
| set time_zone="+05:00"\; | ||
| from employees | ||
| | sort emp_no | ||
| | keep emp_no, hire_date | ||
| | eval hour = date_extract("hour_of_day", hire_date) | ||
| | limit 1; | ||
|
|
||
| emp_no:integer | hire_date:date | hour:long | ||
| 10001 | 1986-06-26T00:00:00.000Z | 5 | ||
| ; |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This came from QL; I removed it here. It wasn't being used anywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍