[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1073: MINIFICPP-1541 Move ODBC dependent SQL testing to the docker integration tests
adamdebreceni commented on a change in pull request #1073: URL: https://github.com/apache/nifi-minifi-cpp/pull/1073#discussion_r678913235 ## File path: libminifi/test/sql-tests/mocks/MockConnectors.cpp ## @@ -0,0 +1,386 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "MockConnectors.h" + +#include +#include +#include +#include +#include + +#include "utils/GeneralUtils.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace sql { + +std::size_t MockRow::size() const { + return column_names_.size(); +} + +std::string MockRow::getColumnName(std::size_t index) const { + return column_names_.at(index); +} + +bool MockRow::isNull(std::size_t index) const { + return column_values_.at(index) == "NULL"; +} + +DataType MockRow::getDataType(std::size_t index) const { + return column_types_.at(index); +} + +std::string MockRow::getString(std::size_t index) const { + return column_values_.at(index); +} + +double MockRow::getDouble(std::size_t index) const { + return std::atof(column_values_.at(index).c_str()); +} + +int MockRow::getInteger(std::size_t index) const { + return std::atoi(column_values_.at(index).c_str()); +} + +long long MockRow::getLongLong(std::size_t index) const { // NOLINT + return std::atoll(column_values_.at(index).c_str()); +} + +unsigned long long MockRow::getUnsignedLongLong(std::size_t index) const { // NOLINT + return static_cast(std::atoll(column_values_.at(index).c_str())); // NOLINT +} + +std::tm MockRow::getDate(std::size_t /*index*/) const { + throw std::runtime_error("date not implemented"); +} + +std::vector MockRow::getValues() const { + return column_values_; +} + +std::string MockRow::getValue(const std::string& col_name) const { + auto it = std::find(column_names_.begin(), column_names_.end(), col_name); + if (it != column_names_.end()) { +return column_values_.at(it-column_names_.begin()); + } + throw std::runtime_error("Unknown column name for getting value"); +} + +void MockRowset::addRow(const std::vector& column_values) { + rows_.emplace_back(column_names_, column_types_, column_values); +} + +void MockRowset::reset() { + current_row_ = rows_.begin(); +} + +bool MockRowset::is_done() { + return current_row_ == rows_.end(); +} + +Row& MockRowset::getCurrent() { + return *current_row_; +} + +void MockRowset::next() { + ++current_row_; +} + +std::vector MockRowset::getColumnNames() const { + return column_names_; +} + +std::vector MockRowset::getColumnTypes() const { + return column_types_; +} + +std::vector MockRowset::getRows() const { + return rows_; +} + +std::size_t MockRowset::getColumnIndex(const std::string& col_name) const { + auto it = std::find(column_names_.begin(), column_names_.end(), col_name); + if (it != column_names_.end()) { +return it-column_names_.begin(); + } + throw std::runtime_error("Unknown column name for getting index"); +} + +void MockRowset::sort(const std::string& order_by_col, bool order_ascending) { + std::sort(rows_.begin(), rows_.end(), [&](const MockRow& first, const MockRow& second) { +if (order_ascending) { + return first.getValue(order_by_col) < second.getValue(order_by_col); +} else { + return first.getValue(order_by_col) > second.getValue(order_by_col); +} + }); +} + +std::unique_ptr MockRowset::select(const std::vector& cols, const std::function& condition, const std::string& order_by_col, bool order_ascending) { + if (!order_by_col.empty()) { +sort(order_by_col, order_ascending); + } + + std::unique_ptr rowset; + if (cols.empty()) { +rowset = utils::make_unique(column_names_, column_types_); + } else { +std::vector col_types; +for (const auto& col : cols) { + col_types.push_back(column_types_.at(getColumnIndex(col))); +} +rowset = utils::make_unique(cols, col_types); + } + + std::vector used_cols = cols.empty() ? column_names_ : cols; + for (const auto& row : rows_) { +if (condition(row)) { + std::vector values; + for (const auto& col : used_cols) { +values.push_back(row.getValue(col)); + } + rowset->addRow(values); +} + } + + return rowset; +} + +std::unique_ptr
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1073: MINIFICPP-1541 Move ODBC dependent SQL testing to the docker integration tests
adamdebreceni commented on a change in pull request #1073: URL: https://github.com/apache/nifi-minifi-cpp/pull/1073#discussion_r678901043 ## File path: win_build_vs.bat ## @@ -65,7 +65,7 @@ for %%x in (%*) do ( mkdir %builddir% pushd %builddir%\ -cmake -G %generator% -A %build_platform% -DINSTALLER_MERGE_MODULES=%installer_merge_modules% -DTEST_CUSTOM_WEL_PROVIDER=%test_custom_wel_provider% -DENABLE_SQL=%build_SQL% -DCMAKE_BUILD_TYPE_INIT=%cmake_build_type% -DCMAKE_BUILD_TYPE=%cmake_build_type% -DWIN32=WIN32 -DENABLE_LIBRDKAFKA=%build_kafka% -DENABLE_JNI=%build_jni% -DOPENSSL_OFF=OFF -DENABLE_COAP=%build_coap% -DENABLE_AWS=%build_AWS% -DENABLE_PDH=%build_PDH% -DENABLE_AZURE=%build_azure% -DENABLE_SFTP=%build_SFTP% -DUSE_SHARED_LIBS=OFF -DDISABLE_CONTROLLER=ON -DBUILD_ROCKSDB=ON -DFORCE_WINDOWS=ON -DUSE_SYSTEM_UUID=OFF -DDISABLE_LIBARCHIVE=OFF -DDISABLE_SCRIPTING=ON -DEXCLUDE_BOOST=ON -DENABLE_WEL=TRUE -DFAIL_ON_WARNINGS=OFF -DSKIP_TESTS=%skiptests% %strict_gsl_checks% %redist% -DENABLE_LINTER=%build_linter% .. && msbuild /m nifi-minifi-cpp.sln /property:Configuration=%cmake_build_type% /property:Platform=%build_platform% && copy main\%cmake_build_type%\minifi.exe main\ +cmake -G %generator% -A %build_platform% -DINSTALLER_MERGE_MODULES=%installer_merge_modules% -DTEST_CUSTOM_WEL_PROVIDER=%test_custom_wel_provider% -DENABLE_SQL=%build_SQL% -DUSE_REAL_ODBC_TEST_DRIVER=ON -DCMAKE_BUILD_TYPE_INIT=%cmake_build_type% -DCMAKE_BUILD_TYPE=%cmake_build_type% -DWIN32=WIN32 -DENABLE_LIBRDKAFKA=%build_kafka% -DENABLE_JNI=%build_jni% -DOPENSSL_OFF=OFF -DENABLE_COAP=%build_coap% -DENABLE_AWS=%build_AWS% -DENABLE_PDH=%build_PDH% -DENABLE_AZURE=%build_azure% -DENABLE_SFTP=%build_SFTP% -DUSE_SHARED_LIBS=OFF -DDISABLE_CONTROLLER=ON -DBUILD_ROCKSDB=ON -DFORCE_WINDOWS=ON -DUSE_SYSTEM_UUID=OFF -DDISABLE_LIBARCHIVE=OFF -DDISABLE_SCRIPTING=ON -DEXCLUDE_BOOST=ON -DENABLE_WEL=TRUE -DFAIL_ON_WARNINGS=OFF -DSKIP_TESTS=%skiptests% %strict_gsl_checks% %redist% -DENABLE_LINTER=%build_linter% .. && msbuild /m nifi-minifi-cpp.sln /property:Configuration=%cmake_build_type% /property:Platform=%build_platform% && copy main\%cmake_build_type%\minifi.exe main\ Review comment: oh you are right, I was looking at the linked commit only -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1073: MINIFICPP-1541 Move ODBC dependent SQL testing to the docker integration tests
adamdebreceni commented on a change in pull request #1073: URL: https://github.com/apache/nifi-minifi-cpp/pull/1073#discussion_r678893397 ## File path: win_build_vs.bat ## @@ -65,7 +65,7 @@ for %%x in (%*) do ( mkdir %builddir% pushd %builddir%\ -cmake -G %generator% -A %build_platform% -DINSTALLER_MERGE_MODULES=%installer_merge_modules% -DTEST_CUSTOM_WEL_PROVIDER=%test_custom_wel_provider% -DENABLE_SQL=%build_SQL% -DCMAKE_BUILD_TYPE_INIT=%cmake_build_type% -DCMAKE_BUILD_TYPE=%cmake_build_type% -DWIN32=WIN32 -DENABLE_LIBRDKAFKA=%build_kafka% -DENABLE_JNI=%build_jni% -DOPENSSL_OFF=OFF -DENABLE_COAP=%build_coap% -DENABLE_AWS=%build_AWS% -DENABLE_PDH=%build_PDH% -DENABLE_AZURE=%build_azure% -DENABLE_SFTP=%build_SFTP% -DUSE_SHARED_LIBS=OFF -DDISABLE_CONTROLLER=ON -DBUILD_ROCKSDB=ON -DFORCE_WINDOWS=ON -DUSE_SYSTEM_UUID=OFF -DDISABLE_LIBARCHIVE=OFF -DDISABLE_SCRIPTING=ON -DEXCLUDE_BOOST=ON -DENABLE_WEL=TRUE -DFAIL_ON_WARNINGS=OFF -DSKIP_TESTS=%skiptests% %strict_gsl_checks% %redist% -DENABLE_LINTER=%build_linter% .. && msbuild /m nifi-minifi-cpp.sln /property:Configuration=%cmake_build_type% /property:Platform=%build_platform% && copy main\%cmake_build_type%\minifi.exe main\ +cmake -G %generator% -A %build_platform% -DINSTALLER_MERGE_MODULES=%installer_merge_modules% -DTEST_CUSTOM_WEL_PROVIDER=%test_custom_wel_provider% -DENABLE_SQL=%build_SQL% -DUSE_REAL_ODBC_TEST_DRIVER=ON -DCMAKE_BUILD_TYPE_INIT=%cmake_build_type% -DCMAKE_BUILD_TYPE=%cmake_build_type% -DWIN32=WIN32 -DENABLE_LIBRDKAFKA=%build_kafka% -DENABLE_JNI=%build_jni% -DOPENSSL_OFF=OFF -DENABLE_COAP=%build_coap% -DENABLE_AWS=%build_AWS% -DENABLE_PDH=%build_PDH% -DENABLE_AZURE=%build_azure% -DENABLE_SFTP=%build_SFTP% -DUSE_SHARED_LIBS=OFF -DDISABLE_CONTROLLER=ON -DBUILD_ROCKSDB=ON -DFORCE_WINDOWS=ON -DUSE_SYSTEM_UUID=OFF -DDISABLE_LIBARCHIVE=OFF -DDISABLE_SCRIPTING=ON -DEXCLUDE_BOOST=ON -DENABLE_WEL=TRUE -DFAIL_ON_WARNINGS=OFF -DSKIP_TESTS=%skiptests% %strict_gsl_checks% %redist% -DENABLE_LINTER=%build_linter% .. && msbuild /m nifi-minifi-cpp.sln /property:Configuration=%cmake_build_type% /property:Platform=%build_platform% && copy main\%cmake_build_type%\minifi.exe main\ Review comment: you seem to have added the `/RO` flag for the ci jobs, but the flag we are looking for in the bat file is `/ODBC` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1073: MINIFICPP-1541 Move ODBC dependent SQL testing to the docker integration tests
adamdebreceni commented on a change in pull request #1073: URL: https://github.com/apache/nifi-minifi-cpp/pull/1073#discussion_r645542861 ## File path: libminifi/include/utils/StringUtils.h ## @@ -137,6 +137,7 @@ class StringUtils { static std::vector split(const std::string &str, const std::string &delimiter); static std::vector splitAndTrim(const std::string &str, const std::string &delimiter); + static std::vector splitAndTrimOnString(std::string str, const std::string& delimiter); Review comment: wow this is "great", I wondered why the following test passed knowing this: ``` TEST_CASE("TestStringUtils::split4", "[test split classname]") { std::vector expected = { "org", "apache", "nifi", "minifi", "utils", "StringUtils" }; REQUIRE(expected == StringUtils::split(org::apache::nifi::minifi::core::getClassName(), "::")); } ``` turns out two wrongs make a right here :D the current implementation implicitly discards zero length segments, so `split("a,,b", ",") == ["a", "b"]` instead of `["a", "", "b"]`, I would definitely change this, I would keep a single function with `std::string` delimiter but with the "correct" semantics, if we would like to interpret each character as a delimiter later, we could add a `splitAny` or something along those lines -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1073: MINIFICPP-1541 Move ODBC dependent SQL testing to the docker integration tests
adamdebreceni commented on a change in pull request #1073: URL: https://github.com/apache/nifi-minifi-cpp/pull/1073#discussion_r644548803 ## File path: win_build_vs.bat ## @@ -65,7 +65,7 @@ for %%x in (%*) do ( mkdir %builddir% pushd %builddir%\ -cmake -G %generator% -A %build_platform% -DINSTALLER_MERGE_MODULES=%installer_merge_modules% -DTEST_CUSTOM_WEL_PROVIDER=%test_custom_wel_provider% -DENABLE_SQL=%build_SQL% -DCMAKE_BUILD_TYPE_INIT=%cmake_build_type% -DCMAKE_BUILD_TYPE=%cmake_build_type% -DWIN32=WIN32 -DENABLE_LIBRDKAFKA=%build_kafka% -DENABLE_JNI=%build_jni% -DOPENSSL_OFF=OFF -DENABLE_COAP=%build_coap% -DENABLE_AWS=%build_AWS% -DENABLE_PDH=%build_PDH% -DENABLE_AZURE=%build_azure% -DENABLE_SFTP=%build_SFTP% -DUSE_SHARED_LIBS=OFF -DDISABLE_CONTROLLER=ON -DBUILD_ROCKSDB=ON -DFORCE_WINDOWS=ON -DUSE_SYSTEM_UUID=OFF -DDISABLE_LIBARCHIVE=OFF -DDISABLE_SCRIPTING=ON -DEXCLUDE_BOOST=ON -DENABLE_WEL=TRUE -DFAIL_ON_WARNINGS=OFF -DSKIP_TESTS=%skiptests% %strict_gsl_checks% %redist% -DENABLE_LINTER=%build_linter% .. && msbuild /m nifi-minifi-cpp.sln /property:Configuration=%cmake_build_type% /property:Platform=%build_platform% && copy main\%cmake_build_type%\minifi.exe main\ +cmake -G %generator% -A %build_platform% -DINSTALLER_MERGE_MODULES=%installer_merge_modules% -DTEST_CUSTOM_WEL_PROVIDER=%test_custom_wel_provider% -DENABLE_SQL=%build_SQL% -DUSE_REAL_ODBC_TEST_DRIVER=ON -DCMAKE_BUILD_TYPE_INIT=%cmake_build_type% -DCMAKE_BUILD_TYPE=%cmake_build_type% -DWIN32=WIN32 -DENABLE_LIBRDKAFKA=%build_kafka% -DENABLE_JNI=%build_jni% -DOPENSSL_OFF=OFF -DENABLE_COAP=%build_coap% -DENABLE_AWS=%build_AWS% -DENABLE_PDH=%build_PDH% -DENABLE_AZURE=%build_azure% -DENABLE_SFTP=%build_SFTP% -DUSE_SHARED_LIBS=OFF -DDISABLE_CONTROLLER=ON -DBUILD_ROCKSDB=ON -DFORCE_WINDOWS=ON -DUSE_SYSTEM_UUID=OFF -DDISABLE_LIBARCHIVE=OFF -DDISABLE_SCRIPTING=ON -DEXCLUDE_BOOST=ON -DENABLE_WEL=TRUE -DFAIL_ON_WARNINGS=OFF -DSKIP_TESTS=%skiptests% %strict_gsl_checks% %redist% -DENABLE_LINTER=%build_linter% .. && msbuild /m nifi-minifi-cpp.sln /property:Configuration=%cmake_build_type% /property:Platform=%build_platform% && copy main\%cmake_build_type%\minifi.exe main\ Review comment: as I understand this will always make the tests try to use the real odbc driver on windows, shouldn't we introduce some flag which is only default-enabled in the ci? ## File path: libminifi/test/sql-tests/mocks/MockConnectors.cpp ## @@ -0,0 +1,386 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "MockConnectors.h" + +#include +#include +#include +#include +#include + +#include "utils/GeneralUtils.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace sql { + +std::size_t MockRow::size() const { + return column_names_.size(); +} + +std::string MockRow::getColumnName(std::size_t index) const { + return column_names_.at(index); +} + +bool MockRow::isNull(std::size_t index) const { + return column_values_.at(index) == "NULL"; +} + +DataType MockRow::getDataType(std::size_t index) const { + return column_types_.at(index); +} + +std::string MockRow::getString(std::size_t index) const { + return column_values_.at(index); +} + +double MockRow::getDouble(std::size_t index) const { + return std::atof(column_values_.at(index).c_str()); +} + +int MockRow::getInteger(std::size_t index) const { + return std::atoi(column_values_.at(index).c_str()); +} + +long long MockRow::getLongLong(std::size_t index) const { // NOLINT + return std::atoll(column_values_.at(index).c_str()); +} + +unsigned long long MockRow::getUnsignedLongLong(std::size_t index) const { // NOLINT + return static_cast(std::atoll(column_values_.at(index).c_str())); // NOLINT +} + +std::tm MockRow::getDate(std::size_t /*index*/) const { + throw std::runtime_error("date not implemented"); +} + +std::vector MockRow::getValues() const { + return column_values_; +} + +std::string MockRow::getValue(const std::string& col_name) const { + auto it = std::find(column_names_.begin(), column_names_.end(), col_name); + if (it != column_names_.end()) { +return column_values_.at(it-column_names_.begin()); + } + thro
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1073: MINIFICPP-1541 Move ODBC dependent SQL testing to the docker integration tests
adamdebreceni commented on a change in pull request #1073: URL: https://github.com/apache/nifi-minifi-cpp/pull/1073#discussion_r644618079 ## File path: libminifi/test/sql-tests/mocks/MockConnectors.h ## @@ -0,0 +1,175 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "data/DatabaseConnectors.h" +#include "utils/StringUtils.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace sql { + +class MockRow : public Row { + public: + MockRow(std::vector& column_names, std::vector& column_types, const std::vector& column_values) +: column_names_(column_names), column_types_(column_types), column_values_(column_values) { + } + + MockRow(MockRow&& other) = default; + MockRow(const MockRow& other) = default; + MockRow& operator=(MockRow&& other) { +column_names_ = other.column_names_; +column_types_ = other.column_types_; Review comment: also won't the lack of `noexcept` make it unavailable for `std::vector`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1073: MINIFICPP-1541 Move ODBC dependent SQL testing to the docker integration tests
adamdebreceni commented on a change in pull request #1073: URL: https://github.com/apache/nifi-minifi-cpp/pull/1073#discussion_r644604564 ## File path: libminifi/test/sql-tests/mocks/MockConnectors.h ## @@ -0,0 +1,175 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "data/DatabaseConnectors.h" +#include "utils/StringUtils.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace sql { + +class MockRow : public Row { + public: + MockRow(std::vector& column_names, std::vector& column_types, const std::vector& column_values) +: column_names_(column_names), column_types_(column_types), column_values_(column_values) { + } + + MockRow(MockRow&& other) = default; + MockRow(const MockRow& other) = default; + MockRow& operator=(MockRow&& other) { +column_names_ = other.column_names_; +column_types_ = other.column_types_; Review comment: using `std::reference_wrapper` would most likely offer the semantics we are looking for here -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1073: MINIFICPP-1541 Move ODBC dependent SQL testing to the docker integration tests
adamdebreceni commented on a change in pull request #1073: URL: https://github.com/apache/nifi-minifi-cpp/pull/1073#discussion_r644601240 ## File path: libminifi/test/sql-tests/mocks/MockConnectors.h ## @@ -0,0 +1,175 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "data/DatabaseConnectors.h" +#include "utils/StringUtils.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace sql { + +class MockRow : public Row { + public: + MockRow(std::vector& column_names, std::vector& column_types, const std::vector& column_values) +: column_names_(column_names), column_types_(column_types), column_values_(column_values) { + } + + MockRow(MockRow&& other) = default; + MockRow(const MockRow& other) = default; + MockRow& operator=(MockRow&& other) { +column_names_ = other.column_names_; +column_types_ = other.column_types_; Review comment: I don't know the exact intention here, but I wager it won't be doing that -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1073: MINIFICPP-1541 Move ODBC dependent SQL testing to the docker integration tests
adamdebreceni commented on a change in pull request #1073: URL: https://github.com/apache/nifi-minifi-cpp/pull/1073#discussion_r644598996 ## File path: libminifi/test/sql-tests/mocks/MockConnectors.cpp ## @@ -0,0 +1,386 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "MockConnectors.h" + +#include +#include +#include +#include +#include + +#include "utils/GeneralUtils.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace sql { + +std::size_t MockRow::size() const { + return column_names_.size(); +} + +std::string MockRow::getColumnName(std::size_t index) const { + return column_names_.at(index); +} + +bool MockRow::isNull(std::size_t index) const { + return column_values_.at(index) == "NULL"; +} + +DataType MockRow::getDataType(std::size_t index) const { + return column_types_.at(index); +} + +std::string MockRow::getString(std::size_t index) const { + return column_values_.at(index); +} + +double MockRow::getDouble(std::size_t index) const { + return std::atof(column_values_.at(index).c_str()); +} + +int MockRow::getInteger(std::size_t index) const { + return std::atoi(column_values_.at(index).c_str()); +} + +long long MockRow::getLongLong(std::size_t index) const { // NOLINT + return std::atoll(column_values_.at(index).c_str()); +} + +unsigned long long MockRow::getUnsignedLongLong(std::size_t index) const { // NOLINT + return static_cast(std::atoll(column_values_.at(index).c_str())); // NOLINT +} + +std::tm MockRow::getDate(std::size_t /*index*/) const { + throw std::runtime_error("date not implemented"); +} + +std::vector MockRow::getValues() const { + return column_values_; +} + +std::string MockRow::getValue(const std::string& col_name) const { + auto it = std::find(column_names_.begin(), column_names_.end(), col_name); + if (it != column_names_.end()) { +return column_values_.at(it-column_names_.begin()); + } + throw std::runtime_error("Unknown column name for getting value"); +} + +void MockRowset::addRow(const std::vector& column_values) { + rows_.emplace_back(column_names_, column_types_, column_values); +} + +void MockRowset::reset() { + current_row_ = rows_.begin(); +} + +bool MockRowset::is_done() { + return current_row_ == rows_.end(); +} + +Row& MockRowset::getCurrent() { + return *current_row_; +} + +void MockRowset::next() { + ++current_row_; +} + +std::vector MockRowset::getColumnNames() const { + return column_names_; +} + +std::vector MockRowset::getColumnTypes() const { + return column_types_; +} + +std::vector MockRowset::getRows() const { + return rows_; +} + +std::size_t MockRowset::getColumnIndex(const std::string& col_name) const { + auto it = std::find(column_names_.begin(), column_names_.end(), col_name); + if (it != column_names_.end()) { +return it-column_names_.begin(); + } + throw std::runtime_error("Unknown column name for getting index"); +} + +void MockRowset::sort(const std::string& order_by_col, bool order_ascending) { + std::sort(rows_.begin(), rows_.end(), [&](const MockRow& first, const MockRow& second) { +if (order_ascending) { + return first.getValue(order_by_col) < second.getValue(order_by_col); +} else { + return first.getValue(order_by_col) > second.getValue(order_by_col); +} + }); +} + +std::unique_ptr MockRowset::select(const std::vector& cols, const std::function& condition, const std::string& order_by_col, bool order_ascending) { + if (!order_by_col.empty()) { +sort(order_by_col, order_ascending); + } + + std::unique_ptr rowset; + if (cols.empty()) { +rowset = utils::make_unique(column_names_, column_types_); + } else { +std::vector col_types; +for (const auto& col : cols) { + col_types.push_back(column_types_.at(getColumnIndex(col))); +} +rowset = utils::make_unique(cols, col_types); + } + + std::vector used_cols = cols.empty() ? column_names_ : cols; + for (const auto& row : rows_) { +if (condition(row)) { + std::vector values; + for (const auto& col : used_cols) { +values.push_back(row.getValue(col)); + } + rowset->addRow(values); +} + } + + return rowset; +} + +std::unique_ptr
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1073: MINIFICPP-1541 Move ODBC dependent SQL testing to the docker integration tests
adamdebreceni commented on a change in pull request #1073: URL: https://github.com/apache/nifi-minifi-cpp/pull/1073#discussion_r644583752 ## File path: libminifi/test/sql-tests/mocks/MockConnectors.cpp ## @@ -0,0 +1,386 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "MockConnectors.h" + +#include +#include +#include +#include +#include + +#include "utils/GeneralUtils.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace sql { + +std::size_t MockRow::size() const { + return column_names_.size(); +} + +std::string MockRow::getColumnName(std::size_t index) const { + return column_names_.at(index); +} + +bool MockRow::isNull(std::size_t index) const { + return column_values_.at(index) == "NULL"; +} + +DataType MockRow::getDataType(std::size_t index) const { + return column_types_.at(index); +} + +std::string MockRow::getString(std::size_t index) const { + return column_values_.at(index); +} + +double MockRow::getDouble(std::size_t index) const { + return std::atof(column_values_.at(index).c_str()); +} + +int MockRow::getInteger(std::size_t index) const { + return std::atoi(column_values_.at(index).c_str()); Review comment: should we use the `std::string` accepting version? (`std::stoi` and others) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1073: MINIFICPP-1541 Move ODBC dependent SQL testing to the docker integration tests
adamdebreceni commented on a change in pull request #1073: URL: https://github.com/apache/nifi-minifi-cpp/pull/1073#discussion_r644579725 ## File path: libminifi/test/sql-tests/mocks/MockConnectors.cpp ## @@ -0,0 +1,386 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "MockConnectors.h" + +#include +#include +#include +#include +#include + +#include "utils/GeneralUtils.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace sql { + +std::size_t MockRow::size() const { + return column_names_.size(); +} + +std::string MockRow::getColumnName(std::size_t index) const { + return column_names_.at(index); +} + +bool MockRow::isNull(std::size_t index) const { + return column_values_.at(index) == "NULL"; +} + +DataType MockRow::getDataType(std::size_t index) const { + return column_types_.at(index); +} + +std::string MockRow::getString(std::size_t index) const { + return column_values_.at(index); +} + +double MockRow::getDouble(std::size_t index) const { + return std::atof(column_values_.at(index).c_str()); +} + +int MockRow::getInteger(std::size_t index) const { + return std::atoi(column_values_.at(index).c_str()); +} + +long long MockRow::getLongLong(std::size_t index) const { // NOLINT + return std::atoll(column_values_.at(index).c_str()); +} + +unsigned long long MockRow::getUnsignedLongLong(std::size_t index) const { // NOLINT + return static_cast(std::atoll(column_values_.at(index).c_str())); // NOLINT +} + +std::tm MockRow::getDate(std::size_t /*index*/) const { + throw std::runtime_error("date not implemented"); +} + +std::vector MockRow::getValues() const { + return column_values_; +} + +std::string MockRow::getValue(const std::string& col_name) const { + auto it = std::find(column_names_.begin(), column_names_.end(), col_name); + if (it != column_names_.end()) { +return column_values_.at(it-column_names_.begin()); + } + throw std::runtime_error("Unknown column name for getting value"); +} + +void MockRowset::addRow(const std::vector& column_values) { + rows_.emplace_back(column_names_, column_types_, column_values); +} + +void MockRowset::reset() { + current_row_ = rows_.begin(); +} + +bool MockRowset::is_done() { + return current_row_ == rows_.end(); +} + +Row& MockRowset::getCurrent() { + return *current_row_; +} + +void MockRowset::next() { + ++current_row_; +} + +std::vector MockRowset::getColumnNames() const { + return column_names_; +} + +std::vector MockRowset::getColumnTypes() const { + return column_types_; +} + +std::vector MockRowset::getRows() const { + return rows_; +} + +std::size_t MockRowset::getColumnIndex(const std::string& col_name) const { + auto it = std::find(column_names_.begin(), column_names_.end(), col_name); + if (it != column_names_.end()) { +return it-column_names_.begin(); + } + throw std::runtime_error("Unknown column name for getting index"); +} + +void MockRowset::sort(const std::string& order_by_col, bool order_ascending) { + std::sort(rows_.begin(), rows_.end(), [&](const MockRow& first, const MockRow& second) { +if (order_ascending) { + return first.getValue(order_by_col) < second.getValue(order_by_col); +} else { + return first.getValue(order_by_col) > second.getValue(order_by_col); +} + }); +} + +std::unique_ptr MockRowset::select(const std::vector& cols, const std::function& condition, const std::string& order_by_col, bool order_ascending) { + if (!order_by_col.empty()) { +sort(order_by_col, order_ascending); + } + + std::unique_ptr rowset; + if (cols.empty()) { +rowset = utils::make_unique(column_names_, column_types_); + } else { +std::vector col_types; +for (const auto& col : cols) { + col_types.push_back(column_types_.at(getColumnIndex(col))); +} +rowset = utils::make_unique(cols, col_types); + } + + std::vector used_cols = cols.empty() ? column_names_ : cols; + for (const auto& row : rows_) { +if (condition(row)) { + std::vector values; + for (const auto& col : used_cols) { +values.push_back(row.getValue(col)); + } + rowset->addRow(values); +} + } + + return rowset; +} + +std::unique_ptr
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1073: MINIFICPP-1541 Move ODBC dependent SQL testing to the docker integration tests
adamdebreceni commented on a change in pull request #1073: URL: https://github.com/apache/nifi-minifi-cpp/pull/1073#discussion_r644555388 ## File path: libminifi/test/sql-tests/mocks/MockConnectors.cpp ## @@ -0,0 +1,386 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "MockConnectors.h" + +#include +#include +#include +#include +#include + +#include "utils/GeneralUtils.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace sql { + +std::size_t MockRow::size() const { + return column_names_.size(); +} + +std::string MockRow::getColumnName(std::size_t index) const { + return column_names_.at(index); +} + +bool MockRow::isNull(std::size_t index) const { + return column_values_.at(index) == "NULL"; +} + +DataType MockRow::getDataType(std::size_t index) const { + return column_types_.at(index); +} + +std::string MockRow::getString(std::size_t index) const { + return column_values_.at(index); +} + +double MockRow::getDouble(std::size_t index) const { + return std::atof(column_values_.at(index).c_str()); +} + +int MockRow::getInteger(std::size_t index) const { + return std::atoi(column_values_.at(index).c_str()); +} + +long long MockRow::getLongLong(std::size_t index) const { // NOLINT + return std::atoll(column_values_.at(index).c_str()); +} + +unsigned long long MockRow::getUnsignedLongLong(std::size_t index) const { // NOLINT + return static_cast(std::atoll(column_values_.at(index).c_str())); // NOLINT +} + +std::tm MockRow::getDate(std::size_t /*index*/) const { + throw std::runtime_error("date not implemented"); +} + +std::vector MockRow::getValues() const { + return column_values_; +} + +std::string MockRow::getValue(const std::string& col_name) const { + auto it = std::find(column_names_.begin(), column_names_.end(), col_name); + if (it != column_names_.end()) { +return column_values_.at(it-column_names_.begin()); + } + throw std::runtime_error("Unknown column name for getting value"); +} + +void MockRowset::addRow(const std::vector& column_values) { + rows_.emplace_back(column_names_, column_types_, column_values); +} + +void MockRowset::reset() { + current_row_ = rows_.begin(); +} + +bool MockRowset::is_done() { + return current_row_ == rows_.end(); +} + +Row& MockRowset::getCurrent() { + return *current_row_; +} + +void MockRowset::next() { + ++current_row_; +} + +std::vector MockRowset::getColumnNames() const { + return column_names_; +} + +std::vector MockRowset::getColumnTypes() const { + return column_types_; +} + +std::vector MockRowset::getRows() const { + return rows_; +} + +std::size_t MockRowset::getColumnIndex(const std::string& col_name) const { + auto it = std::find(column_names_.begin(), column_names_.end(), col_name); + if (it != column_names_.end()) { +return it-column_names_.begin(); + } + throw std::runtime_error("Unknown column name for getting index"); +} + +void MockRowset::sort(const std::string& order_by_col, bool order_ascending) { + std::sort(rows_.begin(), rows_.end(), [&](const MockRow& first, const MockRow& second) { +if (order_ascending) { + return first.getValue(order_by_col) < second.getValue(order_by_col); +} else { + return first.getValue(order_by_col) > second.getValue(order_by_col); +} + }); +} + +std::unique_ptr MockRowset::select(const std::vector& cols, const std::function& condition, const std::string& order_by_col, bool order_ascending) { + if (!order_by_col.empty()) { +sort(order_by_col, order_ascending); + } + + std::unique_ptr rowset; + if (cols.empty()) { +rowset = utils::make_unique(column_names_, column_types_); + } else { +std::vector col_types; +for (const auto& col : cols) { + col_types.push_back(column_types_.at(getColumnIndex(col))); +} +rowset = utils::make_unique(cols, col_types); + } + + std::vector used_cols = cols.empty() ? column_names_ : cols; + for (const auto& row : rows_) { +if (condition(row)) { + std::vector values; + for (const auto& col : used_cols) { +values.push_back(row.getValue(col)); + } + rowset->addRow(values); +} + } + + return rowset; +} + +std::unique_ptr
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1073: MINIFICPP-1541 Move ODBC dependent SQL testing to the docker integration tests
adamdebreceni commented on a change in pull request #1073: URL: https://github.com/apache/nifi-minifi-cpp/pull/1073#discussion_r644548803 ## File path: win_build_vs.bat ## @@ -65,7 +65,7 @@ for %%x in (%*) do ( mkdir %builddir% pushd %builddir%\ -cmake -G %generator% -A %build_platform% -DINSTALLER_MERGE_MODULES=%installer_merge_modules% -DTEST_CUSTOM_WEL_PROVIDER=%test_custom_wel_provider% -DENABLE_SQL=%build_SQL% -DCMAKE_BUILD_TYPE_INIT=%cmake_build_type% -DCMAKE_BUILD_TYPE=%cmake_build_type% -DWIN32=WIN32 -DENABLE_LIBRDKAFKA=%build_kafka% -DENABLE_JNI=%build_jni% -DOPENSSL_OFF=OFF -DENABLE_COAP=%build_coap% -DENABLE_AWS=%build_AWS% -DENABLE_PDH=%build_PDH% -DENABLE_AZURE=%build_azure% -DENABLE_SFTP=%build_SFTP% -DUSE_SHARED_LIBS=OFF -DDISABLE_CONTROLLER=ON -DBUILD_ROCKSDB=ON -DFORCE_WINDOWS=ON -DUSE_SYSTEM_UUID=OFF -DDISABLE_LIBARCHIVE=OFF -DDISABLE_SCRIPTING=ON -DEXCLUDE_BOOST=ON -DENABLE_WEL=TRUE -DFAIL_ON_WARNINGS=OFF -DSKIP_TESTS=%skiptests% %strict_gsl_checks% %redist% -DENABLE_LINTER=%build_linter% .. && msbuild /m nifi-minifi-cpp.sln /property:Configuration=%cmake_build_type% /property:Platform=%build_platform% && copy main\%cmake_build_type%\minifi.exe main\ +cmake -G %generator% -A %build_platform% -DINSTALLER_MERGE_MODULES=%installer_merge_modules% -DTEST_CUSTOM_WEL_PROVIDER=%test_custom_wel_provider% -DENABLE_SQL=%build_SQL% -DUSE_REAL_ODBC_TEST_DRIVER=ON -DCMAKE_BUILD_TYPE_INIT=%cmake_build_type% -DCMAKE_BUILD_TYPE=%cmake_build_type% -DWIN32=WIN32 -DENABLE_LIBRDKAFKA=%build_kafka% -DENABLE_JNI=%build_jni% -DOPENSSL_OFF=OFF -DENABLE_COAP=%build_coap% -DENABLE_AWS=%build_AWS% -DENABLE_PDH=%build_PDH% -DENABLE_AZURE=%build_azure% -DENABLE_SFTP=%build_SFTP% -DUSE_SHARED_LIBS=OFF -DDISABLE_CONTROLLER=ON -DBUILD_ROCKSDB=ON -DFORCE_WINDOWS=ON -DUSE_SYSTEM_UUID=OFF -DDISABLE_LIBARCHIVE=OFF -DDISABLE_SCRIPTING=ON -DEXCLUDE_BOOST=ON -DENABLE_WEL=TRUE -DFAIL_ON_WARNINGS=OFF -DSKIP_TESTS=%skiptests% %strict_gsl_checks% %redist% -DENABLE_LINTER=%build_linter% .. && msbuild /m nifi-minifi-cpp.sln /property:Configuration=%cmake_build_type% /property:Platform=%build_platform% && copy main\%cmake_build_type%\minifi.exe main\ Review comment: as I understand this will always make the tests try to use the real odbc driver on windows, shouldn't we introduce some flag which is only default-enabled in the ci? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org