SDK Tree Hierarchy

The SDK maps the FlowHigh response and its model objects and structures them as a tree. Each object represents a specific SQL element (for an overview of all the model classes and their hierarchy see Class Structure).

For instance:

model.Expr(model.TreeNode)

Wrapper for any of attribute, function, window function, operation, constant, case, asterisk, current, pivot/unpivot, multi-value, inline table, merge, position, querying stage, structured reference, table function, table sample, lateral view, window frame, insert, join, match recognize, update, or dataset.

model.Statement(model.CoordinateBlock)

Mapping for any DDL, DQL, or DML commands

model.Ds(model.BaseExpr, model.ReferencableExpr, model.Named, model.Searchable, model.TypeCast)

Any between select, from, joins, where, groupBy, having, qualify, sorting, and/or paging details.

model.In(model.BaseExprCollectionHolder)

Wraps the Ds used in a FROM clause

model.Attr(model.BaseExpr, model.ReferencableExpr, model.TreeNode)

The smallest unit in the query. Can contain reference to other attributes(in the case of alias), tables, datasets, tables, databases, and schema.

Fields:

  • refatt - Contains the name of reference to the source attribute which has been aliased.
  • refvar - Contains the name of the variable being referenced.
  • refds - Contains the name of the dataset which has been referenced.
  • refdb - Contains the name of the database which has been referenced.
  • refsch - Contains the name of the schema which has been referenced.
  • refoutidx - Numeric value which is used to refer to the Attr based on its position in the select clause.
  • refoutidx - Numeric value which is used to refer to the Attr based on its position in the select clause.
  • value - Holds constant values for the attribute.
  • alias - The display name of the attribute

model.Asterisk(model.ExprExprCollectionHolder, model.ReferencableExpr, model.TreeNode)

Wrapper that contains the set of Attr which are present in the relevant tables, datasets, tables, databases, and schema.

Inside the model package, the SDK also defines a few other classes that help to traverse the hierarchy:

model.TreeNode

Base type with attributes and functions to traverse the tree (parent/children hierarchy). Most of the objects in SDK inherit from this class, making them traversable

List of the main methods:

get_children(self)

Sample Usage

>>> from flowhigh.utils.converter import FlowHighSubmissionClass
>>> fh = FlowHighSubmissionClass.from_file("/home/user/sample.sql")
>>> fh.get_statements()[0].get_children()

Returns

the list of children elements in tree as a WeakSet

{<weakref at 0x7faafeb2cc20; to 'AntiPattern' at 0x7faafeb21490>, <weakref at 0x7faafeac1b30; to 'Ds' at 0x7faafeb212b0>}

get_id(self)

Get current node unique id (incremental)

Sample Usage

>>> from flowhigh.utils.converter import FlowHighSubmissionClass
>>> fh = FlowHighSubmissionClass.from_file("/home/user/sample.sql")
>>> fh.get_statements()[0].get_id()

Returns

The integer representing the node identifier

2

get_parent(self)

Get the ancestor of the current node

Sample Usage

>>> from flowhigh.utils.converter import FlowHighSubmissionClass
>>> fh = FlowHighSubmissionClass.from_file("/home/user/sample.sql")
>>> fh.get_statements()[0].get_parent()

Returns

a WeakProxy reference to the parent object in the hierarchy

<weakproxy at 0x7faafeac1c20 to ParSeQL at 0x7faafeafd640>

model.TreeNode.RegistryBase

A singleton that stores the list of all the SDK objects as a flat iterable collection. As for any singleton, only one instance of this class will be returned.

List of the main class methods:

get_registry() from builtins.type

Sample Usage

>>> from flowhigh.utils.converter import FlowHighSubmissionClass
>>> from flowhigh.model.TreeNode import RegistryBase
>>> fh = FlowHighSubmissionClass.from_file("/home/user/sample.sql")
>>> r = RegistryBase.get_registry()

Returns

the Registry with the set of SDK objects collected in a flat iterable collection

search(node_id) from builtins.type

Extract the node from the registry based on its id

Parameters

node_id: the object internal identifier

Sample Usage

>>> from flowhigh.utils.converter import FlowHighSubmissionClass
>>> from flowhigh.model.TreeNode import RegistryBase
>>> fh = FlowHighSubmissionClass.from_file("/home/user/sample.sql")
>>> RegistryBase.search(node_id=15)

Returns

the object with the given id

<flowhigh.model.Ds.Ds object at 0x7fadd0bb62b0>