Skip to main content

Define Models

The purpose of the model is to establish the logical layer of your data source. It involves describing the specific data you intend to expose using the Accio MDL.

data modeling

For orders table, we can describe it as below:

Model Orders @sql(select * from tpch_tiny.orders) {
orderkey: INTEGER! @primaryKey
custkey: INTEGER!
orderstatus: OrderStatus
totalprice: REAL
}

There are a few things we did here:

  • Describe underlying statement The @sql directive is used to describe the underlying SQL statement that retrieves the original data from the data source. In this case, the SQL statement select * from tpch_tiny.orders is specified, indicating that the data for the orders table is fetched from the specific table within that source is tpch_tiny.orders.
  • List columns: list out column schema The snippet lists the schema for the columns in the orders table, providing details such as the column name, data type, and any additional annotations. Overall, this MDL snippet describes the structure and properties of the orders table, including the source from which the data is fetched and the column definitions with their respective data types and annotations (such as primary key).

Describe your Models and Columns

Accio provides a powerful feature called description that allows users to add annotations, denoted by the @desc tag, to provide meaningful comments for a model or a column.

Model Orders @sql(select * from tpch_tiny.orders) @desc("all received orders"){
orderkey: INTEGER! @primaryKey
custkey: INTEGER!
orderstatus: OrderStatus @desc("the status of an order")
totalprice: REAL @desc("sum of the price of its lineitems")
}

These descriptions are intended to be human-readable and serve multiple purposes. Not only do they enhance the readability of the code for humans, but they also aid the AI in generating the query language effectively. By providing clear and informative descriptions, we can empower the AI model to become more intelligent and accurate in its understanding and generation of queries.

Accio provide a Chatgpt plugin which is used to transfer your business question to an Accio SQL. More detail, see