{"id":3042,"date":"2023-10-18T19:35:10","date_gmt":"2023-10-18T11:35:10","guid":{"rendered":"https:\/\/white-night.club\/?p=3042"},"modified":"2023-11-09T11:07:48","modified_gmt":"2023-11-09T03:07:48","slug":"pg13","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/18\/pg13\/","title":{"rendered":"MIT6.5830 Lab1-GoDB\u5b9e\u9a8c\u8bb0\u5f55\uff08\u4e8c\uff09"},"content":{"rendered":"\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u5c06\u5b8c\u6210tuple.go\u7684\u7f3a\u5931\u4ee3\u7801\uff0c\u5e76\u901a\u8fc7tuple_test.go\u7684\u6d4b\u8bd5\u3002<\/p>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u5b9e\u9a8c\u6b65\u9aa4<\/p>\n<cite><em>\u89c2\u5bdftuple.go<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u89c2\u5bdf\u80af\u5b9a\u662f\u7b2c\u4e00\u6b65\uff0c\u5148\u6253\u5f00tuple.go\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized has-custom-border\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/c935a4551759a7cbd3181ae260c5c86.png\" alt=\"\" class=\"wp-image-3047\" style=\"border-style:none;border-width:0px;border-radius:0px\" width=\"433\" height=\"350\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/c935a4551759a7cbd3181ae260c5c86.png 865w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/c935a4551759a7cbd3181ae260c5c86-300x243.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/c935a4551759a7cbd3181ae260c5c86-768x622.png 768w\" sizes=\"(max-width: 433px) 100vw, 433px\" \/><\/figure>\n\n\n\n<p>\u5feb300\u884c\u4ee3\u7801\uff0c\u52c9\u52c9\u5f3a\u5f3a\u8fd8\u5728\u63a5\u53d7\u8303\u56f4\u4e4b\u5185\u3002\u63a5\u4e0b\u6765\u770b\u770b\u6211\u4eec\u8981\u505a\u4ec0\u4e48\uff0c\u9996\u8981\u76ee\u7684\u80af\u5b9a\u5c31\u662f\u901a\u8fc7go test tuple_test.go\u3002<\/p>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u5b9e\u9a8c\u6b65\u9aa4<\/p>\n<cite><em>\u5206\u6790\u6570\u636e\u7ed3\u6784<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u5f00\u5934\u5c31\u7ed9\u51fa\u4e86DBType\u7684\u5b9a\u4e49\uff0ctuple field\uff1f\u90a3\u6211\u4eec\u6682\u4e14\u628a\u5b83\u5f53\u4f5c\u662f\u5143\u7ec4\u5b57\u6bb5&#8211;\u5373\u6bcf\u4e00\u884c\u7684\u6bcf\u4e00\u4e2a\u6570\u636e\u53ef\u4ee5\u662f\u4ec0\u4e48\u7c7b\u578b\u7684\u3002\u8bf4\u767d\u4e86\u5c31\u662f<mark style=\"background-color:rgba(0, 0, 0, 0);color:#fcb900\" class=\"has-inline-color\">\u5217\u7684\u57df\uff08domain\uff09\u662f{int\uff0cstring}<\/mark>\u3002\u8fd9\u91cc\u9650\u5b9a\u4e86\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u53ea\u80fd\u662fint\u6216\u8005string\uff0c\u5bf9\u5e94\u4e86lab1.md\u4e2d\u63d0\u5230\u7684\u201c<em><strong>Data types except integers and fixed length strings.<\/strong><\/em>\u201d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/\/ DBType is the type of a tuple field, in GoDB, e.g., IntType or StringType\n<\/mark>type DBType int\n\nconst (\n\tIntType     DBType = iota\n\tStringType  DBType = iota\n\tUnknownType DBType = iota \/\/used internally, during parsing, because sometimes the type is unknown\n)\n\nvar typeNames map&#91;DBType]string = map&#91;DBType]string{IntType: \"int\", StringType: \"string\"}<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u4f60\u4e0d\u8bb0\u5f97iota\u662f\u5565\u4e86\uff0c\u8fd9\u91cc\u6709\u4e00\u4e2a\u4f7f\u7528\u4f8b\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/white-night.club\/index.php\/2023\/10\/18\/pg14\/\" target=\"_blank\"><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0086ff\" class=\"has-inline-color\">Golang\u4e2d\u7684iota<\/mark><\/a>\u3002\u8fd9\u91cc\u8fd8\u65b0\u5efa\u4e86\u4e00\u4e2amap\uff0c\u770b\u8d77\u6765\u662f\u5339\u914dint\u548cstring\u4e24\u79cd\u6570\u636e\u7c7b\u578b\u7684\u3002<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\u5b9a\u4e49\u4e86\u4e00\u4e2aFieldType\u7ed3\u6784\u3002FieldType\uff1f\u5b57\u6bb5\u7c7b\u578b\u53c8\u662f\u4ec0\u4e48\u73a9\u610f\uff1f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/\/ FieldType is the type of a field in a tuple, e.g., its name, table, and &#91;godb.DBType].\n\/\/ TableQualifier may or may not be an emtpy string, depending on whether the table\n\/\/ was specified in the query<\/mark>\ntype FieldType struct {\n\tFname          string\n\tTableQualifier string\n\tFtype          DBType\n}<\/code><\/pre>\n\n\n\n<p>\u5148\u522b\u7740\u6025\u3002\u6211\u4eec\u53ef\u4ee5\u89c2\u5bdf\u5230\uff0cFtype\u7684\u7c7b\u578b\u662fDBType\u3002\u8bf4\u660e<mark style=\"background-color:rgba(0, 0, 0, 0);color:#fcb900\" class=\"has-inline-color\">DBType\u5bf9\u4e8eFieldType\u800c\u8a00\u662f\u66f4\u52a0\u5e95\u5c42\u7684\u65b9\u6cd5<\/mark>\u3002<\/p>\n\n\n\n<p>\u4e0a\u9762\u7684DBType\uff0c\u6307\u5411\u7684\u662f\u6bcf\u4e00\u884c\u7684\u6570\u636e\uff0c\u5b83\u9650\u5b9a\u4e86\u6bcf\u4e2a\u5143\u7ec4\u4e2d\u5b57\u6bb5\u7684\u7c7b\u578b\u3002\u800cFieldType\u6307\u5411\u7684\u662f\u6bcf\u4e00\u5217\uff0c\u5b83\u9650\u5b9a\u7684\u662f\u5b57\u6bb5\u6240\u6784\u6210\u7684\u201d\u5143\u7ec4\u201c\u3002\u4e3e\u4e2a\u4f8b\u5b50<\/p>\n\n\n\n<p>\u5047\u8bbe\u6709\u4e2atable\uff0c\u6709\u56db\u5217\uff0c\u6216\u8005\u8bf4\u662f\u56db\u4e2a\u5b57\u6bb5<\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong><em>id,name,email,address<\/em><\/strong><\/p>\n\n\n\n<p>\u5982\u679cid\u9650\u5b9a\u7684\u7c7b\u578b\u4e3aint\uff0c\u5176\u4ed6\u4e09\u8005\u7684\u7c7b\u578b\u4e3astring\u3002\u90a3\u4e48id\u7684\u57df\u5c31\u662f{int}\uff0c\u76f8\u5f53\u4e8eFtype=int\uff1bFname\u5c31\u662f\u201cid\u201d\uff1b\u90a3\u4e48tableQualifier\uff0c\u987e\u540d\u601d\u4e49\uff0c\u201c\u8868\u9650\u5b9a\u7b26\u201d\uff0c\u6307\u4ee3\u7684\u662f\u6570\u636e\u5e93\u4e2d\u7684\u8868\u3002\u6211\u4eec\u8fd9\u91cc\u6ca1\u78b0\u5230\u6682\u65f6\u5c31\u4e0d\u7ba1\u5b83\u3002<\/p>\n\n\n\n<p>\u8fd8\u5269\u4e0b\u6700\u540e\u4e00\u6bb5\uff1aTupelDesc\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/\/ TupleDesc is \"type\" of the tuple, e.g., the field names and types<\/mark>\ntype TupleDesc struct {\n\tFields &#91;]FieldType\n}<\/code><\/pre>\n\n\n\n<p>Desc\u53c8\u662f\u4ec0\u4e48\uff1f\u4e0d\u77e5\u9053\uff0c\u53c8\u662f\u6ca1\u6253\u6ce8\u91ca\u3002Descent\uff1fDescribe\uff1f\u6211\u4eec\u56de\u5230lab1.md\u4e2d\u770b\u770b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Tuples also have a type (or schema), called a <mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">tuple descriptor<\/mark>, represented by a TupleDesc struct, which consists of a collection of FieldType objects, one per field in the tuple, each of which describes the type of the corresponding field.<\/code><\/pre>\n\n\n\n<p>Fieids\u7684\u7c7b\u578b\u662fFieldType\uff0c\u8bf4\u660eTupleDesc\u8981\u6bd4FieldType\u66f4\u9ad8\u7ea7\uff0c\u5b83\u4eceFieldType\u7ee7\u627f\u4e86\u5b83\u7684\u65b9\u6cd5\u548c\u6570\u636e\u7c7b\u578b\u3002<\/p>\n\n\n\n<p>\u603b\u7ed3\u4e00\u4e0b\uff0cTupleDesc>FieldType>DBType\u3002\u800cTupleDesc\u5b58\u50a8\u7740\u6bcf\u4e00\u5217\u5b57\u6bb5\u7684\u540d\u5b57\uff0c\u7c7b\u578b\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\u63a5\u4e0b\u6765\u5c31\u662f\u5b8c\u6210\u5b9e\u9a8c\u4e00\u4e86\uff0c\u4e0b\u7bc7\u6587\u7ae0\u5728\u6162\u6162\u8bb0\u5f55\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lab1\u5b9e\u9a8c\u8bb0\u5f55\uff1a\u5206\u6790GoDB\u7684\u6570\u636e\u7ed3\u6784<\/p>\n","protected":false},"author":1,"featured_media":3047,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[44,33],"tags":[34,80],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3042"}],"collection":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/comments?post=3042"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3042\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/3047"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=3042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=3042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=3042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}