You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/06/18 18:02:32 UTC

[GitHub] [nifi] tpalfy opened a new pull request #4350: NIFI-6934 In PutDatabaseRecord added Postgres UPSERT support

tpalfy opened a new pull request #4350:
URL: https://github.com/apache/nifi/pull/4350


   https://issues.apache.org/jira/browse/NIFI-6934
   
   Implemented using `DatabaseAdapter`
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced 
        in the commit message?
   
   - [ ] 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.
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically `master`)?
   
   - [ ] Is your initial contribution a single, squashed commit? _Additional commits in response to PR reviewer feedback should be made on this branch and pushed to allow change tracking. Do not `squash` or use `--force` when pushing to allow for clean monitoring of changes._
   
   ### For code changes:
   - [ ] Have you ensured that the full suite of tests is executed via `mvn -Pcontrib-check clean install` at the root `nifi` folder?
   - [ ] Have you written or updated unit tests to verify your changes?
   - [ ] Have you verified that the full build is successful on JDK 8?
   - [ ] Have you verified that the full build is successful on JDK 11?
   - [ ] 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:
   - [ ] 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 GitHub Actions CI for build issues and submit an update to your PR as soon as possible.
   


----------------------------------------------------------------
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



[GitHub] [nifi] mattyb149 commented on pull request #4350: NIFI-6934 In PutDatabaseRecord added Postgres UPSERT support

Posted by GitBox <gi...@apache.org>.
mattyb149 commented on pull request #4350:
URL: https://github.com/apache/nifi/pull/4350#issuecomment-647661277


   Looking and working good, just some comments on extending the documentation to make things as clear as possible, should be good to go after 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:
users@infra.apache.org



[GitHub] [nifi] tpalfy commented on a change in pull request #4350: NIFI-6934 In PutDatabaseRecord added Postgres UPSERT support

Posted by GitBox <gi...@apache.org>.
tpalfy commented on a change in pull request #4350:
URL: https://github.com/apache/nifi/pull/4350#discussion_r444174839



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
##########
@@ -29,6 +29,8 @@
 import org.apache.nifi.annotation.lifecycle.OnScheduled;

Review comment:
       Unfortunately we will have to settle for manual testing.
   `TestPutDatabaseRecord ` is not suitable for testing non-standard functionality (it uses derby).




----------------------------------------------------------------
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



[GitHub] [nifi] tpalfy commented on a change in pull request #4350: NIFI-6934 In PutDatabaseRecord added Postgres UPSERT support

Posted by GitBox <gi...@apache.org>.
tpalfy commented on a change in pull request #4350:
URL: https://github.com/apache/nifi/pull/4350#discussion_r444174839



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
##########
@@ -29,6 +29,8 @@
 import org.apache.nifi.annotation.lifecycle.OnScheduled;

Review comment:
       Unfortunately we will have to settle for manual testing.
   `TestMSSQLDatabaseAdapter` is not suitable for testing non-standard functionality (it uses derby).




----------------------------------------------------------------
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



[GitHub] [nifi] mattyb149 commented on a change in pull request #4350: NIFI-6934 In PutDatabaseRecord added Postgres UPSERT support

Posted by GitBox <gi...@apache.org>.
mattyb149 commented on a change in pull request #4350:
URL: https://github.com/apache/nifi/pull/4350#discussion_r443679370



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
##########
@@ -156,7 +162,7 @@
                     + "FlowFile. The 'Use statement.type Attribute' option is the only one that allows the 'SQL' statement type. If 'SQL' is specified, the value of the field specified by the "
                     + "'Field Containing SQL' property is expected to be a valid SQL statement on the target database, and will be executed as-is.")

Review comment:
       We should add some doc here explaining that some Statement Type values may not be supported depending on the value of the Database Type property, and can even include an example ("For example, UPSERT statements are not supported by Oracle" or something like 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:
users@infra.apache.org



[GitHub] [nifi] tpalfy commented on a change in pull request #4350: NIFI-6934 In PutDatabaseRecord added Postgres UPSERT support

Posted by GitBox <gi...@apache.org>.
tpalfy commented on a change in pull request #4350:
URL: https://github.com/apache/nifi/pull/4350#discussion_r444100867



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/db/impl/PostgreSQLDatabaseAdapter.java
##########
@@ -0,0 +1,68 @@
+/*
+ * 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 java.util.Collection;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class PostgreSQLDatabaseAdapter extends GenericDatabaseAdapter {
+    @Override
+    public String getName() {
+        return "PostgreSQL";
+    }
+
+    @Override
+    public String getDescription() {
+        return "Generates PostgreSQL compatible SQL";
+    }
+
+    @Override
+    public boolean supportsUpsert() {
+        return true;
+    }
+
+    @Override
+    public String getUpsertStatement(String table, List<String> columnNames, Collection<String> uniqueKeyColumnNames) {
+        String columns = columnNames.stream()
+            .collect(Collectors.joining(", "));
+
+        String parameterizedInsertValues = columnNames.stream()
+            .map(__ -> "?")
+            .collect(Collectors.joining(", "));
+
+        String updateValues = columnNames.stream()

Review comment:
       But these are values for the update.




----------------------------------------------------------------
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



[GitHub] [nifi] tpalfy commented on a change in pull request #4350: NIFI-6934 In PutDatabaseRecord added Postgres UPSERT support

Posted by GitBox <gi...@apache.org>.
tpalfy commented on a change in pull request #4350:
URL: https://github.com/apache/nifi/pull/4350#discussion_r444296917



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
##########
@@ -156,7 +162,7 @@
                     + "FlowFile. The 'Use statement.type Attribute' option is the only one that allows the 'SQL' statement type. If 'SQL' is specified, the value of the field specified by the "
                     + "'Field Containing SQL' property is expected to be a valid SQL statement on the target database, and will be executed as-is.")

Review comment:
       I'll add the general info to the description but rather not add the example because this part of the code has no direct connection to the adapters so I think it should not comment on _their_ functionality. (The Oracle adapter - or any other that we might refer in the example - might get updated to support UPSERT and almost certainly we won't remember to update this doc.)




----------------------------------------------------------------
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



[GitHub] [nifi] turcsanyip commented on pull request #4350: NIFI-6934 In PutDatabaseRecord added Postgres UPSERT support

Posted by GitBox <gi...@apache.org>.
turcsanyip commented on pull request #4350:
URL: https://github.com/apache/nifi/pull/4350#issuecomment-656107541


   LGTM too.
   @mattyb149 It can be merged from my side.


----------------------------------------------------------------
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



[GitHub] [nifi] mattyb149 closed pull request #4350: NIFI-6934 In PutDatabaseRecord added Postgres UPSERT support

Posted by GitBox <gi...@apache.org>.
mattyb149 closed pull request #4350:
URL: https://github.com/apache/nifi/pull/4350


   


----------------------------------------------------------------
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



[GitHub] [nifi] turcsanyip commented on a change in pull request #4350: NIFI-6934 In PutDatabaseRecord added Postgres UPSERT support

Posted by GitBox <gi...@apache.org>.
turcsanyip commented on a change in pull request #4350:
URL: https://github.com/apache/nifi/pull/4350#discussion_r444111607



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
##########
@@ -101,6 +106,7 @@
     static final String UPDATE_TYPE = "UPDATE";
     static final String INSERT_TYPE = "INSERT";
     static final String DELETE_TYPE = "DELETE";
+    static final String UPSERT_TYPE = "UPSERT";

Review comment:
       I would vote for the original UPSERT but don't want to veto the change.




----------------------------------------------------------------
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



[GitHub] [nifi] simonbence commented on pull request #4350: NIFI-6934 In PutDatabaseRecord added Postgres UPSERT support

Posted by GitBox <gi...@apache.org>.
simonbence commented on pull request #4350:
URL: https://github.com/apache/nifi/pull/4350#issuecomment-656087965


   I got answer for my questions, thanks! LGTM


----------------------------------------------------------------
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



[GitHub] [nifi] mattyb149 commented on pull request #4350: NIFI-6934 In PutDatabaseRecord added Postgres UPSERT support

Posted by GitBox <gi...@apache.org>.
mattyb149 commented on pull request #4350:
URL: https://github.com/apache/nifi/pull/4350#issuecomment-655679853


   +1 LGTM, ran contrib-check and tested a few scenarios. @simonbence @turcsanyip Are your reviews complete? If so I can merge to main. Thanks for this improvement! It will also make it easier to do DB-specific things now that we have the Database Type property in there.


----------------------------------------------------------------
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



[GitHub] [nifi] tpalfy commented on a change in pull request #4350: NIFI-6934 In PutDatabaseRecord added Postgres UPSERT support

Posted by GitBox <gi...@apache.org>.
tpalfy commented on a change in pull request #4350:
URL: https://github.com/apache/nifi/pull/4350#discussion_r444100533



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
##########
@@ -101,6 +106,7 @@
     static final String UPDATE_TYPE = "UPDATE";
     static final String INSERT_TYPE = "INSERT";
     static final String DELETE_TYPE = "DELETE";
+    static final String UPSERT_TYPE = "UPSERT";

Review comment:
       `UPSERT` is a fairly widespread expression, although not a standard.
   
   The standard would be `MERGE` but many RDBMS - Postgres for one - doesn't support it. (And it's a more than 10 year old standard so I guess we'll just have to live without it.)
   
   Okay, let's got with "UPDATE_OR_INSERT" to describe the _concept_.
   




----------------------------------------------------------------
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



[GitHub] [nifi] simonbence commented on a change in pull request #4350: NIFI-6934 In PutDatabaseRecord added Postgres UPSERT support

Posted by GitBox <gi...@apache.org>.
simonbence commented on a change in pull request #4350:
URL: https://github.com/apache/nifi/pull/4350#discussion_r444009133



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
##########
@@ -101,6 +106,7 @@
     static final String UPDATE_TYPE = "UPDATE";
     static final String INSERT_TYPE = "INSERT";
     static final String DELETE_TYPE = "DELETE";
+    static final String UPSERT_TYPE = "UPSERT";

Review comment:
       Minor: I think this is not a really widely known terminology. It might worth to think about UPDATE_OR_INSERT for better readability. (at least in variable name)

##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
##########
@@ -29,6 +29,8 @@
 import org.apache.nifi.annotation.lifecycle.OnScheduled;

Review comment:
       Could you please extend  TestPutDatabaseRecord with relevant case?

##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/db/impl/PostgreSQLDatabaseAdapter.java
##########
@@ -0,0 +1,68 @@
+/*
+ * 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 java.util.Collection;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class PostgreSQLDatabaseAdapter extends GenericDatabaseAdapter {
+    @Override
+    public String getName() {
+        return "PostgreSQL";
+    }
+
+    @Override
+    public String getDescription() {
+        return "Generates PostgreSQL compatible SQL";
+    }
+
+    @Override
+    public boolean supportsUpsert() {
+        return true;
+    }
+
+    @Override
+    public String getUpsertStatement(String table, List<String> columnNames, Collection<String> uniqueKeyColumnNames) {
+        String columns = columnNames.stream()
+            .collect(Collectors.joining(", "));
+
+        String parameterizedInsertValues = columnNames.stream()
+            .map(__ -> "?")
+            .collect(Collectors.joining(", "));
+
+        String updateValues = columnNames.stream()

Review comment:
       Minor: updateColumns?

##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/db/impl/PostgreSQLDatabaseAdapter.java
##########
@@ -0,0 +1,68 @@
+/*

Review comment:
       Could you please add a test like TestMSSQLDatabaseAdapter?




----------------------------------------------------------------
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



[GitHub] [nifi] mattyb149 commented on a change in pull request #4350: NIFI-6934 In PutDatabaseRecord added Postgres UPSERT support

Posted by GitBox <gi...@apache.org>.
mattyb149 commented on a change in pull request #4350:
URL: https://github.com/apache/nifi/pull/4350#discussion_r443710657



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
##########
@@ -156,7 +162,7 @@
                     + "FlowFile. The 'Use statement.type Attribute' option is the only one that allows the 'SQL' statement type. If 'SQL' is specified, the value of the field specified by the "
                     + "'Field Containing SQL' property is expected to be a valid SQL statement on the target database, and will be executed as-is.")

Review comment:
       Also probably some text saying "please refer to the database documentation for a description of the behavior of each operation." This is because even the different DBs that `do` support "upsert" may do them differently, for instance PostgreSQL requires a unique or exclusion constraint on the update key column(s)




----------------------------------------------------------------
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



[GitHub] [nifi] tpalfy commented on a change in pull request #4350: NIFI-6934 In PutDatabaseRecord added Postgres UPSERT support

Posted by GitBox <gi...@apache.org>.
tpalfy commented on a change in pull request #4350:
URL: https://github.com/apache/nifi/pull/4350#discussion_r444299023



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
##########
@@ -101,6 +106,7 @@
     static final String UPDATE_TYPE = "UPDATE";
     static final String INSERT_TYPE = "INSERT";
     static final String DELETE_TYPE = "DELETE";
+    static final String UPSERT_TYPE = "UPSERT";

Review comment:
       I'll keep it as "UPSERT" after all. It's sufficiently understandable (the expression is widely used), simpler and don't want to rename `supportsUpsert` to something like `supportsInsertOrUpdate`.




----------------------------------------------------------------
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



[GitHub] [nifi] mattyb149 commented on pull request #4350: NIFI-6934 In PutDatabaseRecord added Postgres UPSERT support

Posted by GitBox <gi...@apache.org>.
mattyb149 commented on pull request #4350:
URL: https://github.com/apache/nifi/pull/4350#issuecomment-654910951


   Can you please change the base branch of this PR to `main` and rebase against the latest `main` branch? That's the one we'll be using from now on. Thanks in advance!


----------------------------------------------------------------
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