You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by mattyb149 <gi...@git.apache.org> on 2017/03/10 19:17:06 UTC

[GitHub] nifi pull request #1584: NIFI-3585: Add DatabaseAdapter impl for MS SQL 2008

GitHub user mattyb149 opened a pull request:

    https://github.com/apache/nifi/pull/1584

    NIFI-3585: Add DatabaseAdapter impl for MS SQL 2008

    Thank you for submitting a contribution to Apache NiFi.
    
    In order to streamline the review of the contribution we ask you
    to ensure the following steps have been taken:
    
    ### For all changes:
    - [x] Is there a JIRA ticket associated with this PR? Is it referenced 
         in the commit message?
    
    - [x] Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
    
    - [x] Has your PR been rebased against the latest commit within the target branch (typically master)?
    
    - [x] Is your initial contribution a single, squashed commit?
    
    ### For code changes:
    - [x] Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
    - [x] Have you written or updated unit tests to verify your changes?
    - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? 
    - [ ] If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?
    - [ ] If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly?
    - [ ] If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties?
    
    ### For documentation related changes:
    - [x] Have you ensured that format looks appropriate for the output in which it is rendered?
    
    ### Note:
    Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/mattyb149/nifi NIFI-3585

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/nifi/pull/1584.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1584
    
----
commit 30efa7234185ee2c059a326e9f4c62d8b6c1cffc
Author: Matt Burgess <ma...@apache.org>
Date:   2017-03-10T19:16:07Z

    NIFI-3585: Add DatabaseAdapter impl for MS SQL 2008

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1584: NIFI-3585: Add DatabaseAdapter impl for MS SQL 2008

Posted by jfrazee <gi...@git.apache.org>.
Github user jfrazee commented on the issue:

    https://github.com/apache/nifi/pull/1584
  
    @mattyb149 Ok LGTM now so +1
    
    I tested with [NIFI-3585.xml](https://gist.github.com/jfrazee/63fc76f25bc5cdcfaf66d246cf232d19) on an Amazon RDS SQL Server instance using the Orders table + OrderID column in the Northwind database [1,2,3].
    
    1. https://northwinddatabase.codeplex.com
    2. http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/SQLServer.Procedural.Importing.html#SQLServer.Procedural.Importing.Native.Using.Restore
    3. https://aws.amazon.com/blogs/database/migrating-microsoft-sql-server-enterprise-workloads-to-amazon-rds-part-1/


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1584: NIFI-3585: Add DatabaseAdapter impl for MS SQL 2008

Posted by jfrazee <gi...@git.apache.org>.
Github user jfrazee commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1584#discussion_r105506187
  
    --- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/db/impl/MSSQL2008DatabaseAdapter.java ---
    @@ -0,0 +1,89 @@
    +/*
    + * 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.
    + */
    +package org.apache.nifi.processors.standard.db.impl;
    +
    +import org.apache.commons.lang3.StringUtils;
    +import org.apache.nifi.processors.standard.db.DatabaseAdapter;
    +
    +/**
    + * A database adapter that generates MS SQL Compatible SQL for version 2008.
    + */
    +public class MSSQL2008DatabaseAdapter implements DatabaseAdapter {
    +    @Override
    +    public String getName() {
    +        return "MS SQL 2008";
    +    }
    +
    +    @Override
    +    public String getDescription() {
    +        return "Generates MS SQL Compatible SQL for version 2008";
    +    }
    +
    +    @Override
    +    public String getSelectStatement(String tableName, String columnNames, String whereClause, String orderByClause, Long limit, Long offset) {
    +        if (StringUtils.isEmpty(tableName)) {
    +            throw new IllegalArgumentException("Table name cannot be null or empty");
    +        }
    +
    +        final StringBuilder query = new StringBuilder("SELECT ");
    +
    +        // If this is a limit query and not a paging query then use TOP in MS SQL
    +        if (limit != null) {
    +
    +            if (offset != null) {
    +                query.append("* FROM (SELECT ");
    +            }
    +            final long effectiveOffset = (offset == null) ? 0 : offset;
    +            if (effectiveOffset + limit > 0) {
    +                query.append("TOP ");
    +                query.append(effectiveOffset + limit);
    +                query.append(" ");
    +            }
    +        }
    +
    +        if (StringUtils.isEmpty(columnNames) || columnNames.trim().equals("*")) {
    +            query.append("*");
    +        } else {
    +            query.append(columnNames);
    +        }
    +
    +        if (limit != null && offset != null) {
    +            query.append(", ROW_NUMBER() OVER(ORDER BY ID asc) rnum");
    --- End diff --
    
    @mattyb149 I don't think there's a guarantee that the `ORDBER BY` column is `ID`. You meant for this to be `orderByClause`, right?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1584: NIFI-3585: Add DatabaseAdapter impl for MS SQL 2008

Posted by jfrazee <gi...@git.apache.org>.
Github user jfrazee commented on the issue:

    https://github.com/apache/nifi/pull/1584
  
    @mattyb149 I think I'll be able to say LGTM if this `orderByClause` thing gets fixed. Right now I think it only works on tables where the max value column is ID.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1584: NIFI-3585: Add DatabaseAdapter impl for MS SQL 2008

Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on the issue:

    https://github.com/apache/nifi/pull/1584
  
    @patricker do you mind taking a look at this? I am no MS SQL expert by any means, but I tested GenerateTableFetch and QueryDatabaseTable and they seem ok to me.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1584: NIFI-3585: Add DatabaseAdapter impl for MS SQL 2008

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/nifi/pull/1584


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---