Skip to content

convert ConcatFilesTask.groovy to .java#34476

Closed
ghost wants to merge 2 commits intomasterfrom
unknown repository
Closed

convert ConcatFilesTask.groovy to .java#34476
ghost wants to merge 2 commits intomasterfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Oct 15, 2018

No description provided.

@rjernst
Copy link
Copy Markdown
Member

rjernst commented Oct 15, 2018

Thanks for the PR @mara2701. It looks like this is incomplete? The .groovy file still exists, and the java implementation doesn't have a TaskAction annotated method, nor input/outputs.

@rjernst rjernst added :Delivery/Build Build or test infrastructure >refactoring labels Oct 15, 2018
@elasticmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-core-infra

Copy link
Copy Markdown
Contributor

@alpar-t alpar-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @mara2701 ! We appreciate your effort.
I think this is a good starting point, I added some comments.
I also added more details to #34459 as to what we expect with this transition,
sorry I should have added these to begin with.

public void concatFiles() {
final StringBuilder output = new StringBuilder();

if (headerLine != null) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is not necessary, Gradle doesn't allow for it unless the task is marked @Optional


final StringBuilder sb = new StringBuilder();
for (File f: files) {
Scanner scanner = new Scanner(f, "UTF-8" );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use a try-with-resources syntax with this.

final StringBuilder sb = new StringBuilder();
for (File f: files) {
Scanner scanner = new Scanner(f, "UTF-8" );
String text = scanner.useDelimiter("\\A").next();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using nextLine might be easier to read, and since we need all the lines in memory to perform the de-duplication anyhow, I would consider doing it in one step.
Using java streams and a set as the Groovy implementation did to take care of the de-duplication would make this concise and easy to understand:

  files.getFiles().stream()
            .flatMap(Files.readLines(null, StandardCharsets.UTF_8).stream())
            .collect(Collectors.toSet())
            .forEach( line -> {
                    // write each line to target        
            })

You will probably have to collect to a different set implementation to preserve order but this is the general idea. Writing a test will make that obvious.

@akki
Copy link
Copy Markdown
Contributor

akki commented Jan 4, 2019

@mara2701 Are you planning to work further on this?
Since there is no activity on this thread for more than 2 months, is it fine if I take this task ahead?

@akki
Copy link
Copy Markdown
Contributor

akki commented Jan 15, 2019

Picking this task due to long inactivity.

@danielmitterdorfer
Copy link
Copy Markdown
Member

This PR might be obsolete due to #37497.

@alpar-t
Copy link
Copy Markdown
Contributor

alpar-t commented Mar 7, 2019

Closing since #37497 was merged.

@alpar-t alpar-t closed this Mar 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Delivery/Build Build or test infrastructure >refactoring stalled

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants