Konstantin Orlov created IGNITE-20018:
-----------------------------------------
Summary: Introduce system view definition API
Key: IGNITE-20018
URL: https://issues.apache.org/jira/browse/IGNITE-20018
Project: Ignite
Issue Type: Improvement
Reporter: Konstantin Orlov
Let's introduce API to define a system view. Below is a few examples of how it
may look like:
{code:java}
SystemView.<Table>clusterViewBuilder()
.name("USERS")
.addColumn("ID", Integer.class, Table::id)
.addColumn("SCHEMA_ID", Integer.class, Table::schemaId)
.addColumn("NAME", String.class, Table::name)
.addColumn("COLUMN_NAMES", String.class, Table::columnNames)
.dataProvider(() -> toAsyncCursor(tableManager.allTables()))
.build();
SystemView.<Connection>nodeViewBuilder()
.name("CONNECTIONS")
.addColumn("USER", String.class, Connection::user)
.addColumn("ADDRESS", String.class, Connection::address)
.addColumn("ATTRS", String.class, Connection::attrs)
.localNodeColumnAlias("NODE_ID")
.dataProvider(() -> toAsyncCursor(connManager.connections()))
.build();
{code}
Explanation of the code snippet above:
* We need to distinguish between views exposing data with cluster-wide semantic
and views exposing data with node-specific semantic. Such segregation is
required to properly map queries' fragments to nodes owning data.
* *name* attribute – is a name of the view under which it will be available in
sql
* *addColumn* attribute – appends a column to the view definition. View
definition should have columns in the order of invocation of addColumn method.
This method accepts three parameters: name, column type represented by class,
and property reader. Name is a name of the column, under which the column under
which it will be available in sql. Class is required to properly build the
view's description. Property reader is a function which accepts objects of type
specified in generic of builder, and returns value for the column of interest.
* *dataProvider* attribute – provides an access to data this view is supposed
to expose. Data provider accepts the supplier of AsyncCursor (see
org.apache.ignite.internal.sql.engine.AsyncCursor; should be moved to core).
AsyncCursor is required, because some of the data may be not stored locally,
thus remote call will be required. To avoid blocking of query engine threads,
it's better to integrate with async primitives, rather than force every module
to store required state in local collections.
* *localNodeColumnAlias* attribute – alias for the column exposing node id.
This attribute is available only for nodeView’s, since node id will be injected
automatically only for this type of view.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)