{"id":3103,"date":"2023-10-19T14:07:04","date_gmt":"2023-10-19T06:07:04","guid":{"rendered":"https:\/\/white-night.club\/?p=3103"},"modified":"2023-11-09T11:07:47","modified_gmt":"2023-11-09T03:07:47","slug":"pg15","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/19\/pg15\/","title":{"rendered":"MIT6.5830 Lab1-GoDB\u5b9e\u9a8c\u8bb0\u5f55\uff08\u4e09\uff09"},"content":{"rendered":"\n<p>\u5728\u5206\u6790\u5b8ctuple.go\u7684\u7ec4\u6210\u4e4b\u540e\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u5c06\u8865\u5168tuple.go\u7684\u7f3a\u5931\u90e8\u5206\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>\u7ed3\u6784\u4f53\u6570\u7ec4\u7684\u6bd4\u8f83\uff0c\u590d\u5236\u4e0e\u5408\u5e76<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u4e0a\u4e00\u7bc7\u8bb0\u5f55\u7684\u7ed3\u5c3e\u6211\u4eec\u63d0\u5230\u4e86\u201c<em>tuple descriptor<\/em>\u201d\uff0c\u5373\u201c\u5143\u7ec4\u63cf\u8ff0\u7b26\u201d\u3002\u9996\u5148\u770b\u5230\u7b2c\u4e00\u4e2aTODO<\/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\">\/\/ Compare two tuple descs, and return true iff\n\/\/ all of their field objects are equal and they\n\/\/ are the same length<\/mark>\nfunc (d1 *TupleDesc) equals(d2 *TupleDesc) bool {\n\t<mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/\/ TODO: some code goes here<\/mark>\n\treturn true\n}<\/code><\/pre>\n\n\n\n<p>\u201c\u6bd4\u8f83\u4e24\u4e2a\u5143\u7ec4\u63cf\u8ff0\u7b26\u201d\u7ed3\u6784\u4f53\u662f\u5426\u76f8\u7b49\u3002\u8bf4\u767d\u4e86\u5c31\u662f\u6bd4\u8f83\u4e24\u7ec4\uff08<mark style=\"background-color:rgba(0, 0, 0, 0);color:#fcb900\" class=\"has-inline-color\">\u4e0d\u662f\u201c\u4e2a\u201d\uff01\uff01\uff01TupleDesc\u5305\u542b\u7684\u662f\u5b57\u6bb5\u5207\u7247\uff0c\u800c\u4e0d\u662f\u5355\u4e2a\u5b57\u6bb5<\/mark>\uff09\u5c5e\u6027\uff08\u5217\uff09\u662f\u5426\u76f8\u7b49\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote has-vivid-cyan-blue-color has-text-color\">\n<p>\u5199\u8005\u6ce8<\/p>\n<cite>\u6570\u636e\u5e93\u8fd9\u4e00\u5757\u7684\u201c\u522b\u540d\u201d\u5c31\u548cSQL\u4e2d\u7528\u5230\u522b\u540d\u7684\u5730\u65b9\u4e00\u6837\u591a\u3002\u627e\u4e2a\u65f6\u95f4\u518d\u597d\u597d\u68b3\u7406\u8fd9\u4e9b\u6570\u636e\u5e93\u76f8\u5173\u7684\u672f\u8bed\u5427\u3002<\/cite><\/blockquote>\n\n\n\n<p>\u4e3a\u4ec0\u4e48\u8981\u4f5c\u8fd9\u4e48\u4e2a\u6bd4\u8f83\uff1f\u6211\u4eec\u67e5\u627eequals\u7684\u5168\u90e8\u5f15\u7528\uff0c\u5e76\u5728\u6700\u540e\u4e00\u8def\u627e\u5230\u4e86tuple_test.go\u4e2d\u7684<\/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\/84f1b355d82cd78ee2bed45607c44aa.png\" alt=\"\" class=\"wp-image-3110\" style=\"border-style:none;border-width:0px;border-radius:0px\" width=\"668\" height=\"322\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/84f1b355d82cd78ee2bed45607c44aa.png 890w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/84f1b355d82cd78ee2bed45607c44aa-300x145.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/84f1b355d82cd78ee2bed45607c44aa-768x370.png 768w\" sizes=\"(max-width: 668px) 100vw, 668px\" \/><\/figure>\n\n\n\n<p>\u90a3\u4e48\u63a5\u4e0b\u6765\u5c31\u662f\u5148\u8865\u5168\u201d\u6bd4\u8f83\u201c\u7684\u4ee3\u7801\uff0c\u76f8\u7b49\u8fd4\u56detrue\uff0c\u4e0d\u76f8\u7b49\u8fd4\u56defalse\u3002\u6bd4\u8f83\u7b80\u5355<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func (d1 *TupleDesc) equals(d2 *TupleDesc) bool {\n\t<mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/\/ TODO: some code goes here<\/mark>\n\tif len(d1.Fields) != len(d2.Fields) {\n\t\treturn false\n\t}\n\tfor i := range d1.Fields { <mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/\/i\u4e3a\u4e0b\u6807<\/mark>\n\t\tif d1.Fields&#91;i] != d2.Fields&#91;i] {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}<\/code><\/pre>\n\n\n\n<p>run test\u4e00\u4e0b\uff0c\u80fdpass\u5c31\u8bf4\u660eOK\u4e86\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized has-custom-border\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/de9775b9803c3bd23caa2a50333c60a-1024x655.png\" alt=\"\" class=\"wp-image-3114\" style=\"border-style:none;border-width:0px;border-radius:0px\" width=\"768\" height=\"491\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/de9775b9803c3bd23caa2a50333c60a-1024x655.png 1024w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/de9775b9803c3bd23caa2a50333c60a-300x192.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/de9775b9803c3bd23caa2a50333c60a-768x491.png 768w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/de9775b9803c3bd23caa2a50333c60a.png 1189w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote has-vivid-cyan-blue-color has-text-color\">\n<p>\u5199\u8005\u6ce8<\/p>\n<cite>\u7b2c\u4e00\u6b21\u53d1\u73b0\u80fd\u5355\u72ec\u6d4b\u8bd5\u4ee3\u7801\u4e2d\u7684\u67d0\u4e2a\u51fd\u6570\uff0c\u5c5e\u5b9e\u662f\u5218\u59e5\u59e5\u8fdb\u4e86\u5927\u89c2\u56ed\u3002<\/cite><\/blockquote>\n\n\n\n<p>\u63a5\u4e0b\u6765\u662f\u62f7\u8d1d\u3002\u4e00\u4e2a\u7ed3\u6784\u4f53\u5207\u7247\u62f7\u8d1d\u5230\u53e6\u4e00\u4e2a\u7ed3\u6784\u4f53\u5207\u7247\uff0c\u4e5f\u6bd4\u8f83\u7b80\u5355\uff0c\u8c03\u7528copy\u62f7\u8d1d\u5207\u7247\u5373\u53ef\u3002\u6700\u540e\u8fd4\u56de\u7684\u662fTupleDesc\uff0c\u6240\u4ee5\u8981\u7ed9\u8fd9\u4e2a\u8fd4\u56de\u7684TupleDesc.Fields\u8d4b\u503c\u4e3anewTupleDesc\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func (td *TupleDesc) copy() *TupleDesc {\n\t<mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/\/ TODO: some code goes here<\/mark>\n\tnewTupleDesc := make(&#91;]FieldType, len(td.Fields))\n\tcopy(newTupleDesc, td.Fields)\n\treturn &amp;TupleDesc{Fields: newTupleDesc} <mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/\/replace me<\/mark>\n}<\/code><\/pre>\n\n\n\n<p>\u8dd1\u4e00\u4e0btest\uff0cpass\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\/f382d8f69390a7189784c4962b6bd5f.png\" alt=\"\" class=\"wp-image-3116\" style=\"border-style:none;border-width:0px;border-radius:0px\" width=\"767\" height=\"564\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/f382d8f69390a7189784c4962b6bd5f.png 1022w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/f382d8f69390a7189784c4962b6bd5f-300x221.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/f382d8f69390a7189784c4962b6bd5f-768x565.png 768w\" sizes=\"(max-width: 767px) 100vw, 767px\" \/><\/figure>\n\n\n\n<p>\u63a5\u4e0b\u6765\u662f\u5408\u5e76\u3002\u66f4\u7b80\u5355\uff0c\u76f4\u63a5append\u5b8c\u4e8b\u3002\u4e0d\u8fc7\u8981\u8bb0\u4f4f\u662f\u628adesc2\u7684Fields\u5408\u5e76\u5230desc.Fields\u7684\u540e\u9762\uff0c\u987a\u5e8f\u4e0d\u8981\u5f04\u9519\u4e86\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\">\/\/ Merge two TupleDescs together.  The resulting TupleDesc\n\/\/ should consist of the fields of desc2\n\/\/ appended onto the fields of desc.<\/mark>\nfunc (desc *TupleDesc) merge(desc2 *TupleDesc) *TupleDesc {\n\t\/\/ TODO: some code goes here\n\tdesc.Fields = append(desc.Fields, desc2.Fields...)\n\treturn &amp;TupleDesc{desc.Fields} \/\/replace me\n}<\/code><\/pre>\n\n\n\n<p>run test\u4e00\u4e0b\uff0c\u8fc7\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\/a505564192b8fa488d3ab7ee5571519.png\" alt=\"\" class=\"wp-image-3176\" style=\"border-style:none;border-width:0px;border-radius:0px\" width=\"729\" height=\"409\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/a505564192b8fa488d3ab7ee5571519.png 972w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/a505564192b8fa488d3ab7ee5571519-300x168.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/a505564192b8fa488d3ab7ee5571519-768x431.png 768w\" sizes=\"(max-width: 729px) 100vw, 729px\" \/><\/figure>\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 Methods<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u6709\u4e86DBType&#8211;\u6570\u636e\u5e93\u53ef\u7528\u7684\u57fa\u7840\u6570\u636e\u7c7b\u578b\uff0cFieldType&#8211;\u7ba1\u7406\u5b57\u6bb5\u7684\u7ed3\u6784\u4f53\uff0c\u6709\u4e86TupleDesc&#8211;\u7ba1\u7406\u5143\u7ec4\u7684\u7ed3\u6784\u4f53\uff0c\u90a3\u4e48\u63a5\u4e0b\u6765\u5b9e\u73b0\u7684\u5c31\u662fTuple&#8211;\u5143\u7ec4\u672c\u8eab\u4e86\u3002\u6211\u4eec\u5148\u6765\u770b\u770b\u5b83\u7684\u6570\u636e\u7ed3\u6784<\/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\/b31853e1ebdb210349857be77e64ccb.png\" alt=\"\" class=\"wp-image-3178\" style=\"border-style:none;border-width:0px;border-radius:0px\" width=\"661\" height=\"387\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/b31853e1ebdb210349857be77e64ccb.png 881w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/b31853e1ebdb210349857be77e64ccb-300x176.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/b31853e1ebdb210349857be77e64ccb-768x450.png 768w\" sizes=\"(max-width: 661px) 100vw, 661px\" \/><\/figure>\n\n\n\n<p>Tuple\u6709\u4e09\u4e2a\u6570\u636e\u6210\u5458\uff0cTupleDesc\u4e0d\u7528\u591a\u8bf4\uff0c\u7528\u4e8e\u63cf\u8ff0xxx\u5b57\u6bb5\u7684\u6570\u636e\u7c7b\u578b\u662f\u4ec0\u4e48\uff1bFields\u4e5f\u4e0d\u7528\u591a\u8bf4\uff0c\u7528\u4e8e\u5b58\u50a8\u5177\u4f53\u7684\u6570\u636e\uff1b\u95ee\u9898\u5728\u4e8eRid\u662f\u4ec0\u4e48\u3002<\/p>\n\n\n\n<p>\u6839\u636e\u6ce8\u91ca\uff0c\u53ef\u4ee5\u5f97\u77e5\u6211\u4eec\u901a\u8fc7RID\u6765\u8ffd\u8e2a\u8be5\u8bb0\u5f55\u662f\u5728\u54ea\u4e00\u9875\u7684\u54ea\u4e00\u4e2a\u4f4d\u7f6e\u3002\u6bd4\u5982\u5728oracle\u4e2d\u7684RID\uff0c\u8bf4\u767d\u4e86\u5c31\u662f\u6bcf\u4e00\u884c\u90fd\u6709\u4e2a\u5185\u7f6e\u7684\u6807\u8bc6\u7b26\uff0c\u8fd9\u4e2a\u6807\u8bc6\u7b26\u4f60\u76f4\u63a5SELECT\u7684\u65f6\u5019\u662f\u770b\u4e0d\u5230\u7684\uff0c\u4f46\u662f\u4f60\u53ef\u4ee5\u901a\u8fc7RID\u5feb\u901f\u7684\u627e\u5230\u67d0\u4e2a\u7279\u5b9a\u7684\u884c\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>\u8bfb\u5199\u7f13\u51b2\u533a<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u5f00\u59cb\u62bd\u8c61\u8d77\u6765\u4e86\u3002\u4e2a\u4eba\u611f\u89c9\u5e94\u8be5\u662f\u672c\u6b21\u5b9e\u9a8c\u8bb0\u5f55\u4e2d\u6700\u96be\u7684\u90e8\u5206\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u7bc7\u5e45\u4f1a\u5f88\u957f\uff0c\u5f97\u5f00\u53e6\u4e00\u4e2a\u6587\u7ae0\u6765\u5355\u72ec\u8bb0\u5f55\uff0c\u6240\u4ee5\u8fd9\u91cc\u5148\u8df3\u8fc7\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>\u8865\u5168\u5269\u4f59\u7684Tuple\u51fd\u6570<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u5143\u7ec4\u4e4b\u95f4\u7684\u6bd4\u8f83\u76f8\u5bf9\u6765\u8bf4\u6bd4\u8f83\u7b80\u5355\uff0c\u5143\u7ec4\u63cf\u8ff0\u7b26\u7684\u6bd4\u8f83\u76f4\u63a5\u8c03\u7528\u4e4b\u524d\u5199\u7684Desc.equals\u5373\u53ef\u3002\u63a5\u4e0b\u6765\u518d\u5bf9\u5143\u7ec4\u7684\u5b57\u6bb5\u8fdb\u884c\u6bd4\u8f83\u3002<\/p>\n\n\n\n<p>\u4f46\u662f\u5143\u7ec4\u7684recordId\u9700\u8981\u6bd4\u8f83\u5417\uff1f\u6bcf\u4e2a\u5143\u7ec4\u90fd\u6709\u81ea\u5df1\u72ec\u7279\u7684RID\uff0c\u6bd4\u8f83RID\u7684\u610f\u4e49\u5728\u4e8e\u201cA\u5143\u7ec4\u662f\u5426\u7b49\u4e8eA\u5143\u7ec4\u201d\uff0c\u4e0d\u6bd4\u8f83\u7684\u8bddequals\u7684\u610f\u4e49\u5c31\u53d8\u6210\u4e86\u201cA\u5143\u7ec4\u662f\u5426\u7b49\u4e8eB\u5143\u7ec4\u201d\u3002\u8fd9\u91cc\u6ca1\u8bf4\u8981\u4e0d\u8981\u6bd4\u8f83RID\uff0c\u90a3\u5c31\u5148\u4e0d\u6bd4\u8f83\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\">\/\/ Compare two tuples for equality.  Equality means that the TupleDescs are equal\n\/\/ and all of the fields are equal.  TupleDescs should be compared with\n\/\/ the &#91;TupleDesc.equals] method, but fields can be compared directly with equality\n\/\/ operators.<\/mark>\nfunc (t1 *Tuple) equals(t2 *Tuple) bool {\n\t\/\/ TODO: some code goes here\n\tif t1.Desc.equals(&amp;t2.Desc) == false {\n\t\treturn false\n\t}\n\tfor i := range t1.Fields {\n\t\tif t1.Fields&#91;i] != t2.Fields&#91;i] {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}<\/code><\/pre>\n\n\n\n<p>\u63a5\u4e0b\u6765\u662f\u5408\u5e76\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\u4e0d\u80fd\u76f4\u63a5\u5199\u6210<em>t1.Fields=append(t1,Fields,t2.Fields)<\/em>\u3002\u4e0d\u5e26\u201d&#8230;\u201c\u7684append\u662f\u76f4\u63a5\u628a\u6574\u4e2at2.Fields\u4f5c\u4e3a\u4e00\u4e2a\u5bf9\u8c61\u90fd\u5408\u5e76\u5230t1.Fields\u4e2d\uff0c\u800c\u6211\u4eec\u9700\u8981\u7684\u662f\u679a\u4e3eFields\u4e2d\u7684\u6bcf\u4e2a\u6570\u636e\u518d\u628a\u5b83\u5408\u5e76\u8fdb\u884c\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\">\/\/ Merge two tuples together, producing a new tuple with the fields of t2 appended to t1.<\/mark>\nfunc joinTuples(t1 *Tuple, t2 *Tuple) *Tuple {\n\t<mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/\/ TODO: some code goes here<\/mark>\n\tt1.Fields = append(t1.Fields, t2.Fields...)\n\treturn &amp;Tuple{Fields: t1.Fields}\n}\n<\/code><\/pre>\n\n\n\n<p>\u63a5\u4e0b\u6765\u7ee7\u7eed\u89c2\u5bdf\u3002\u53ea\u5269\u6700\u540e\u4e24\u4e2aTODO\u4e86\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\/1df3533362da641c672ca172d77be00.png\" alt=\"\" class=\"wp-image-3185\" style=\"border-style:none;border-width:0px;border-radius:0px\" width=\"703\" height=\"328\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/1df3533362da641c672ca172d77be00.png 937w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/1df3533362da641c672ca172d77be00-300x140.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/1df3533362da641c672ca172d77be00-768x358.png 768w\" sizes=\"(max-width: 703px) 100vw, 703px\" \/><\/figure>\n\n\n\n<p>compareField\uff0c\u5f88\u660e\u663e\u5c31\u662f\u5b57\u6bb5\u4e4b\u95f4\u7684\u6bd4\u8f83\u3002\u5728compareField\u7684\u6ce8\u91ca\u4e2d\u63d0\u5230\u4e86\u6211\u4eec\u9700\u8981\u7528\u7684Expr.EvalExpr\u51fd\u6570\u3002\u6211\u4eec\u5148\u4e0d\u7ba1\u5b83\u662f\u4ec0\u4e48\uff0c\u4f46\u662f\u5728\u8865\u5168compareField\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u5148\u8865\u5168project\u51fd\u6570\u3002<\/p>\n\n\n\n<p>\u8fd9\u662f\u56e0\u4e3a\u5728EvalExpr\u4e2d\u6211\u4eec\u9700\u8981\u8c03\u7528project\u51fd\u6570\u53bb\u83b7\u53d6\u67d0\u4e2a\u7279\u5b9a\u7684\u5b57\u6bb5\u3002\u5426\u5219\u6700\u540eproject\u7684\u9ed8\u8ba4\u8fd4\u56de\u503c\u4e3anil\uff0c\u80af\u5b9a\u6ca1\u6cd5\u901a\u8fc7\u6d4b\u8bd5\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\/72b17771142d4030bc99a0e12acf610.png\" alt=\"\" class=\"wp-image-3186\" style=\"border-style:none;border-width:0px;border-radius:0px\" width=\"523\" height=\"208\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/72b17771142d4030bc99a0e12acf610.png 697w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/72b17771142d4030bc99a0e12acf610-300x119.png 300w\" sizes=\"(max-width: 523px) 100vw, 523px\" \/><\/figure>\n\n\n\n<p>\u90a3\u5c31\u5148\u8865\u5168project\u3002\u90a3\u4e48project\u662f\u4ec0\u4e48\uff1f\u9879\u76ee\u5417\uff1f\u5f53\u7136\u4e0d\u662f\u3002<\/p>\n\n\n\n<p>\u5728\u6570\u5b66\u4e2d\uff0cproject\u7ecf\u5e38\u7528\u4e8e\u8868\u793a\u201c\u6295\u5f71\u201d\u3002\u800c\u5728SQL\u4e2d\uff0c\u6295\u5f71\u7b80\u5355\u6765\u8bf4\u5c31\u662f\u4ece\u8868\u4e2d\u9009\u53d6\u7279\u5b9a\u7684\u884c\u3002\u6bd4\u5982\u4e0b\u9762\u8fd9\u4e24\u4e2aSQL\u8bed\u53e5\u5c31\u5c06\u8bf4\u660e\u6295\u5f71\uff08Projection\uff09\u548c\u9009\u62e9\uff08Selection\uff09\u7684\u533a\u522b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM table <mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/\/\u9009\u62e9<\/mark>\nSELECT name,id FROM table <mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/\/\u6295\u5f71<\/mark><\/code><\/pre>\n\n\n\n<p>\u660e\u767d\u4e86project\u662f\u5e72\u4ec0\u4e48\u7684\uff0c\u90a3\u4e48\u63a5\u4e0b\u6765\u5c31\u662f\u8865\u5168\u5b83\u3002<\/p>\n\n\n\n<p>\u4ece\u4e00\u4e2a\u5143\u7ec4\u4e2d\u9009\u62e9\u51fa\u7279\u5b9a\u7684\u5b57\u6bb5\uff0c\u5e76\u4e14\u88ab\u9009\u4e2d\u7684\u5b57\u6bb5\u5e94\u8be5\u4f5c\u4e3a\u4e00\u4e2a\u65b0\u7684\u5143\u7ec4\u3002\u6709\u70b9\u50cf\u5728MySQL\u4e2d\u6211\u4eecSELECT xxx\u65f6\u4f1a\u751f\u6210\u4e00\u4e2a\u865a\u62df\u8868\uff0c\u6b64\u65f6\u6211\u4eec\u5f97\u5230\u7684\u662f\u65b0\u7684\u7ed3\u679c\u96c6\uff0c\u800c\u539f\u8868\u7684\u4fe1\u606f\u662f\u4e0d\u4f1a\u66f4\u6539\u7684\u3002<\/p>\n\n\n\n<p>\u5f53\u7136\u4e86\uff0c\u5373\u4f7f\u662f\u65b0\u7684\u5143\u7ec4\uff0c\u5b83\u4eec\u7684\u63cf\u8ff0\u7b26\u8fd8\u662f\u4e00\u6837\u7684\uff0c\u53ea\u662f\u5b57\u6bb5\u7684\u6570\u91cf\u6539\u53d8\u4e86&#8211;\u56e0\u4e3a\u6211\u4eec\u8981\u9009\u62e9\u51fa\u7279\u5b9a\u5b57\u6bb5\u3002\u540c\u65f6\u5728\u8fd9\u91cc\u6211\u4eec\u8fd8\u9700\u8981\u7528\u5230\u524d\u9762\u7684findFieldInTd\u51fd\u6570\u3002\u56e0\u4e3a\u5143\u7ec4Desc\u7684\u5b57\u6bb5\u548c\u6211\u4eec\u8981\u9009\u62e9\u5b57\u6bb5\u7684\u4e0b\u6807\u662f\u4e00\u81f4\u7684\uff0c\u5b83\u4eec\u7684\u5173\u7cfb\u4e3e\u4f8b\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>TupleDesc:{\"name\",\"age\",...}\nTuple:{\"Sam\",\"19\",...}\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/\/\u5047\u8bbe\u53eaSELECT name<\/mark>\nnewTupleDesc:{\"name\"}\nnewTuple:{\"Sam\"} <mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/\/\u4e24\u8005\u5bf9\u5e94\u7684\u4e0b\u6807\u76f8\u7b49\uff0c\u6b64\u5904\u90fd\u4e3a0<\/mark><\/code><\/pre>\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\">\/\/ Project out the supplied fields from the tuple. Should return a new Tuple\n\/\/ with just the fields named in fields.\n\/\/\n\/\/ Should not require a match on TableQualifier, but should prefer fields that\n\/\/ do match on TableQualifier (e.g., a field  t1.name in fields should match an\n\/\/ entry t2.name in t, but only if there is not an entry t1.name in t)<\/mark>\nfunc (t *Tuple) project(fields &#91;]FieldType) (*Tuple, error) {\n\t<mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/\/ TODO: some code goes here<\/mark>\n\tnewTupleDesc := &amp;TupleDesc{Fields: fields}\n\tnewTuple := &amp;Tuple{Desc: *newTupleDesc}\n\tfor _, field := range fields {\n\t\tindex, err := <mark style=\"background-color:rgba(0, 0, 0, 0);color:#ffdf00\" class=\"has-inline-color\">findFieldInTd<\/mark>(field, &amp;t.Desc)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tnewTuple.Fields = append(newTuple.Fields, t.Fields&#91;index])\n\t\tfmt.Println(t.Fields&#91;index])\n\t}\n\n\treturn newTuple, nil <mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/\/replace me<\/mark>\n}<\/code><\/pre>\n\n\n\n<p>run test\u4e00\u4e0b\uff0c\u8fc7\u3002\u4e0d\u8fc7lab1\u63d0\u4f9b\u7684\u6d4b\u8bd5\u6837\u4f8b\u592a\u5c11\uff0c\u6211\u4eec\u540e\u7eed\u9700\u8981\u81ea\u5b9a\u4e49\u4e00\u4e0b\u8f93\u5165\u4ee5\u6d4b\u8bd5\u6211\u4eec\u7684\u4ee3\u7801\u4e2d\u4e0d\u540c\u60c5\u51b5\u4e0b\u90fd\u80fd\u6b63\u5e38\u8fd0\u884c\u3002\u540e\u7eed\u7684\u5b9e\u9a8c\u8bb0\u5f55\u4e2d\u4f1a\u518d\u6b21\u63d0\u5230\u8fd9\u70b9\uff0c\u8fd9\u91cc\u6211\u4eec\u5148\u8df3\u8fc7\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\/099df891fc2efe638a4de209b2228ea.png\" alt=\"\" class=\"wp-image-3204\" style=\"border-style:none;border-width:0px;border-radius:0px\" width=\"560\" height=\"523\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/099df891fc2efe638a4de209b2228ea.png 747w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/099df891fc2efe638a4de209b2228ea-300x280.png 300w\" sizes=\"(max-width: 560px) 100vw, 560px\" \/><\/figure>\n\n\n\n<p>project\u641e\u5b9a\u3002\u63a5\u4e0b\u6765\u5c31\u662f\u5b57\u6bb5\u4e4b\u95f4\u7684\u6bd4\u8f83\u4e86\u3002<\/p>\n\n\n\n<p>\u5b57\u6bb5\u4e4b\u95f4\u7684\u6bd4\u8f83\u5206\u4e3a\u4e24\u79cd\uff0cIntField\u4e4b\u95f4\u7684\u6bd4\u8f83\u548cStringField\u4e4b\u95f4\u7684\u6bd4\u8f83\u3002int\u7c7b\u578b\u7684\u5f88\u597d\u7406\u89e3\uff0c\u4f46\u662f\u5b57\u7b26\u4e32\u6211\u4eec\u8be5\u600e\u4e48\u6bd4\u8f83\u5927\u5c0f\u5462\uff1f\u8fd9\u91cc\u6ce8\u91ca\u4e5f\u53ea\u662f\u53eb\u6211\u4eec\u6bd4\u8f83\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\uff0c\u6ca1\u8bf4\u6309\u4ec0\u4e48\u65b9\u5f0f\u6392\u5e8f\uff0c\u90a3\u6211\u4eec\u5f97\u81ea\u5df1\u7814\u7a76\u7814\u7a76\u3002<\/p>\n\n\n\n<p>\u770b\u770b\u6d4b\u8bd5\u6837\u4f8b\uff0c\u8f93\u5165\u201csam\u201d\u548c\u201cgeorge jones\u201d\uff0c\u524d\u8005\u6bd4\u540e\u8005\u5927\u3002\u90a3\u4e48\u5927\u6982\u7387\u662f\u6309\u7167\u5b57\u5178\u5e8f\u6392\u5217\u7684\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\/a26112b82d915b7b79ae4e6e24aeb85.png\" alt=\"\" class=\"wp-image-3231\" style=\"border-style:none;border-width:0px;border-radius:0px\" width=\"624\" height=\"270\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/a26112b82d915b7b79ae4e6e24aeb85.png 832w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/a26112b82d915b7b79ae4e6e24aeb85-300x130.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/a26112b82d915b7b79ae4e6e24aeb85-768x332.png 768w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/figure>\n\n\n\n<p>\u90a3\u4e48\u63a5\u4e0b\u6765\u5f00\u59cb\u8865\u5168\u4ee3\u7801\u3002\u6211\u4eec\u9700\u8981\u5148\u5224\u65ad\u4e24\u4e2a\u5b57\u6bb5\u7684\u7c7b\u578b\uff0c\u76f8\u540c\u7c7b\u578b\u624d\u80fd\u8fdb\u884c\u6bd4\u8f83\u3002\u90a3\u4e48\u4ee3\u7801\u5982\u4e0b<\/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\">\/\/ Apply the supplied expression to both t and t2, and compare the results,\n\/\/ returning an orderByState value.\n\/\/\n\/\/ Takes an arbitrary expressions rather than a field, because, e.g., for an\n\/\/ ORDER BY SQL may ORDER BY arbitrary expressions, e.g., substr(name, 1, 2)\n\/\/\n\/\/ Note that in most cases Expr will be a &#91;godb.FieldExpr], which simply\n\/\/ extracts a named field from a supplied tuple.\n\/\/\n\/\/ Calling the &#91;Expr.EvalExpr] method on a tuple will return the value of the\n\/\/ expression on the supplied tuple.<\/mark>\nfunc (t *Tuple) compareField(t2 *Tuple, field Expr) (orderByState, error) {\n\t<mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/\/ TODO: some code goes here<\/mark>\n\tvalue, err := field.EvalExpr(t)\n\tif err != nil {\n\t\treturn -1, err\n\t}\n\tvalue2, err := field.EvalExpr(t2)\n\tif err != nil {\n\t\treturn -1, err\n\t}\n\tswitch a := value.(type) {\n\tcase IntField:\n\t\tb, ok := value2.(IntField)\n\t\tif !ok {\n\t\t\treturn 0, fmt.Errorf(\"b is not an IntField\")\n\t\t}\n\t\tif a.Value > b.Value {\n\t\t\treturn OrderedGreaterThan, nil\n\t\t} else if a.Value &lt; b.Value {\n\t\t\treturn OrderedLessThan, nil\n\t\t} else if a.Value == b.Value {\n\t\t\treturn OrderedEqual, nil\n\t\t}\n\tcase StringField:\n\t\tb, ok := value2.(StringField)\n\t\tif !ok {\n\t\t\treturn 0, fmt.Errorf(\"b is not an StringField\")\n\t\t}\n\t\tif a.Value > b.Value {\n\t\t\treturn OrderedGreaterThan, nil\n\t\t} else if a.Value &lt; b.Value {\n\t\t\treturn OrderedLessThan, nil\n\t\t} else if a.Value == b.Value {\n\t\t\treturn OrderedEqual, nil\n\t\t}\n\t}\n\treturn -1, nil <mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/\/ replace me<\/mark>\n}<\/code><\/pre>\n\n\n\n<p>run test\u4e00\u4e0b\uff0c\u5982\u679c\u80fd\u6b63\u5e38\u8fd0\u884c\u8bf4\u660eproject\u548ccompareField\u6ca1\u4ec0\u4e48\u95ee\u9898\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"513\" src=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/73f1a2e1dea404147885c2d7234630d-1024x513.png\" alt=\"\" class=\"wp-image-3232\" style=\"border-style:none;border-width:0px;border-radius:0px\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/73f1a2e1dea404147885c2d7234630d-1024x513.png 1024w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/73f1a2e1dea404147885c2d7234630d-300x150.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/73f1a2e1dea404147885c2d7234630d-768x385.png 768w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/73f1a2e1dea404147885c2d7234630d.png 1057w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Lab1\u5b9e\u9a8c\u8bb0\u5f55\uff1a\u901a\u8fc7tuple_test.go\u6d4b\u8bd5<\/p>\n","protected":false},"author":1,"featured_media":3110,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[44,33],"tags":[34],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3103"}],"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=3103"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3103\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/3110"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=3103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=3103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=3103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}