-
Notifications
You must be signed in to change notification settings - Fork 13.9k
[FLINK-5714] [table] Use a builder pattern for creating CsvTableSource #3273
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
Conversation
10ffca1 to
751e7a7
Compare
docs/dev/table_api.md
Outdated
| - `fieldDelimiter(String delim)` Sets the field delimiter, `","` by default. | ||
| - `lineDelimiter(String delim)` Sets the line delimiter, `"\n"` by default. | ||
| - `quoteCharacter(Character quote)` Sets the quote character for String values, `null` by default. | ||
| - `commentPrefix(String prefix)` Sets a prefix to indicate comments, null by default. |
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.
Shall we change to null to null to keep consistency
docs/dev/table_api.md
Outdated
| - `lineDelimiter(String delim)` Sets the line delimiter, `"\n"` by default. | ||
| - `quoteCharacter(Character quote)` Sets the quote character for String values, `null` by default. | ||
| - `commentPrefix(String prefix)` Sets a prefix to indicate comments, null by default. | ||
| - `ignoreFirstLine()` Ignore the first line. Not skip the first line by default. |
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.
disabled by default?
| * For example: | ||
| * | ||
| * {{{ | ||
| * val source: CsvTableSource = new CsvTableSourceBuilder() |
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.
CsvTableSourceBuilder should be CsvTableSource.builder()
and does this comment a little duplicated with method builder ?
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.
Yes, new CsvTableSourceBuilder() should be new CsvTableSource.Builder(). The comment is a little duplicate. But I think it is reasonable to let user create a builder by the constructor, not only the static builder method.
| */ | ||
| class Builder { | ||
|
|
||
| private val fieldNames: ListBuffer[String] = ListBuffer[String]() |
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.
Can we bind the name and type to a MutableMap and do some check when we adding fields? Like can not have duplicated filed names?
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.
Good point!
| ignoreFirstLine: Boolean = false, | ||
| ignoreComments: String = null, | ||
| lenient: Boolean = false) | ||
| private val path: String, |
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.
I think these two forms are identical
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.
Actually, I want to access these fields in the equals(Object) by that.path. The private val modifier will create getter/setter implicitly.
| * @return a newly-created [[CsvTableSource]]. | ||
| */ | ||
| def build: CsvTableSource = { | ||
| Preconditions.checkNotNull(path, "Path must not be null.") |
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.
Fields can not be empty too?
KurtYoung
left a comment
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.
Thanks for the work, looks good to me, i only have some minor comments
|
Thank you for your advice. I will update the PR soon. |
|
updated! |
| def build: CsvTableSource = { | ||
| Preconditions.checkNotNull(path, "Path must not be null.") | ||
| if (path == null) { | ||
| throw new IllegalArgumentException("Path must be defined.") |
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.
You can still use Preconditions.checkArgument though.
KurtYoung
left a comment
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.
LGTM
|
Looks good to merge. Merging... |
|
I found another issue: We should use a |
Thanks for contributing to Apache Flink. Before you open your pull request, please take the following check list into consideration.
If your changes take all of the items into account, feel free to open your pull request. For more information and/or questions please refer to the How To Contribute guide.
In addition to going through the list, please provide a meaningful description of your changes.
General
Documentation
Tests & Build
mvn clean verifyhas been executed successfully locally or a Travis build has passedAdd a builder to create CsvTableSource. And I have also updated the documentation.