Example data
Connect with an Enterprise SQL client. The examples use a small document table and a separate label table. Expand the setup below to create them.Create the example tables
Create the example tables
curation_documents has six records describing four documents.
curation_labels has one label for each of three documents. row_id identifies
a record; doc_id identifies the document it describes.Run each statement separately in a scratch database or namespace. Create these
tables once for the whole section, using fresh names if they already exist.score is a sample quality score, not a search result score. Document 10 has
two versions. Document 30 has two records at the same version. Document 40
has no label. These cases let you check the effect of each operation.Count records and missing values
Usecount(*) to count rows and count(column) to count non-null values.
Add DISTINCT to count unique values:
count(column) excludes null values; it does not check whether a
string is empty or whether a value is useful for the task.
Group records by label
UseGROUP BY to calculate a summary for each label:
Count records that match a condition
FILTER applies a condition to one aggregate. Here, books has 2 records,
1 high-score record and no missing captions. web has 4 records, 1 high-score
record and 2 missing captions. Counts are per record, so repeated document IDs
still contribute more than once.
Group numeric values into ranges
Usecount(DISTINCT column) for the number of distinct non-null values.
For numeric fields, group by a range or summarize their distribution. For
example, this query counts records in score buckets of width 0.1:
Aggregate over a Function’s result
An aggregate can summarize a Function’s output the same as any other expression — the engine computes the Function once per row, then aggregates. Registercaption_quality the
same way any other curation Function is registered: