diff options
author | stanly <stanly@yandex-team.com> | 2023-04-04 12:10:23 +0300 |
---|---|---|
committer | stanly <stanly@yandex-team.com> | 2023-04-04 12:10:23 +0300 |
commit | 9c48614ae2f89da0fdea72887e14ba87717bddd2 (patch) | |
tree | 182ff6981781fcea80b7f06453e5fa998a692cca | |
parent | 7c5ef2a5f8a2b7e1be3102dd0920bb0a44bc3a73 (diff) | |
download | ydb-9c48614ae2f89da0fdea72887e14ba87717bddd2.tar.gz |
use std::move to pass fields to Schema
The fields parameter passed to constructor of arrow:Schema via value.
By using std::move we slightly reduce numbers of temporary copies of FieldVector.
-rw-r--r-- | ydb/core/formats/arrow_helpers.cpp | 4 | ||||
-rw-r--r-- | ydb/core/formats/converter.cpp | 6 | ||||
-rw-r--r-- | ydb/core/formats/program.cpp | 6 | ||||
-rw-r--r-- | ydb/core/formats/ut_arrow.cpp | 2 | ||||
-rw-r--r-- | ydb/core/kqp/executer_actor/kqp_executer_impl.cpp | 2 | ||||
-rw-r--r-- | ydb/core/kqp/runtime/kqp_scan_data_ut.cpp | 2 | ||||
-rw-r--r-- | ydb/core/testlib/cs_helper.cpp | 2 | ||||
-rw-r--r-- | ydb/core/tx/columnshard/engines/portion_info.cpp | 6 | ||||
-rw-r--r-- | ydb/core/tx/columnshard/engines/ut_logs_engine.cpp | 6 |
9 files changed, 17 insertions, 19 deletions
diff --git a/ydb/core/formats/arrow_helpers.cpp b/ydb/core/formats/arrow_helpers.cpp index 1f69013daf6..9e7efe684a5 100644 --- a/ydb/core/formats/arrow_helpers.cpp +++ b/ydb/core/formats/arrow_helpers.cpp @@ -377,7 +377,7 @@ std::shared_ptr<arrow::RecordBatch> ExtractColumns(const std::shared_ptr<arrow:: columns.push_back(srcBatch->column(pos)); } - return arrow::RecordBatch::Make(std::make_shared<arrow::Schema>(fields), srcBatch->num_rows(), columns); + return arrow::RecordBatch::Make(std::make_shared<arrow::Schema>(std::move(fields)), srcBatch->num_rows(), std::move(columns)); } std::shared_ptr<arrow::RecordBatch> ExtractColumns(const std::shared_ptr<arrow::RecordBatch>& srcBatch, @@ -425,7 +425,7 @@ std::shared_ptr<arrow::RecordBatch> ExtractExistedColumns(const std::shared_ptr< } } - return arrow::RecordBatch::Make(std::make_shared<arrow::Schema>(fields), srcBatch->num_rows(), columns); + return arrow::RecordBatch::Make(std::make_shared<arrow::Schema>(std::move(fields)), srcBatch->num_rows(), std::move(columns)); } std::shared_ptr<arrow::Table> CombineInTable(const std::vector<std::shared_ptr<arrow::RecordBatch>>& batches) { diff --git a/ydb/core/formats/converter.cpp b/ydb/core/formats/converter.cpp index e43f615d048..f34ad2eaac8 100644 --- a/ydb/core/formats/converter.cpp +++ b/ydb/core/formats/converter.cpp @@ -114,7 +114,7 @@ std::shared_ptr<arrow::RecordBatch> ConvertColumns(const std::shared_ptr<arrow:: } } } - return arrow::RecordBatch::Make(std::make_shared<arrow::Schema>(fields), batch->num_rows(), columns); + return arrow::RecordBatch::Make(std::make_shared<arrow::Schema>(std::move(fields)), batch->num_rows(), std::move(columns)); } static std::shared_ptr<arrow::Array> InplaceConvertColumn(const std::shared_ptr<arrow::Array>& column, @@ -157,8 +157,8 @@ std::shared_ptr<arrow::RecordBatch> InplaceConvertColumns(const std::shared_ptr< } fields.push_back(std::make_shared<arrow::Field>(colName, columns[i]->type())); } - auto resultSchemaFixed = std::make_shared<arrow::Schema>(fields); - auto convertedBatch = arrow::RecordBatch::Make(resultSchemaFixed, batch->num_rows(), columns); + auto resultSchemaFixed = std::make_shared<arrow::Schema>(std::move(fields)); + auto convertedBatch = arrow::RecordBatch::Make(resultSchemaFixed, batch->num_rows(), std::move(columns)); Y_VERIFY(convertedBatch->ValidateFull() == arrow::Status::OK()); return convertedBatch; } diff --git a/ydb/core/formats/program.cpp b/ydb/core/formats/program.cpp index 3c9fcda4b1e..4099208f3af 100644 --- a/ydb/core/formats/program.cpp +++ b/ydb/core/formats/program.cpp @@ -603,7 +603,7 @@ arrow::Status TProgramStep::ApplyAggregates( res.Rows = gbBatch->num_rows(); } - res.Schema = std::make_shared<arrow::Schema>(fields); + res.Schema = std::make_shared<arrow::Schema>(std::move(fields)); batch = std::move(res); return arrow::Status::OK(); } @@ -701,7 +701,7 @@ arrow::Status TProgramStep::ApplyProjection(TDatumBatch& batch) const { newFields.push_back(batch.Schema->field(schemaFieldIndex)); newDatums.push_back(batch.Datums[schemaFieldIndex]); } - batch.Schema = std::make_shared<arrow::Schema>(newFields); + batch.Schema = std::make_shared<arrow::Schema>(std::move(newFields)); batch.Datums = std::move(newDatums); return arrow::Status::OK(); } @@ -718,7 +718,7 @@ arrow::Status TProgramStep::ApplyProjection(std::shared_ptr<arrow::RecordBatch>& return arrow::Status::Invalid("Wrong projection column '" + column + "'."); } } - batch = NArrow::ExtractColumns(batch, std::make_shared<arrow::Schema>(fields)); + batch = NArrow::ExtractColumns(batch, std::make_shared<arrow::Schema>(std::move(fields))); return arrow::Status::OK(); } diff --git a/ydb/core/formats/ut_arrow.cpp b/ydb/core/formats/ut_arrow.cpp index f57ee48e25d..777a8ff64ad 100644 --- a/ydb/core/formats/ut_arrow.cpp +++ b/ydb/core/formats/ut_arrow.cpp @@ -113,7 +113,7 @@ struct TDataRow { //arrow::field("dec", arrow::decimal(NScheme::DECIMAL_PRECISION, NScheme::DECIMAL_SCALE)), }; - return std::make_shared<arrow::Schema>(fields); + return std::make_shared<arrow::Schema>(std::move(fields)); } static TVector<std::pair<TString, TTypeInfo>> MakeYdbSchema() { diff --git a/ydb/core/kqp/executer_actor/kqp_executer_impl.cpp b/ydb/core/kqp/executer_actor/kqp_executer_impl.cpp index ee789ce294f..466853600f8 100644 --- a/ydb/core/kqp/executer_actor/kqp_executer_impl.cpp +++ b/ydb/core/kqp/executer_actor/kqp_executer_impl.cpp @@ -100,7 +100,7 @@ std::pair<TString, TString> SerializeKqpTasksParametersForOlap(const TStageInfo& data.emplace_back(std::move(array)); } - auto schema = std::make_shared<arrow::Schema>(columns); + auto schema = std::make_shared<arrow::Schema>(std::move(columns)); auto recordBatch = arrow::RecordBatch::Make(schema, 1, data); return std::make_pair<TString, TString>( diff --git a/ydb/core/kqp/runtime/kqp_scan_data_ut.cpp b/ydb/core/kqp/runtime/kqp_scan_data_ut.cpp index 451e9160ba4..bd7ac9eef20 100644 --- a/ydb/core/kqp/runtime/kqp_scan_data_ut.cpp +++ b/ydb/core/kqp/runtime/kqp_scan_data_ut.cpp @@ -82,7 +82,7 @@ struct TDataRow { arrow::field("dec", arrow::decimal(NScheme::DECIMAL_PRECISION, NScheme::DECIMAL_SCALE)), }; - return std::make_shared<arrow::Schema>(fields); + return std::make_shared<arrow::Schema>(std::move(fields)); } }; diff --git a/ydb/core/testlib/cs_helper.cpp b/ydb/core/testlib/cs_helper.cpp index 6aa1a0aa2c6..ff4e639389f 100644 --- a/ydb/core/testlib/cs_helper.cpp +++ b/ydb/core/testlib/cs_helper.cpp @@ -110,7 +110,7 @@ std::shared_ptr<arrow::Schema> THelper::GetArrowSchema() { if (GetWithJsonDocument()) { fields.emplace_back(arrow::field("json_payload", arrow::utf8())); } - return std::make_shared<arrow::Schema>(fields); + return std::make_shared<arrow::Schema>(std::move(fields)); } std::shared_ptr<arrow::RecordBatch> THelper::TestArrowBatch(ui64 pathIdBegin, ui64 tsBegin, size_t rowCount) { diff --git a/ydb/core/tx/columnshard/engines/portion_info.cpp b/ydb/core/tx/columnshard/engines/portion_info.cpp index 122711d278d..343587642cd 100644 --- a/ydb/core/tx/columnshard/engines/portion_info.cpp +++ b/ydb/core/tx/columnshard/engines/portion_info.cpp @@ -7,8 +7,7 @@ TString TPortionInfo::SerializeColumn(const std::shared_ptr<arrow::Array>& array const std::shared_ptr<arrow::Field>& field, const arrow::ipc::IpcWriteOptions& writeOptions) { - std::vector<std::shared_ptr<arrow::Field>> tmp{field}; - auto schema = std::make_shared<arrow::Schema>(tmp); + auto schema = std::make_shared<arrow::Schema>(arrow::FieldVector{field}); auto batch = arrow::RecordBatch::Make(schema, array->length(), {array}); Y_VERIFY(batch); @@ -19,8 +18,7 @@ namespace { std::shared_ptr<arrow::ChunkedArray> DeserializeBlobs(const TVector<TString>& blobs, std::shared_ptr<arrow::Field> field) { Y_VERIFY(!blobs.empty()); - std::vector<std::shared_ptr<arrow::Field>> tmp{field}; - auto schema = std::make_shared<arrow::Schema>(tmp); + auto schema = std::make_shared<arrow::Schema>(arrow::FieldVector{field}); std::vector<std::shared_ptr<arrow::RecordBatch>> batches; batches.reserve(blobs.size()); diff --git a/ydb/core/tx/columnshard/engines/ut_logs_engine.cpp b/ydb/core/tx/columnshard/engines/ut_logs_engine.cpp index f9a6aa08522..d121dc3023a 100644 --- a/ydb/core/tx/columnshard/engines/ut_logs_engine.cpp +++ b/ydb/core/tx/columnshard/engines/ut_logs_engine.cpp @@ -361,7 +361,7 @@ std::shared_ptr<TPredicate> MakePredicate(int64_t ts, NArrow::EOperation op) { auto res = arrow::MakeArrayFromScalar(arrow::TimestampScalar(ts, type), 1); std::vector<std::shared_ptr<arrow::Field>> fields = { std::make_shared<arrow::Field>("timestamp", type) }; - p->Batch = arrow::RecordBatch::Make(std::make_shared<arrow::Schema>(fields), 1, {*res}); + p->Batch = arrow::RecordBatch::Make(std::make_shared<arrow::Schema>(std::move(fields)), 1, {*res}); return p; } @@ -373,11 +373,11 @@ std::shared_ptr<TPredicate> MakeStrPredicate(const std::string& key, NArrow::EOp auto res = arrow::MakeArrayFromScalar(arrow::StringScalar(key), 1); std::vector<std::shared_ptr<arrow::Field>> fields = { std::make_shared<arrow::Field>("resource_type", type) }; - p->Batch = arrow::RecordBatch::Make(std::make_shared<arrow::Schema>(fields), 1, {*res}); + p->Batch = arrow::RecordBatch::Make(std::make_shared<arrow::Schema>(std::move(fields)), 1, {*res}); return p; } -} +} // namespace Y_UNIT_TEST_SUITE(TColumnEngineTestLogs) { |