Versions Compared

Key

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

...

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.

...

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 As an example, please see the DTI housing example located Housing Coverage Example here: https://github.com/c3aidti/HouseCoverageExample

In this example, the BlockInfo Type BlockInfo defines contains information aggregated about census blocks. We can for example, fetch BlockInfo types fetch BlockInfo records, for which the 'prp_bf_lr' property is defined. Then we can order them based on field exists (i.e., is not null). We can also retrieve these records in descending order by their 'id' properly.

Code Block
languagejs
BlockInfo.fetch({
	'limit': -1,
	'filter': 'exists(prp_bf_lr)',
	'order': 'descending(id)',
	'include': 'pct_i_l,pct_t_l,prp_res_lr,pop10_ha_lr,hu10_ha_lr,eroom_ha_lr,med10_age,prp_bf_lr',
})

Here's how you would perform the same fetch in pythonYou can run this same fetch in Python:

Code Block
languagepy
raw_data = c3.BlockInfo.fetch(spec={
    'limit': -1,
    'filter': 'exists(prp_bf_lr)',
    'order': 'descending(id)',
    'include': 'pct_i_l,pct_t_l,prp_res_lr,pop10_ha_lr,hu10_ha_lr,eroom_ha_lr,med10_age,prp_bf_lr'
})

Another useful fetch command is fetchCount. This function is nearly identical to the fetch commands above, but it just returns a count of the number of objects which match the fetch filter. This is useful when trying to determine whether a given search is refined enough.

In the Javascript Console this is:

Code Block
BlockInfo.fetchCount({'filter': 'exists(prp_bf_lr)'})

The same in python is:

Code Block
c3.BlockInfo.fetchCount(spec={'filter': 'exists(prp_bf_lr)'})

...

Additional details on "Fetching in Python" are available in this C3.ai Developer Documentation: https://developer.c3.ai/docs/7.12.0/topic/ds-jupyter-notebooks

Additional examples of fetch calls can be found in our examples here:

Here is a list of C3 documentation mentioning fetching:

...

Another useful fetch command is fetchCount. This function is nearly identical to the fetch commands above, but it just returns a count of the number of objects which match the fetch filter. This is useful when trying to determine whether a given search is refined enough.

In the Javascript Console this is:

Code Block
BlockInfo.fetchCount({'filter': 'exists(prp_bf_lr)'})

The same in python is:

Code Block
c3.BlockInfo.fetchCount(spec={'filter': 'exists(prp_bf_lr)'})

...


Converting Fetch results to usable forms in Jupyter Notebook

...