Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Fetching Instances of Types

All data in C3 is represented by a 'Type'. Data for a specific type can be 'fetched' from C3 using the C3 AI Suite are stored in C3.ai Types.Users can access data from a C3.ai Type with the 'fetch' API. In each language, each Type has a method. Behind the scenes, the 'fetch' function to which a FetchSpec Type can be passed. This function then retrieves the data in a FetchResult Type which can be opened and used for data analysis.

Fetching is governed by the FetchSpec Type and you can find full documentation of that type here. However, as a simple API description, may not be particularly helpful at first. Generally, the FetchSpec type defines a set of constraints to apply when gathering Type data. it can be 'empty' i.e. without constraints, but generally you'll want to apply one or more to get reasonable results.

The most useful properties of the FetchSpec are:

  • filter: Defines an expression to evaluate for each type. When the expression evaluates as true, that type is fetched.
  • limit: Fetch only 'limit' results. Can be useful to debug a fetch which might grab a lot of results.
  • include: Define specific properties of the Type to include in the fetch result. If not defined, all properties will be grabbed.
  • order: An expression which defines the order to return the results in.

...

method submits a query directly to the database underlying a C3.ai Type, and retrieves and presents query results to C3 AI Suite users.

The C3 AI Suite returns the 'fetch' query's response, which includes (1) data from the C3.ai Type itself; (2) Metadata for the 'fetch' query (e.g., the number of objects, whether additional data exists in the database) into the FetchResult type, for data analysis (see example below).

To learn more about the 'fetch' method, please see the following C3.ai Developer Documentation:

Users can also provide a FetchSpec (or parameters) to the 'fetch' method to describe particular data to retrieve (e.g., only retrieve gene sequences collected in Germany). The FetchSpec can be 'empty' (e.g., OutbreakLocation.fetch()), or contain several parameters to return a subset of the data.

Some example FetchSpec parameters include:

  • filter: Filter expression to return a subset of the data (e.g., age <= 20). Filter expressions must evaluate to a Boolean type (i.e., true or false)
  • limit: the maximum number of rows that should be returned. Be default, if no limit is specified, the C3 AI Suite returns 2,000 rows from the C3.ai Type. Specifying a limit is often helpful to debug a fetch 'method', without returning too many records.
  • include: Specifies the particular fields from a C3.ai Type to return to the FetchResult. By default, if no include spec is defined, all fields from the C3.ai Type will be returned.
  • order: Specifies the order to return the query's results (either "ascending" or "descending")

Note: Please see this C3.ai Developer Documentation for full list of FetchSpec parameters: https://developer.c3.ai/docs/7.12.17/type/FetchSpec

Examples of Fetch Calls

Consider the DTI housing example located here: https://github.com/c3aidti/HouseCoverageExample

...