序
  
  本文主要研究一下flink的CsvTableSource
  
  TableSource
  
  flink-table_2.11-1.7.1-sources.jar!/org/apache/flink/table/sources/TableSource.scala
  
  trait TableSource[T] {
  
  /** Returns the [[TypeInformation]] for the return type of the [[TableSource]].
  
  * The fields of the return type are mapped to the table schema based on their name.
  
  *
  
  * @return The type of the returned [[DataSet]] or [[DataStream]].
  
  */
  
  def getReturnType: TypeInformation[T]
  
  /**
  
  * Returns the schema of the produced table.
  
  *
  
  * @return The [[TableSchema]] of the produced table.
  
  */
  
  def getTableSchema: TableSchema
  
  /**
  
  * Describes the table source.
  
  *
  
  * @return A String explaining the [[TableSource]].
  
  */
  
  def explainSource(): String =
  
  TableConnectorUtil.generateRuntimeName(getClass, getTableSchema.getFieldNames)
  
  }
  
  TableSource定义了三个方法,分别是getReturnType、getTableSchema、explainSource
  
  BatchTableSource
  
  flink-table_2.11-1.7.1-sources.jar!/org/apache/flink/table/sources/BatchTableSource.scala
  
  trait BatchTableSource[T] extends TableSource[T] {
  
  /**
  
  * Returns the data of the table as a [[DataSet]].
  
  *
  
  * NOTE: This method is for internal use only for defining a [[TableSource]].
  
  * Do not use it in Table API programs.
  
  */
  
  def getDataSet(execEnv: ExecutionEnvironment): DataSet[T]
  
  }
  
  BatchTableSource继承了TableSource,它定义了getDataSet方法
  
  StreamTableSource
  
  flink-table_2.11-1.7.1-sources.jar!/org/apache/flink/table/sources/StreamTableSource.scala
  
  trait StreamTableSource[T] extends TableSource[T] {
  
  /**
  
  * Returns the data of the table as a [[DataStream]].
  
  *
  
  * NOTE: This method is for internal use only for defining a [[TableSource]].
  
  * Do not use it in Table API programs.
  
  */
  
  def getDataStream(execEnv: StreamExecutionEnvironment): DataStream[T]
  
  }
  
  StreamTableSource继承了TableSource,它定义了getDataStream方法
  
  CsvTableSource
  
  flink-table_2.11-1.7.1-sources.jar!/org/apache/flink/table/sources/CsvTableSource.scala
  
  class CsvTableSource private (
  
  private val path: String,
  
  private val fieldNames: Array[String],
  
  private val fieldTypes: Array[TypeInformation[_]],
  
  private val selectedFields: Array[Int],
  
  private val fieldDelim: String,
  
  private val rowDelim: String,
  
  private val quoteCharacter: Character,
  
  private val ignoreFirstLine: Boolean,
  
  private val ignoreComments: String,
  
  private val lenient: Boolean)
  
  extends BatchTableSource[Row]
  
  with StreamTableSource[Row]
  
  with ProjectableTableSource[Row] {
  
  def this(
  
  path: String,
  
  fieldNames: Array[String],
  
  fieldTypes: Array[TypeInformation[_]],
  
  fieldDelim: String = CsvInputFormat.DEFAULT_FIELD_DELIMITER,
  
  rowDelim: String = CsvInputFormat.DEFAULT_LINE_DELIMITER,
  
  quoteCharacter: Character = null,
  
  ignoreFirstLine: Boolean = false,
  
  ignoreComments: String = null,
  
  lenient: Boolean = false)www.michenggw.com = {
  
  this(
  
  path,
  
  fieldNames,
  
  fieldTypes,
  
  fieldTypes.indices.toArray, // initially, all fields are returned
  
  fieldDelim,
  
  rowDelim,
  
  quoteCharacter,
  
  ignoreFirstLine,
  
  ignoreComments,
  
  lenient)
  
  }
  
  def this(path: String, fieldNames: Array[String]www.fengshen157.com/, fieldTypes: Array[TypeInformation[_]]) = {
  
  this(path, fieldNames, fieldTypes, CsvInputFormat.DEFAULT_FIELD_DELIMITER,
  
  CsvInputFormat.DEFAULT_LINE_DELIMITER, null, false, null, false)
  
  }
  
  if (fieldNames.length != fieldTypes.length) {
  
  throw new TableException("Number of field names and field types must be equal.")
  
  }
  
  private val selectedFieldTypes = selectedFields.map(fieldTypes(_))
  
  private val selectedFieldNames = selectedFields.map(fieldNames(_))
  
  private val returnType: RowTypeInfo = new RowTypeInfo(selectedFieldTypes, selectedFieldNames)
  
  override def getDataSet(execEnv: ExecutionEnvironment): DataSet[Row] = {
  
  execEnv.createInput(createCsvInput(), returnType).name(explainSource())
  
  }
  
  /** Returns the [[RowTypeInfo]] for the return type of the [[CsvTableSource]]. */
  
  override def getReturnType: www.leyouzaixian2.com RowTypeInfo = returnType
  
  override def getDataStream(streamExecEnv: StreamExecutionEnvironment): DataStream[Row] = {
  
  streamExecEnv.createInput(createCsvInput(), returnType).name(explainSource())
  
  }
  
  /** Returns the schema of the produced table. */
  
  override def getTableSchema = new TableSchema(fieldNames, fieldTypes)
  
  /** Returns a copy of [[TableSource]] with ability to project fields */
  
  override def projectFields(fields: Array[Int]): CsvTableSource = {
  
  val selectedFields = if (fields.isEmpty) Array(0) else fields
  
  new CsvTableSource(
  
  path,
  
  fieldNames,
  
  fieldTypes,
  
  selectedFields,
  
  fieldDelim,
  
  rowDelim,
  
  quoteCharacter,
  
  ignoreFirstLine,
  
  ignoreComments,
  
  lenient)
  
  }
  
  private def createCsvInput(): RowCsvInputFormat = {
  
  val inputFormat = new RowCsvInputFormat(
  
  new Path(path),
  
  selectedFieldTypes,
  
  rowDelim,
  
  fieldDelim,
  
  selectedFields)
  
  inputFormat.setSkipFirstLineAsHeader(ignoreFirstLine)
  
  inputFormat.setLenient(www.dasheng178.com lenient)
  
  if (quoteCharacter != null) {
  
  inputFormat.enableQuotedStringParsing(quoteCharacter)
  
  }
  
  if (ignoreComments != null) {
  
  inputFormat.setCommentPrefix(ignoreComments)
  
  }
  
  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(www.hengda157.com): Int = {
  
  returnType.hashCode()
  
  }
  
  override def explainSource(): String = {
  
  s"CsvTableSource(" +
  
  s"read fields: ${getReturnType.getFieldNames.mkString(", ")})"
  
  }
  
  }
  
  CsvTableSource同时实现了BatchTableSource及StreamTableSource接口;getDataSet方法使用ExecutionEnvironment.createInput创建DataSet;getDataStream方法使用StreamExecutionEnvironment.createInput创建DataStream
  
  ExecutionEnvironment.createInput及StreamExecutionEnvironment.createInput接收的InputFormat为RowCsvInputFormat,通过createCsvInput创建而来
  
  getTableSchema方法返回的TableSchema通过fieldNames及fieldTypes创建;getReturnType方法返回的RowTypeInfo通过selectedFieldTypes及selectedFieldNames创建;explainSource方法这里返回的是CsvTableSource开头的字符串
  
  小结
  
  TableSource定义了三个方法,分别是getReturnType、getTableSchema、explainSource;BatchTableSource继承了TableSource,它定义了getDataSet方法;StreamTableSource继承了TableSource,它定义了getDataStream方法
  
  CsvTableSource同时实现了BatchTableSource及StreamTableSource接口;getDataSet方法使用ExecutionEnvironment.createInput创建DataSet;getDataStream方法使用StreamExecutionEnvironment.createInput创建DataStream
  
  ExecutionEnvironment.createInput及StreamExecutionEnvironment.createInput接收的InputFormat为RowCsvInputFormat,通过createCsvInput创建而来;getTableSchema方法返回的TableSchema通过fieldNames及fieldTypes创建;getReturnType方法返回的RowTypeInfo通过selectedFieldTypes及selectedFieldNames创建;explainSource方法这里返回的是CsvTableSource开头的字符串

聊聊flink的CsvTableSource的更多相关文章

  1. 聊聊flink的NetworkEnvironmentConfiguration

    本文主要研究一下flink的NetworkEnvironmentConfiguration NetworkEnvironmentConfiguration flink-1.7.2/flink-runt ...

  2. 聊聊flink Table的groupBy操作

    本文主要研究一下flink Table的groupBy操作 Table.groupBy flink-table_2.11-1.7.0-sources.jar!/org/apache/flink/tab ...

  3. 聊聊flink的AsyncWaitOperator

    序本文主要研究一下flink的AsyncWaitOperator AsyncWaitOperatorflink-streaming-java_2.11-1.7.0-sources.jar!/org/a ...

  4. 聊聊flink的Async I/O

    // This example implements the asynchronous request and callback with Futures that have the // inter ...

  5. 聊聊flink的log.file配置

    本文主要研究一下flink的log.file配置 log4j.properties flink-release-1.6.2/flink-dist/src/main/flink-bin/conf/log ...

  6. [case49]聊聊flink的checkpoint配置

    序 本文主要研究下flink的checkpoint配置 实例 StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecut ...

  7. 聊聊flink的BlobStoreService

    序 本文主要研究一下flink的BlobStoreService BlobView flink-release-1.7.2/flink-runtime/src/main/java/org/apache ...

  8. [源码分析] 从源码入手看 Flink Watermark 之传播过程

    [源码分析] 从源码入手看 Flink Watermark 之传播过程 0x00 摘要 本文将通过源码分析,带领大家熟悉Flink Watermark 之传播过程,顺便也可以对Flink整体逻辑有一个 ...

  9. Flink与Spark Streaming在与kafka结合的区别!

    本文主要是想聊聊flink与kafka结合.当然,单纯的介绍flink与kafka的结合呢,比较单调,也没有可对比性,所以的准备顺便帮大家简单回顾一下Spark Streaming与kafka的结合. ...

随机推荐

  1. 小计Tomcat的调优思路

    描述 最近在补充自己的短板,刚好整理到Tomcat调优这块,基本上面试必问,于是就花了点时间去搜集一下tomcat调优 都调了些什么,先记录一下调优手段,更多详细的原理和实现以后用到时候再来补充记录, ...

  2. Wince 中访问WCF服务

    由于本文并非WinCE开发普及篇,所以一些WinCE开发和WCF开发的基础还请移步百度和谷歌寻找答案,然后结合本文开发出WinCE中如何访问WCF,谢谢. 开发环境 IDE:Visual Studio ...

  3. Bug 级别定义标准

    缺陷种类 缺陷级别 详细说明 功能缺陷 Urgent (V级) 1.操作系统无法正常使用,死机,出现致命错误 2.数据丢失 3.被测试系统频繁崩溃,程序出错,使功能不能继续使用 4.性能与需求不一致 ...

  4. Unity FSM 有限状态机

    翻译了一下unity wiki上对于有限状态机的案例,等有空时在详细写一下.在场景中添加两个游戏物体,一个为玩家并修改其Tag为Player,另一个为NPC为其添加NPCControl脚本,并为其将玩 ...

  5. iOS开发之多线程技术—GCD篇

    本篇将从四个方面对iOS开发中GCD的使用进行详尽的讲解: 一.什么是GCD 二.我们为什么要用GCD技术 三.在实际开发中如何使用GCD更好的实现我们的需求 一.Synchronous & ...

  6. SQL语句--连接查询

    一.连接查询有以下几种 1.内连接查询 select * from t1 inner join t2 on t1.x = t2.x;  返回有关联的行 2.外链接查询 以下写法都省略了 中间的 out ...

  7. JAVA学习笔记--简介几个常见关键字static、final、this、super

    一.static static(静态的),可以放在类.方法.字段之前. 通常,当创建类时,就是在描述那个类的外观与行为.除非用 new 创建那个类的对象,否则,实际上并未获得任何对象.执行 new 来 ...

  8. mysql group by 取第一条

    select * from table where id in (select max(id) from table group by sku) 说明:id是自增序列,sku是表中的一个字段

  9. SpringMVC Controller介绍及常用注解——@Controller

    一 在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理层处理之后封装成一个Model ,然后再把该Model ...

  10. ES6的新特性(6)——正则的扩展

    正则的扩展 RegExp 构造函数 在 ES5 中,RegExp构造函数的参数有两种情况. 第一种情况是,参数是字符串,这时第二个参数表示正则表达式的修饰符(flag). var regex = ne ...