JBoss.orgCommunity Documentation

Chapter 3. Command Language

3.1. Language Interfaces
3.1.1. Expressions
3.1.2. Criteria
3.1.3. The FROM Clause
3.1.4. IQueryCommand Structure
3.1.5. IQuery Structure
3.1.6. ISetQuery Structure
3.1.7. IInsert Structure
3.1.8. IUpdate Structure
3.1.9. IDelete Structure
3.1.10. IProcedure Structure
3.1.11. IBatchedUpdate Structure
3.2. Language Utilities
3.2.1. Data Types
3.2.2. Language Manipulation
3.3. Runtime Metadata
3.3.1. Language Objects
3.3.2. Access to Runtime Metadata
3.4. Language Visitors
3.4.1. Framework
3.4.2. Provided Visitors
3.4.3. Writing a Visitor
3.5. Connector Capabilities
3.5.1. Capability Scope
3.5.2. Capabilities
3.5.3. Command Form
3.5.4. Scalar Functions
3.5.5. Physical Limits
3.5.6. Update Execution Modes

Teiid sends commands to your connector in object form. The interfaces for these objects are all defined in the org.teiid.connector.language package. These interfaces can be combined to represent any possible command that Teiid may send to the connector. However, it is possible to notify Teiid that your connector can only accept certain kinds of commands via the ConnectorCapabilities class. See the section on using Connector Capabilities for more information.

The language interfaces all extend from the ILanguageObject interface. Language objects should be thought of as a tree where each node is a language object that has zero or more child language objects of types that are dependent on the current node.

All commands sent to your connector are in the form of these language trees, where the root of the tree is a subclass of ICommand. ICommand has several sub-interfaces, namely: IQueryCommand, IInsert, IUpdate, IDelete, IBatchedUpdate, and IProcedure.   Important components of these commands are expressions, criteria, and joins, which are examined in closer detail below. Also see the Teiid JavaDocs for more on the classes and interfaces described here.

This section covers utilities available when using, creating, and manipulating the language interfaces.

Teiid uses a library of metadata, known as "runtime metadata” for each virtual database that is deployed in Teiid. The runtime metadata is a subset of metadata as defined by models in the Teiid models that compose the virtual database.  

Connectors can access runtime metadata by using the interfaces defined in org.teiid.connector.metadata.runtime.  This package defines interfaces representing a MetadataID, a MetadataObject, and ways to navigate those IDs and objects.

The Connector API provides a language visitor framework in the org.teiid.connector.visitor.framework package.   The framework provides utilities useful in navigating and extracting information from trees of language objects.

The visitor framework is a variant of the Visitor design pattern, which is documented in several popular design pattern references.  The visitor pattern encompasses two primary operations: traversing the nodes of a graph (also known as iteration) and performing some action at each node of the graph.  In this case, the nodes are language interface objects and the graph is really a tree rooted at some node.  The provided framework allows for customization of both aspects of visiting.

The base LanguageObjectVisitor class defines the visit methods for all leaf language interfaces that can exist in the tree.  The LanguageObject interface defines an acceptVisitor() method – this method will call back on the visit method of the visitor to complete the contract.  A base class with empty visit methods is provided as AbstractLanguageVisitor.  The AbstractLanguageVisitor is just a visitor shell – it performs no actions when visiting nodes and does not provide any iteration.

The HierarchyVisitor provides the basic code for walking a language object tree.  The HierarchyVisitor performs no action as it walks the tree – it just encapsulates the knowledge of how to walk it.  If your connector wants to provide a custom iteration that walks the objects in a special order (to exclude nodes, include nodes multiple times, conditionally include nodes, etc) then you must either extend HierarchyVisitor or build your own iteration visitor.  In general, that is not necessary.

The DelegatingHierarchyVisitor is a special subclass of the HierarchyVisitor that provides the ability to perform a different visitor’s processing before and after iteration.  This allows users of this class to implement either pre- or post-order processing based on the HierarchyVisitor.  Two helper methods are provided on DelegatingHierarchyVisitor to aid in executing pre- and post-order visitors.  

All connectors must return a ConnectorCapabilities class from the Connection.getCapabilities() or Connector.getCapabilities() method. This class is used by the Connector Manager to determine what kinds of commands the connector is capable of executing. A basic implementation of the ConnectorCapabilities interface is supplied at BasicConnectorCapabilities. This capabilities class specifies that the connector does not support any capability. You should extend this class and override the necessary methods to specify which capabilities your connector supports.  

The following table lists the capabilities that can be specified in the ConnectorCapabilities class.

Table 3.1. Available Connector Capabilities

Capability

Requires

Description

SelectDistinct

Connector can support SELECT DISTINCT in queries.

SelectExpression

Connector can support SELECT of more than just element references.

AliasedGroup

Connector can support groups in the FROM clause that have an alias.

SupportedJoinCriteria

At least one of the join type supports.

Returns one of the SupportedJoinCriteria enum types: ANY, THETA, EQUI, KEY. KEY is the most restrictive, indicating that the source only supports equi-join criteria specified on the primary key of at least one of the tables in join.

InnerJoins

Connector can support inner and cross joins

SelfJoins

AliasedGroups and at least on of the join type supports.

Connector can support a self join between two aliased versions of the same group.

OuterJoins

Connector can support LEFT and RIGHT OUTER JOIN.

FullOuterJoins

Connector can support FULL OUTER JOIN.

InlineViews

AliasedGroup

Connector can support a named subquery in the FROM clause.

BetweenCriteria

Not currently used - between criteria is rewriten as compound comparisions.

CompareCriteriaEquals

Connector can support comparison criteria with the operator "=”.

CompareCriteriaOrdered

Connector can support comparison criteria with the operator ">” or "<".

LikeCriteria

Connector can support LIKE criteria.

LikeCriteriaEscapeCharacter

LikeCriteria

Connector can support LIKE criteria with an ESCAPE character clause.

InCriteria

Connector can support IN predicate criteria.

InCriteriaSubquery

Connector can support IN predicate criteria where values are supplied by a subquery.

IsNullCriteria

Connector can support IS NULL predicate criteria.

OrCriteria

Connector can support the OR logical criteria.

NotCriteria

Connector can support the NOT logical criteria. IMPORTANT: This capability also applies to negation of predicates, such as specifying IS NOT NULL, "<=" (not ">"), ">=" (not "<"), etc.

ExistsCriteria

Connector can support EXISTS predicate criteria.

QuantifiedCompareCriteriaAll

Connector can support a quantified comparison criteria using the ALL quantifier.

QuantifiedCompareCriteriaSome

Connector can support a quantified comparison criteria using the SOME or ANY quantifier.

OrderBy

Connector can support the ORDER BY clause in queries.

OrderByUnrelated

OrderBy

Connector can support the ORDER BY items that are not directly specified in the select clause.

GroupBy

Connector can support an explict GROUP BY clause.

Having

GroupBy

Connector can support the HAVING clause.

AggregatesAvg

Connector can support the AVG aggregate function.

AggregatesCount

Connector can support the COUNT aggregate function.

AggregatesCountStar

Connector can support the COUNT(*) aggregate function.

AggregatesDistinct

At least one of the aggregate functions.

Connector can support the keyword DISTINCT inside an aggregate function.  This keyword indicates that duplicate values within a group of rows will be ignored.

AggregatesMax

Connector can support the MAX aggregate function.

AggregatesMin

Connector can support the MIN aggregate function.

AggregatesSum

Connector can support the SUM aggregate function.

ScalarSubqueries

Connector can support the use of a subquery in a scalar context (wherever an expression is valid).

CorrelatedSubqueries

At least one of the subquery pushdown capabilities.

Connector can support a correlated subquery that refers to an element in the outer query.

CaseExpressions

Not currently used - simple case is rewriten as searched case.

SearchedCaseExpressions

Connector can support "searched” CASE expressions anywhere that expressions are accepted.

Unions

Connector support UNION and UNION ALL

Intersect

Connector supports INTERSECT

Except

Connector supports Except

SetQueryOrderBy

Unions, Intersect, or Except

Connector supports set queries with an ORDER BY

RowLimit

Connector can support the limit portion of the limit clause

RowOffset

Connector can support the offset portion of the limit clause

FunctionsInGroupBy

GroupBy

Not currently used - non-element expressions in the group by create an inline view.

InsertWithQueryExpression

Connector supports INSERT statements with values specified by an IQueryCommand.


Note that any pushdown subquery must itself be compliant with the connector capabilities.

The method ConnectorCapabilities.getSupportedFunctions() can be used to specify which scalar functions the connector supports.  The set of possible functions is based on the set of functions supported by Teiid.  This set can be found in the Reference documentation.  If the connector states that it supports a function, it must support all type combinations and overloaded forms of that function.

There are also five standard operators that can also be specified in the supported function list: +, -, *, /, and ||.

The constants interface SourceSystemFunctions contains the string names of all possible built-in pushdown functions. Note that not all system functions appear in this list. This is because some system functions will always be evaluted in Teiid, are simple aliases to other functions, or are rewriten to a more standard expression.