Repository navigation
グループ化と集約を行う GroupByPlan を入れる - #35
Merged
Merged
Conversation
…value a field holds in it グループ化で使う集約関数。グループの最初の行で値をやり直し、続く行で更新する形にする。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… by groups on グループ化で、行が直前のグループに属するかを判定し、グループのフィールドの値を返すのに使う。 Constant は == で比べられるので、map ではなく slice で持って slices.Equal で比べる。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the values of its aggregation functions ソート済みの入力では同じグループの行が隣り合うので、入力を一度読むだけでグループごとの集約値を出せる。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…with the values of its aggregation functions 入力をグループのフィールドでソートしてから GroupByScan で読む。 集約結果のフィールドの型は各集約関数が決め、varchar の max が int にならないようにする。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
プランの行をフィールドの値でグループに分け、グループごとに count / max を求める
GroupByPlanを追加した。SimpleDB のAggregationFn/CountFn/MaxFn/GroupValue/GroupByScan/GroupByPlanに相当する。#34 のSortPlanの上に作っている。この PR ではまだ planner からは使わない(
group byも集約関数も解析しない)。materializeAggregationFn:グループの行を 1 行ずつ受け取って値を求める集約関数のインターフェース。グループの最初の行でProcessFirst、続く行でProcessNextを呼ぶCountFn(countof<field>)、MaxFn(maxof<field>)GroupValue:グループ化するフィールドについて、行が持つ値の組GroupByScan:グループ化するフィールドでソート済みの入力を 1 回読み、グループごとに 1 行を返すplanGroupByPlan:入力をSortPlanでグループ化するフィールドの順に並べ、GroupByScanで読む設計上の判断
AggregationFn.AddFieldTo)。 SimpleDB のGroupByPlanは、集約結果のフィールドをすべて int としてスキーマに足すので、varchar の max が int になる。CountFnは int、MaxFnは元のフィールドと同じ型と長さにした。NewGroupByPlanで拒む。 グループ化するフィールドと max のフィールドが入力にないとErrFieldNotFoundを返す。ProjectPlanと同じく、プランを組む段階でわかるようにするため。GroupValueは map ではなく、フィールド名と値の 2 つの slice で持つ。Constantは==で比べられるので、slices.Equalでグループの境目を判定できる。Go の map は==で比べられない。GroupByPlan.DistinctValuesは、グループ化するフィールドなら入力の値、それ以外(集約結果)ならグループ数を返す。 SimpleDB は「入力のスキーマにあるか」で分けるので、グループ化していない入力のフィールドにも入力の値を返してしまう。RecordsOutputは、グループ化するフィールドごとの distinct の積(SimpleDB と同じ)。 フィールドがなければ 1。BlocksAccessedはSortPlanと同じく、ソート済みの行を 1 回読むコストだけ。GroupByScan.GetValueは、グループの上にいなければErrNoCurrentRecord、グループ化も集約もしていないフィールドならErrFieldNotFoundを返す。既知の制限
GroupByPlanから 2 つのスキャンを同時に開くと、互いの値を上書きする。今は 1 つのプランを 1 回だけ開く使い方しかないので、そのままにした。select count(x) from tは空の表でも count 0 の 1 行を返すが、それには合わせていない(SimpleDB と同じ)。GroupByPlanはまだどの planner からも使われない。テスト
CountFn/MaxFn:フィールド名、1 行・複数行のグループの値、次のグループで値をやり直すこと、int と varchar の max、max で型の違う値を比べるとErrConstantTypeMismatch、AddFieldToの型と長さ、ないフィールドの max はErrFieldNotFoundGroupValue:グループ化するフィールドの値を返すこと、グループ化していないフィールドは持たないこと、Equals(同じ値、1 つのフィールドだけ違う値、グループ化していないフィールドだけ違う値)GroupByScan:3 つのグループ、1 つのグループ、0 行、グループ化するフィールドなし(全体で 1 グループ)、読み直し、知らないフィールドでErrFieldNotFound、移動の前に読むとErrNoCurrentRecord、HasFieldGroupByPlan:ないフィールドでErrFieldNotFound、順番がばらばらの表をグループ化(ソートされること)、フィールドなし、空の表、BlocksAccessed/RecordsOutput/DistinctValues/SchemaCountFn/MaxFn:次のグループで値をやり直さないGroupValue:グループ化していないフィールドも持つと答える、最後のフィールドを比べないGroupByScan:グループの境目を見ない、最後のグループを返さない、読み直しで入力を巻き戻さない、HasFieldが常に true、知らないフィールドで別のエラーを返すGroupByPlan:入力をソートしない、グループ数を distinct の和にする、集約フィールドのDistinctValuesに入力の値を返す🤖 Generated with Claude Code