From issues-return-92164-archive-asf-public=cust-asf.ponee.io@nifi.apache.org Fri Feb 14 10:16:59 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id A7392180647 for ; Fri, 14 Feb 2020 11:16:58 +0100 (CET) Received: (qmail 84279 invoked by uid 500); 14 Feb 2020 10:16:58 -0000 Mailing-List: contact issues-help@nifi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@nifi.apache.org Delivered-To: mailing list issues@nifi.apache.org Received: (qmail 84270 invoked by uid 99); 14 Feb 2020 10:16:58 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Feb 2020 10:16:58 +0000 From: GitBox To: issues@nifi.apache.org Subject: [GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #732: MINIFICPP-1013 Message-ID: <158167541797.22675.8600944815394085088.gitbox@gitbox.apache.org> References: In-Reply-To: Date: Fri, 14 Feb 2020 10:16:57 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit am-c-p-p commented on a change in pull request #732: MINIFICPP-1013 URL: https://github.com/apache/nifi-minifi-cpp/pull/732#discussion_r379351360 ########## File path: extensions/sql/processors/ExecuteSQL.cpp ########## @@ -0,0 +1,123 @@ +/** + * @file ExecuteSQL.cpp + * ExecuteSQL class declaration + * + * 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 "ExecuteSQL.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "io/DataStream.h" +#include "core/ProcessContext.h" +#include "core/ProcessSession.h" +#include "Exception.h" +#include "utils/OsUtils.h" +#include "data/DatabaseConnectors.h" +#include "data/JSONSQLWriter.h" +#include "data/SQLRowsetProcessor.h" +#include "data/WriteCallback.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace processors { + +const std::string ExecuteSQL::ProcessorName("ExecuteSQL"); + +const core::Property ExecuteSQL::s_sqlSelectQuery( + core::PropertyBuilder::createProperty("SQL select query")->isRequired(true)->withDescription( + "The SQL select query to execute. The query can be empty, a constant value, or built from attributes using Expression Language. " + "If this property is specified, it will be used regardless of the content of incoming flowfiles. " + "If this property is empty, the content of the incoming flow file is expected to contain a valid SQL select query, to be issued by the processor to the database. " + "Note that Expression Language is not evaluated for flow file contents.")->supportsExpressionLanguage(true)->build()); + +const core::Property ExecuteSQL::s_maxRowsPerFlowFile( + core::PropertyBuilder::createProperty("Max Rows Per Flow File")->isRequired(true)->withDefaultValue(0)->withDescription( + "The maximum number of result rows that will be included intoi a flow file. If zero then all will be placed into the flow file")->supportsExpressionLanguage(true)->build()); + +const core::Relationship ExecuteSQL::s_success("success", "Successfully created FlowFile from SQL query result set."); + +static const std::string ResultRowCount = "executesql.row.count"; + +ExecuteSQL::ExecuteSQL(const std::string& name, utils::Identifier uuid) + : SQLProcessor(name, uuid), max_rows_(0) { +} + +ExecuteSQL::~ExecuteSQL() { +} + +void ExecuteSQL::initialize() { + //! Set the supported properties + setSupportedProperties( { dbControllerService(), outputFormat(), s_sqlSelectQuery, s_maxRowsPerFlowFile}); + + //! Set the supported relationships + setSupportedRelationships( { s_success }); +} + +void ExecuteSQL::processOnSchedule(const core::ProcessContext &context) { + initOutputFormat(context); + + context.getProperty(s_sqlSelectQuery.getName(), sqlSelectQuery_); + context.getProperty(s_maxRowsPerFlowFile.getName(), max_rows_); +} + +void ExecuteSQL::processOnTrigger(core::ProcessSession &session) { + auto statement = connection_->prepareStatement(sqlSelectQuery_); + + auto rowset = statement->execute(); + + int count = 0; + size_t rowCount = 0; + sql::JSONSQLWriter sqlWriter(isJSONPretty()); + sql::SQLRowsetProcessor sqlRowsetProcessor(rowset, { &sqlWriter }); + + // Process rowset. + do { + rowCount = sqlRowsetProcessor.process(max_rows_ == 0 ? std::numeric_limits::max() : max_rows_); + count++; + if (rowCount == 0) + break; + + const auto& output = sqlWriter.toString(); Review comment: Changed in QueryDatabaseTable as well. ---------------------------------------------------------------- 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: users@infra.apache.org With regards, Apache Git Services