[ 
https://issues.apache.org/jira/browse/FLINK-5714?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15860504#comment-15860504
 ] 

ASF GitHub Bot commented on FLINK-5714:
---------------------------------------

Github user KurtYoung commented on a diff in the pull request:

    https://github.com/apache/flink/pull/3273#discussion_r100454106
  
    --- Diff: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/sources/CsvTableSource.scala
 ---
    @@ -138,4 +141,160 @@ class CsvTableSource(
     
         inputFormat
       }
    +
    +  override def equals(other: Any): Boolean = other match {
    +    case that: CsvTableSource => returnType == that.returnType &&
    +        path == that.path &&
    +        fieldDelim == that.fieldDelim &&
    +        rowDelim == that.rowDelim &&
    +        quoteCharacter == that.quoteCharacter &&
    +        ignoreFirstLine == that.ignoreFirstLine &&
    +        ignoreComments == that.ignoreComments &&
    +        lenient == that.lenient
    +    case _ => false
    +  }
    +
    +  override def hashCode(): Int = {
    +    val state = Seq(returnType)
    +    state.map(_.hashCode()).foldLeft(0)((a, b) => 31 * a + b)
    +  }
    +}
    +
    +object CsvTableSource {
    +
    +  /**
    +    * A builder for creating [[CsvTableSource]] instances.
    +    *
    +    * For example:
    +    *
    +    * {{{
    +    *   val source: CsvTableSource = new CsvTableSourceBuilder()
    +    *     .path("/path/to/your/file.csv")
    +    *     .field("myfield", Types.STRING)
    +    *     .field("myfield2", Types.INT)
    +    *     .build()
    +    * }}}
    +    *
    +    */
    +  class Builder {
    +
    +    private val fieldNames: ListBuffer[String] = ListBuffer[String]()
    --- End diff --
    
    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?


> Use a builder pattern for creating CsvTableSource
> -------------------------------------------------
>
>                 Key: FLINK-5714
>                 URL: https://issues.apache.org/jira/browse/FLINK-5714
>             Project: Flink
>          Issue Type: Improvement
>          Components: Table API & SQL
>            Reporter: Timo Walther
>            Assignee: Jark Wu
>
> Right now, the constructor of the CsvTableSource can have up to 9 parameters. 
> In Scala this might not be a problem because of default values, but Java 
> doesn't have this functionality.
> I propose to have a builder pattern here:
> {code}
> CsvTableSource
> .builder()
> .field("myfield", Types.STRING)
> .field("myfield2", Types.INT)
> .quoteCharacter(';')
> .build()
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to