{"id":4133,"date":"2023-11-05T14:36:49","date_gmt":"2023-11-05T06:36:49","guid":{"rendered":"https:\/\/white-night.club\/?p=4133"},"modified":"2024-02-22T19:29:20","modified_gmt":"2024-02-22T11:29:20","slug":"pg24","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/11\/05\/pg24\/","title":{"rendered":"MIT6.5830 Lab 2: GoDB Operators\u5b9e\u9a8c\u8bb0\u5f55\uff08\u4e00\uff09"},"content":{"rendered":"\n<p>\u5b8c\u6210Lab1\u540e\uff0c\u5c31\u8be5\u5f00Lab2\u7684\u65b0\u5751\u4e86\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>\u9605\u8bfblab2.md<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u90a3\u5148\u6765\u770b\u770blab2\u5927\u81f4\u8981\u505a\u4e9b\u4ec0\u4e48\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Here's a rough outline of one way you might proceed with your GoDB implementation; more details on the steps in this outline, including exercises, are given in Section 2 below.\n\nImplement the operators Filter (filter_op.go) and Join (join_op.go) and verify that their corresponding tests work. The comments in these operators contain details about how they should work.\n\nImplement CountAggState, SumAggState, AvgAggState, MinAggState, and MaxAggState in agg_state.go. Here, you will write the logic that actually maintains an aggregation state over a particular field across multiple groups over a running sequence of input tuples. Use integer division for computing the average, since GoDB only supports integers. Only CountAggState, MinAggState, and MaxAggState needs to support both strings and integers, since the other operations do not make sense for strings.\n\nImplement the Aggregate (agg_op.go) operator. As with other operators, aggregates implement the Iterator method so that they can be placed in GoDB query plans. Note that the output of an Aggregate operator is an aggregate value of an entire group for each call to the iterator, and that the aggregate constructor takes the aggregation and grouping fields.\n\nImplement the Insert (insert_op.go) and Delete (delete_op.go) operators. Like all operators, Insert and Delete implement Iterator, accepting a stream of tuples to insert or delete and outputting a single tuple with an integer field that indicates the number of tuples inserted or deleted. Check that the tests for inserting and deleting tuples work properly.\n\nImplement the Project (project_op.go), OrderBy (order_by_op.go), and Limit (limit_op.go) operators.\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\">Here&#39;s a rough outline of one way you might proceed with your GoDB implementation; more details on the steps in this outline, including exercises, are given in Section 2 below.<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">Implement the operators Filter (filter_op.go) and Join (join_op.go) and verify that their corresponding tests work. The comments in these operators contain details about how they should work.<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">Implement CountAggState, SumAggState, AvgAggState, MinAggState, and MaxAggState in agg_state.go. Here, you will write the logic that actually maintains an aggregation state over a particular field across multiple groups over a running sequence of input tuples. Use integer division for computing the average, since GoDB only supports integers. Only CountAggState, MinAggState, and MaxAggState needs to support both strings and integers, since the other operations do not make sense for strings.<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">Implement the Aggregate (agg_op.go) operator. As with other operators, aggregates implement the Iterator method so that they can be placed in GoDB query plans. Note that the output of an Aggregate operator is an aggregate value of an entire group for each call to the iterator, and that the aggregate constructor takes the aggregation and grouping fields.<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">Implement the Insert (insert_op.go) and Delete (delete_op.go) operators. Like all operators, Insert and Delete implement Iterator, accepting a stream of tuples to insert or delete and outputting a single tuple with an integer field that indicates the number of tuples inserted or deleted. Check that the tests for inserting and deleting tuples work properly.<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">Implement the Project (project_op.go), OrderBy (order_by_op.go), and Limit (limit_op.go) operators.<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul>\n<li>\u9996\u5148\u662fFilter\u548cJoin\u4e24\u4e2a\u8fd0\u7b97\u7b26\u3002Join\u5e94\u8be5\u5f88\u719f\u6089\u4e86\uff0c\u5929\u5929LEFT JOIN\u554aINNER JOIN\u7684\u3002\u4f46\u662fFilter\u53ef\u80fd\u6bd4\u8f83\u5c11\u89c1\uff1f\u5177\u4f53\u7684\u8fb9\u505a\u5b9e\u9a8c\u8fb9\u8bb2\u3002<\/li>\n\n\n\n<li>aggregation&#8211;\u805a\u5408\u3002\u90a3\u5c31\u662f\u5b9e\u73b0GROUP BY\uff1f<\/li>\n\n\n\n<li>\u5404\u79cd\u805a\u5408\u51fd\u6570\u3002SUM\u554a\uff0cAVG\u554a\uff0cCOUNT\u554a\uff0c\u8fd9\u4e9b\u5e73\u65f6\u4e5f\u5f88\u719f\u6089\u4e86\u3002<\/li>\n\n\n\n<li>crud\u4e2d\u7684c\u548cd\u3002\u589e\u5220\u529f\u80fd\u3002<\/li>\n\n\n\n<li>\u6295\u5f71\uff0c\u6392\u5e8f\u548climit\u3002project\u53ef\u80fd\u4e0d\u592a\u719f\u6089\u4f46\u53e6\u5916\u4e24\u4e2a\u4e5f\u5f88\u719f\u6089\u4e86\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u5927\u81f4\u8981\u5b8c\u6210\u7684\u76ee\u6807\u6709\u4e86\u3002\u770b\u8d77\u6765\u5b8c\u6210lab2\u5c31\u80fd\u770b\u5230\u4e00\u4e2a\u6bd4\u8f83\u57fa\u7840\u7684dbms\u4e86\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>Exercise 1<\/em><\/cite><\/blockquote>\n\n\n\n<p>join\u8981\u5b8c\u6210\u7684\u4ee3\u7801\u6bd4\u8f83\u591a\uff0c\u800c\u4e14\u6709\u70b9\u96be\u5ea6\u3002\u90a3\u5148\u6765\u770b\u770bFilter\u3002<\/p>\n\n\n\n<p>\u5148\u6765\u770b\u770bFilter\u7684\u7ed3\u6784\u3002T constraints.Ordered\u8868\u793a\u7684\u662f\u201c\u5b9a\u4e49\u4e00\u4e2a\u7c7b\u578bT\uff0c\u8be5\u7c7b\u578b\u6ee1\u8db3constraints.Ordered\u7ea6\u675f\u201d\u3002\u800cconstraints.Ordered\u7ea6\u675f\u6307\u7684\u662f\u201c\u8be5\u7c7b\u578b\u7684\u503c\u5fc5\u987b\u53ef\u4ee5\u8fdb\u884c\u5927\u5c0f\u6bd4\u8f83\u201d\u3002\u6bd4\u5982int\u554a\uff0cstring\uff08\u6309\u5b57\u5178\u5e8f\u6392\u5e8f\uff09\u554a\u8fd9\u4e9b\u3002getter func(DBValue) T\u76f8\u5f53\u4e8e\u4e00\u4e2a\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"type Filter[T constraints.Ordered] struct {\n\top     BoolOp\n\tleft   Expr\n\tright  Expr\n\tchild  Operator\n\tgetter func(DBValue) T\n}   \" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">type<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">Filter<\/span><span style=\"color: #D4D4D4\">[T constraints.Ordered] <\/span><span style=\"color: #569CD6\">struct<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\top     BoolOp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tleft   Expr<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tright  Expr<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tchild  Operator<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tgetter <\/span><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\">(DBValue) T<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}   <\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u518d\u6765\u770b\u770bfilter_op_test\u4e2d\u662f\u600e\u4e48\u521d\u59cb\u5316filter\u7684\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"_, t1, t2, hf, _, tid := makeTestVars()\n\thf.insertTuple(&amp;t1, tid)\n\thf.insertTuple(&amp;t2, tid)\n\tvar f FieldType = FieldType{&quot;name&quot;, &quot;&quot;, StringType}\n\tfilt, err := NewStringFilter(&amp;ConstExpr{StringField{&quot;sam&quot;}, StringType}, OpEq, &amp;FieldExpr{f}, hf)\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">t1<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">t2<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">hf<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">tid<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">makeTestVars<\/span><span style=\"color: #D4D4D4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\thf.<\/span><span style=\"color: #DCDCAA\">insertTuple<\/span><span style=\"color: #D4D4D4\">(&amp;t1, tid)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\thf.<\/span><span style=\"color: #DCDCAA\">insertTuple<\/span><span style=\"color: #D4D4D4\">(&amp;t2, tid)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #569CD6\">var<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">f<\/span><span style=\"color: #D4D4D4\"> FieldType = FieldType{<\/span><span style=\"color: #CE9178\">&quot;name&quot;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&quot;&quot;<\/span><span style=\"color: #D4D4D4\">, StringType}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">filt<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">NewStringFilter<\/span><span style=\"color: #D4D4D4\">(&amp;ConstExpr{StringField{<\/span><span style=\"color: #CE9178\">&quot;sam&quot;<\/span><span style=\"color: #D4D4D4\">}, StringType}, OpEq, &amp;FieldExpr{f}, hf)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func NewIntFilter(constExpr Expr, op BoolOp, field Expr, child Operator) (*Filter[int64], error) {\n\tif constExpr.GetExprType().Ftype != IntType || field.GetExprType().Ftype != IntType {\n\t\treturn nil, GoDBError{IncompatibleTypesError, &quot;cannot apply int filter to non int-types&quot;}\n\t}\n\tf, err := newFilter[int64](constExpr, op, field, child, intFilterGetter)\n\treturn f, err\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">NewIntFilter<\/span><span style=\"color: #D4D4D4\">(constExpr Expr, op BoolOp, field Expr, child Operator) (*Filter[<\/span><span style=\"color: #4EC9B0\">int64<\/span><span style=\"color: #D4D4D4\">], <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> constExpr.<\/span><span style=\"color: #DCDCAA\">GetExprType<\/span><span style=\"color: #D4D4D4\">().Ftype != IntType || field.<\/span><span style=\"color: #DCDCAA\">GetExprType<\/span><span style=\"color: #D4D4D4\">().Ftype != IntType {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, GoDBError{IncompatibleTypesError, <\/span><span style=\"color: #CE9178\">&quot;cannot apply int filter to non int-types&quot;<\/span><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">f<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := newFilter[<\/span><span style=\"color: #4EC9B0\">int64<\/span><span style=\"color: #D4D4D4\">](constExpr, op, field, child, intFilterGetter)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> f, err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p> \u7ee7\u7eed\u6765\u76f4\u63a5\u770bToDo\u3002\u8fd4\u56de\u4e00\u4e2aDesc\uff1f\u4f46\u662fFilter\u91cc\u9762\u53ea\u6709child\uff0c\u4f5c\u4e3aheapfile\u6709Descriptor\u65b9\u6cd5\uff0c\u90a3\u76f4\u63a5\u8fd4\u56de\u5373\u53ef\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ Return a TupleDescriptor for this filter op.\nfunc (f *Filter[T]) Descriptor() *TupleDesc {\n\t\/\/ TODO: some code goes here\n\treturn f.child.Descriptor()\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">\/\/ Return a TupleDescriptor for this filter op.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (f *Filter[T]) <\/span><span style=\"color: #DCDCAA\">Descriptor<\/span><span style=\"color: #D4D4D4\">() *TupleDesc {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> f.child.<\/span><span style=\"color: #DCDCAA\">Descriptor<\/span><span style=\"color: #D4D4D4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u81ea\u5df1\u5199\u4e2atest\u770b\u770b\u8f93\u51fa\u7ed3\u679c<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func TestDescriptor(t *testing.T) {\n\t_, t1, t2, hf, _, tid := makeTestVars()\n\thf.insertTuple(&amp;t1, tid)\n\thf.insertTuple(&amp;t2, tid)\n\tvar f FieldType = FieldType{&quot;age&quot;, &quot;&quot;, IntType}\n\tfilt, err := NewIntFilter(&amp;ConstExpr{IntField{25}, IntType}, OpGt, &amp;FieldExpr{f}, hf)\n\tif err != nil {\n\t\tt.Errorf(err.Error())\n\t}\n\tdesc := filt.Descriptor()\n\tfmt.Printf(&quot;filter desc: %v\\n&quot;, desc)\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">TestDescriptor<\/span><span style=\"color: #D4D4D4\">(t *testing.T) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">t1<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">t2<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">hf<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">tid<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">makeTestVars<\/span><span style=\"color: #D4D4D4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\thf.<\/span><span style=\"color: #DCDCAA\">insertTuple<\/span><span style=\"color: #D4D4D4\">(&amp;t1, tid)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\thf.<\/span><span style=\"color: #DCDCAA\">insertTuple<\/span><span style=\"color: #D4D4D4\">(&amp;t2, tid)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #569CD6\">var<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">f<\/span><span style=\"color: #D4D4D4\"> FieldType = FieldType{<\/span><span style=\"color: #CE9178\">&quot;age&quot;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&quot;&quot;<\/span><span style=\"color: #D4D4D4\">, IntType}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">filt<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">NewIntFilter<\/span><span style=\"color: #D4D4D4\">(&amp;ConstExpr{IntField{<\/span><span style=\"color: #B5CEA8\">25<\/span><span style=\"color: #D4D4D4\">}, IntType}, OpGt, &amp;FieldExpr{f}, hf)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tt.<\/span><span style=\"color: #DCDCAA\">Errorf<\/span><span style=\"color: #D4D4D4\">(err.<\/span><span style=\"color: #DCDCAA\">Error<\/span><span style=\"color: #D4D4D4\">())<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">desc<\/span><span style=\"color: #D4D4D4\"> := filt.<\/span><span style=\"color: #DCDCAA\">Descriptor<\/span><span style=\"color: #D4D4D4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tfmt.<\/span><span style=\"color: #DCDCAA\">Printf<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;filter desc: <\/span><span style=\"color: #9CDCFE\">%v<\/span><span style=\"color: #D7BA7D\">\\n<\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #D4D4D4\">, desc)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u55ef\uff0c\u6ca1\u6bdb\u75c5\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"964\" height=\"770\" src=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/5916c306212b6ba0ef6ce0a5ffeac71.png\" alt=\"\" class=\"wp-image-4171\" style=\"border-style:none;border-width:0px;border-radius:0px;width:723px;height:578px\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/5916c306212b6ba0ef6ce0a5ffeac71.png 964w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/5916c306212b6ba0ef6ce0a5ffeac71-300x240.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/5916c306212b6ba0ef6ce0a5ffeac71-768x613.png 768w\" sizes=\"(max-width: 964px) 100vw, 964px\" \/><\/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>Iterator<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u53c8\u8981\u5199\u4e2a\u8fed\u4ee3\u5668\uff0c\u90a3\u5148\u6765\u770b\u770b\u8981\u5b9e\u73b0\u4ec0\u4e48\u5427\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ Filter operator implementation. This function should iterate over\n\/\/ the results of the child iterator and return a tuple if it satisfies\n\/\/ the predicate.\n\/\/ HINT: you can use the evalPred function defined in types.go to compare two values\nfunc (f *Filter[T]) Iterator(tid TransactionID) (func() (*Tuple, error), error) {\n\t\/\/ TODO: some code goes here\n\t\n\treturn nil, nil\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">\/\/ Filter operator implementation. This function should iterate over<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ the results of the child iterator and return a tuple if it satisfies<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ the predicate.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ HINT: you can use the evalPred function defined in types.go to compare two values<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (f *Filter[T]) <\/span><span style=\"color: #DCDCAA\">Iterator<\/span><span style=\"color: #D4D4D4\">(tid TransactionID) (<\/span><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\">() (*Tuple, <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">), <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u6839\u636e\u4e4b\u524d\u5728heap file\u548cheap page\u4e2d\u7f16\u5199\u8fed\u4ee3\u5668\u7684\u7ecf\u9a8c\uff0c\u5148\u5199\u4e2a\u533f\u540d\u51fd\u6570\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func (f *Filter[T]) Iterator(tid TransactionID) (func() (*Tuple, error), error) {\n\t\/\/ TODO: some code goes here\n\treturn func() (*Tuple, error) {\n\t\treturn nil, nil\n\t}, nil\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (f *Filter[T]) <\/span><span style=\"color: #DCDCAA\">Iterator<\/span><span style=\"color: #D4D4D4\">(tid TransactionID) (<\/span><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\">() (*Tuple, <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">), <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\">() (*Tuple, <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}, <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u63a5\u4e0b\u6765\u60f3\u4e0b\u8be5\u5b9e\u73b0\u4ec0\u4e48\u529f\u80fd\u3002Filter\uff0c\u5b57\u9762\u610f\u601d\u6765\u7406\u89e3\u7684\u8bdd\u5c31\u662f\u7b5b\u9009\u51fa\u7279\u5b9a\u7684\u5b57\u6bb5\u3002\u540c\u65f6\u6ce8\u91ca\u4e2d\u53c8\u63d0\u5230\u4e86\u904d\u5386\u5b50\u8fed\u4ee3\u5668\u7684\u6240\u6709\u7ed3\u679c\uff0c\u5e76\u8fd4\u56de\u5408\u9002\u7684tuple\u3002\u90a3\u5148\u5199\u4e2a\u5927\u81f4\u7ed3\u6784\u51fa\u6765\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func (f *Filter[T]) Iterator(tid TransactionID) (func() (*Tuple, error), error) {\n\t\/\/ TODO: some code goes here\n\titer, err := f.child.Iterator(tid)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn func() (*Tuple, error) {\n\t\tfor {\n\t\t\ttuple, err := iter()\n\t\t\tif err != nil || tuple == nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\treturn tuple, nil\n\t\t}\n\t}, nil\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (f *Filter[T]) <\/span><span style=\"color: #DCDCAA\">Iterator<\/span><span style=\"color: #D4D4D4\">(tid TransactionID) (<\/span><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\">() (*Tuple, <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">), <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">iter<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := f.child.<\/span><span style=\"color: #DCDCAA\">Iterator<\/span><span style=\"color: #D4D4D4\">(tid)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\">() (*Tuple, <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #9CDCFE\">tuple<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">iter<\/span><span style=\"color: #D4D4D4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> || tuple == <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> tuple, <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}, <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>test\u4e00\u4e0b\u770b\u770b\u80fd\u8f93\u51fa\u4ec0\u4e48\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"785\" height=\"785\" src=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/f1dfbdb9fafe24f0f120373c6a4a0a8.png\" alt=\"\" class=\"wp-image-4174\" style=\"border-style:none;border-width:0px;border-radius:0px;width:589px;height:589px\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/f1dfbdb9fafe24f0f120373c6a4a0a8.png 785w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/f1dfbdb9fafe24f0f120373c6a4a0a8-300x300.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/f1dfbdb9fafe24f0f120373c6a4a0a8-150x150.png 150w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/f1dfbdb9fafe24f0f120373c6a4a0a8-768x768.png 768w\" sizes=\"(max-width: 785px) 100vw, 785px\" \/><\/figure>\n\n\n\n<p>\u8fd4\u56de\u7684cnt\u662f2\uff0c\u800c\u6211\u4eec\u9700\u89811\uff0c\u8bf4\u660e\u7f3a\u5c11if\u5224\u65ad\u662f\u5426\u5339\u914d\u7684\u6761\u4ef6\u3002\u4f46\u662fif\u5230\u5e95\u5e94\u8be5\u5224\u65ad\u4ec0\u4e48\u5462\uff1f<\/p>\n\n\n\n<p>\u522b\u5fd8\u4e86\u6211\u4eec\u8fd8\u6ca1\u7528\u4e0aFilter\u3002\u6211\u4eec\u6253\u4e2a\u65ad\u70b9\u770b\u770b\u6b64\u65f6filter\u4e2d\uff0c\u5404\u4e2a\u6570\u636e\u6210\u5458\u7684\u503c\u662f\u4ec0\u4e48\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"280\" src=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/abdfee010879ecb4737ba888f43609e-1024x280.png\" alt=\"\" class=\"wp-image-4177\" style=\"border-style:none;border-width:0px;border-radius:0px;width:768px;height:210px\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/abdfee010879ecb4737ba888f43609e-1024x280.png 1024w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/abdfee010879ecb4737ba888f43609e-300x82.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/abdfee010879ecb4737ba888f43609e-768x210.png 768w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/abdfee010879ecb4737ba888f43609e.png 1416w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>op\u7684\u503c\u662fopgt?\u60f3\u5230gt\u90a3\u5c31\u662fgreater than\u3002\u90a3\u4e48\u4e3a\u4ec0\u4e48\u8981\u63d0\u5230op\u5462\uff1f\u6ce8\u91ca\u4e2d\u63d0\u5230\u4e00\u70b9<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ HINT: you can use the evalPred function defined in types.go to compare two values\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">\/\/ HINT: you can use the evalPred function defined in types.go to compare two values<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u90a3\u6211\u4eec\u5c31\u770b\u770bevalPred\u662f\u5e72\u4ec0\u4e48\u7684\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func evalPred[T constraints.Ordered](i1 T, i2 T, op BoolOp) bool {\n\tswitch op {\n\tcase OpEq:\n\t\treturn i1 == i2\n\tcase OpNeq:\n\t\treturn i1 != i2\n\tcase OpGt:\n\t\treturn i1 &gt; i2\n\tcase OpGe:\n\t\treturn i1 &gt;= i2\n\tcase OpLt:\n\t\treturn i1 &lt; i2\n\tcase OpLe:\n\t\treturn i1 &lt;= i2\n\tcase OpLike:\n\t\ts1, ok := any(i1).(string)\n\t\tif !ok {\n\t\t\treturn false\n\t\t}\n\t\tregex, ok := any(i2).(string)\n\t\tif !ok {\n\t\t\treturn false\n\t\t}\n\t\tregex = &quot;^&quot; + regex + &quot;$&quot;\n\t\tregex = strings.Replace(regex, &quot;%&quot;, &quot;.*?&quot;, -1)\n\t\tmatch, _ := regexp.MatchString(regex, s1)\n\t\treturn match\n\t}\n\treturn false\n\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> evalPred[T constraints.Ordered](i1 T, i2 T, op BoolOp) <\/span><span style=\"color: #4EC9B0\">bool<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">switch<\/span><span style=\"color: #D4D4D4\"> op {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">case<\/span><span style=\"color: #D4D4D4\"> OpEq:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> i1 == i2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">case<\/span><span style=\"color: #D4D4D4\"> OpNeq:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> i1 != i2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">case<\/span><span style=\"color: #D4D4D4\"> OpGt:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> i1 &gt; i2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">case<\/span><span style=\"color: #D4D4D4\"> OpGe:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> i1 &gt;= i2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">case<\/span><span style=\"color: #D4D4D4\"> OpLt:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> i1 &lt; i2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">case<\/span><span style=\"color: #D4D4D4\"> OpLe:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> i1 &lt;= i2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">case<\/span><span style=\"color: #D4D4D4\"> OpLike:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #9CDCFE\">s1<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">ok<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">any<\/span><span style=\"color: #D4D4D4\">(i1).(<\/span><span style=\"color: #4EC9B0\">string<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> !ok {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">false<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #9CDCFE\">regex<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">ok<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">any<\/span><span style=\"color: #D4D4D4\">(i2).(<\/span><span style=\"color: #4EC9B0\">string<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> !ok {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">false<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #9CDCFE\">regex<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;^&quot;<\/span><span style=\"color: #D4D4D4\"> + regex + <\/span><span style=\"color: #CE9178\">&quot;$&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #9CDCFE\">regex<\/span><span style=\"color: #D4D4D4\"> = strings.<\/span><span style=\"color: #DCDCAA\">Replace<\/span><span style=\"color: #D4D4D4\">(regex, <\/span><span style=\"color: #CE9178\">&quot;%&quot;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&quot;.*?&quot;<\/span><span style=\"color: #D4D4D4\">, -<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #9CDCFE\">match<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\"> := regexp.<\/span><span style=\"color: #DCDCAA\">MatchString<\/span><span style=\"color: #D4D4D4\">(regex, s1)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> match<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">false<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u8fd9\u4e0d\u5c31\u662f\u6839\u636e\u8f93\u5165\u7684op\uff0c\u518d\u8fdb\u884c\u76f8\u5e94\u7684\u6761\u4ef6\u5224\u65ad\u561b\u3002\u6bd4\u5982op\u662fopgt\uff0c\u5de6\u503c\u662fuser_id\uff0c\u53f3\u8fb9\u662f2\u7684\u8bdd\uff0c\u5199\u6210\u5bf9\u5e94\u7684SQL\u5c31\u5e94\u8be5\u662f<\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong><em>WHERE user_id opgt 2<\/em><\/strong><\/p>\n\n\n\n<p>\u90a3\u5c31\u597d\u5199\u4e86\u3002\u53bb\u5bf9\u5e94\u5b57\u6bb5\u7684\u503c\uff0c\u7136\u540e\u6839\u636eop\u8fd4\u56detrue\u8fd8\u662ffalse\u6765\u7b5b\u9009\u6700\u540e\u5f97\u5230\u7684\u6570\u636e\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func (f *Filter[T]) Iterator(tid TransactionID) (func() (*Tuple, error), error) {\n\t\/\/ TODO: some code goes here\n\titer, err := f.child.Iterator(tid)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn func() (*Tuple, error) {\n\t\tfor {\n\t\t\ttuple, err := iter()\n\t\t\tif err != nil || tuple == nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tleftVal, _ := f.left.EvalExpr(tuple)\n\t\t\trightVal, _ := f.right.EvalExpr(tuple)\n\t\t\ttmp := evalPred(f.getter(leftVal), f.getter(rightVal), f.op)\n\t\t\t_ = tmp\n\t\t\tif evalPred(f.getter(leftVal), f.getter(rightVal), f.op) {\n\t\t\t\treturn tuple, nil\n\t\t\t}\n\t\t}\n\t}, nil\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> (f *Filter[T]) <\/span><span style=\"color: #DCDCAA\">Iterator<\/span><span style=\"color: #D4D4D4\">(tid TransactionID) (<\/span><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\">() (*Tuple, <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">), <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">\/\/ TODO: some code goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #9CDCFE\">iter<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := f.child.<\/span><span style=\"color: #DCDCAA\">Iterator<\/span><span style=\"color: #D4D4D4\">(tid)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\">() (*Tuple, <\/span><span style=\"color: #4EC9B0\">error<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t<\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #9CDCFE\">tuple<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">err<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">iter<\/span><span style=\"color: #D4D4D4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> err != <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> || tuple == <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">nil<\/span><span style=\"color: #D4D4D4\">, err<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #9CDCFE\">leftVal<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\"> := f.left.<\/span><span style=\"color: #DCDCAA\">EvalExpr<\/span><span style=\"color: #D4D4D4\">(tuple)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #9CDCFE\">rightVal<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\"> := f.right.<\/span><span style=\"color: #DCDCAA\">EvalExpr<\/span><span style=\"color: #D4D4D4\">(tuple)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #9CDCFE\">tmp<\/span><span style=\"color: #D4D4D4\"> := <\/span><span style=\"color: #DCDCAA\">evalPred<\/span><span style=\"color: #D4D4D4\">(f.<\/span><span style=\"color: #DCDCAA\">getter<\/span><span style=\"color: #D4D4D4\">(leftVal), f.<\/span><span style=\"color: #DCDCAA\">getter<\/span><span style=\"color: #D4D4D4\">(rightVal), f.op)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\"> = tmp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">evalPred<\/span><span style=\"color: #D4D4D4\">(f.<\/span><span style=\"color: #DCDCAA\">getter<\/span><span style=\"color: #D4D4D4\">(leftVal), f.<\/span><span style=\"color: #DCDCAA\">getter<\/span><span style=\"color: #D4D4D4\">(rightVal), f.op) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t\t<\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> tuple, <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t}, <\/span><span style=\"color: #569CD6\">nil<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>run\u4e00\u4e0btest\uff0c\u4e24\u4e2atest\u90fd\u80fd\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\" width=\"812\" height=\"635\" src=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/56a90d90c3a08336828689c8a2e1bdc.png\" alt=\"\" class=\"wp-image-4180\" style=\"border-style:none;border-width:0px;border-radius:0px;width:609px;height:476px\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/56a90d90c3a08336828689c8a2e1bdc.png 812w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/56a90d90c3a08336828689c8a2e1bdc-300x235.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/56a90d90c3a08336828689c8a2e1bdc-768x601.png 768w\" sizes=\"(max-width: 812px) 100vw, 812px\" \/><\/figure>\n\n\n\n<p>\u4e0b\u7bc7\u518d\u770b\u770b\u600e\u4e48\u5b9e\u73b0join\uff0c\u4e89\u53d62\u5929\u5185\u5199\u5b8c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lab2\u5b9e\u9a8c\u8bb0\u5f55\uff1a\u4e86\u89e3lab2<\/p>\n","protected":false},"author":1,"featured_media":4171,"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\/4133"}],"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=4133"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/4133\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/4171"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=4133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=4133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=4133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}