Class JsonView

java.lang.Object
org.apache.calcite.model.JsonTable
org.apache.calcite.model.JsonView

public class JsonView extends JsonTable
View schema element.

Like base class JsonTable, occurs within JsonMapSchema.tables.

Modifiable views

A view is modifiable if contains only SELECT, FROM, WHERE (no JOIN, aggregation or sub-queries) and every column:

  • is specified once in the SELECT clause; or
  • occurs in the WHERE clause with a column = literal predicate; or
  • is nullable.

The second clause allows Calcite to automatically provide the correct value for hidden columns. It is useful in, say, a multi-tenant environment, where the tenantId column is hidden, mandatory (NOT NULL), and has a constant value for a particular view.

Errors regarding modifiable views:

  • If a view is marked modifiable: true and is not modifiable, Calcite throws an error while reading the schema.
  • If you submit an INSERT, UPDATE or UPSERT command to a non-modifiable view, Calcite throws an error when validating the statement.
  • If a DML statement creates a row that would not appear in the view (for example, a row in female_emps, above, with gender = 'M'), Calcite throws an error when executing the statement.
See Also:
  • Field Details

    • sql

      public final Object sql
      SQL query that is the definition of the view.

      Must be a string or a list of strings (which are concatenated into a multi-line SQL string, separated by newlines).

    • path

      public final @Nullable List<String> path
      Schema name(s) to use when resolving query.

      If not specified, defaults to current schema.

    • modifiable

      public final @Nullable Boolean modifiable
      Whether this view should allow INSERT requests.

      The values have the following meanings:

      • If true, Calcite throws an error when validating the schema if the view is not modifiable.
      • If null, Calcite deduces whether the view is modifiable.
      • If false, Calcite will not allow inserts.

      The default value is null.

  • Constructor Details

  • Method Details

    • accept

      public void accept(ModelHandler handler)
      Specified by:
      accept in class JsonTable
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getSql

      public String getSql()
      Returns the SQL query as a string, concatenating a list of lines if necessary.