{"action":"created","comment":{"url":"https://api.github.com/repos/Teradata/presto/pulls/comments/79017077","id":79017077,"diff_hunk":"@@ -0,0 +1,188 @@\n+/*\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package com.facebook.presto.tpcds;\n+\n+import com.facebook.presto.spi.RecordCursor;\n+import com.facebook.presto.spi.RecordSet;\n+import com.facebook.presto.spi.type.DecimalParseResult;\n+import com.facebook.presto.spi.type.DecimalType;\n+import com.facebook.presto.spi.type.Decimals;\n+import com.facebook.presto.spi.type.Type;\n+import com.google.common.collect.ImmutableList;\n+import com.teradata.tpcds.Results;\n+import com.teradata.tpcds.column.Column;\n+import com.teradata.tpcds.column.ColumnType;\n+import io.airlift.slice.Slice;\n+import io.airlift.slice.Slices;\n+\n+import java.time.LocalDate;\n+import java.time.LocalTime;\n+import java.util.Iterator;\n+import java.util.List;\n+import java.util.stream.Collectors;\n+\n+import static com.facebook.presto.spi.type.Decimals.rescale;\n+import static com.facebook.presto.tpcds.TpcdsMetadata.getPrestoType;\n+import static com.google.common.base.Preconditions.checkState;\n+import static java.lang.Double.parseDouble;\n+import static java.lang.Integer.parseInt;\n+import static java.lang.Long.parseLong;\n+import static java.util.Objects.requireNonNull;\n+\n+public class TpcdsRecordSet\n+        implements RecordSet\n+{\n+    private final Results results;\n+    private final List<Column> columns;\n+\n+    private final List<Type> columnTypes;\n+\n+    public TpcdsRecordSet(Results results, List<Column> columns)\n+    {\n+        requireNonNull(results, \"results is null\");\n+\n+        this.results = results;\n+        this.columns = ImmutableList.copyOf(columns);\n+        this.columnTypes = ImmutableList.copyOf(this.columns.stream().map(column -> getPrestoType(column.getType())).collect(Collectors.toList()));\n+    }\n+\n+    @Override\n+    public List<Type> getColumnTypes()\n+    {\n+        return columnTypes;\n+    }\n+\n+    @Override\n+    public RecordCursor cursor()\n+    {\n+        return new TpcdsRecordCursor(results.iterator(), columns);\n+    }\n+\n+    public class TpcdsRecordCursor\n+            implements RecordCursor\n+    {\n+        private final Iterator<List<List<String>>> rows;\n+        private final List<Column> columns;\n+        private List<String> row;\n+        private boolean closed;\n+\n+        public TpcdsRecordCursor(Iterator<List<List<String>>> rows, List<Column> columns)\n+        {\n+            this.rows = rows;\n+            this.columns = columns;\n+        }\n+\n+        @Override\n+        public long getTotalBytes()\n+        {\n+            return 0;\n+        }\n+\n+        @Override\n+        public long getCompletedBytes()\n+        {\n+            return 0;\n+        }\n+\n+        @Override\n+        public long getReadTimeNanos()\n+        {\n+            return 0;\n+        }\n+\n+        @Override\n+        public Type getType(int field)\n+        {\n+            return getPrestoType(columns.get(field).getType());\n+        }\n+\n+        @Override\n+        public boolean advanceNextPosition()\n+        {\n+            if (closed || !rows.hasNext()) {\n+                closed = true;\n+                row = null;\n+                return false;\n+            }\n+\n+            row = rows.next().get(0);\n+            return true;\n+        }\n+\n+        @Override\n+        public boolean getBoolean(int field)\n+        {\n+            throw new UnsupportedOperationException();\n+        }\n+\n+        @Override\n+        public long getLong(int field)\n+        {\n+            checkState(row != null, \"No current row\");\n+            Column column = columns.get(field);\n+            if (column.getType().getBase() == ColumnType.Base.DATE) {\n+                return LocalDate.parse(row.get(column.getPosition())).toEpochDay();\n+            }\n+            if (column.getType().getBase() == ColumnType.Base.TIME) {\n+                return LocalTime.parse(row.get(column.getPosition())).toNanoOfDay() / 1000000;\n+            }\n+            if (column.getType().getBase() == ColumnType.Base.INTEGER) {\n+                return parseInt(row.get(column.getPosition()));\n+            }\n+            if (column.getType().getBase() == ColumnType.Base.DECIMAL) {\n+                DecimalParseResult decimalParseResult = Decimals.parse(row.get(column.getPosition()));\n+                return rescale((Long) decimalParseResult.getObject(), decimalParseResult.getType().getScale(), ((DecimalType) columnTypes.get(field)).getScale());","path":"presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsRecordSet.java","position":145,"original_position":145,"commit_id":"219107c90087f51a1a5d023a473a0144fa5cc004","original_commit_id":"219107c90087f51a1a5d023a473a0144fa5cc004","user":{"login":"petroav","id":665991,"avatar_url":"https://avatars.githubusercontent.com/u/665991?v=3","gravatar_id":"","url":"https://api.github.com/users/petroav","html_url":"https://github.com/petroav","followers_url":"https://api.github.com/users/petroav/followers","following_url":"https://api.github.com/users/petroav/following{/other_user}","gists_url":"https://api.github.com/users/petroav/gists{/gist_id}","starred_url":"https://api.github.com/users/petroav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petroav/subscriptions","organizations_url":"https://api.github.com/users/petroav/orgs","repos_url":"https://api.github.com/users/petroav/repos","events_url":"https://api.github.com/users/petroav/events{/privacy}","received_events_url":"https://api.github.com/users/petroav/received_events","type":"User","site_admin":false},"body":"Why do we need to rescale? Wouldn't `Decimals.parse()` return the correct scale?","created_at":"2016-09-15T17:22:28Z","updated_at":"2016-09-15T17:22:28Z","html_url":"https://github.com/Teradata/presto/pull/345#discussion_r79017077","pull_request_url":"https://api.github.com/repos/Teradata/presto/pulls/345","_links":{"self":{"href":"https://api.github.com/repos/Teradata/presto/pulls/comments/79017077"},"html":{"href":"https://github.com/Teradata/presto/pull/345#discussion_r79017077"},"pull_request":{"href":"https://api.github.com/repos/Teradata/presto/pulls/345"}}},"pull_request":{"url":"https://api.github.com/repos/Teradata/presto/pulls/345","id":84900551,"html_url":"https://github.com/Teradata/presto/pull/345","diff_url":"https://github.com/Teradata/presto/pull/345.diff","patch_url":"https://github.com/Teradata/presto/pull/345.patch","issue_url":"https://api.github.com/repos/Teradata/presto/issues/345","number":345,"state":"open","locked":false,"title":"Add the data getting part of tpcds connector","user":{"login":"rschlussel","id":10963789,"avatar_url":"https://avatars.githubusercontent.com/u/10963789?v=3","gravatar_id":"","url":"https://api.github.com/users/rschlussel","html_url":"https://github.com/rschlussel","followers_url":"https://api.github.com/users/rschlussel/followers","following_url":"https://api.github.com/users/rschlussel/following{/other_user}","gists_url":"https://api.github.com/users/rschlussel/gists{/gist_id}","starred_url":"https://api.github.com/users/rschlussel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rschlussel/subscriptions","organizations_url":"https://api.github.com/users/rschlussel/orgs","repos_url":"https://api.github.com/users/rschlussel/repos","events_url":"https://api.github.com/users/rschlussel/events{/privacy}","received_events_url":"https://api.github.com/users/rschlussel/received_events","type":"User","site_admin":false},"body":"@petroav ","created_at":"2016-09-12T16:16:39Z","updated_at":"2016-09-15T17:22:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"460755bd0c29d41574e9d5ccc8d5206446412e94","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/Teradata/presto/pulls/345/commits","review_comments_url":"https://api.github.com/repos/Teradata/presto/pulls/345/comments","review_comment_url":"https://api.github.com/repos/Teradata/presto/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Teradata/presto/issues/345/comments","statuses_url":"https://api.github.com/repos/Teradata/presto/statuses/219107c90087f51a1a5d023a473a0144fa5cc004","head":{"label":"Teradata:tpcds-splits","ref":"tpcds-splits","sha":"219107c90087f51a1a5d023a473a0144fa5cc004","user":{"login":"Teradata","id":1615979,"avatar_url":"https://avatars.githubusercontent.com/u/1615979?v=3","gravatar_id":"","url":"https://api.github.com/users/Teradata","html_url":"https://github.com/Teradata","followers_url":"https://api.github.com/users/Teradata/followers","following_url":"https://api.github.com/users/Teradata/following{/other_user}","gists_url":"https://api.github.com/users/Teradata/gists{/gist_id}","starred_url":"https://api.github.com/users/Teradata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Teradata/subscriptions","organizations_url":"https://api.github.com/users/Teradata/orgs","repos_url":"https://api.github.com/users/Teradata/repos","events_url":"https://api.github.com/users/Teradata/events{/privacy}","received_events_url":"https://api.github.com/users/Teradata/received_events","type":"Organization","site_admin":false},"repo":{"id":36903368,"name":"presto","full_name":"Teradata/presto","owner":{"login":"Teradata","id":1615979,"avatar_url":"https://avatars.githubusercontent.com/u/1615979?v=3","gravatar_id":"","url":"https://api.github.com/users/Teradata","html_url":"https://github.com/Teradata","followers_url":"https://api.github.com/users/Teradata/followers","following_url":"https://api.github.com/users/Teradata/following{/other_user}","gists_url":"https://api.github.com/users/Teradata/gists{/gist_id}","starred_url":"https://api.github.com/users/Teradata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Teradata/subscriptions","organizations_url":"https://api.github.com/users/Teradata/orgs","repos_url":"https://api.github.com/users/Teradata/repos","events_url":"https://api.github.com/users/Teradata/events{/privacy}","received_events_url":"https://api.github.com/users/Teradata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Teradata/presto","description":"Teradata Distribution of Presto -- A Distributed SQL Query Engine for Big Data","fork":true,"url":"https://api.github.com/repos/Teradata/presto","forks_url":"https://api.github.com/repos/Teradata/presto/forks","keys_url":"https://api.github.com/repos/Teradata/presto/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Teradata/presto/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Teradata/presto/teams","hooks_url":"https://api.github.com/repos/Teradata/presto/hooks","issue_events_url":"https://api.github.com/repos/Teradata/presto/issues/events{/number}","events_url":"https://api.github.com/repos/Teradata/presto/events","assignees_url":"https://api.github.com/repos/Teradata/presto/assignees{/user}","branches_url":"https://api.github.com/repos/Teradata/presto/branches{/branch}","tags_url":"https://api.github.com/repos/Teradata/presto/tags","blobs_url":"https://api.github.com/repos/Teradata/presto/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Teradata/presto/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Teradata/presto/git/refs{/sha}","trees_url":"https://api.github.com/repos/Teradata/presto/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Teradata/presto/statuses/{sha}","languages_url":"https://api.github.com/repos/Teradata/presto/languages","stargazers_url":"https://api.github.com/repos/Teradata/presto/stargazers","contributors_url":"https://api.github.com/repos/Teradata/presto/contributors","subscribers_url":"https://api.github.com/repos/Teradata/presto/subscribers","subscription_url":"https://api.github.com/repos/Teradata/presto/subscription","commits_url":"https://api.github.com/repos/Teradata/presto/commits{/sha}","git_commits_url":"https://api.github.com/repos/Teradata/presto/git/commits{/sha}","comments_url":"https://api.github.com/repos/Teradata/presto/comments{/number}","issue_comment_url":"https://api.github.com/repos/Teradata/presto/issues/comments{/number}","contents_url":"https://api.github.com/repos/Teradata/presto/contents/{+path}","compare_url":"https://api.github.com/repos/Teradata/presto/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Teradata/presto/merges","archive_url":"https://api.github.com/repos/Teradata/presto/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Teradata/presto/downloads","issues_url":"https://api.github.com/repos/Teradata/presto/issues{/number}","pulls_url":"https://api.github.com/repos/Teradata/presto/pulls{/number}","milestones_url":"https://api.github.com/repos/Teradata/presto/milestones{/number}","notifications_url":"https://api.github.com/repos/Teradata/presto/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Teradata/presto/labels{/name}","releases_url":"https://api.github.com/repos/Teradata/presto/releases{/id}","deployments_url":"https://api.github.com/repos/Teradata/presto/deployments","created_at":"2015-06-05T00:38:37Z","updated_at":"2016-08-29T16:52:50Z","pushed_at":"2016-09-15T15:52:12Z","git_url":"git://github.com/Teradata/presto.git","ssh_url":"git@github.com:Teradata/presto.git","clone_url":"https://github.com/Teradata/presto.git","svn_url":"https://github.com/Teradata/presto","homepage":"http://www.teradata.com/presto","size":159192,"stargazers_count":56,"watchers_count":56,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":11,"mirror_url":null,"open_issues_count":18,"forks":11,"open_issues":18,"watchers":56,"default_branch":"master"}},"base":{"label":"Teradata:tpcds-connector","ref":"tpcds-connector","sha":"e79bfe4bb4a3d018667d1661e3d0b28ec6f70ea5","user":{"login":"Teradata","id":1615979,"avatar_url":"https://avatars.githubusercontent.com/u/1615979?v=3","gravatar_id":"","url":"https://api.github.com/users/Teradata","html_url":"https://github.com/Teradata","followers_url":"https://api.github.com/users/Teradata/followers","following_url":"https://api.github.com/users/Teradata/following{/other_user}","gists_url":"https://api.github.com/users/Teradata/gists{/gist_id}","starred_url":"https://api.github.com/users/Teradata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Teradata/subscriptions","organizations_url":"https://api.github.com/users/Teradata/orgs","repos_url":"https://api.github.com/users/Teradata/repos","events_url":"https://api.github.com/users/Teradata/events{/privacy}","received_events_url":"https://api.github.com/users/Teradata/received_events","type":"Organization","site_admin":false},"repo":{"id":36903368,"name":"presto","full_name":"Teradata/presto","owner":{"login":"Teradata","id":1615979,"avatar_url":"https://avatars.githubusercontent.com/u/1615979?v=3","gravatar_id":"","url":"https://api.github.com/users/Teradata","html_url":"https://github.com/Teradata","followers_url":"https://api.github.com/users/Teradata/followers","following_url":"https://api.github.com/users/Teradata/following{/other_user}","gists_url":"https://api.github.com/users/Teradata/gists{/gist_id}","starred_url":"https://api.github.com/users/Teradata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Teradata/subscriptions","organizations_url":"https://api.github.com/users/Teradata/orgs","repos_url":"https://api.github.com/users/Teradata/repos","events_url":"https://api.github.com/users/Teradata/events{/privacy}","received_events_url":"https://api.github.com/users/Teradata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Teradata/presto","description":"Teradata Distribution of Presto -- A Distributed SQL Query Engine for Big Data","fork":true,"url":"https://api.github.com/repos/Teradata/presto","forks_url":"https://api.github.com/repos/Teradata/presto/forks","keys_url":"https://api.github.com/repos/Teradata/presto/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Teradata/presto/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Teradata/presto/teams","hooks_url":"https://api.github.com/repos/Teradata/presto/hooks","issue_events_url":"https://api.github.com/repos/Teradata/presto/issues/events{/number}","events_url":"https://api.github.com/repos/Teradata/presto/events","assignees_url":"https://api.github.com/repos/Teradata/presto/assignees{/user}","branches_url":"https://api.github.com/repos/Teradata/presto/branches{/branch}","tags_url":"https://api.github.com/repos/Teradata/presto/tags","blobs_url":"https://api.github.com/repos/Teradata/presto/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Teradata/presto/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Teradata/presto/git/refs{/sha}","trees_url":"https://api.github.com/repos/Teradata/presto/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Teradata/presto/statuses/{sha}","languages_url":"https://api.github.com/repos/Teradata/presto/languages","stargazers_url":"https://api.github.com/repos/Teradata/presto/stargazers","contributors_url":"https://api.github.com/repos/Teradata/presto/contributors","subscribers_url":"https://api.github.com/repos/Teradata/presto/subscribers","subscription_url":"https://api.github.com/repos/Teradata/presto/subscription","commits_url":"https://api.github.com/repos/Teradata/presto/commits{/sha}","git_commits_url":"https://api.github.com/repos/Teradata/presto/git/commits{/sha}","comments_url":"https://api.github.com/repos/Teradata/presto/comments{/number}","issue_comment_url":"https://api.github.com/repos/Teradata/presto/issues/comments{/number}","contents_url":"https://api.github.com/repos/Teradata/presto/contents/{+path}","compare_url":"https://api.github.com/repos/Teradata/presto/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Teradata/presto/merges","archive_url":"https://api.github.com/repos/Teradata/presto/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Teradata/presto/downloads","issues_url":"https://api.github.com/repos/Teradata/presto/issues{/number}","pulls_url":"https://api.github.com/repos/Teradata/presto/pulls{/number}","milestones_url":"https://api.github.com/repos/Teradata/presto/milestones{/number}","notifications_url":"https://api.github.com/repos/Teradata/presto/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Teradata/presto/labels{/name}","releases_url":"https://api.github.com/repos/Teradata/presto/releases{/id}","deployments_url":"https://api.github.com/repos/Teradata/presto/deployments","created_at":"2015-06-05T00:38:37Z","updated_at":"2016-08-29T16:52:50Z","pushed_at":"2016-09-15T15:52:12Z","git_url":"git://github.com/Teradata/presto.git","ssh_url":"git@github.com:Teradata/presto.git","clone_url":"https://github.com/Teradata/presto.git","svn_url":"https://github.com/Teradata/presto","homepage":"http://www.teradata.com/presto","size":159192,"stargazers_count":56,"watchers_count":56,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":11,"mirror_url":null,"open_issues_count":18,"forks":11,"open_issues":18,"watchers":56,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Teradata/presto/pulls/345"},"html":{"href":"https://github.com/Teradata/presto/pull/345"},"issue":{"href":"https://api.github.com/repos/Teradata/presto/issues/345"},"comments":{"href":"https://api.github.com/repos/Teradata/presto/issues/345/comments"},"review_comments":{"href":"https://api.github.com/repos/Teradata/presto/pulls/345/comments"},"review_comment":{"href":"https://api.github.com/repos/Teradata/presto/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Teradata/presto/pulls/345/commits"},"statuses":{"href":"https://api.github.com/repos/Teradata/presto/statuses/219107c90087f51a1a5d023a473a0144fa5cc004"}}}}
{"actor":{"display_login":"petroav"}}