Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced scan_info definition with the range class #129

Merged
merged 4 commits into from
Nov 13, 2024

Conversation

YoshiakiNishimura
Copy link
Contributor

#127 の続き

@YoshiakiNishimura YoshiakiNishimura force-pushed the move-key-to-scan-info4 branch 3 times, most recently from f3cc94f to d304948 Compare October 31, 2024 07:50
@YoshiakiNishimura
Copy link
Contributor Author

@kuron99 scan_infoをrangeに書き換えました。まだtestを通ってませんのでtestが通るように随時調整していきます

@YoshiakiNishimura
Copy link
Contributor Author

YoshiakiNishimura commented Oct 31, 2024

テスト失敗メモ

場所

api_test.scan_with_host_variable

fail_log.txt

Expected equality of these values:
  ""
    Which is: 0x560488566cbb
  builder() .text(query) .params(params) .vars(variables) .output_records(out) .run() .report()
    Which is: "execution failed. executor::execute() - err_integrity_constraint_violation"

/home/nishimura/git/tsurugidb/jogasaki/test/jogasaki/api/api_test_base.cpp:158: Failure
Expected equality of these values:
  ""
    Which is: 0x560488566cbb                                                                                    builder() .text(query) .params(params) .vars(variables) .output_records(out) .run() .report()
    Which is: "execution failed. executor::execute() - err_integrity_constraint_violation"    

テスト考察

実際のQueryは通るのでテスト固有の問題

tgsql> CREATE TABLE T0 (C0 INT,C1 FLOAT);
     | INSERT INTO T0 (C0, C1) VALUES (20,20.0);
     | INSERT INTO T0 (C0, C1) VALUES (10,10.0);
     |
     | SELECT * FROM T0 WHERE C0 > 15 AND C0 < 25;
     | SELECT * FROM T0 WHERE C0 > 15 AND C0 < null;
     | SELECT * FROM T0 WHERE C0 > null AND C0 < 15;

[C0: INT4, C1: FLOAT4]
[20, 20.0]
(1 row)

[C0: INT4, C1: FLOAT4]
(0 rows)

[C0: INT4, C1: FLOAT4]
(0 rows)

@kuron99
Copy link
Contributor

kuron99 commented Nov 11, 2024

@YoshiakiNishimura 変更前のコードだと下記部分で「レンジの上端または下端がNULLの場合はnot foundにする」というケアをしているのでこのパスが変更後にどうなったかを調べてもらうといいかもしれません。

if(res == status::err_integrity_constraint_violation) {

@YoshiakiNishimura
Copy link
Contributor Author

@YoshiakiNishimura 変更前のコードだと下記部分で「レンジの上端または下端がNULLの場合はnot foundにする」というケアをしているのでこのパスが変更後にどうなったかを調べてもらうといいかもしれません。

if(res == status::err_integrity_constraint_violation) {

@kuron99

問題の箇所は以下です

VLOG_LP(log_debug) << "Null assigned for non-nullable field.";

直観として下のコードを書いた場合、上のreturnを通りそうですが、従来はどのような考えで上の処理を通らないようにしていたのですか?

        ps->set_null("p0");
        std::vector<mock::basic_record> result{};
        execute_query("SELECT * FROM T0 WHERE C0 < :p0", variables, *ps, result);

@kuron99
Copy link
Contributor

kuron99 commented Nov 11, 2024

@YoshiakiNishimura

直観として下のコードを書いた場合、上のreturnを通りそうですが、従来はどのような考えで上の処理を通らないようにしていたのですか?

上のreturnを通っていたと思いますよ。通ったうえでその戻り値 status::err_integrity_constraint_violationが、#129 (comment) のところまで行って、NULLが検知されたことをケアするという動きになっていました。

@kuron99
Copy link
Contributor

kuron99 commented Nov 11, 2024

考え方としては、INSERT文などでnon-nullableなフィールドにnullをアサインしようとするとNULL制約違反のためencode_keyはstatus::err_integrity_constraint_violationを戻すのですが、encode_keyをscanに使用した場合は条件文の中の話なのでNULL制約違反とはいえなくて「その条件で検索しても何もみつからない」というscanになになります。

厳密にはencode_keyがerr_integrity_constraint_violationを戻すのはやりすぎで「エンコードしようとしたものがNULLだった」ということを返して呼び出し側が判定すべきですが、encode_keyは古いコードでよくないですね。

@YoshiakiNishimura
Copy link
Contributor Author

考え方としては、INSERT文などでnon-nullableなフィールドにnullをアサインしようとするとNULL制約違反のためencode_keyはstatus::err_integrity_constraint_violationを戻すのですが、encode_keyをscanに使用した場合は条件文の中の話なのでNULL制約違反とはいえなくて「その条件で検索しても何もみつからない」というscanになになります。

厳密にはencode_keyがerr_integrity_constraint_violationを戻すのはやりすぎで「エンコードしようとしたものがNULLだった」ということを返して呼び出し側が判定すべきですが、encode_keyは古いコードでよくないですね。

@kuron99

原因わかりました。
今までは
scan::open のdetails::encode_keyのreturn値がstatus::err_integrity_constraint_violationの場合scan::operatorが


152行でreturnします。

今回details::encode_keyを前に移動して下記の通り処理してますので152行でreturnしません。

    auto status_result = details::two_encode_keys(request_context_,
        details::create_search_key_fields(secondary_or_primary_index, node.lower().keys(), *info_),
        details::create_search_key_fields(secondary_or_primary_index, node.upper().keys(), *info_),
        vars, *resource_ptr, *key_begin, blen, *key_end, elen);
    if (status_result != status::ok) {
        auto msg = string_builder{} << to_string_view(status_result) << string_builder::to_string;
        throw_exception(jogasaki::plan::impl::compile_exception{create_error_info(
            error_code::sql_execution_exception, msg, status::err_compiler_error)});
    }

今回scan_infoをrangeにしてbegin_,end_だけにしましたが、scan::openにstatus::err_integrity_constraint_violationの情報を伝えるために情報を保持する、statusメンバーを追加いたします。

class range
  private:
    std::unique_ptr<bound> begin_;
    std::unique_ptr<bound> end_;
};

@kuron99
Copy link
Contributor

kuron99 commented Nov 11, 2024

今回scan_infoをrangeにしてbegin_,end_だけにしましたが、scan::openにstatus::err_integrity_constraint_violationの情報を伝えるために情報を保持する、statusメンバーを追加いたします。

scan結果が空になるということを伝えるためですよね。であれば、statusメンバではなく bool is_empty みたいなプロパティで「空のレンジ」を示すようにするのでどうでしょうか。encode_keyからstatus::err_integrity_constraint_violationから戻された場合は空のレンジを作るようにすると。

@YoshiakiNishimura YoshiakiNishimura force-pushed the move-key-to-scan-info4 branch 2 times, most recently from 286bf39 to c492896 Compare November 11, 2024 10:05
@YoshiakiNishimura YoshiakiNishimura marked this pull request as ready for review November 11, 2024 10:40
@YoshiakiNishimura
Copy link
Contributor Author

@kuron99
対応完了しました

@@ -48,15 +48,15 @@ class processor : public process::abstract::processor {
* @param io_info input/output information
* @param relation_io_map mapping from relation to input/output indices
* @param io_exchange_map map from input/output to exchange operator
* @param resource the memory resource to build the structures needed by this processor
* @param request_context memory resource for initializing and managing processor structures
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

渡しているものは request_contextで、コメントの説明は memory resource と言っているのでズレがあります。
あくまで渡すmemory resourceの説明をしたいなら、request_context to pass memory resource ... あたりでしょうか。

@@ -57,15 +57,15 @@ class task_context : public abstract::task_context {
* @brief create new object
* @param partition the index of partition assigned to this object (used as index of source on the input exchange)
* @param io_exchange_map mapping from input/output indices to exchanges
* @param scan_info the scan information, nullptr if the task doesn't contain scan
* @param range the range information, nullptr if the task doesn't contain range
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the task doesn't contain range の最後の rangescan のままでいいです。タスクが scan処理を含まなければscan_infoやrangeの指定は不要だという意味なので。

{
(void)resource_; //TODO remove if not necessary
}
operator_builder::operator_builder(std::shared_ptr<processor_info> info,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このファイル全体にフォーマッターが適用されているように見えますが、意図的なものでしょうか?

不要なフォーマット変更がdiffに含まれているようなので、レビューしやすいように今回の変更に必要なものだけにしてもらえますか。

もしフォーマットを一括で変更したい場合は別途相談してください。
またその場合もレビューの邪魔にならないようにコミットを分けて適用しましょう。

@@ -83,14 +83,14 @@ class operator_builder {
* @param compiler_ctx compiler context
* @param io_info I/O information
* @param relation_io_map mapping from relation to I/O index
* @param resource the memory resource used to building operators
* @param request_context the memory resource used to building operators
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the memory resource used to building operators の部分も合わせて変更してください。

*/
class scan_info {
public:
class range {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

趣味の問題に近いですが、rangeという単純名だとstd::rangeみたいなものもあるので、scan_rangeあたりにしませんか?rangeだと一般名で検索でヒットしすぎるので少しだけ修飾したいという思いです。

range& operator=(range const& other) = delete;
range(range&& other) noexcept = default;
range& operator=(range&& other) noexcept = default;
[[nodiscard]] bound const* begin() const noexcept;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rangeが保持するboundがnullptrであるという状態はどういうレンジを表現していると考えるべきでしょうか?もしその状態が必須でなければ、レンジは必ずboundを持つことにして、この関数の戻り値を bound const& にしてもいいような気がします。その方が呼び出し側で boundがnullptrがどうかというチェックが不要になるので使いやすそう。

@@ -238,6 +237,7 @@ inline std::ostream& operator<<(std::ostream& out, storage const& value) {
out << "storage(handle:" << std::hex << value.handle() << ")";
return out;
}

end_point_kind adjust_endpoint_kind(bool use_secondary, kvs::end_point_kind endpoint);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc commentを追加して用途と目的を簡単に書いてください。

Copy link
Contributor

@kuron99 kuron99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

レビューしてコメントしました。

@YoshiakiNishimura YoshiakiNishimura marked this pull request as draft November 13, 2024 04:50
@YoshiakiNishimura YoshiakiNishimura marked this pull request as ready for review November 13, 2024 05:19
@YoshiakiNishimura
Copy link
Contributor Author

@kuron99 指摘反映しました

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

すごい細かい話ですが、ファイルの末尾に改行だけを含む空の行を追加してもらえますか?
古いC言語の規約でファイル末尾は空の行でないとならないという話があって、最近のC++では関係ないはずなのですが、各種フォーマッタがこれに準じて勝手に空行を挿入しgitにdiffとして検出されてしまうことがあるので。

: begin_(std::move(begin)), end_(std::move(end)), is_empty_(is_empty) {

BOOST_ASSERT(&begin_);
BOOST_ASSERT(&end_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この2つのassertはthisがnullptrになる場合くらいしかfalseにならないのであまり意味がなさそうに見えます。

@@ -20,18 +20,17 @@

namespace jogasaki::executor::process::impl {

class range : public abstract::range {
class scan_range : public abstract::range {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scan_rangeをコンテナに入れることがありそうな気がするので、デフォルトコンストラクタも追加しませんか。空のレンジ(is_empty_ = true)を作るものということにするといいと思います。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

クラス名に合わせてファイル名も scan_range.h/.cppへ変更お願いします。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらのファイルも末尾に空行追加おねがいします。

@@ -39,14 +39,14 @@ class operator_container {
* @param root the root of the operator tree
* @param operator_count the number of operators
* @param io_exchange_map the mapping from input/output index to exchange
* @param range the range gathered from the scan operator in the operator tree (if any).
* @param scan_range the range gathered from the scan operator in the operator tree (if any).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@param の直後は変数名なのでここは range のままでOKです。

@@ -53,7 +53,7 @@ class scan_context : public context_base {
std::unique_ptr<kvs::storage> stg,
std::unique_ptr<kvs::storage> secondary_stg,
transaction_context* tx,
impl::range const* range_,
impl::scan_range const* range_,
Copy link
Contributor

@kuron99 kuron99 Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

仮変数名は末尾のアンダースコア不要ですね。


}

} // jogasaki::executor::process::mock
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここも空行を維持でお願いします。

};

}
} // namespace jogasaki::executor::process::mock
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここも空行を維持でお願いします。


}

} // namespace jogasaki::data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここも空行を維持でお願いします。

Copy link
Contributor

@kuron99 kuron99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

レビュー完了しました。ファイル末尾の空行は全部指摘していませんが、抜けているものがあれば空行を維持する方向でお願いします。

@YoshiakiNishimura YoshiakiNishimura marked this pull request as draft November 13, 2024 07:14
@YoshiakiNishimura YoshiakiNishimura force-pushed the move-key-to-scan-info4 branch 2 times, most recently from 726575d to 0814847 Compare November 13, 2024 07:52
@YoshiakiNishimura YoshiakiNishimura marked this pull request as ready for review November 13, 2024 08:22
@kuron99
Copy link
Contributor

kuron99 commented Nov 13, 2024

@YoshiakiNishimura #129 (comment) だけまだ未対応でしょうか?

Copy link
Contributor

@kuron99 kuron99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上記( #129 (comment) )が完了したらマージしてもらってOKです。

@YoshiakiNishimura YoshiakiNishimura merged commit 4d467d6 into master Nov 13, 2024
10 checks passed
@YoshiakiNishimura YoshiakiNishimura deleted the move-key-to-scan-info4 branch November 13, 2024 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants