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.Basic join
An inner join keeps matching records:Find records without a match
A left join keeps every record from the left table and fills missing right-side values withNULL. Add WHERE l.doc_id IS NULL to return only unlabeled documents:
Handle duplicate keys
This example joinscuration_documents.doc_id to curation_labels.doc_id.
First check whether the label table contains more than one row per document:
Call a Function across the join
A Function can read columns from either side of a join, the same as any other expression — it runs once the join has matched rows, not before. Registercaption_quality first:
caption_quality only
runs on rows that actually matched a label — a document with no label
never pays for the Function call.
Join tables across namespaces
Use a table’s qualified path to address it in another namespace. For example, a table namedimages in
prod.media is addressed as prod.media.images. The same matching-key and
join-type rules apply; your identity needs access to the source objects.