bakaid commented on a change in pull request #656: MINIFI-1013 Used soci library. URL: https://github.com/apache/nifi-minifi-cpp/pull/656#discussion_r367498994
########## File path: extensions/sql/data/SQLRowsetProcessor.cpp ########## @@ -0,0 +1,120 @@ +/** + * + * 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 "SQLRowsetProcessor.h" + +#include "Exception.h" +#include "Utils.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace sql { + +SQLRowsetProcessor::SQLRowsetProcessor(const soci::rowset<soci::row>& rowset, const std::vector<SQLRowSubscriber*>& rowSubscribers) + : rowset_(rowset), rowSubscribers_(rowSubscribers) { + iter_ = rowset_.begin(); +} + +size_t SQLRowsetProcessor::process(size_t max) { + size_t count = 0; + + for (; iter_ != rowset_.end(); ) { + addRow(*iter_, count); + iter_++; + count++; + totalCount_++; + if (max > 0 && count >= max) { + break; + } + } + + return count; +} + +void SQLRowsetProcessor::addRow(const soci::row& row, size_t rowCount) { + for (const auto& pRowSubscriber : rowSubscribers_) { + pRowSubscriber->beginProcessRow(); + } + + if (rowCount == 0) { + for (std::size_t i = 0; i != row.size(); ++i) { + for (const auto& pRowSubscriber : rowSubscribers_) { + pRowSubscriber->processColumnName(utils::toLower(row.get_properties(i).get_name())); + } + } + } + + for (std::size_t i = 0; i != row.size(); ++i) { + const soci::column_properties& props = row.get_properties(i); + + const auto& name = utils::toLower(props.get_name()); + + if (row.get_indicator(i) == soci::i_null) { + processColumn(name, "NULL"); + } else { + switch (const auto dataType = props.get_data_type()) { + case soci::data_type::dt_string: { + processColumn(name, row.get<std::string>(i)); + } + break; + case soci::data_type::dt_double: { + processColumn(name, row.get<double>(i)); + } + break; + case soci::data_type::dt_integer: { + processColumn(name, row.get<int>(i)); + } + break; + case soci::data_type::dt_long_long: { + processColumn(name, row.get<long long>(i)); + } + break; + case soci::data_type::dt_unsigned_long_long: { + processColumn(name, row.get<unsigned long long>(i)); + } + break; + case soci::data_type::dt_date: { Review comment: I can't find any provisions to solve the problem described in https://github.com/apache/nifi-minifi-cpp/pull/656#discussion_r359796941 In the original version .999 was appended, which potentially resulted in data loss. This version can result in potential duplication, which is better, but still not good. We either have to patch soci to get the milliseconds, or store the already seen rows in the last second to our state, as described in my comment. The first solution would be the completely correct one, but I suspect it would be quite hard. The second has the problem that if the only unique key is the timestamp (which does not seem good practice), we can drop "intentionally duplicated" rows as well. I am OK with making this a follow-up issue, but then we should indiciate somehow in the processor documentation what limitations using a dt_date type for a max value column has. ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
