[ 
https://issues.apache.org/jira/browse/NIFI-3585?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15905829#comment-15905829
 ] 

ASF GitHub Bot commented on NIFI-3585:
--------------------------------------

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?


> DB Adapter for MS SQL 2008
> --------------------------
>
>                 Key: NIFI-3585
>                 URL: https://issues.apache.org/jira/browse/NIFI-3585
>             Project: Apache NiFi
>          Issue Type: Improvement
>          Components: Core Framework
>    Affects Versions: 1.2.0
>            Reporter: Matt Burgess
>            Assignee: Matt Burgess
>            Priority: Minor
>             Fix For: 1.2.0
>
>
> NIFI-3481 introduced a DatabaseAdapter implementation for Microsoft SQL 
> Server 2012+, it is not compatible with MS SQL 2008 because of its use of 
> OFFSET and FETCH, e.g.
> This case is to introduce support for earlier versions of SQL Server to the 
> database fetching processors such as QueryDatabaseTable and 
> GenerateTableFetch. It may be the case that the generated SQL is awkward and 
> less-than-ideal (more like Oracle's pagination query), but this will enable 
> those processors to interact with SQL Server versions prior to 2012.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to