{"action":"created","comment":{"url":"https://api.github.com/repos/apache/arrow/pulls/comments/62486168","id":62486168,"diff_hunk":"@@ -23,7 +23,122 @@\n #include <vector>\n \n #include \"arrow/type.h\"\n+#include \"arrow/types/list.h\"\n+#include \"arrow/types/primitive.h\"\n \n-namespace arrow {}  // namespace arrow\n+namespace arrow {\n+\n+class StructArray : public Array {\n+ public:\n+  StructArray(const TypePtr& type, int32_t length, std::vector<ArrayPtr>& field_arrays,\n+      int32_t null_count = 0, std::shared_ptr<Buffer> null_bitmap = nullptr)\n+      : Array(type, length, null_count, null_bitmap) {\n+    type_ = type;\n+    field_arrays_ = field_arrays;\n+  }\n+\n+  Status Validate() const override;\n+\n+  virtual ~StructArray() {}\n+\n+  // Return a shared pointer in case the requestor desires to share ownership\n+  // with this array.\n+  const std::shared_ptr<Array>& field(int32_t pos) const { return field_arrays_.at(pos); }\n+  const std::vector<ArrayPtr>& fields() const { return field_arrays_; }\n+\n+  const std::shared_ptr<DataType>& field_type(int32_t pos) const {\n+    return field_arrays_.at(pos)->type();\n+  }\n+\n+  bool EqualsExact(const StructArray& other) const;\n+  bool Equals(const std::shared_ptr<Array>& arr) const override;\n+\n+ protected:\n+  // The child arrays corresponding to each field of the struct data type.\n+  std::vector<ArrayPtr> field_arrays_;\n+};\n+\n+// ---------------------------------------------------------------------------------\n+// StructArray builder\n+class StructBuilder : public ArrayBuilder {\n+ public:\n+  StructBuilder(MemoryPool* pool, const std::shared_ptr<DataType>& type,\n+      std::vector<std::shared_ptr<ArrayBuilder>>& field_builders)\n+      : ArrayBuilder(pool, type) {\n+    field_builders_ = field_builders;\n+  }\n+\n+  Status Init(int32_t elements) override {\n+    RETURN_NOT_OK(ArrayBuilder::Init(elements));\n+    return Status::OK();\n+  }\n+\n+  Status Resize(int32_t capacity) override {\n+    // Need space for the end offset\n+    if (capacity < MIN_BUILDER_CAPACITY) { capacity = MIN_BUILDER_CAPACITY; }\n+\n+    if (capacity_ == 0) {\n+      RETURN_NOT_OK(ArrayBuilder::Init(capacity));\n+    } else {\n+      RETURN_NOT_OK(ArrayBuilder::Resize(capacity));\n+    }\n+    capacity_ = capacity;\n+\n+    for (auto it : field_builders_) {\n+      RETURN_NOT_OK(it->Resize(capacity));\n+    }\n+    return Status::OK();\n+  }\n+\n+  // null_bitmap is of equal length to every child field, and any zero byte\n+  // will be considered as a null for that field, but users must using app-\n+  // end methods or advance methods of the child builders independently to\n+  // insert data.\n+  Status Append(const uint8_t* null_bitmap, int32_t length) {\n+    RETURN_NOT_OK(Reserve(length));\n+    UnsafeAppendToBitmap(null_bitmap, length);\n+    return Status::OK();\n+  }\n+\n+  std::shared_ptr<Array> Finish() override {\n+    DCHECK(field_builders_.size());\n+\n+    std::vector<ArrayPtr> fields;\n+    for (auto it : field_builders_) {\n+      fields.push_back(it->Finish());\n+    }\n+\n+    auto result =\n+        std::make_shared<StructArray>(type_, length_, fields, null_count_, null_bitmap_);\n+\n+    null_bitmap_ = nullptr;\n+    capacity_ = length_ = null_count_ = 0;\n+\n+    return result;\n+  }\n+\n+  // This function just appends elements to StructBuilder, if you want to\n+  // inserting data into the child fields, please make sure that the chi-\n+  // ld builders' append methods must be called independently before that.\n+  Status Append(bool is_valid = true) {\n+    RETURN_NOT_OK(Reserve(1));\n+    UnsafeAppendToBitmap(is_valid);\n+    return Status::OK();\n+  }\n+\n+  Status AppendNull() { return Append(false); }\n+\n+  const std::shared_ptr<ArrayBuilder> field_builder(int pos) const {\n+    return field_builders_.at(pos);","path":"cpp/src/arrow/types/struct.h","position":111,"original_position":111,"commit_id":"85a02ac5eb727907350b9a899b69e4400a7c71ef","original_commit_id":"85a02ac5eb727907350b9a899b69e4400a7c71ef","user":{"login":"fengguangyuan","id":10569747,"avatar_url":"https://avatars.githubusercontent.com/u/10569747?v=3","gravatar_id":"","url":"https://api.github.com/users/fengguangyuan","html_url":"https://github.com/fengguangyuan","followers_url":"https://api.github.com/users/fengguangyuan/followers","following_url":"https://api.github.com/users/fengguangyuan/following{/other_user}","gists_url":"https://api.github.com/users/fengguangyuan/gists{/gist_id}","starred_url":"https://api.github.com/users/fengguangyuan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fengguangyuan/subscriptions","organizations_url":"https://api.github.com/users/fengguangyuan/orgs","repos_url":"https://api.github.com/users/fengguangyuan/repos","events_url":"https://api.github.com/users/fengguangyuan/events{/privacy}","received_events_url":"https://api.github.com/users/fengguangyuan/received_events","type":"User","site_admin":false},"body":"No problem, easily, I will change all the same semantics.\r\nThanks for you comments.:)","created_at":"2016-05-09T11:53:06Z","updated_at":"2016-05-09T11:53:06Z","html_url":"https://github.com/apache/arrow/pull/66#discussion_r62486168","pull_request_url":"https://api.github.com/repos/apache/arrow/pulls/66","_links":{"self":{"href":"https://api.github.com/repos/apache/arrow/pulls/comments/62486168"},"html":{"href":"https://github.com/apache/arrow/pull/66#discussion_r62486168"},"pull_request":{"href":"https://api.github.com/repos/apache/arrow/pulls/66"}}},"pull_request":{"url":"https://api.github.com/repos/apache/arrow/pulls/66","id":67142210,"html_url":"https://github.com/apache/arrow/pull/66","diff_url":"https://github.com/apache/arrow/pull/66.diff","patch_url":"https://github.com/apache/arrow/pull/66.patch","issue_url":"https://api.github.com/repos/apache/arrow/issues/66","number":66,"state":"open","locked":false,"title":"ARROW-60[C++]: Struct type builder API","user":{"login":"fengguangyuan","id":10569747,"avatar_url":"https://avatars.githubusercontent.com/u/10569747?v=3","gravatar_id":"","url":"https://api.github.com/users/fengguangyuan","html_url":"https://github.com/fengguangyuan","followers_url":"https://api.github.com/users/fengguangyuan/followers","following_url":"https://api.github.com/users/fengguangyuan/following{/other_user}","gists_url":"https://api.github.com/users/fengguangyuan/gists{/gist_id}","starred_url":"https://api.github.com/users/fengguangyuan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fengguangyuan/subscriptions","organizations_url":"https://api.github.com/users/fengguangyuan/orgs","repos_url":"https://api.github.com/users/fengguangyuan/repos","events_url":"https://api.github.com/users/fengguangyuan/events{/privacy}","received_events_url":"https://api.github.com/users/fengguangyuan/received_events","type":"User","site_admin":false},"body":"Implement the basic classes, `StructArray` and `StructBuilder,` meanwhile,\r\n\r\nadd the perspective test cases for them.\r\n\r\nOther necessary methods will be added subsequently.","created_at":"2016-04-20T07:49:39Z","updated_at":"2016-05-09T11:53:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8065436976361ed432c1598c7eddaeb447c730e8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/arrow/pulls/66/commits","review_comments_url":"https://api.github.com/repos/apache/arrow/pulls/66/comments","review_comment_url":"https://api.github.com/repos/apache/arrow/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/arrow/issues/66/comments","statuses_url":"https://api.github.com/repos/apache/arrow/statuses/85a02ac5eb727907350b9a899b69e4400a7c71ef","head":{"label":"fengguangyuan:ARROW-60","ref":"ARROW-60","sha":"85a02ac5eb727907350b9a899b69e4400a7c71ef","user":{"login":"fengguangyuan","id":10569747,"avatar_url":"https://avatars.githubusercontent.com/u/10569747?v=3","gravatar_id":"","url":"https://api.github.com/users/fengguangyuan","html_url":"https://github.com/fengguangyuan","followers_url":"https://api.github.com/users/fengguangyuan/followers","following_url":"https://api.github.com/users/fengguangyuan/following{/other_user}","gists_url":"https://api.github.com/users/fengguangyuan/gists{/gist_id}","starred_url":"https://api.github.com/users/fengguangyuan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fengguangyuan/subscriptions","organizations_url":"https://api.github.com/users/fengguangyuan/orgs","repos_url":"https://api.github.com/users/fengguangyuan/repos","events_url":"https://api.github.com/users/fengguangyuan/events{/privacy}","received_events_url":"https://api.github.com/users/fengguangyuan/received_events","type":"User","site_admin":false},"repo":{"id":55202118,"name":"arrow","full_name":"fengguangyuan/arrow","owner":{"login":"fengguangyuan","id":10569747,"avatar_url":"https://avatars.githubusercontent.com/u/10569747?v=3","gravatar_id":"","url":"https://api.github.com/users/fengguangyuan","html_url":"https://github.com/fengguangyuan","followers_url":"https://api.github.com/users/fengguangyuan/followers","following_url":"https://api.github.com/users/fengguangyuan/following{/other_user}","gists_url":"https://api.github.com/users/fengguangyuan/gists{/gist_id}","starred_url":"https://api.github.com/users/fengguangyuan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fengguangyuan/subscriptions","organizations_url":"https://api.github.com/users/fengguangyuan/orgs","repos_url":"https://api.github.com/users/fengguangyuan/repos","events_url":"https://api.github.com/users/fengguangyuan/events{/privacy}","received_events_url":"https://api.github.com/users/fengguangyuan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fengguangyuan/arrow","description":"Mirror of Apache Arrow","fork":true,"url":"https://api.github.com/repos/fengguangyuan/arrow","forks_url":"https://api.github.com/repos/fengguangyuan/arrow/forks","keys_url":"https://api.github.com/repos/fengguangyuan/arrow/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fengguangyuan/arrow/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fengguangyuan/arrow/teams","hooks_url":"https://api.github.com/repos/fengguangyuan/arrow/hooks","issue_events_url":"https://api.github.com/repos/fengguangyuan/arrow/issues/events{/number}","events_url":"https://api.github.com/repos/fengguangyuan/arrow/events","assignees_url":"https://api.github.com/repos/fengguangyuan/arrow/assignees{/user}","branches_url":"https://api.github.com/repos/fengguangyuan/arrow/branches{/branch}","tags_url":"https://api.github.com/repos/fengguangyuan/arrow/tags","blobs_url":"https://api.github.com/repos/fengguangyuan/arrow/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fengguangyuan/arrow/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fengguangyuan/arrow/git/refs{/sha}","trees_url":"https://api.github.com/repos/fengguangyuan/arrow/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fengguangyuan/arrow/statuses/{sha}","languages_url":"https://api.github.com/repos/fengguangyuan/arrow/languages","stargazers_url":"https://api.github.com/repos/fengguangyuan/arrow/stargazers","contributors_url":"https://api.github.com/repos/fengguangyuan/arrow/contributors","subscribers_url":"https://api.github.com/repos/fengguangyuan/arrow/subscribers","subscription_url":"https://api.github.com/repos/fengguangyuan/arrow/subscription","commits_url":"https://api.github.com/repos/fengguangyuan/arrow/commits{/sha}","git_commits_url":"https://api.github.com/repos/fengguangyuan/arrow/git/commits{/sha}","comments_url":"https://api.github.com/repos/fengguangyuan/arrow/comments{/number}","issue_comment_url":"https://api.github.com/repos/fengguangyuan/arrow/issues/comments{/number}","contents_url":"https://api.github.com/repos/fengguangyuan/arrow/contents/{+path}","compare_url":"https://api.github.com/repos/fengguangyuan/arrow/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fengguangyuan/arrow/merges","archive_url":"https://api.github.com/repos/fengguangyuan/arrow/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fengguangyuan/arrow/downloads","issues_url":"https://api.github.com/repos/fengguangyuan/arrow/issues{/number}","pulls_url":"https://api.github.com/repos/fengguangyuan/arrow/pulls{/number}","milestones_url":"https://api.github.com/repos/fengguangyuan/arrow/milestones{/number}","notifications_url":"https://api.github.com/repos/fengguangyuan/arrow/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fengguangyuan/arrow/labels{/name}","releases_url":"https://api.github.com/repos/fengguangyuan/arrow/releases{/id}","deployments_url":"https://api.github.com/repos/fengguangyuan/arrow/deployments","created_at":"2016-04-01T03:49:15Z","updated_at":"2016-04-01T03:49:18Z","pushed_at":"2016-05-06T08:33:17Z","git_url":"git://github.com/fengguangyuan/arrow.git","ssh_url":"git@github.com:fengguangyuan/arrow.git","clone_url":"https://github.com/fengguangyuan/arrow.git","svn_url":"https://github.com/fengguangyuan/arrow","homepage":null,"size":1024,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"0b472d860260f7063aee742939be23b921382741","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":51905353,"name":"arrow","full_name":"apache/arrow","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/arrow","description":"Mirror of Apache Arrow","fork":false,"url":"https://api.github.com/repos/apache/arrow","forks_url":"https://api.github.com/repos/apache/arrow/forks","keys_url":"https://api.github.com/repos/apache/arrow/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/arrow/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/arrow/teams","hooks_url":"https://api.github.com/repos/apache/arrow/hooks","issue_events_url":"https://api.github.com/repos/apache/arrow/issues/events{/number}","events_url":"https://api.github.com/repos/apache/arrow/events","assignees_url":"https://api.github.com/repos/apache/arrow/assignees{/user}","branches_url":"https://api.github.com/repos/apache/arrow/branches{/branch}","tags_url":"https://api.github.com/repos/apache/arrow/tags","blobs_url":"https://api.github.com/repos/apache/arrow/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/arrow/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/arrow/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/arrow/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/arrow/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/arrow/languages","stargazers_url":"https://api.github.com/repos/apache/arrow/stargazers","contributors_url":"https://api.github.com/repos/apache/arrow/contributors","subscribers_url":"https://api.github.com/repos/apache/arrow/subscribers","subscription_url":"https://api.github.com/repos/apache/arrow/subscription","commits_url":"https://api.github.com/repos/apache/arrow/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/arrow/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/arrow/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/arrow/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/arrow/contents/{+path}","compare_url":"https://api.github.com/repos/apache/arrow/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/arrow/merges","archive_url":"https://api.github.com/repos/apache/arrow/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/arrow/downloads","issues_url":"https://api.github.com/repos/apache/arrow/issues{/number}","pulls_url":"https://api.github.com/repos/apache/arrow/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/arrow/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/arrow/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/arrow/labels{/name}","releases_url":"https://api.github.com/repos/apache/arrow/releases{/id}","deployments_url":"https://api.github.com/repos/apache/arrow/deployments","created_at":"2016-02-17T08:00:23Z","updated_at":"2016-05-09T10:51:27Z","pushed_at":"2016-05-09T05:21:38Z","git_url":"git://github.com/apache/arrow.git","ssh_url":"git@github.com:apache/arrow.git","clone_url":"https://github.com/apache/arrow.git","svn_url":"https://github.com/apache/arrow","homepage":null,"size":1298,"stargazers_count":541,"watchers_count":541,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":103,"mirror_url":"git://git.apache.org/arrow.git","open_issues_count":11,"forks":103,"open_issues":11,"watchers":541,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/arrow/pulls/66"},"html":{"href":"https://github.com/apache/arrow/pull/66"},"issue":{"href":"https://api.github.com/repos/apache/arrow/issues/66"},"comments":{"href":"https://api.github.com/repos/apache/arrow/issues/66/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/arrow/pulls/66/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/arrow/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/arrow/pulls/66/commits"},"statuses":{"href":"https://api.github.com/repos/apache/arrow/statuses/85a02ac5eb727907350b9a899b69e4400a7c71ef"}}}}