{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/235123168","pull_request_review_id":176917291,"id":235123168,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzNTEyMzE2OA==","diff_hunk":"@@ -0,0 +1,223 @@\n+/*\n+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n+ * or more contributor license agreements. Licensed under the Elastic License;\n+ * you may not use this file except in compliance with the Elastic License.\n+ */\n+\n+package org.elasticsearch.xpack.sql.expression.literal;\n+\n+import org.elasticsearch.test.ESTestCase;\n+import org.elasticsearch.xpack.sql.parser.ParsingException;\n+\n+import java.time.Duration;\n+import java.time.Period;\n+import java.time.temporal.TemporalAmount;\n+import java.util.Locale;\n+\n+import static java.lang.String.format;\n+import static org.elasticsearch.xpack.sql.expression.literal.IntervalUtils.parseInterval;\n+import static org.elasticsearch.xpack.sql.tree.Location.EMPTY;\n+import static org.elasticsearch.xpack.sql.type.DataType.INTERVAL_DAY;\n+import static org.elasticsearch.xpack.sql.type.DataType.INTERVAL_DAY_TO_HOUR;\n+import static org.elasticsearch.xpack.sql.type.DataType.INTERVAL_DAY_TO_MINUTE;\n+import static org.elasticsearch.xpack.sql.type.DataType.INTERVAL_DAY_TO_SECOND;\n+import static org.elasticsearch.xpack.sql.type.DataType.INTERVAL_HOUR;\n+import static org.elasticsearch.xpack.sql.type.DataType.INTERVAL_HOUR_TO_MINUTE;\n+import static org.elasticsearch.xpack.sql.type.DataType.INTERVAL_HOUR_TO_SECOND;\n+import static org.elasticsearch.xpack.sql.type.DataType.INTERVAL_MINUTE;\n+import static org.elasticsearch.xpack.sql.type.DataType.INTERVAL_MINUTE_TO_SECOND;\n+import static org.elasticsearch.xpack.sql.type.DataType.INTERVAL_MONTH;\n+import static org.elasticsearch.xpack.sql.type.DataType.INTERVAL_SECOND;\n+import static org.elasticsearch.xpack.sql.type.DataType.INTERVAL_YEAR;\n+import static org.elasticsearch.xpack.sql.type.DataType.INTERVAL_YEAR_TO_MONTH;\n+\n+public class IntervalUtilsTests extends ESTestCase {\n+\n+    public void testYearInterval() throws Exception {\n+        String randomSign = randomSign();\n+        int random = randomNonNegativeInt();\n+        TemporalAmount amount = parseInterval(EMPTY, randomSign + random, INTERVAL_YEAR);\n+        assertEquals(maybeNegate(randomSign, Period.ofYears(random)), amount);\n+    }\n+\n+    public void testMonthInterval() throws Exception {\n+        String randomSign = randomSign();\n+        int random = randomNonNegativeInt();\n+        TemporalAmount amount = parseInterval(EMPTY, randomSign + random, INTERVAL_MONTH);\n+        assertEquals(maybeNegate(randomSign, Period.ofMonths(random)), amount);\n+    }\n+\n+    public void testDayInterval() throws Exception {\n+        String randomSign = randomSign();\n+        int random = randomNonNegativeInt();\n+        TemporalAmount amount = parseInterval(EMPTY, randomSign + random, INTERVAL_DAY);\n+        assertEquals(maybeNegate(randomSign, Duration.ofDays(random)), amount);\n+    }\n+\n+    public void testHourInterval() throws Exception {\n+        String randomSign = randomSign();\n+        int random = randomNonNegativeInt();\n+        TemporalAmount amount = parseInterval(EMPTY, randomSign + random, INTERVAL_HOUR);\n+        assertEquals(maybeNegate(randomSign, Duration.ofHours(random)), amount);\n+    }\n+\n+    public void testMinuteInterval() throws Exception {\n+        String randomSign = randomSign();\n+        int random = randomNonNegativeInt();\n+        TemporalAmount amount = parseInterval(EMPTY, randomSign + random, INTERVAL_MINUTE);\n+        assertEquals(maybeNegate(randomSign, Duration.ofMinutes(random)), amount);\n+    }\n+\n+    public void testSecondInterval() throws Exception {\n+        String randomSign = randomSign();\n+        int randomSeconds = randomNonNegativeInt();\n+        int randomMillis = randomInt(999999999);","path":"x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/expression/literal/IntervalUtilsTests.java","position":null,"original_position":74,"commit_id":"3d62531318add90046750c6936786661d6f90e71","original_commit_id":"beae06981f512ed9871710c74f01a549b333ae57","user":{"login":"costin","id":76245,"node_id":"MDQ6VXNlcjc2MjQ1","avatar_url":"https://avatars3.githubusercontent.com/u/76245?v=4","gravatar_id":"","url":"https://api.github.com/users/costin","html_url":"https://github.com/costin","followers_url":"https://api.github.com/users/costin/followers","following_url":"https://api.github.com/users/costin/following{/other_user}","gists_url":"https://api.github.com/users/costin/gists{/gist_id}","starred_url":"https://api.github.com/users/costin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/costin/subscriptions","organizations_url":"https://api.github.com/users/costin/orgs","repos_url":"https://api.github.com/users/costin/repos","events_url":"https://api.github.com/users/costin/events{/privacy}","received_events_url":"https://api.github.com/users/costin/received_events","type":"User","site_admin":false},"body":"Added a random which picks the limits (0 or 9999999) or a random of the interval.","created_at":"2018-11-20T18:40:49Z","updated_at":"2018-11-20T18:40:49Z","html_url":"https://github.com/elastic/elasticsearch/pull/35521#discussion_r235123168","pull_request_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/35521","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/235123168"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/35521#discussion_r235123168"},"pull_request":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/35521"}},"in_reply_to_id":233741927},"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/35521","id":230644358,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMwNjQ0MzU4","html_url":"https://github.com/elastic/elasticsearch/pull/35521","diff_url":"https://github.com/elastic/elasticsearch/pull/35521.diff","patch_url":"https://github.com/elastic/elasticsearch/pull/35521.patch","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/35521","number":35521,"state":"open","locked":false,"title":"SQL: Introduce INTERVAL support  ","user":{"login":"costin","id":76245,"node_id":"MDQ6VXNlcjc2MjQ1","avatar_url":"https://avatars3.githubusercontent.com/u/76245?v=4","gravatar_id":"","url":"https://api.github.com/users/costin","html_url":"https://github.com/costin","followers_url":"https://api.github.com/users/costin/followers","following_url":"https://api.github.com/users/costin/following{/other_user}","gists_url":"https://api.github.com/users/costin/gists{/gist_id}","starred_url":"https://api.github.com/users/costin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/costin/subscriptions","organizations_url":"https://api.github.com/users/costin/orgs","repos_url":"https://api.github.com/users/costin/repos","events_url":"https://api.github.com/users/costin/events{/privacy}","received_events_url":"https://api.github.com/users/costin/received_events","type":"User","site_admin":false},"body":"Sorry for the big PR. It had rippling effects through the code base.\r\n\r\nIntroduce INTERVAL as a DataType\r\nAdd INTERVAL to the grammar which supports the standard SQL declaration\r\n (without precision):\r\n > INTERVAL '1 23:45:01.123456789' DAY TO SECOND\r\n\r\n but also number for single unit intervals:\r\n > INTERVAL 1 YEAR\r\n\r\n as well as the plurals of the units:\r\n > INTERVAL 2 YEARS\r\n\r\nInterval are internally supported as just another Literal being backed\r\n by java.time.Period and java.time.Duration\r\nMove JDBC away from JDBCType enum to SQLType interface\r\nRefactor DataType by:\r\n - move it into server core\r\n - add dedicated (and much simpler) JDBC type\r\nImprove internal JDBC conversion by normalizing on the DataType\r\nRename JDBC columnInfo to JdbcColumnInfo to differentiate between it and\r\n the SQL ColumnInfo\r\nExtended arithmetic operations to support operations between intervals and intervals and dates\r\n (underlying folding operation not implemented yet)\r\n\r\nLeft to do:\r\n\r\n4. add basic operation +/- between intervals\r\n5. add basic operation +/- between timestamps and intervals\r\n6. introduce now/current date/current time/current timestamp methods (likely another PR)\r\n\r\nFix #29990","created_at":"2018-11-13T22:16:22Z","updated_at":"2018-11-20T18:40:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"86b5e0468ad62d1e8cde15e00285373f2d81573a","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":912794284,"node_id":"MDU6TGFiZWw5MTI3OTQyODQ=","url":"https://api.github.com/repos/elastic/elasticsearch/labels/:Search/SQL","name":":Search/SQL","color":"0e8a16","default":false},{"id":23172,"node_id":"MDU6TGFiZWwyMzE3Mg==","url":"https://api.github.com/repos/elastic/elasticsearch/labels/%3Efeature","name":">feature","color":"006b75","default":false},{"id":130371191,"node_id":"MDU6TGFiZWwxMzAzNzExOTE=","url":"https://api.github.com/repos/elastic/elasticsearch/labels/WIP","name":"WIP","color":"fef2c0","default":false},{"id":1102494662,"node_id":"MDU6TGFiZWwxMTAyNDk0NjYy","url":"https://api.github.com/repos/elastic/elasticsearch/labels/v6.6.0","name":"v6.6.0","color":"dddddd","default":false},{"id":484855464,"node_id":"MDU6TGFiZWw0ODQ4NTU0NjQ=","url":"https://api.github.com/repos/elastic/elasticsearch/labels/v7.0.0","name":"v7.0.0","color":"dddddd","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/35521/commits","review_comments_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/35521/comments","review_comment_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/35521/comments","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/3d62531318add90046750c6936786661d6f90e71","head":{"label":"costin:introduce-sql-interval","ref":"introduce-sql-interval","sha":"3d62531318add90046750c6936786661d6f90e71","user":{"login":"costin","id":76245,"node_id":"MDQ6VXNlcjc2MjQ1","avatar_url":"https://avatars3.githubusercontent.com/u/76245?v=4","gravatar_id":"","url":"https://api.github.com/users/costin","html_url":"https://github.com/costin","followers_url":"https://api.github.com/users/costin/followers","following_url":"https://api.github.com/users/costin/following{/other_user}","gists_url":"https://api.github.com/users/costin/gists{/gist_id}","starred_url":"https://api.github.com/users/costin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/costin/subscriptions","organizations_url":"https://api.github.com/users/costin/orgs","repos_url":"https://api.github.com/users/costin/repos","events_url":"https://api.github.com/users/costin/events{/privacy}","received_events_url":"https://api.github.com/users/costin/received_events","type":"User","site_admin":false},"repo":{"id":12863902,"node_id":"MDEwOlJlcG9zaXRvcnkxMjg2MzkwMg==","name":"elasticsearch","full_name":"costin/elasticsearch","private":false,"owner":{"login":"costin","id":76245,"node_id":"MDQ6VXNlcjc2MjQ1","avatar_url":"https://avatars3.githubusercontent.com/u/76245?v=4","gravatar_id":"","url":"https://api.github.com/users/costin","html_url":"https://github.com/costin","followers_url":"https://api.github.com/users/costin/followers","following_url":"https://api.github.com/users/costin/following{/other_user}","gists_url":"https://api.github.com/users/costin/gists{/gist_id}","starred_url":"https://api.github.com/users/costin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/costin/subscriptions","organizations_url":"https://api.github.com/users/costin/orgs","repos_url":"https://api.github.com/users/costin/repos","events_url":"https://api.github.com/users/costin/events{/privacy}","received_events_url":"https://api.github.com/users/costin/received_events","type":"User","site_admin":false},"html_url":"https://github.com/costin/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":true,"url":"https://api.github.com/repos/costin/elasticsearch","forks_url":"https://api.github.com/repos/costin/elasticsearch/forks","keys_url":"https://api.github.com/repos/costin/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/costin/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/costin/elasticsearch/teams","hooks_url":"https://api.github.com/repos/costin/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/costin/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/costin/elasticsearch/events","assignees_url":"https://api.github.com/repos/costin/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/costin/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/costin/elasticsearch/tags","blobs_url":"https://api.github.com/repos/costin/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/costin/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/costin/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/costin/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/costin/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/costin/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/costin/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/costin/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/costin/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/costin/elasticsearch/subscription","commits_url":"https://api.github.com/repos/costin/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/costin/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/costin/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/costin/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/costin/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/costin/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/costin/elasticsearch/merges","archive_url":"https://api.github.com/repos/costin/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/costin/elasticsearch/downloads","issues_url":"https://api.github.com/repos/costin/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/costin/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/costin/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/costin/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/costin/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/costin/elasticsearch/releases{/id}","deployments_url":"https://api.github.com/repos/costin/elasticsearch/deployments","created_at":"2013-09-16T09:51:43Z","updated_at":"2018-09-13T18:56:16Z","pushed_at":"2018-11-20T17:33:22Z","git_url":"git://github.com/costin/elasticsearch.git","ssh_url":"git@github.com:costin/elasticsearch.git","clone_url":"https://github.com/costin/elasticsearch.git","svn_url":"https://github.com/costin/elasticsearch","homepage":"http://elasticsearch.org","size":412368,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"elastic:master","ref":"master","sha":"89cf4a7397b891e48369e5873921be4635c1b1de","user":{"login":"elastic","id":6764390,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY3NjQzOTA=","avatar_url":"https://avatars0.githubusercontent.com/u/6764390?v=4","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":507775,"node_id":"MDEwOlJlcG9zaXRvcnk1MDc3NzU=","name":"elasticsearch","full_name":"elastic/elasticsearch","private":false,"owner":{"login":"elastic","id":6764390,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY3NjQzOTA=","avatar_url":"https://avatars0.githubusercontent.com/u/6764390?v=4","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/elastic/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":false,"url":"https://api.github.com/repos/elastic/elasticsearch","forks_url":"https://api.github.com/repos/elastic/elasticsearch/forks","keys_url":"https://api.github.com/repos/elastic/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/elasticsearch/teams","hooks_url":"https://api.github.com/repos/elastic/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/elasticsearch/events","assignees_url":"https://api.github.com/repos/elastic/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/elasticsearch/tags","blobs_url":"https://api.github.com/repos/elastic/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/elastic/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/elastic/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/elastic/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/elastic/elasticsearch/subscription","commits_url":"https://api.github.com/repos/elastic/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/elasticsearch/merges","archive_url":"https://api.github.com/repos/elastic/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/elasticsearch/downloads","issues_url":"https://api.github.com/repos/elastic/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/elastic/elasticsearch/releases{/id}","deployments_url":"https://api.github.com/repos/elastic/elasticsearch/deployments","created_at":"2010-02-08T13:20:56Z","updated_at":"2018-11-20T18:36:59Z","pushed_at":"2018-11-20T18:35:55Z","git_url":"git://github.com/elastic/elasticsearch.git","ssh_url":"git@github.com:elastic/elasticsearch.git","clone_url":"https://github.com/elastic/elasticsearch.git","svn_url":"https://github.com/elastic/elasticsearch","homepage":"https://www.elastic.co/products/elasticsearch","size":532522,"stargazers_count":36178,"watchers_count":36178,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":12228,"mirror_url":null,"archived":false,"open_issues_count":1807,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":12228,"open_issues":1807,"watchers":36178,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/35521"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/35521"},"issue":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/35521"},"comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/35521/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/35521/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/35521/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/elasticsearch/statuses/3d62531318add90046750c6936786661d6f90e71"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"costin"}}