Skip to main content

%SQL.FDW.Wrapper.BaseWrapper

abstract class %SQL.FDW.Wrapper.BaseWrapper extends %Library.RegisteredObject

FOR INTERNAL USE - do not invoke directly The %SQL.FDW.Wrapper.BaseWrapper defines the API required to create a custom Foreign Data Wrapper (FDW) implementation. All implementations must extend this class (or one of its subclasses) in order to be considered a wrapper by the SQL engine, which is the primary consumer of FDWs. All methods that are not provided with a default implementation must be implemented in order for a wrapper to be utilized properly. Wrappers are initialized using a config object that represents a serializaton of foreign server/table information, and some additional optional parameters, that a wrapper might need to connect to a source and perform its duties. For more information on the structure of these config objects, see the %OnNew() method. Wrappers should provide entry points to validate that the config serialization of a given foreign server/foreign table provides sufficient information for the wrapper to function. As such, the validateServerConfig() and validateTableConfig() methods are provided and must be implemented. Wrappers are expected to clean up any resources they create, such as database connections or External Language Server object handles. The close() is provided as the main entrypoint to do so. The %OnClose() provides a default implementation to automatically call close() in order to perform resource cleanup if the wrapper is ever killed or goes out of scope. Subclasses of %SQL.FDW.Wrapper.BaseWrapper are considered plain foreign data wrappers and by default do not have any special behavior attached to them. Custom wrappers can be created in any package, as long as they extend the proper superclass. No pushdown logic (i.e. logic that will push some portions of the query to an external system) will be performed for subclasses of the BaseWrapper. Pushdown logic occurs via selective reconstruction of SQL statement text. In order to signal that a wrapper supports pushdown, the wrapper should subclass %SQL.FDW.Wrapper.SqlWrapper instead. Reference that class for more information on the config details passed to such wrappers.

Property Inventory

Method Inventory

Properties

property atEnd as %Boolean [ InitialExpression = 0 ];
This property specifies whether or not the entire set of rows expected to be returned by the wrapper execution has been exhausted, i.e. there are not more rows to be returned by this wrapper.
Property methods: atEndDisplayToLogical(), atEndGet(), atEndIsValid(), atEndLogicalToDisplay(), atEndNormalize(), atEndSet()
property row as %RawString [ MultiDimensional ];
A multidimensional property representing the current row that the wrapper is pointing to. This property must be populated after each next() call, with the current row's data, to provide fast access to the current row. This property should take the format of row(columnIndex) = row value. For example, a row returned by the wrapper with the first column containing an ID number and the second column containing a name might look like:
  row(1) = 32887
  row(2) = "John Smith"
  
When next() has exhausted all rows, this property should be nulled out.
Property methods: rowGet(), rowIsValid(), rowSet()

Methods

abstract method %OnClose() as %Status
Inherited description: This callback method is invoked automatically when the OREF goes out of scope and its reference count drops to zero.

The return value of this method is ignored.

abstract method %OnNew(config As %DynamicObject) as %Status
All foreign data wrappers should define an %OnNew() method that will accept a JSON config object containing relevant information for that wrapper to perform its intended behavior based on a given foreign server and foreign table. Upon wrapper construction, the wrapper should be in a state that is sufficient to call execute() and to provide metadata via the getMetadata() method. Note that the actual metadata does not need to be fetched until getMetadata() is called, but that the wrapper should be prepared to do so upon execution without any other interaction from the caller. The wrapper config object conforms to the following format. The types listed are JSON types. For more information about manipulating this object, see %Library.DynamicAbstractObject. { "server": { "connection": string, corresponds to CONNECTION parameter the foreign server was created with. "delimitedIds": boolean, corresponds to DELIMITEDIDS parameter the foreign server was created with. "fdwName": string, name of the %SQL.FDW.Wrapper.BaseWrapper subclass that this server was intended to be used with. "host": string, corresponds to HOST parameter the foreign server was created with. "passthrough": boolean, corresponds to [ ENABLE | DISABLE ] PASSTHROUGH setting the foreign server was created with and specifies whether the server supports the PASSTHROUGH feature. "pushdownType": string, if this wrapper is a subclass of %SQL.FDW.Wrapper.SqlWrapper, this setting corresponds to the PUSHDOWN setting the foreign server was created with. "using": object, corresponds to the USING parameter the foreign server was created with, which can be used to specify any arbitrary table parameters your wrapper might need to function. }, Note that this is a JSON array of tables involved in this wrapper. For example, this may be populated with multiple tables if pushdown logic decided to combine multiple tables into one pushdown unit. "tables": [ { "columns": array, corresponds to the COLUMNS parameter the foreign table was created with. This only applies to CSV foreign tables and is used to specify a custom header row. "columnsTypes": array, names of datatypes corresponding to the indices in the columns array above. This only applies to CSV foreign tables. "values": array, corresponds to the VALUES parameter the foreign table was created with (i.e. external column names.) "query": string, corresponds to the QUERY parameter the foreign table was created with. "table": string, corresponds to the TABLE parameter the foreign table was created with. Note that for foreign tables created under a foreign server that utilizes %SQL.FDW.Wrapper.CsvWrapper, this field contains the value entered for the FILE parameter upon creation of the foreign table. "using": object, corresponds to the USING parameter the foreign table was created with, which can be used to specify any arbitrary table parameters your wrapper might need to function. }, ], "sql": string, specifies the SQL text determined via internal pushdown logic. This logic is only performed during SQL query execution for foreign tables that belong to servers using wrappers that extend the %SQL.FDW.Wrapper.SqlWrapper class. "sqlParameters": array, containing subarrays of the format [type, value] where each subarray corresponds positionally to a ? parameter in the config.sql parameter. The type is an integer corresponding to ODBC type numbers. For more information, see the %SQL.FDW.Wrapper.SqlWrapper class. }
abstract method close() as %Status
Clean up any associated structures and close this wrapper. This method is called automatically by %OnClose(), but may also be manually called prior to object deletion/going out of scope. This method should return a %Status value. Consider using status code $$$ForeignDataWrapperError when reporting custom error status messages.
classmethod delimitIdentifier(identifier As %String) as %String
Given an identifier of the format identifierPart{.identifierPart}, this method should return the input identifier represented as a delimited identifier, as expected by the source this foreign data wrapper interacts with. The default implementation is returning the string unmodified.
abstract method execute() as %Status
Execute this wrapper, which has already been initialized via the constructor. Upon completion of this method, the consumer of the wrapper should be able to reliably call next() to loop over the result set provided by the wrapper. This method should return a %Status value. Consider using status code $$$ForeignDataWrapperError when reporting custom error status messages.
abstract method get(columnIndex As %Integer) as %RawString
Get the value at column index columnIndex for the current row. This should match the value in row(columnIndex). If the
abstract method getMetadata() as %SQL.FDW.Metadata.ResultMetadata
Creates and returns an instance of %SQL.FDW.Metadata.ResultMetadata, which describes the result being returned by this wrapper. For more information on the metadata object, see the %SQL.FDW.Metadata.ResultMetadata class.
The next() advances the wrapper to the next row. If such a row is found, this method returns 1. If no additional row is found, this method returns 0. This method should always populate the multidimensional row property with the current row's data in the structure of row(columnIndex) = value.
abstract method reset() as %Status
Resets the result set being looped over by the wrapper, effectively positioning the pointer before the first row again. The wrapper API places no constraint on how this is done. For example, this method may require cleaning up all resources and executing from the beginning; that is an implementation detail. Upon finishing reset(), the wrapper should be as though execute() was just called the first time. In other words, the wrapper should be prepared to loop over the result set that it projects, with the first next() call following the reset returning the first row. This method should return a %Status value. Consider using status code $$$ForeignDataWrapperError when reporting custom error status messages.
abstract classmethod validateServerConfig(serverConfig As %DynamicObject) as %Status
Given a %DynamicObject representing the server portion of a config object, validate that information contained in the object is sufficient for this wrapper to act upon. For example, if a wrapper requires the server to specify a "host" key, this method should validate that the serialized server information contains a relevant value:
  if serverConfig.%Get("host") = "" { RETURN $$$ERROR(...) }
  
This method should return a %Status value. Consider using status code $$$ForeignDataWrapperError when reporting custom error status messages.
abstract classmethod validateTableConfig(tableConfig As %DynamicObject) as %Status
Given a %DynamicObject representing one table in the "tables" portion of a JSON config object, validate that information contained in the object is sufficient for this wrapper to act upon. For example, if a wrapper requires the tables to specify "table", this method should validate that the serialized table information contains a relevant value. This method should return a %Status value. Consider using status code $$$ForeignDataWrapperError when reporting custom error status messages.
classmethod validateTablesConfigArray(tableConfigArray As %DynamicArray) as %Status
For more information on wrapper config objects, see the %OnNew() method. Note that there may be multiple foreign tables involved in one wrapper execution (for example, for subclasses of %SQL.FDW.Wrapper.SqlWrapper after pushdown logic occurs.) As such, the table configuration is an array of objects, with each object representing one foreign table. These are JSON objects and are 0-indexed. This method provides a default implementation that will iterate over each foreign table JSON serialization in the array and call validateTableConfig(), which should be implemented as necessary. It is not likely that this default method implementation needs to be overridden.

Inherited Members

Inherited Methods

Subclasses

FeedbackOpens in a new tab