You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by ak-arun <gi...@git.apache.org> on 2018/03/29 16:23:45 UTC
[GitHub] nifi pull request #2597: NIFI-5017 expression language support for rows and ...
GitHub user ak-arun opened a pull request:
https://github.com/apache/nifi/pull/2597
NIFI-5017 expression language support for rows and columns to skip
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:
- [ ] 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?
### 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?
- [ ] 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 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/ak-arun/nifi-1 NIFI-5017
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/nifi/pull/2597.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 #2597
----
commit 7b93fd132988feeb3ce02e5db396775648e69c9c
Author: Arun A K <ar...@...>
Date: 2018-03-29T16:21:05Z
NIFI-5017 expression language support for rows and columns to skip
----
---
[GitHub] nifi pull request #2597: NIFI-5017 expression language support for rows and ...
Posted by ak-arun <gi...@git.apache.org>.
Github user ak-arun commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2597#discussion_r178138228
--- Diff: nifi-nar-bundles/nifi-poi-bundle/nifi-poi-processors/src/test/java/org/apache/nifi/processors/poi/ConvertExcelToCSVProcessorTest.java ---
@@ -187,6 +213,34 @@ public void testSkipColumns() throws Exception {
"9.8765E+08,\n");
}
+ @Test
+ public void testSkipColumnsWithEL() throws Exception {
+ testRunner.enqueue(new File("src/test/resources/dataformatting.xlsx").toPath());
--- End diff --
@pvillard31 : okay got it. Will make this change.
---
[GitHub] nifi pull request #2597: NIFI-5017 expression language support for rows and ...
Posted by pvillard31 <gi...@git.apache.org>.
Github user pvillard31 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2597#discussion_r178135297
--- Diff: nifi-nar-bundles/nifi-poi-bundle/nifi-poi-processors/src/test/java/org/apache/nifi/processors/poi/ConvertExcelToCSVProcessorTest.java ---
@@ -187,6 +213,34 @@ public void testSkipColumns() throws Exception {
"9.8765E+08,\n");
}
+ @Test
+ public void testSkipColumnsWithEL() throws Exception {
+ testRunner.enqueue(new File("src/test/resources/dataformatting.xlsx").toPath());
--- End diff --
I'm fine with the tests you added. I just suggest that instead of directly setting the EL expression in the property value, you do a check against attributes that would come with the incoming flow file. Something like:
````java
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("columnsToSkip", "2");
testRunner.enqueue(new File("src/test/resources/dataformatting.xlsx").toPath(), variables);
testRunner.setProperty(ConvertExcelToCSVProcessor.COLUMNS_TO_SKIP, "${columnsToSkip}");
````
This way we check that EL is correctly evaluated against the attributes of the incoming flow files.
---
[GitHub] nifi pull request #2597: NIFI-5017 expression language support for rows and ...
Posted by pvillard31 <gi...@git.apache.org>.
Github user pvillard31 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2597#discussion_r178111781
--- Diff: nifi-nar-bundles/nifi-poi-bundle/nifi-poi-processors/src/main/java/org/apache/nifi/processors/poi/ConvertExcelToCSVProcessor.java ---
@@ -202,9 +204,9 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
final CSVFormat csvFormat = CSVUtils.createCSVFormat(context);
//Switch to 0 based index
- final int firstRow = context.getProperty(ROWS_TO_SKIP).asInteger() - 1;
+ final int firstRow = Integer.parseInt(context.getProperty(ROWS_TO_SKIP).evaluateAttributeExpressions().getValue()) - 1;
final String[] sColumnsToSkip = StringUtils
- .split(context.getProperty(COLUMNS_TO_SKIP).getValue(), ",");
+ .split(context.getProperty(COLUMNS_TO_SKIP).evaluateAttributeExpressions().getValue(), ",");
--- End diff --
````java
.split(context.getProperty(COLUMNS_TO_SKIP).evaluateAttributeExpressions(flowFile).getValue(), ",");
````
---
[GitHub] nifi pull request #2597: NIFI-5017 expression language support for rows and ...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/nifi/pull/2597
---
[GitHub] nifi pull request #2597: NIFI-5017 expression language support for rows and ...
Posted by pvillard31 <gi...@git.apache.org>.
Github user pvillard31 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2597#discussion_r178112354
--- Diff: nifi-nar-bundles/nifi-poi-bundle/nifi-poi-processors/src/test/java/org/apache/nifi/processors/poi/ConvertExcelToCSVProcessorTest.java ---
@@ -187,6 +213,34 @@ public void testSkipColumns() throws Exception {
"9.8765E+08,\n");
}
+ @Test
+ public void testSkipColumnsWithEL() throws Exception {
+ testRunner.enqueue(new File("src/test/resources/dataformatting.xlsx").toPath());
--- End diff --
To test the EL evaluation againt attributes of the flow file, you can pass a Map<String, String> representing the flow file attributes in the enqueue() method.
---
[GitHub] nifi pull request #2597: NIFI-5017 expression language support for rows and ...
Posted by ak-arun <gi...@git.apache.org>.
Github user ak-arun commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2597#discussion_r178115417
--- Diff: nifi-nar-bundles/nifi-poi-bundle/nifi-poi-processors/src/main/java/org/apache/nifi/processors/poi/ConvertExcelToCSVProcessor.java ---
@@ -202,9 +204,9 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
final CSVFormat csvFormat = CSVUtils.createCSVFormat(context);
//Switch to 0 based index
- final int firstRow = context.getProperty(ROWS_TO_SKIP).asInteger() - 1;
+ final int firstRow = Integer.parseInt(context.getProperty(ROWS_TO_SKIP).evaluateAttributeExpressions().getValue()) - 1;
--- End diff --
I got what you meant, evaluate the expression across the incoming flowfile attribute. I will include the change.
---
[GitHub] nifi pull request #2597: NIFI-5017 expression language support for rows and ...
Posted by pvillard31 <gi...@git.apache.org>.
Github user pvillard31 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2597#discussion_r178111708
--- Diff: nifi-nar-bundles/nifi-poi-bundle/nifi-poi-processors/src/main/java/org/apache/nifi/processors/poi/ConvertExcelToCSVProcessor.java ---
@@ -202,9 +204,9 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
final CSVFormat csvFormat = CSVUtils.createCSVFormat(context);
//Switch to 0 based index
- final int firstRow = context.getProperty(ROWS_TO_SKIP).asInteger() - 1;
+ final int firstRow = Integer.parseInt(context.getProperty(ROWS_TO_SKIP).evaluateAttributeExpressions().getValue()) - 1;
--- End diff --
I'd do:
````java
final int firstRow = context.getProperty(ROWS_TO_SKIP).evaluateAttributeExpressions(flowFile).asInteger() - 1;
````
Note that I use the EL evaluation against the flow file, otherwise you won't look at the incoming FF attributes.
---
[GitHub] nifi pull request #2597: NIFI-5017 expression language support for rows and ...
Posted by ak-arun <gi...@git.apache.org>.
Github user ak-arun commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2597#discussion_r178116509
--- Diff: nifi-nar-bundles/nifi-poi-bundle/nifi-poi-processors/src/test/java/org/apache/nifi/processors/poi/ConvertExcelToCSVProcessorTest.java ---
@@ -187,6 +213,34 @@ public void testSkipColumns() throws Exception {
"9.8765E+08,\n");
}
+ @Test
+ public void testSkipColumnsWithEL() throws Exception {
+ testRunner.enqueue(new File("src/test/resources/dataformatting.xlsx").toPath());
--- End diff --
@pvillard31 do you want me to re-write the tests into a single method? initially there were separate methods for testing the skipRows and skipColumns, I just maintained the same format.
---
[GitHub] nifi issue #2597: NIFI-5017 expression language support for rows and columns...
Posted by ak-arun <gi...@git.apache.org>.
Github user ak-arun commented on the issue:
https://github.com/apache/nifi/pull/2597
Unit test failures are unrelated
---
[GitHub] nifi pull request #2597: NIFI-5017 expression language support for rows and ...
Posted by ak-arun <gi...@git.apache.org>.
Github user ak-arun commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2597#discussion_r178113911
--- Diff: nifi-nar-bundles/nifi-poi-bundle/nifi-poi-processors/src/main/java/org/apache/nifi/processors/poi/ConvertExcelToCSVProcessor.java ---
@@ -202,9 +204,9 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
final CSVFormat csvFormat = CSVUtils.createCSVFormat(context);
//Switch to 0 based index
- final int firstRow = context.getProperty(ROWS_TO_SKIP).asInteger() - 1;
+ final int firstRow = Integer.parseInt(context.getProperty(ROWS_TO_SKIP).evaluateAttributeExpressions().getValue()) - 1;
--- End diff --
Okay, will take care.
---
[GitHub] nifi pull request #2597: NIFI-5017 expression language support for rows and ...
Posted by pvillard31 <gi...@git.apache.org>.
Github user pvillard31 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2597#discussion_r178112075
--- Diff: nifi-nar-bundles/nifi-poi-bundle/nifi-poi-processors/src/main/java/org/apache/nifi/processors/poi/ConvertExcelToCSVProcessor.java ---
@@ -202,9 +204,9 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
final CSVFormat csvFormat = CSVUtils.createCSVFormat(context);
//Switch to 0 based index
- final int firstRow = context.getProperty(ROWS_TO_SKIP).asInteger() - 1;
+ final int firstRow = Integer.parseInt(context.getProperty(ROWS_TO_SKIP).evaluateAttributeExpressions().getValue()) - 1;
--- End diff --
Since you're on this... could also be nice to do the EL evaluation against the incoming flow file on DESIRED_SHEETS few lines above...
---
[GitHub] nifi issue #2597: NIFI-5017 expression language support for rows and columns...
Posted by ak-arun <gi...@git.apache.org>.
Github user ak-arun commented on the issue:
https://github.com/apache/nifi/pull/2597
@pvillard31 : incorporated the recommended changes.
---
[GitHub] nifi pull request #2597: NIFI-5017 expression language support for rows and ...
Posted by ak-arun <gi...@git.apache.org>.
Github user ak-arun commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2597#discussion_r178114923
--- Diff: nifi-nar-bundles/nifi-poi-bundle/nifi-poi-processors/src/main/java/org/apache/nifi/processors/poi/ConvertExcelToCSVProcessor.java ---
@@ -202,9 +204,9 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
final CSVFormat csvFormat = CSVUtils.createCSVFormat(context);
//Switch to 0 based index
- final int firstRow = context.getProperty(ROWS_TO_SKIP).asInteger() - 1;
+ final int firstRow = Integer.parseInt(context.getProperty(ROWS_TO_SKIP).evaluateAttributeExpressions().getValue()) - 1;
--- End diff --
The DESIRED_SHEETS is already supporting EL
---