{"action":"created","comment":{"url":"https://api.github.com/repos/youtube/vitess/pulls/comments/29025492","id":29025492,"diff_hunk":"@@ -1,27 +1,214 @@\n package com.youtube.vitess.vtgate;\n \n+import com.google.common.primitives.UnsignedLong;\n+\n+import com.youtube.vitess.vtgate.Field.Flag;\n+import com.youtube.vitess.vtgate.Row.Cell;\n+\n+import org.apache.commons.lang.CharEncoding;\n+import org.joda.time.DateTime;\n+import org.joda.time.format.DateTimeFormat;\n+import org.joda.time.format.ISODateTimeFormat;\n+\n+import java.io.UnsupportedEncodingException;\n+import java.math.BigDecimal;\n+\n public class Field {\n+  /**\n+   * MySQL field flags bitset values e.g. to distinguish between signed and unsigned integer.\n+   * Comments are taken from the original source code.\n+   * These numbers should exactly match values defined in dist/mysql-5.1.52/include/mysql_com.h\n+   */\n+  public enum Flag {\n+    // VT_ZEROVALUE_FLAG is not part of the MySQL specification and only used in unit tests.\n+    VT_ZEROVALUE_FLAG(0),\n+    VT_NOT_NULL_FLAG (1),     /* Field can't be NULL */\n+    VT_PRI_KEY_FLAG(2),       /* Field is part of a primary key */\n+    VT_UNIQUE_KEY_FLAG(4),        /* Field is part of a unique key */\n+    VT_MULTIPLE_KEY_FLAG(8),      /* Field is part of a key */\n+    VT_BLOB_FLAG(16),     /* Field is a blob */\n+    VT_UNSIGNED_FLAG(32),     /* Field is unsigned */\n+    VT_ZEROFILL_FLAG(64),     /* Field is zerofill */\n+    VT_BINARY_FLAG(128),      /* Field is binary   */\n+      /* The following are only sent to new clients */\n+    VT_ENUM_FLAG(256),        /* field is an enum */\n+    VT_AUTO_INCREMENT_FLAG(512),      /* field is a autoincrement field */\n+    VT_TIMESTAMP_FLAG(1024),      /* Field is a timestamp */\n+    VT_SET_FLAG(2048),        /* field is a set */\n+    VT_NO_DEFAULT_VALUE_FLAG(4096),   /* Field doesn't have default value */\n+    VT_ON_UPDATE_NOW_FLAG(8192),         /* Field is set to NOW on UPDATE */\n+    VT_NUM_FLAG(32768),       /* Field is num (for clients) */\n+    VT_PART_KEY_FLAG(16384),      /* Intern; Part of some key */\n+    VT_GROUP_FLAG(32768),     /* Intern: Group field */\n+    VT_UNIQUE_FLAG(65536),        /* Intern: Used by sql_yacc */\n+    VT_BINCMP_FLAG(131072);       /* Intern: Used by sql_yacc */\n+    \n+    public int mysqlFlag;\n+    \n+    Flag(int mysqlFlag) {\n+      this.mysqlFlag = mysqlFlag;\n+    }\n+  }\n+\n+  /**\n+   * Represents all field types supported by Vitess and their corresponding types in Java. mysqlType\n+   * numbers should exactly match values defined in dist/mysql-5.1.52/include/mysql/mysql_com.h\n+   *\n+   */\n+  enum FieldType {\n+    VT_DECIMAL(0, BigDecimal.class),\n+    VT_TINY(1, Integer.class),\n+    VT_SHORT(2, Integer.class),\n+    VT_LONG(3, Long.class),\n+    VT_FLOAT(4, Float.class),\n+    VT_DOUBLE(5, Double.class),\n+    VT_NULL(6, null),\n+    VT_TIMESTAMP(7, DateTime.class),\n+    VT_LONGLONG(8, Long.class, UnsignedLong.class),\n+    VT_INT24(9, Integer.class),\n+    VT_DATE(10, DateTime.class),\n+    VT_TIME(11, DateTime.class),\n+    VT_DATETIME(12, DateTime.class),\n+    VT_YEAR(13, Short.class),\n+    VT_NEWDATE(14, DateTime.class),\n+    VT_VARCHAR(15, byte[].class),\n+    VT_BIT(16, byte[].class),\n+    VT_NEWDECIMAL(246, BigDecimal.class),\n+    VT_ENUM(247, String.class),\n+    VT_SET(248, String.class),\n+    VT_TINY_BLOB(249, byte[].class),\n+    VT_MEDIUM_BLOB(250, byte[].class),\n+    VT_LONG_BLOB(251, byte[].class),\n+    VT_BLOB(252, byte[].class),\n+    VT_VAR_STRING(253, byte[].class),\n+    VT_STRING(254, byte[].class),\n+    VT_GEOMETRY(255, byte[].class);\n+\n+    public final int mysqlType;\n+    public final Class javaType;\n+    public final Class unsignedJavaType;\n+\n+    FieldType(int mysqlType, Class javaType) {\n+      this.mysqlType = mysqlType;\n+      this.javaType = javaType;\n+      this.unsignedJavaType = javaType;\n+    }\n+\n+    FieldType(int mysqlType, Class javaType, Class unsignedJavaType) {\n+      this.mysqlType = mysqlType;\n+      this.javaType = javaType;\n+      this.unsignedJavaType = unsignedJavaType;\n+    }\n+  }\n+  \n   private String name;\n   private FieldType type;\n-\n-  public Field(String name, FieldType type) {\n-    this.name = name;\n-    this.type = type;\n+  private int flags;\n+  \n+  public static Field newFieldFromMysql(String name, int mysqlTypeId, int mysqlFlags) {\n+    for (FieldType ft : FieldType.values()) {\n+      if (ft.mysqlType == mysqlTypeId) {\n+        return new Field(name, ft, mysqlFlags);\n+      }\n+    }\n+    \n+    throw new RuntimeException(\"Unknown MySQL type: \" + mysqlTypeId);\n   }\n \n-  public String getName() {\n-    return name;\n+  public static Field newFieldForTest(FieldType fieldType, Flag flag) {","path":"java/vtgate-client/src/main/java/com/youtube/vitess/vtgate/Field.java","position":124,"original_position":124,"commit_id":"c686b55494de1bd72b86d2899e5cfd5857fa493b","original_commit_id":"c686b55494de1bd72b86d2899e5cfd5857fa493b","user":{"login":"henryanand","id":1332584,"avatar_url":"https://avatars.githubusercontent.com/u/1332584?v=3","gravatar_id":"","url":"https://api.github.com/users/henryanand","html_url":"https://github.com/henryanand","followers_url":"https://api.github.com/users/henryanand/followers","following_url":"https://api.github.com/users/henryanand/following{/other_user}","gists_url":"https://api.github.com/users/henryanand/gists{/gist_id}","starred_url":"https://api.github.com/users/henryanand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/henryanand/subscriptions","organizations_url":"https://api.github.com/users/henryanand/orgs","repos_url":"https://api.github.com/users/henryanand/repos","events_url":"https://api.github.com/users/henryanand/events{/privacy}","received_events_url":"https://api.github.com/users/henryanand/received_events","type":"User","site_admin":false},"body":"Package scoped constructor sounds good to me. And yes, I agree static creator methods are useful - even if the constructor is public. In this case, my only concern is we are mixing testing and production code. ","created_at":"2015-04-24T06:04:30Z","updated_at":"2015-04-24T06:04:30Z","html_url":"https://github.com/youtube/vitess/pull/618#discussion_r29025492","pull_request_url":"https://api.github.com/repos/youtube/vitess/pulls/618","_links":{"self":{"href":"https://api.github.com/repos/youtube/vitess/pulls/comments/29025492"},"html":{"href":"https://github.com/youtube/vitess/pull/618#discussion_r29025492"},"pull_request":{"href":"https://api.github.com/repos/youtube/vitess/pulls/618"}}},"pull_request":{"url":"https://api.github.com/repos/youtube/vitess/pulls/618","id":34002896,"html_url":"https://github.com/youtube/vitess/pull/618","diff_url":"https://github.com/youtube/vitess/pull/618.diff","patch_url":"https://github.com/youtube/vitess/pull/618.patch","issue_url":"https://api.github.com/repos/youtube/vitess/issues/618","number":618,"state":"open","locked":false,"title":"Pass \"Flags\" from MySQL field from the result set e.g. to preserve if integers are unsigned.","user":{"login":"michael-berlin","id":3919251,"avatar_url":"https://avatars.githubusercontent.com/u/3919251?v=3","gravatar_id":"","url":"https://api.github.com/users/michael-berlin","html_url":"https://github.com/michael-berlin","followers_url":"https://api.github.com/users/michael-berlin/followers","following_url":"https://api.github.com/users/michael-berlin/following{/other_user}","gists_url":"https://api.github.com/users/michael-berlin/gists{/gist_id}","starred_url":"https://api.github.com/users/michael-berlin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michael-berlin/subscriptions","organizations_url":"https://api.github.com/users/michael-berlin/orgs","repos_url":"https://api.github.com/users/michael-berlin/repos","events_url":"https://api.github.com/users/michael-berlin/events{/privacy}","received_events_url":"https://api.github.com/users/michael-berlin/received_events","type":"User","site_admin":false},"body":"Adapted Java client so far, see second commit.\r\n\r\n@alainjobart @henryanand ","created_at":"2015-04-23T22:23:31Z","updated_at":"2015-04-24T06:04:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"996a87053771d377e75c4cc4915ab557641a0985","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/youtube/vitess/pulls/618/commits","review_comments_url":"https://api.github.com/repos/youtube/vitess/pulls/618/comments","review_comment_url":"https://api.github.com/repos/youtube/vitess/pulls/comments{/number}","comments_url":"https://api.github.com/repos/youtube/vitess/issues/618/comments","statuses_url":"https://api.github.com/repos/youtube/vitess/statuses/c686b55494de1bd72b86d2899e5cfd5857fa493b","head":{"label":"youtube:mysql_flags","ref":"mysql_flags","sha":"c686b55494de1bd72b86d2899e5cfd5857fa493b","user":{"login":"youtube","id":4052902,"avatar_url":"https://avatars.githubusercontent.com/u/4052902?v=3","gravatar_id":"","url":"https://api.github.com/users/youtube","html_url":"https://github.com/youtube","followers_url":"https://api.github.com/users/youtube/followers","following_url":"https://api.github.com/users/youtube/following{/other_user}","gists_url":"https://api.github.com/users/youtube/gists{/gist_id}","starred_url":"https://api.github.com/users/youtube/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/youtube/subscriptions","organizations_url":"https://api.github.com/users/youtube/orgs","repos_url":"https://api.github.com/users/youtube/repos","events_url":"https://api.github.com/users/youtube/events{/privacy}","received_events_url":"https://api.github.com/users/youtube/received_events","type":"Organization","site_admin":false},"repo":{"id":11008207,"name":"vitess","full_name":"youtube/vitess","owner":{"login":"youtube","id":4052902,"avatar_url":"https://avatars.githubusercontent.com/u/4052902?v=3","gravatar_id":"","url":"https://api.github.com/users/youtube","html_url":"https://github.com/youtube","followers_url":"https://api.github.com/users/youtube/followers","following_url":"https://api.github.com/users/youtube/following{/other_user}","gists_url":"https://api.github.com/users/youtube/gists{/gist_id}","starred_url":"https://api.github.com/users/youtube/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/youtube/subscriptions","organizations_url":"https://api.github.com/users/youtube/orgs","repos_url":"https://api.github.com/users/youtube/repos","events_url":"https://api.github.com/users/youtube/events{/privacy}","received_events_url":"https://api.github.com/users/youtube/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/youtube/vitess","description":"vitess provides servers and tools which facilitate scaling of MySQL databases for large scale web services.","fork":false,"url":"https://api.github.com/repos/youtube/vitess","forks_url":"https://api.github.com/repos/youtube/vitess/forks","keys_url":"https://api.github.com/repos/youtube/vitess/keys{/key_id}","collaborators_url":"https://api.github.com/repos/youtube/vitess/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/youtube/vitess/teams","hooks_url":"https://api.github.com/repos/youtube/vitess/hooks","issue_events_url":"https://api.github.com/repos/youtube/vitess/issues/events{/number}","events_url":"https://api.github.com/repos/youtube/vitess/events","assignees_url":"https://api.github.com/repos/youtube/vitess/assignees{/user}","branches_url":"https://api.github.com/repos/youtube/vitess/branches{/branch}","tags_url":"https://api.github.com/repos/youtube/vitess/tags","blobs_url":"https://api.github.com/repos/youtube/vitess/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/youtube/vitess/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/youtube/vitess/git/refs{/sha}","trees_url":"https://api.github.com/repos/youtube/vitess/git/trees{/sha}","statuses_url":"https://api.github.com/repos/youtube/vitess/statuses/{sha}","languages_url":"https://api.github.com/repos/youtube/vitess/languages","stargazers_url":"https://api.github.com/repos/youtube/vitess/stargazers","contributors_url":"https://api.github.com/repos/youtube/vitess/contributors","subscribers_url":"https://api.github.com/repos/youtube/vitess/subscribers","subscription_url":"https://api.github.com/repos/youtube/vitess/subscription","commits_url":"https://api.github.com/repos/youtube/vitess/commits{/sha}","git_commits_url":"https://api.github.com/repos/youtube/vitess/git/commits{/sha}","comments_url":"https://api.github.com/repos/youtube/vitess/comments{/number}","issue_comment_url":"https://api.github.com/repos/youtube/vitess/issues/comments{/number}","contents_url":"https://api.github.com/repos/youtube/vitess/contents/{+path}","compare_url":"https://api.github.com/repos/youtube/vitess/compare/{base}...{head}","merges_url":"https://api.github.com/repos/youtube/vitess/merges","archive_url":"https://api.github.com/repos/youtube/vitess/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/youtube/vitess/downloads","issues_url":"https://api.github.com/repos/youtube/vitess/issues{/number}","pulls_url":"https://api.github.com/repos/youtube/vitess/pulls{/number}","milestones_url":"https://api.github.com/repos/youtube/vitess/milestones{/number}","notifications_url":"https://api.github.com/repos/youtube/vitess/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/youtube/vitess/labels{/name}","releases_url":"https://api.github.com/repos/youtube/vitess/releases{/id}","created_at":"2013-06-27T21:20:28Z","updated_at":"2015-04-23T20:49:06Z","pushed_at":"2015-04-23T23:12:31Z","git_url":"git://github.com/youtube/vitess.git","ssh_url":"git@github.com:youtube/vitess.git","clone_url":"https://github.com/youtube/vitess.git","svn_url":"https://github.com/youtube/vitess","homepage":null,"size":67024,"stargazers_count":2463,"watchers_count":2463,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":291,"mirror_url":null,"open_issues_count":21,"forks":291,"open_issues":21,"watchers":2463,"default_branch":"master"}},"base":{"label":"youtube:master","ref":"master","sha":"e702c3744a6ddfdf3491bfac4c3ca9ed563a51cf","user":{"login":"youtube","id":4052902,"avatar_url":"https://avatars.githubusercontent.com/u/4052902?v=3","gravatar_id":"","url":"https://api.github.com/users/youtube","html_url":"https://github.com/youtube","followers_url":"https://api.github.com/users/youtube/followers","following_url":"https://api.github.com/users/youtube/following{/other_user}","gists_url":"https://api.github.com/users/youtube/gists{/gist_id}","starred_url":"https://api.github.com/users/youtube/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/youtube/subscriptions","organizations_url":"https://api.github.com/users/youtube/orgs","repos_url":"https://api.github.com/users/youtube/repos","events_url":"https://api.github.com/users/youtube/events{/privacy}","received_events_url":"https://api.github.com/users/youtube/received_events","type":"Organization","site_admin":false},"repo":{"id":11008207,"name":"vitess","full_name":"youtube/vitess","owner":{"login":"youtube","id":4052902,"avatar_url":"https://avatars.githubusercontent.com/u/4052902?v=3","gravatar_id":"","url":"https://api.github.com/users/youtube","html_url":"https://github.com/youtube","followers_url":"https://api.github.com/users/youtube/followers","following_url":"https://api.github.com/users/youtube/following{/other_user}","gists_url":"https://api.github.com/users/youtube/gists{/gist_id}","starred_url":"https://api.github.com/users/youtube/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/youtube/subscriptions","organizations_url":"https://api.github.com/users/youtube/orgs","repos_url":"https://api.github.com/users/youtube/repos","events_url":"https://api.github.com/users/youtube/events{/privacy}","received_events_url":"https://api.github.com/users/youtube/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/youtube/vitess","description":"vitess provides servers and tools which facilitate scaling of MySQL databases for large scale web services.","fork":false,"url":"https://api.github.com/repos/youtube/vitess","forks_url":"https://api.github.com/repos/youtube/vitess/forks","keys_url":"https://api.github.com/repos/youtube/vitess/keys{/key_id}","collaborators_url":"https://api.github.com/repos/youtube/vitess/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/youtube/vitess/teams","hooks_url":"https://api.github.com/repos/youtube/vitess/hooks","issue_events_url":"https://api.github.com/repos/youtube/vitess/issues/events{/number}","events_url":"https://api.github.com/repos/youtube/vitess/events","assignees_url":"https://api.github.com/repos/youtube/vitess/assignees{/user}","branches_url":"https://api.github.com/repos/youtube/vitess/branches{/branch}","tags_url":"https://api.github.com/repos/youtube/vitess/tags","blobs_url":"https://api.github.com/repos/youtube/vitess/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/youtube/vitess/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/youtube/vitess/git/refs{/sha}","trees_url":"https://api.github.com/repos/youtube/vitess/git/trees{/sha}","statuses_url":"https://api.github.com/repos/youtube/vitess/statuses/{sha}","languages_url":"https://api.github.com/repos/youtube/vitess/languages","stargazers_url":"https://api.github.com/repos/youtube/vitess/stargazers","contributors_url":"https://api.github.com/repos/youtube/vitess/contributors","subscribers_url":"https://api.github.com/repos/youtube/vitess/subscribers","subscription_url":"https://api.github.com/repos/youtube/vitess/subscription","commits_url":"https://api.github.com/repos/youtube/vitess/commits{/sha}","git_commits_url":"https://api.github.com/repos/youtube/vitess/git/commits{/sha}","comments_url":"https://api.github.com/repos/youtube/vitess/comments{/number}","issue_comment_url":"https://api.github.com/repos/youtube/vitess/issues/comments{/number}","contents_url":"https://api.github.com/repos/youtube/vitess/contents/{+path}","compare_url":"https://api.github.com/repos/youtube/vitess/compare/{base}...{head}","merges_url":"https://api.github.com/repos/youtube/vitess/merges","archive_url":"https://api.github.com/repos/youtube/vitess/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/youtube/vitess/downloads","issues_url":"https://api.github.com/repos/youtube/vitess/issues{/number}","pulls_url":"https://api.github.com/repos/youtube/vitess/pulls{/number}","milestones_url":"https://api.github.com/repos/youtube/vitess/milestones{/number}","notifications_url":"https://api.github.com/repos/youtube/vitess/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/youtube/vitess/labels{/name}","releases_url":"https://api.github.com/repos/youtube/vitess/releases{/id}","created_at":"2013-06-27T21:20:28Z","updated_at":"2015-04-23T20:49:06Z","pushed_at":"2015-04-23T23:12:31Z","git_url":"git://github.com/youtube/vitess.git","ssh_url":"git@github.com:youtube/vitess.git","clone_url":"https://github.com/youtube/vitess.git","svn_url":"https://github.com/youtube/vitess","homepage":null,"size":67024,"stargazers_count":2463,"watchers_count":2463,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":291,"mirror_url":null,"open_issues_count":21,"forks":291,"open_issues":21,"watchers":2463,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/youtube/vitess/pulls/618"},"html":{"href":"https://github.com/youtube/vitess/pull/618"},"issue":{"href":"https://api.github.com/repos/youtube/vitess/issues/618"},"comments":{"href":"https://api.github.com/repos/youtube/vitess/issues/618/comments"},"review_comments":{"href":"https://api.github.com/repos/youtube/vitess/pulls/618/comments"},"review_comment":{"href":"https://api.github.com/repos/youtube/vitess/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/youtube/vitess/pulls/618/commits"},"statuses":{"href":"https://api.github.com/repos/youtube/vitess/statuses/c686b55494de1bd72b86d2899e5cfd5857fa493b"}}}}