Class TRedshiftTableAttributes

Object
gudusoft.gsqlparser.nodes.TParseTreeNode
gudusoft.gsqlparser.nodes.redshift.TRedshiftTableAttributes
All Implemented Interfaces:
Visitable, Iterator<TSourceToken>

Represents the table_attributes for Redshift materialized views Based on: https://docs.aws.amazon.com/redshift/latest/dg/materialized-view-create-sql-command.html
  • Constructor Details

  • Method Details

    • init

      public void init(Object arg1)
      Description copied from class: TParseTreeNode
      Initialize a query tree node. Used internally
      Overrides:
      init in class TParseTreeNode
      Parameters:
      arg1 - first argument
    • init

      public void init(Object arg1, Object arg2)
      Overrides:
      init in class TParseTreeNode
    • getAttributeType

      Get the attribute type
      Returns:
      The type of table attribute
    • setAttributeType

      public void setAttributeType(ETableAttributeType attributeType)
      Set the attribute type
      Parameters:
      attributeType - The type of table attribute
    • getDistStyle

      Get the distribution style
      Returns:
      The distribution style
    • setDistStyle

      Set the distribution style
      Parameters:
      distStyle - The distribution style
      Returns:
      this object for method chaining
    • getDistKey

      Get the distribution key
      Returns:
      The distribution key column identifier
    • setDistKey

      Set the distribution key
      Parameters:
      distKey - The column identifier to use as distribution key
      Returns:
      this object for method chaining
    • getSortKeyColumns

      Get the sort key columns
      Returns:
      List of sort key columns
    • toSql

      public String toSql()
      Generate the SQL fragment for table_attributes
      Returns:
      SQL string representing the table attributes
    • toString

      public String toString()
      Description copied from class: TParseTreeNode

      将一个语法树节点(TParseTreeNode)转换回它对应的原始SQL字符串。 它通过遍历一个由 startToken(起始词法单元)和 endToken(结束词法单元)界定的双向链表来实现这一功能。

      这个方法的设计采用了“两遍扫描”(Two-Pass)的策略,也就是使用了两个 while 循环。 第一个循环是预处理阶段,用于清理格式;第二个循环则负责构建最终的字符串。

      第一个 while 循环

      这个循环的主要目标是识别并“软删除”多余的换行符(newline tokens)。这种情况尤其在SQL被程序动态修改后容易出现。 这个循环本身不构建字符串,只负责分析和更新词法单元的状态。 其工作原理是:

      1. 遍历: 它从 startToken 开始,通过 getNextTokenInChain() 方法遍历到 endToken
      2. 检测链表变化: 它通过比较当前和前一个词法单元的 posinlist(词法单元在原始完整列表中的位置索引)来判断链表是否“自然”。 如果不连续,意味着词法单元被插入或重排了,此时 isChainModified 标志位会被设为 true
      3. 标记换行符: 当遇到第一个换行符时,它会设置一个标志。如果紧接着又遇到了另一个换行符,并且此时链表已经被修改过, 那么它会将这个多余的换行符标记为待删除状态。这个逻辑能有效地将代码被修改后可能产生的多个连续换行压缩成一个。
      简而言之,第一个循环是一个格式清理过程,它为后续生成整洁的字符串做准备。

      第二个 while 循环

      这个循环负责从(经过第一步清理后的)词法单元流中实际地构建最终的输出字符串。 其工作原理是:

      1. 遍历: 它再次遍历完全相同的词法单元序列。
      2. 构建字符串: 在将每个词法单元追加到 StringBuffer 之前,它会进行检查。
      3. 跳过特定单元: 如果一个词法单元在第一个循环中被标记为待删除,或者它是一个注释(且配置为不包含注释),那么它将被跳过。
      4. 拼接字符串: 对于所有未被跳过的词法单元,它会将其字符串值追加到 StringBuffer 中。
      当这个循环结束后,StringBuffer 就包含了该语法树节点的最终、重构后的SQL文本。

      Overrides:
      toString in class TParseTreeNode
      Returns:
      节点对应的SQL字符串。
    • accept

      public void accept(TParseTreeVisitor v)
      Description copied from class: TParseTreeNode
      Accept a visitor
      Specified by:
      accept in interface Visitable
      Overrides:
      accept in class TParseTreeNode
      Parameters:
      v - visitor is a descendant class of TParseTreeVisitor
    • acceptChildren

      Description copied from class: TParseTreeNode
      Accept a visitor to iterate this class and sub-nodes of this class
      Specified by:
      acceptChildren in interface Visitable
      Overrides:
      acceptChildren in class TParseTreeNode
      Parameters:
      v - visitor is a descendant class of TParseTreeVisitor