-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Implement user defined delimiter for value format #3393
Merged
purplefox
merged 59 commits into
confluentinc:master
from
purplefox:hasnat-add_optional_delimiter_for_delimited_format
Sep 26, 2019
Merged
Changes from 52 commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
51f416f
Merge pull request #1 from confluentinc/master
hasnat 7945d62
Added optional for FORMAT_VALUE DELIMITED
hasnat 6710357
Tests + Code review changes
hasnat e3481be
Fix formatting in sytax reference docs
hasnat cc38ab1
Merge remote-tracking branch 'fork/master'
hasnat eb230a4
Adds option to use custom delimiters when VALUE_FORMAT='DELIMITED'
hasnat 4148ba9
Merge branch 'master' into add_optional_delimiter_for_delimited_format
hasnat 007ad4a
Merge branch 'master' into add_optional_delimiter_for_delimited_format
hasnat c6d0092
Allow only single character delimiters
hasnat 426b8f6
Merge branch 'master' into add_optional_delimiter_for_delimited_format
hasnat c774b09
Updates to master merge
hasnat aaf6fa4
Adds seralizer with custom delimiter
hasnat 5dbcfaa
Merge branch 'master' into add_optional_delimiter_for_delimited_format
hasnat 077699d
Fix max line issue
hasnat ab21e53
Fix logger classes
hasnat 7794be0
Try default delimiter type with custom character
hasnat ef4ca56
Use utf 8
hasnat 2b2491a
fix query
hasnat d1a64e3
Fix value delimiter WITH argument
hasnat 5c58d25
use default with delimiter
hasnat 8eecc8d
remove old test
hasnat a4bed15
Merge pull request #2 from confluentinc/master
hasnat c29017d
Merge origin/master
hasnat 66ab934
style fix
hasnat 3dce9e9
Missing default
hasnat 9676843
bug fixes
hasnat a5b496a
more style fixes
hasnat 5f27f02
fix: Merged PR into master
b1075d4
fix: Get the PR to work as the original author intended against curre…
924aa36
Merge branch 'master' into hasnat-add_optional_delimiter_for_delimite…
3af05b5
fix: mainly nits
0038c3e
fix: checkstyle issue
c469f85
Removed 2 param of() method for FormatInfo that was only used in tests
b1344ed
Add special handling for TAB and SPACE
4992a91
fix: nit and add more tests
ad6a8d2
fix: update docs, nits and make sure datagen supports TAB and SPACE
8167721
Merge branch 'master' into hasnat-add_optional_delimiter_for_delimite…
28b433f
fix:checkstyle nit
e2a690a
fix: Removed some debug code
4a215d5
fix: nit
543fdee
fix:nit
d2699ef
fix:nits
49426b8
fix:nits
53cdf5f
fix:nits
1e421ec
Improved CommonCreateConfigs description for value_delimiter
2f05ad3
Use validator to check value_delimiter is not empty
8cf99d3
Use concatenated delimiter named values in error message
1d7a223
Use value delimiter from source if sink doesn't specify one
33e7358
Remove file that shouldn't be there
0bbbb37
Created delimiter class
854b6ec
Review comments
4e7b0a7
Added getter for delimiter
ea33711
more nits
fa12f03
Add invalid value to exception message for Delimiter
a261c35
review
6f322e5
Merge branch 'master' into hasnat-add_optional_delimiter_for_delimite…
0552373
fixed test
6c27d26
fixed get of delimiter
87f8342
Fixed merge conflict
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
ksql-common/src/main/java/io/confluent/ksql/serde/Delimiter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright 2019 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (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.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.serde; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.errorprone.annotations.Immutable; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
@Immutable | ||
public final class Delimiter { | ||
|
||
private final char delimiter; | ||
|
||
public static Delimiter parse(final char ch) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol - I only mean change the |
||
return new Delimiter(ch); | ||
} | ||
|
||
private Delimiter(final char delimiter) { | ||
this.delimiter = delimiter; | ||
} | ||
|
||
public static Delimiter parse(final String str) { | ||
if (str == null) { | ||
throw new NullPointerException(); | ||
} | ||
if (str.trim().isEmpty()) { | ||
throw new IllegalArgumentException( | ||
purplefox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"Delimiter cannot be empty, if you meant to have a tab or space for delimiter, please " | ||
+ "use the special values 'TAB' or 'SPACE'" | ||
+ System.lineSeparator() | ||
+ "Example valid value: ';'" | ||
); | ||
} | ||
if (str.length() == 1) { | ||
return new Delimiter(str.charAt(0)); | ||
} | ||
final Character delim = NAMED_DELIMITERS.get(str); | ||
if (delim != null) { | ||
return new Delimiter(delim); | ||
} | ||
throw new IllegalArgumentException( | ||
"Delimiter must be a single character or " | ||
+ NAMED_DELIMITERS_STRING | ||
+ System.lineSeparator() | ||
+ "Example valid value: ';'" | ||
); | ||
} | ||
|
||
private static final Map<String, Character> NAMED_DELIMITERS = ImmutableMap | ||
purplefox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.<String, Character>builder() | ||
.put("TAB", '\t') | ||
.put("SPACE", ' ') | ||
.build(); | ||
|
||
private static final String NAMED_DELIMITERS_STRING = getNamedDelimitersString(); | ||
purplefox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private static String getNamedDelimitersString() { | ||
final StringBuilder sb = new StringBuilder(); | ||
final Iterator<String> iter = NAMED_DELIMITERS.keySet().iterator(); | ||
while (iter.hasNext()) { | ||
sb.append(iter.next()); | ||
if (iter.hasNext()) { | ||
sb.append(", "); | ||
} | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final Delimiter delimiter1 = (Delimiter) o; | ||
return delimiter == delimiter1.delimiter; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(delimiter); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.valueOf(delimiter); | ||
} | ||
|
||
public char getDelimiter() { | ||
return delimiter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would benefit from a unit test - there's some in the patch I sent you.