Versions Compared

Key

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

...

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

As an example, please see the DTI Housing Coverage Example here: https://github.com/c3aidti/HouseCoverageExample

In this example, the BlockInfo Type contains information aggregated about census blocksThe OutbreakLocation Type contains information various locations for which the Covid-19 DataLake has virus-related information. We can fetch BlockInfo OutbreakLocation records, for which the 'prp_bf_lrlatestTotalPopulation' field exists (i.e., is not null). We can also retrieve these records in descending order by their 'idcountryArea'.

Code Block
languagejs
BlockInfores = OutbreakLocation.fetch({
	'limit': -1,
	'filter': 'exists(prp_bf_lrlatestTotalPopulation)',
	'order': 'descending(idlatestTotalPopulation)',
	'include': 'pct_i_l,pct_t_l,prp_res_lr,pop10_ha_lr,hu10_ha_lr,eroom_ha_lr,med10_age,prp_bf_lr',
})id, name, latestTotalPopulation, populationOfAllChildren, countryArea, countryCode'
})

And we can show these results in the C3 static console using the c3Grid command.

Image Added

You can run this same fetch in Python:

Code Block
languagepy
raw_data = c3.BlockInfoOutbreakLocation.fetch(spec={
    	'limit': -1,
    	'filter': 'exists(prp_bf_lrlatestTotalPopulation)',
    	'order': 'descending(idlatestTotalPopulation)',
    	'include': 'pct_i_l,pct_t_l,prp_res_lr,pop10_ha_lr,hu10_ha_lr,eroom_ha_lr,med10_age,prp_bf_lrid, name, latestTotalPopulation, populationOfAllChildren, countryArea, countryCode'
})

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

...

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

Code Block
BlockInfoOutbreakLocation.fetchCount({'filter': 'exists(prp_bf_lrlatestTotalPopulation)'})

The same in python is:

Code Block
c3.BlockInfoOutbreakLocation.fetchCount(spec={'filter': 'exists(prp_bf_lrlatestTotalPopulation)'})


Converting Fetch results to usable forms in Jupyter Notebook

...