Malloy Documentation
search

Malloy has a special query operator that builds _Dimensional Search Indexes for sources. A Dimensional Search Index is a table with 4 columns. Dimensional indexes are useful for a variety of things including filtering suggestions and LLMs.

When filtering data, you might know a term, but not necessarily which column in the one of the join data contains it. Indexing the data on field names and high cardinality fields let's you qucikly find the term and the associated value.

Indexing could be used by LLMs to find the interesting column/term mapping in the data set.

  • fieldName - The path to the column in the source

  • fieldValue - The dimensional value for the field (or range if fieldType is not a string)

  • fieldType - Type type of the column.

  • weight - a weighting to use as to the importance the distinct dimensional value. Defaults to cardinality of the field.

Simple Example

We're going to take the airports table and index it. The results are an un ordered list of distinct fieldName/fieldValue pairs appear in the table. The weight, in this case is the number of rows that partciular occurs on.

document
run: duckdb.table('../data/airports.parquet') -> {
  index: *
}
QUERY RESULTS
fieldNamefieldPathfieldValuefieldTypeweight
act_dateact_date04/1983string76
act_dateact_date02/1985string42
act_dateact_date12/1991string62
act_dateact_date09/1983string25
act_dateact_date04/1988string52
act_dateact_date03/1993string127
act_dateact_date08/1993string18
act_dateact_date09/1988string14
act_dateact_date04/1987string36
act_dateact_date10/1984string69
act_dateact_date08/1992string35
act_dateact_date05/1995string22
act_dateact_date10/1985string45
act_dateact_date09/1984string11
act_dateact_date01/1983string23
act_dateact_date02/1990string37
act_dateact_date11/2000string70
act_dateact_date06/1993string52
act_dateact_date08/1982string50
act_dateact_date04/1993string145
act_dateact_date03/1995string3
act_dateact_date05/1989string59
act_dateact_date06/1986string13
act_dateact_date06/1989string56
act_dateact_date05/1994string22
act_dateact_date10/1988string5
act_dateact_date05/1998string57
act_dateact_date12/1982string48
act_dateact_date07/1989string83
act_dateact_date12/2000string13
act_dateact_date07/1991string16
act_dateact_date11/1983string51
act_dateact_date11/1999string8
act_dateact_date08/2000string19
act_dateact_date12/1984string7
aero_chtaero_chtCAPE LISBURNEstring20
aero_chtaero_chtMC GRATHstring53
aero_chtaero_chtKODIAKstring86
aero_chtaero_chtDAWSONstring9
aero_chtaero_chtDUTCH HARBORstring5
aero_chtaero_chtCOLD BAYstring11
aero_chtaero_chtMEMPHISstring605
aero_chtaero_chtALBUQUERQUEstring174
cbd_dircbd_dirNstring3,694
cbd_dircbd_dirstring119
cbd_dircbd_dirNWstring2,438
certcertBS 07/1973string2
certcertLU 12/1981string2
certcertBS 05/1973string81
certcertLU 08/1976string7
certcertEU 05/1973string1
certcertAS 06/1989string2
certcertAS 01/1989string1
certcertBS 06/1973string1
certcertAS 04/1988string1
certcertAU 05/1973string25
citycityUTIRIK ISLANDstring1
citycityANGAUR ISLANDstring1
citycityKOSRAE ISLANDstring1
citycityPOHNPEI ISLANDstring1
citycityMAJURO ATOLLstring1
citycityANIAKstring1
citycityNORTH POLEstring6
citycitySKETNAstring1
citycityKENAIstring8
citycityBUCKLANDstring1
citycityKUPARUKstring1
citycityCHANDALAR LAKEstring1
citycityCANTWELLstring3
citycityCENTRALstring1
citycityCHUATHBALUKstring1
citycityNELSON LAGOONstring1
citycityCHENEGAstring1
citycityTAYLOR MOUNTAIN MINEstring1
citycityANVIKstring2
citycityRUSSIAN MISSIONstring2
citycityBETHELstring8
citycityOLD HARBORstring1
citycityCIRCLEstring2
citycityANCHOR POINTstring1
citycityHOUSTONstring108
citycityKOTLIKstring1
citycityNIKISKIstring1
citycityRED DOGstring1
citycityCHANDALAR CAMPstring1
citycityEMMONAKstring1
citycityYUKON CHARLEY RIVERSstring1
citycityCANDLEstring1
citycityGALBRAITH LAKEstring1
citycityCHIGNIKstring3
citycityPORT CLARENCEstring1
citycityUNALAKLEETstring1
citycityRAINY PASSstring1
citycityAKHIOKstring1
citycityGOLDEN HORN LODGEstring1
citycitySELDOVIAstring2
citycityCHITINAstring1
citycityNOATAKstring1
citycityPURKEYPILEstring1
citycityTRADING BAYstring1
[
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "04/1983",
    "weight": 76
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "02/1985",
    "weight": 42
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "12/1991",
    "weight": 62
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "09/1983",
    "weight": 25
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "04/1988",
    "weight": 52
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "03/1993",
    "weight": 127
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "08/1993",
    "weight": 18
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "09/1988",
    "weight": 14
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "04/1987",
    "weight": 36
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "10/1984",
    "weight": 69
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "08/1992",
    "weight": 35
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "05/1995",
    "weight": 22
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "10/1985",
    "weight": 45
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "09/1984",
    "weight": 11
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "01/1983",
    "weight": 23
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "02/1990",
    "weight": 37
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "11/2000",
    "weight": 70
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "06/1993",
    "weight": 52
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "08/1982",
    "weight": 50
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "04/1993",
    "weight": 145
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "03/1995",
    "weight": 3
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "05/1989",
    "weight": 59
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "06/1986",
    "weight": 13
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "06/1989",
    "weight": 56
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "05/1994",
    "weight": 22
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "10/1988",
    "weight": 5
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "05/1998",
    "weight": 57
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "12/1982",
    "weight": 48
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "07/1989",
    "weight": 83
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "12/2000",
    "weight": 13
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "07/1991",
    "weight": 16
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "11/1983",
    "weight": 51
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "11/1999",
    "weight": 8
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "08/2000",
    "weight": 19
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": "12/1984",
    "weight": 7
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "CAPE LISBURNE",
    "weight": 20
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "MC GRATH",
    "weight": 53
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "KODIAK",
    "weight": 86
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "DAWSON",
    "weight": 9
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "DUTCH HARBOR",
    "weight": 5
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "COLD BAY",
    "weight": 11
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "MEMPHIS",
    "weight": 605
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "ALBUQUERQUE",
    "weight": 174
  },
  {
    "fieldName": "cbd_dir",
    "fieldPath": "cbd_dir",
    "fieldType": "string",
    "fieldValue": "N",
    "weight": 3694
  },
  {
    "fieldName": "cbd_dir",
    "fieldPath": "cbd_dir",
    "fieldType": "string",
    "fieldValue": null,
    "weight": 119
  },
  {
    "fieldName": "cbd_dir",
    "fieldPath": "cbd_dir",
    "fieldType": "string",
    "fieldValue": "NW",
    "weight": 2438
  },
  {
    "fieldName": "cert",
    "fieldPath": "cert",
    "fieldType": "string",
    "fieldValue": "BS 07/1973",
    "weight": 2
  },
  {
    "fieldName": "cert",
    "fieldPath": "cert",
    "fieldType": "string",
    "fieldValue": "LU 12/1981",
    "weight": 2
  },
  {
    "fieldName": "cert",
    "fieldPath": "cert",
    "fieldType": "string",
    "fieldValue": "BS 05/1973",
    "weight": 81
  },
  {
    "fieldName": "cert",
    "fieldPath": "cert",
    "fieldType": "string",
    "fieldValue": "LU 08/1976",
    "weight": 7
  },
  {
    "fieldName": "cert",
    "fieldPath": "cert",
    "fieldType": "string",
    "fieldValue": "EU 05/1973",
    "weight": 1
  },
  {
    "fieldName": "cert",
    "fieldPath": "cert",
    "fieldType": "string",
    "fieldValue": "AS 06/1989",
    "weight": 2
  },
  {
    "fieldName": "cert",
    "fieldPath": "cert",
    "fieldType": "string",
    "fieldValue": "AS 01/1989",
    "weight": 1
  },
  {
    "fieldName": "cert",
    "fieldPath": "cert",
    "fieldType": "string",
    "fieldValue": "BS 06/1973",
    "weight": 1
  },
  {
    "fieldName": "cert",
    "fieldPath": "cert",
    "fieldType": "string",
    "fieldValue": "AS 04/1988",
    "weight": 1
  },
  {
    "fieldName": "cert",
    "fieldPath": "cert",
    "fieldType": "string",
    "fieldValue": "AU 05/1973",
    "weight": 25
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "UTIRIK ISLAND",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "ANGAUR ISLAND",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "KOSRAE ISLAND",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "POHNPEI ISLAND",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "MAJURO ATOLL",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "ANIAK",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "NORTH POLE",
    "weight": 6
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "SKETNA",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "KENAI",
    "weight": 8
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "BUCKLAND",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "KUPARUK",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "CHANDALAR LAKE",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "CANTWELL",
    "weight": 3
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "CENTRAL",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "CHUATHBALUK",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "NELSON LAGOON",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "CHENEGA",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "TAYLOR MOUNTAIN MINE",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "ANVIK",
    "weight": 2
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "RUSSIAN MISSION",
    "weight": 2
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "BETHEL",
    "weight": 8
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "OLD HARBOR",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "CIRCLE",
    "weight": 2
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "ANCHOR POINT",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "HOUSTON",
    "weight": 108
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "KOTLIK",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "NIKISKI",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "RED DOG",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "CHANDALAR CAMP",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "EMMONAK",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "YUKON CHARLEY RIVERS",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "CANDLE",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "GALBRAITH LAKE",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "CHIGNIK",
    "weight": 3
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "PORT CLARENCE",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "UNALAKLEET",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "RAINY PASS",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "AKHIOK",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "GOLDEN HORN LODGE",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "SELDOVIA",
    "weight": 2
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "CHITINA",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "NOATAK",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "PURKEYPILE",
    "weight": 1
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "TRADING BAY",
    "weight": 1
  }
]
WITH __stage0 AS (
  SELECT
    group_set,
    CASE group_set
      WHEN 0 THEN 'act_date'
      WHEN 1 THEN 'aero_cht'
      WHEN 2 THEN 'c_ldg_rts'
      WHEN 3 THEN 'cbd_dir'
      WHEN 4 THEN 'cbd_dist'
      WHEN 5 THEN 'cert'
      WHEN 6 THEN 'city'
      WHEN 7 THEN 'cntl_twr'
      WHEN 8 THEN 'code'
      WHEN 9 THEN 'county'
      WHEN 10 THEN 'cust_intl'
      WHEN 11 THEN 'elevation'
      WHEN 12 THEN 'faa_dist'
      WHEN 13 THEN 'faa_region'
      WHEN 14 THEN 'fac_type'
      WHEN 15 THEN 'fac_use'
      WHEN 16 THEN 'fed_agree'
      WHEN 17 THEN 'full_name'
      WHEN 18 THEN 'id'
      WHEN 19 THEN 'joint_use'
      WHEN 20 THEN 'latitude'
      WHEN 21 THEN 'longitude'
      WHEN 22 THEN 'major'
      WHEN 23 THEN 'mil_rts'
      WHEN 24 THEN 'own_type'
      WHEN 25 THEN 'site_number'
      WHEN 26 THEN 'state'
    END as "fieldName",
    CASE group_set
      WHEN 0 THEN 'act_date'
      WHEN 1 THEN 'aero_cht'
      WHEN 2 THEN 'c_ldg_rts'
      WHEN 3 THEN 'cbd_dir'
      WHEN 4 THEN 'cbd_dist'
      WHEN 5 THEN 'cert'
      WHEN 6 THEN 'city'
      WHEN 7 THEN 'cntl_twr'
      WHEN 8 THEN 'code'
      WHEN 9 THEN 'county'
      WHEN 10 THEN 'cust_intl'
      WHEN 11 THEN 'elevation'
      WHEN 12 THEN 'faa_dist'
      WHEN 13 THEN 'faa_region'
      WHEN 14 THEN 'fac_type'
      WHEN 15 THEN 'fac_use'
      WHEN 16 THEN 'fed_agree'
      WHEN 17 THEN 'full_name'
      WHEN 18 THEN 'id'
      WHEN 19 THEN 'joint_use'
      WHEN 20 THEN 'latitude'
      WHEN 21 THEN 'longitude'
      WHEN 22 THEN 'major'
      WHEN 23 THEN 'mil_rts'
      WHEN 24 THEN 'own_type'
      WHEN 25 THEN 'site_number'
      WHEN 26 THEN 'state'
    END as "fieldPath",
    CASE group_set
      WHEN 0 THEN 'string'
      WHEN 1 THEN 'string'
      WHEN 2 THEN 'string'
      WHEN 3 THEN 'string'
      WHEN 4 THEN 'number'
      WHEN 5 THEN 'string'
      WHEN 6 THEN 'string'
      WHEN 7 THEN 'string'
      WHEN 8 THEN 'string'
      WHEN 9 THEN 'string'
      WHEN 10 THEN 'string'
      WHEN 11 THEN 'number'
      WHEN 12 THEN 'string'
      WHEN 13 THEN 'string'
      WHEN 14 THEN 'string'
      WHEN 15 THEN 'string'
      WHEN 16 THEN 'string'
      WHEN 17 THEN 'string'
      WHEN 18 THEN 'number'
      WHEN 19 THEN 'string'
      WHEN 20 THEN 'number'
      WHEN 21 THEN 'number'
      WHEN 22 THEN 'string'
      WHEN 23 THEN 'string'
      WHEN 24 THEN 'string'
      WHEN 25 THEN 'string'
      WHEN 26 THEN 'string'
    END as "fieldType",  CASE group_set WHEN 99999 THEN CAST(NULL as VARCHAR)
      WHEN 0 THEN base."act_date"
      WHEN 1 THEN base."aero_cht"
      WHEN 2 THEN base."c_ldg_rts"
      WHEN 3 THEN base."cbd_dir"
      WHEN 5 THEN base."cert"
      WHEN 6 THEN base."city"
      WHEN 7 THEN base."cntl_twr"
      WHEN 8 THEN base."code"
      WHEN 9 THEN base."county"
      WHEN 10 THEN base."cust_intl"
      WHEN 12 THEN base."faa_dist"
      WHEN 13 THEN base."faa_region"
      WHEN 14 THEN base."fac_type"
      WHEN 15 THEN base."fac_use"
      WHEN 16 THEN base."fed_agree"
      WHEN 17 THEN base."full_name"
      WHEN 19 THEN base."joint_use"
      WHEN 22 THEN base."major"
      WHEN 23 THEN base."mil_rts"
      WHEN 24 THEN base."own_type"
      WHEN 25 THEN base."site_number"
      WHEN 26 THEN base."state"
    END as "fieldValue",
   COUNT(*) as weight,
    CASE group_set
      WHEN 99999 THEN ''    WHEN 4 THEN MIN(CAST(base."cbd_dist" as VARCHAR)) || ' to ' || CAST(MAX(base."cbd_dist") as VARCHAR)
      WHEN 11 THEN MIN(CAST(base."elevation" as VARCHAR)) || ' to ' || CAST(MAX(base."elevation") as VARCHAR)
      WHEN 18 THEN MIN(CAST(base."id" as VARCHAR)) || ' to ' || CAST(MAX(base."id") as VARCHAR)
      WHEN 20 THEN MIN(CAST(base."latitude" as VARCHAR)) || ' to ' || CAST(MAX(base."latitude") as VARCHAR)
      WHEN 21 THEN MIN(CAST(base."longitude" as VARCHAR)) || ' to ' || CAST(MAX(base."longitude") as VARCHAR)
    END as "fieldRange"
  FROM '../data/airports.parquet' as base
  CROSS JOIN (SELECT UNNEST(GENERATE_SERIES(0,27,1)) as group_set  ) as group_set
  GROUP BY 1,2,3,4,5
)
SELECT
  "fieldName",
  "fieldPath",
  "fieldType",
  COALESCE("fieldValue", "fieldRange") as "fieldValue",
  weight
FROM __stage0

Add Ordering

Adding a second query stage to filter on string columns and ordering by weight descending shows us the most common fieldName/fieldValue pairs in the dataset.

All Malloy queries run as a single SQL query. The index: operator is no different. Click the SQL tab to see how this works.

document
run: duckdb.table('../data/airports.parquet') -> {
  index: *
} -> {
  where: fieldType = 'string'
  select: *
  order_by: weight desc
}
QUERY RESULTS
fieldNamefieldPathfieldTypefieldValueweight
majormajorstringN19,523
certcertstring19,142
cntl_twrcntl_twrstringN19,124
fed_agreefed_agreestring16,252
cust_intlcust_intlstring15,145
c_ldg_rtsc_ldg_rtsstring15,145
joint_usejoint_usestring14,804
mil_rtsmil_rtsstring14,716
fac_usefac_usestringPR14,428
own_typeown_typestringPR14,306
fac_typefac_typestringAIRPORT13,925
act_dateact_datestring12,040
faa_distfaa_diststringNONE7,085
fac_usefac_usestringPU5,365
own_typeown_typestringPU5,174
fac_typefac_typestringHELIPORT5,135
joint_usejoint_usestringN4,779
cust_intlcust_intlstringN4,575
faa_regionfaa_regionstringAGL4,437
c_ldg_rtsc_ldg_rtsstringN4,365
cbd_dircbd_dirstringN3,694
faa_regionfaa_regionstringASW3,268
mil_rtsmil_rtsstringY2,958
faa_regionfaa_regionstringASO2,924
faa_regionfaa_regionstringAEA2,586
cbd_dircbd_dirstringNW2,438
cbd_dircbd_dirstringSW2,427
cbd_dircbd_dirstringNE2,393
cbd_dircbd_dirstringSE2,281
cbd_dircbd_dirstringS2,155
cbd_dircbd_dirstringE2,127
mil_rtsmil_rtsstringN2,119
faa_regionfaa_regionstringANM2,102
cbd_dircbd_dirstringW2,065
statestatestringTX1,845
fed_agreefed_agreestringNGY1,682
aero_chtaero_chtstringNEW YORK1,581
faa_regionfaa_regionstringACE1,579
faa_distfaa_diststringCHI1,528
faa_regionfaa_regionstringAWP1,503
aero_chtaero_chtstringCHICAGO1,480
aero_chtaero_chtstringDETROIT1,262
faa_distfaa_diststringDET1,240
faa_distfaa_diststringSEA1,162
faa_distfaa_diststringMSP1,046
faa_distfaa_diststringATL1,029
statestatestringCA984
faa_distfaa_diststringNYC957
faa_distfaa_diststringORL905
statestatestringIL890
aero_chtaero_chtstringDALLAS-FT WORTH888
aero_chtaero_chtstringWASHINGTON887
statestatestringFL856
aero_chtaero_chtstringST LOUIS847
faa_distfaa_diststringHAR846
statestatestringPA804
aero_chtaero_chtstringATLANTA780
aero_chtaero_chtstringHOUSTON765
faa_regionfaa_regionstringANE763
statestatestringOH749
aero_chtaero_chtstringSEATTLE749
aero_chtaero_chtstringKANSAS CITY713
aero_chtaero_chtstringTWIN CITIES699
faa_distfaa_diststringDEN679
cntl_twrcntl_twrstringY669
faa_distfaa_diststringDCA667
statestatestringIN643
aero_chtaero_chtstringCINCINNATI624
faa_distfaa_diststringBIS616
statestatestringAK608
faa_regionfaa_regionstringAAL608
aero_chtaero_chtstringMEMPHIS605
faa_distfaa_diststringSFO585
statestatestringNY576
aero_chtaero_chtstringOMAHA551
statestatestringWI543
statestatestringMO537
fed_agreefed_agreestringN515
statestatestringMN507
aero_chtaero_chtstringSAN ANTONIO503
faa_distfaa_diststringJAN502
statestatestringLA500
aero_chtaero_chtstringLOS ANGELES498
statestatestringMI489
faa_distfaa_diststringMEM487
statestatestringWA484
fac_typefac_typestringSEAPLANE BASE473
aero_chtaero_chtstringJACKSONVILLE467
aero_chtaero_chtstringNEW ORLEANS444
statestatestringOK443
statestatestringOR441
statestatestringGA440
statestatestringND436
aero_chtaero_chtstringSAN FRANCISCO427
statestatestringCO425
statestatestringVA421
aero_chtaero_chtstringGREEN BAY418
statestatestringKS415
statestatestringNC400
aero_chtaero_chtstringCHARLOTTE380
[
  {
    "fieldName": "major",
    "fieldPath": "major",
    "fieldType": "string",
    "fieldValue": "N",
    "weight": 19523
  },
  {
    "fieldName": "cert",
    "fieldPath": "cert",
    "fieldType": "string",
    "fieldValue": null,
    "weight": 19142
  },
  {
    "fieldName": "cntl_twr",
    "fieldPath": "cntl_twr",
    "fieldType": "string",
    "fieldValue": "N",
    "weight": 19124
  },
  {
    "fieldName": "fed_agree",
    "fieldPath": "fed_agree",
    "fieldType": "string",
    "fieldValue": null,
    "weight": 16252
  },
  {
    "fieldName": "cust_intl",
    "fieldPath": "cust_intl",
    "fieldType": "string",
    "fieldValue": null,
    "weight": 15145
  },
  {
    "fieldName": "c_ldg_rts",
    "fieldPath": "c_ldg_rts",
    "fieldType": "string",
    "fieldValue": null,
    "weight": 15145
  },
  {
    "fieldName": "joint_use",
    "fieldPath": "joint_use",
    "fieldType": "string",
    "fieldValue": null,
    "weight": 14804
  },
  {
    "fieldName": "mil_rts",
    "fieldPath": "mil_rts",
    "fieldType": "string",
    "fieldValue": null,
    "weight": 14716
  },
  {
    "fieldName": "fac_use",
    "fieldPath": "fac_use",
    "fieldType": "string",
    "fieldValue": "PR",
    "weight": 14428
  },
  {
    "fieldName": "own_type",
    "fieldPath": "own_type",
    "fieldType": "string",
    "fieldValue": "PR",
    "weight": 14306
  },
  {
    "fieldName": "fac_type",
    "fieldPath": "fac_type",
    "fieldType": "string",
    "fieldValue": "AIRPORT",
    "weight": 13925
  },
  {
    "fieldName": "act_date",
    "fieldPath": "act_date",
    "fieldType": "string",
    "fieldValue": null,
    "weight": 12040
  },
  {
    "fieldName": "faa_dist",
    "fieldPath": "faa_dist",
    "fieldType": "string",
    "fieldValue": "NONE",
    "weight": 7085
  },
  {
    "fieldName": "fac_use",
    "fieldPath": "fac_use",
    "fieldType": "string",
    "fieldValue": "PU",
    "weight": 5365
  },
  {
    "fieldName": "own_type",
    "fieldPath": "own_type",
    "fieldType": "string",
    "fieldValue": "PU",
    "weight": 5174
  },
  {
    "fieldName": "fac_type",
    "fieldPath": "fac_type",
    "fieldType": "string",
    "fieldValue": "HELIPORT",
    "weight": 5135
  },
  {
    "fieldName": "joint_use",
    "fieldPath": "joint_use",
    "fieldType": "string",
    "fieldValue": "N",
    "weight": 4779
  },
  {
    "fieldName": "cust_intl",
    "fieldPath": "cust_intl",
    "fieldType": "string",
    "fieldValue": "N",
    "weight": 4575
  },
  {
    "fieldName": "faa_region",
    "fieldPath": "faa_region",
    "fieldType": "string",
    "fieldValue": "AGL",
    "weight": 4437
  },
  {
    "fieldName": "c_ldg_rts",
    "fieldPath": "c_ldg_rts",
    "fieldType": "string",
    "fieldValue": "N",
    "weight": 4365
  },
  {
    "fieldName": "cbd_dir",
    "fieldPath": "cbd_dir",
    "fieldType": "string",
    "fieldValue": "N",
    "weight": 3694
  },
  {
    "fieldName": "faa_region",
    "fieldPath": "faa_region",
    "fieldType": "string",
    "fieldValue": "ASW",
    "weight": 3268
  },
  {
    "fieldName": "mil_rts",
    "fieldPath": "mil_rts",
    "fieldType": "string",
    "fieldValue": "Y",
    "weight": 2958
  },
  {
    "fieldName": "faa_region",
    "fieldPath": "faa_region",
    "fieldType": "string",
    "fieldValue": "ASO",
    "weight": 2924
  },
  {
    "fieldName": "faa_region",
    "fieldPath": "faa_region",
    "fieldType": "string",
    "fieldValue": "AEA",
    "weight": 2586
  },
  {
    "fieldName": "cbd_dir",
    "fieldPath": "cbd_dir",
    "fieldType": "string",
    "fieldValue": "NW",
    "weight": 2438
  },
  {
    "fieldName": "cbd_dir",
    "fieldPath": "cbd_dir",
    "fieldType": "string",
    "fieldValue": "SW",
    "weight": 2427
  },
  {
    "fieldName": "cbd_dir",
    "fieldPath": "cbd_dir",
    "fieldType": "string",
    "fieldValue": "NE",
    "weight": 2393
  },
  {
    "fieldName": "cbd_dir",
    "fieldPath": "cbd_dir",
    "fieldType": "string",
    "fieldValue": "SE",
    "weight": 2281
  },
  {
    "fieldName": "cbd_dir",
    "fieldPath": "cbd_dir",
    "fieldType": "string",
    "fieldValue": "S",
    "weight": 2155
  },
  {
    "fieldName": "cbd_dir",
    "fieldPath": "cbd_dir",
    "fieldType": "string",
    "fieldValue": "E",
    "weight": 2127
  },
  {
    "fieldName": "mil_rts",
    "fieldPath": "mil_rts",
    "fieldType": "string",
    "fieldValue": "N",
    "weight": 2119
  },
  {
    "fieldName": "faa_region",
    "fieldPath": "faa_region",
    "fieldType": "string",
    "fieldValue": "ANM",
    "weight": 2102
  },
  {
    "fieldName": "cbd_dir",
    "fieldPath": "cbd_dir",
    "fieldType": "string",
    "fieldValue": "W",
    "weight": 2065
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "TX",
    "weight": 1845
  },
  {
    "fieldName": "fed_agree",
    "fieldPath": "fed_agree",
    "fieldType": "string",
    "fieldValue": "NGY",
    "weight": 1682
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "NEW YORK",
    "weight": 1581
  },
  {
    "fieldName": "faa_region",
    "fieldPath": "faa_region",
    "fieldType": "string",
    "fieldValue": "ACE",
    "weight": 1579
  },
  {
    "fieldName": "faa_dist",
    "fieldPath": "faa_dist",
    "fieldType": "string",
    "fieldValue": "CHI",
    "weight": 1528
  },
  {
    "fieldName": "faa_region",
    "fieldPath": "faa_region",
    "fieldType": "string",
    "fieldValue": "AWP",
    "weight": 1503
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "CHICAGO",
    "weight": 1480
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "DETROIT",
    "weight": 1262
  },
  {
    "fieldName": "faa_dist",
    "fieldPath": "faa_dist",
    "fieldType": "string",
    "fieldValue": "DET",
    "weight": 1240
  },
  {
    "fieldName": "faa_dist",
    "fieldPath": "faa_dist",
    "fieldType": "string",
    "fieldValue": "SEA",
    "weight": 1162
  },
  {
    "fieldName": "faa_dist",
    "fieldPath": "faa_dist",
    "fieldType": "string",
    "fieldValue": "MSP",
    "weight": 1046
  },
  {
    "fieldName": "faa_dist",
    "fieldPath": "faa_dist",
    "fieldType": "string",
    "fieldValue": "ATL",
    "weight": 1029
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "CA",
    "weight": 984
  },
  {
    "fieldName": "faa_dist",
    "fieldPath": "faa_dist",
    "fieldType": "string",
    "fieldValue": "NYC",
    "weight": 957
  },
  {
    "fieldName": "faa_dist",
    "fieldPath": "faa_dist",
    "fieldType": "string",
    "fieldValue": "ORL",
    "weight": 905
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "IL",
    "weight": 890
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "DALLAS-FT WORTH",
    "weight": 888
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "WASHINGTON",
    "weight": 887
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "FL",
    "weight": 856
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "ST LOUIS",
    "weight": 847
  },
  {
    "fieldName": "faa_dist",
    "fieldPath": "faa_dist",
    "fieldType": "string",
    "fieldValue": "HAR",
    "weight": 846
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "PA",
    "weight": 804
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "ATLANTA",
    "weight": 780
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "HOUSTON",
    "weight": 765
  },
  {
    "fieldName": "faa_region",
    "fieldPath": "faa_region",
    "fieldType": "string",
    "fieldValue": "ANE",
    "weight": 763
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "OH",
    "weight": 749
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "SEATTLE",
    "weight": 749
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "KANSAS CITY",
    "weight": 713
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "TWIN CITIES",
    "weight": 699
  },
  {
    "fieldName": "faa_dist",
    "fieldPath": "faa_dist",
    "fieldType": "string",
    "fieldValue": "DEN",
    "weight": 679
  },
  {
    "fieldName": "cntl_twr",
    "fieldPath": "cntl_twr",
    "fieldType": "string",
    "fieldValue": "Y",
    "weight": 669
  },
  {
    "fieldName": "faa_dist",
    "fieldPath": "faa_dist",
    "fieldType": "string",
    "fieldValue": "DCA",
    "weight": 667
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "IN",
    "weight": 643
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "CINCINNATI",
    "weight": 624
  },
  {
    "fieldName": "faa_dist",
    "fieldPath": "faa_dist",
    "fieldType": "string",
    "fieldValue": "BIS",
    "weight": 616
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "AK",
    "weight": 608
  },
  {
    "fieldName": "faa_region",
    "fieldPath": "faa_region",
    "fieldType": "string",
    "fieldValue": "AAL",
    "weight": 608
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "MEMPHIS",
    "weight": 605
  },
  {
    "fieldName": "faa_dist",
    "fieldPath": "faa_dist",
    "fieldType": "string",
    "fieldValue": "SFO",
    "weight": 585
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "NY",
    "weight": 576
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "OMAHA",
    "weight": 551
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "WI",
    "weight": 543
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "MO",
    "weight": 537
  },
  {
    "fieldName": "fed_agree",
    "fieldPath": "fed_agree",
    "fieldType": "string",
    "fieldValue": "N",
    "weight": 515
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "MN",
    "weight": 507
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "SAN ANTONIO",
    "weight": 503
  },
  {
    "fieldName": "faa_dist",
    "fieldPath": "faa_dist",
    "fieldType": "string",
    "fieldValue": "JAN",
    "weight": 502
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "LA",
    "weight": 500
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "LOS ANGELES",
    "weight": 498
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "MI",
    "weight": 489
  },
  {
    "fieldName": "faa_dist",
    "fieldPath": "faa_dist",
    "fieldType": "string",
    "fieldValue": "MEM",
    "weight": 487
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "WA",
    "weight": 484
  },
  {
    "fieldName": "fac_type",
    "fieldPath": "fac_type",
    "fieldType": "string",
    "fieldValue": "SEAPLANE BASE",
    "weight": 473
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "JACKSONVILLE",
    "weight": 467
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "NEW ORLEANS",
    "weight": 444
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "OK",
    "weight": 443
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "OR",
    "weight": 441
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "GA",
    "weight": 440
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "ND",
    "weight": 436
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "SAN FRANCISCO",
    "weight": 427
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "CO",
    "weight": 425
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "VA",
    "weight": 421
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "GREEN BAY",
    "weight": 418
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "KS",
    "weight": 415
  },
  {
    "fieldName": "state",
    "fieldPath": "state",
    "fieldType": "string",
    "fieldValue": "NC",
    "weight": 400
  },
  {
    "fieldName": "aero_cht",
    "fieldPath": "aero_cht",
    "fieldType": "string",
    "fieldValue": "CHARLOTTE",
    "weight": 380
  }
]
WITH __stage0 AS (
  SELECT
    group_set,
    CASE group_set
      WHEN 0 THEN 'act_date'
      WHEN 1 THEN 'aero_cht'
      WHEN 2 THEN 'c_ldg_rts'
      WHEN 3 THEN 'cbd_dir'
      WHEN 4 THEN 'cbd_dist'
      WHEN 5 THEN 'cert'
      WHEN 6 THEN 'city'
      WHEN 7 THEN 'cntl_twr'
      WHEN 8 THEN 'code'
      WHEN 9 THEN 'county'
      WHEN 10 THEN 'cust_intl'
      WHEN 11 THEN 'elevation'
      WHEN 12 THEN 'faa_dist'
      WHEN 13 THEN 'faa_region'
      WHEN 14 THEN 'fac_type'
      WHEN 15 THEN 'fac_use'
      WHEN 16 THEN 'fed_agree'
      WHEN 17 THEN 'full_name'
      WHEN 18 THEN 'id'
      WHEN 19 THEN 'joint_use'
      WHEN 20 THEN 'latitude'
      WHEN 21 THEN 'longitude'
      WHEN 22 THEN 'major'
      WHEN 23 THEN 'mil_rts'
      WHEN 24 THEN 'own_type'
      WHEN 25 THEN 'site_number'
      WHEN 26 THEN 'state'
    END as "fieldName",
    CASE group_set
      WHEN 0 THEN 'act_date'
      WHEN 1 THEN 'aero_cht'
      WHEN 2 THEN 'c_ldg_rts'
      WHEN 3 THEN 'cbd_dir'
      WHEN 4 THEN 'cbd_dist'
      WHEN 5 THEN 'cert'
      WHEN 6 THEN 'city'
      WHEN 7 THEN 'cntl_twr'
      WHEN 8 THEN 'code'
      WHEN 9 THEN 'county'
      WHEN 10 THEN 'cust_intl'
      WHEN 11 THEN 'elevation'
      WHEN 12 THEN 'faa_dist'
      WHEN 13 THEN 'faa_region'
      WHEN 14 THEN 'fac_type'
      WHEN 15 THEN 'fac_use'
      WHEN 16 THEN 'fed_agree'
      WHEN 17 THEN 'full_name'
      WHEN 18 THEN 'id'
      WHEN 19 THEN 'joint_use'
      WHEN 20 THEN 'latitude'
      WHEN 21 THEN 'longitude'
      WHEN 22 THEN 'major'
      WHEN 23 THEN 'mil_rts'
      WHEN 24 THEN 'own_type'
      WHEN 25 THEN 'site_number'
      WHEN 26 THEN 'state'
    END as "fieldPath",
    CASE group_set
      WHEN 0 THEN 'string'
      WHEN 1 THEN 'string'
      WHEN 2 THEN 'string'
      WHEN 3 THEN 'string'
      WHEN 4 THEN 'number'
      WHEN 5 THEN 'string'
      WHEN 6 THEN 'string'
      WHEN 7 THEN 'string'
      WHEN 8 THEN 'string'
      WHEN 9 THEN 'string'
      WHEN 10 THEN 'string'
      WHEN 11 THEN 'number'
      WHEN 12 THEN 'string'
      WHEN 13 THEN 'string'
      WHEN 14 THEN 'string'
      WHEN 15 THEN 'string'
      WHEN 16 THEN 'string'
      WHEN 17 THEN 'string'
      WHEN 18 THEN 'number'
      WHEN 19 THEN 'string'
      WHEN 20 THEN 'number'
      WHEN 21 THEN 'number'
      WHEN 22 THEN 'string'
      WHEN 23 THEN 'string'
      WHEN 24 THEN 'string'
      WHEN 25 THEN 'string'
      WHEN 26 THEN 'string'
    END as "fieldType",  CASE group_set WHEN 99999 THEN CAST(NULL as VARCHAR)
      WHEN 0 THEN base."act_date"
      WHEN 1 THEN base."aero_cht"
      WHEN 2 THEN base."c_ldg_rts"
      WHEN 3 THEN base."cbd_dir"
      WHEN 5 THEN base."cert"
      WHEN 6 THEN base."city"
      WHEN 7 THEN base."cntl_twr"
      WHEN 8 THEN base."code"
      WHEN 9 THEN base."county"
      WHEN 10 THEN base."cust_intl"
      WHEN 12 THEN base."faa_dist"
      WHEN 13 THEN base."faa_region"
      WHEN 14 THEN base."fac_type"
      WHEN 15 THEN base."fac_use"
      WHEN 16 THEN base."fed_agree"
      WHEN 17 THEN base."full_name"
      WHEN 19 THEN base."joint_use"
      WHEN 22 THEN base."major"
      WHEN 23 THEN base."mil_rts"
      WHEN 24 THEN base."own_type"
      WHEN 25 THEN base."site_number"
      WHEN 26 THEN base."state"
    END as "fieldValue",
   COUNT(*) as weight,
    CASE group_set
      WHEN 99999 THEN ''    WHEN 4 THEN MIN(CAST(base."cbd_dist" as VARCHAR)) || ' to ' || CAST(MAX(base."cbd_dist") as VARCHAR)
      WHEN 11 THEN MIN(CAST(base."elevation" as VARCHAR)) || ' to ' || CAST(MAX(base."elevation") as VARCHAR)
      WHEN 18 THEN MIN(CAST(base."id" as VARCHAR)) || ' to ' || CAST(MAX(base."id") as VARCHAR)
      WHEN 20 THEN MIN(CAST(base."latitude" as VARCHAR)) || ' to ' || CAST(MAX(base."latitude") as VARCHAR)
      WHEN 21 THEN MIN(CAST(base."longitude" as VARCHAR)) || ' to ' || CAST(MAX(base."longitude") as VARCHAR)
    END as "fieldRange"
  FROM '../data/airports.parquet' as base
  CROSS JOIN (SELECT UNNEST(GENERATE_SERIES(0,27,1)) as group_set  ) as group_set
  GROUP BY 1,2,3,4,5
)
, __stage1 AS (
  SELECT
    "fieldName",
    "fieldPath",
    "fieldType",
    COALESCE("fieldValue", "fieldRange") as "fieldValue",
    weight
  FROM __stage0
)
SELECT 
   base."fieldName" as "fieldName",
   base."fieldPath" as "fieldPath",
   base."fieldType" as "fieldType",
   base."fieldValue" as "fieldValue",
   base."weight" as "weight"
FROM __stage1 as base
WHERE base."fieldType"='string'
ORDER BY 5 desc NULLS LAST

Index For Filtering User Interfaces

Indexes can be used find the best way to filter a dataset. For example supposed we'd like to find 'SANTA CRUZ' in the dataset. Upon approaching the dataset, but we don't which column might contain it. In a UI you might imagine that you type 'SANTA' and let have suggestons for values that might be appropriate. In the results we can see that top value, 'SANTA ROSA', appears as county on 26 rows in the table. We can also see that 'SANTA CRUZ' is both a city and a county..

document
run: duckdb.table('../data/airports.parquet') -> {
  index: *
} -> {
  where: fieldValue ~ r'SANTA'
  select: *
  order_by: weight desc
  limit: 15
}
QUERY RESULTS
fieldNamefieldPathfieldTypefieldValueweight
countycountystringSANTA ROSA26
countycountystringSANTA BARBARA22
countycountystringSANTA CRUZ10
countycountystringSANTA CLARA10
countycountystringSANTA FE9
citycitystringSANTA FE6
citycitystringSANTA ANA6
citycitystringSANTA BARBARA5
citycitystringSANTA ROSA4
citycitystringSANTA YNEZ3
citycitystringSANTA MARIA3
citycitystringSANTA YSABEL2
citycitystringRANCHO SANTA MARGARITA2
citycitystringSANTA CRUZ2
citycitystringSANTA ELENA2
[
  {
    "fieldName": "county",
    "fieldPath": "county",
    "fieldType": "string",
    "fieldValue": "SANTA ROSA",
    "weight": 26
  },
  {
    "fieldName": "county",
    "fieldPath": "county",
    "fieldType": "string",
    "fieldValue": "SANTA BARBARA",
    "weight": 22
  },
  {
    "fieldName": "county",
    "fieldPath": "county",
    "fieldType": "string",
    "fieldValue": "SANTA CRUZ",
    "weight": 10
  },
  {
    "fieldName": "county",
    "fieldPath": "county",
    "fieldType": "string",
    "fieldValue": "SANTA CLARA",
    "weight": 10
  },
  {
    "fieldName": "county",
    "fieldPath": "county",
    "fieldType": "string",
    "fieldValue": "SANTA FE",
    "weight": 9
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "SANTA FE",
    "weight": 6
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "SANTA ANA",
    "weight": 6
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "SANTA BARBARA",
    "weight": 5
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "SANTA ROSA",
    "weight": 4
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "SANTA YNEZ",
    "weight": 3
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "SANTA MARIA",
    "weight": 3
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "SANTA YSABEL",
    "weight": 2
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "RANCHO SANTA MARGARITA",
    "weight": 2
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "SANTA CRUZ",
    "weight": 2
  },
  {
    "fieldName": "city",
    "fieldPath": "city",
    "fieldType": "string",
    "fieldValue": "SANTA ELENA",
    "weight": 2
  }
]
WITH __stage0 AS (
  SELECT
    group_set,
    CASE group_set
      WHEN 0 THEN 'act_date'
      WHEN 1 THEN 'aero_cht'
      WHEN 2 THEN 'c_ldg_rts'
      WHEN 3 THEN 'cbd_dir'
      WHEN 4 THEN 'cbd_dist'
      WHEN 5 THEN 'cert'
      WHEN 6 THEN 'city'
      WHEN 7 THEN 'cntl_twr'
      WHEN 8 THEN 'code'
      WHEN 9 THEN 'county'
      WHEN 10 THEN 'cust_intl'
      WHEN 11 THEN 'elevation'
      WHEN 12 THEN 'faa_dist'
      WHEN 13 THEN 'faa_region'
      WHEN 14 THEN 'fac_type'
      WHEN 15 THEN 'fac_use'
      WHEN 16 THEN 'fed_agree'
      WHEN 17 THEN 'full_name'
      WHEN 18 THEN 'id'
      WHEN 19 THEN 'joint_use'
      WHEN 20 THEN 'latitude'
      WHEN 21 THEN 'longitude'
      WHEN 22 THEN 'major'
      WHEN 23 THEN 'mil_rts'
      WHEN 24 THEN 'own_type'
      WHEN 25 THEN 'site_number'
      WHEN 26 THEN 'state'
    END as "fieldName",
    CASE group_set
      WHEN 0 THEN 'act_date'
      WHEN 1 THEN 'aero_cht'
      WHEN 2 THEN 'c_ldg_rts'
      WHEN 3 THEN 'cbd_dir'
      WHEN 4 THEN 'cbd_dist'
      WHEN 5 THEN 'cert'
      WHEN 6 THEN 'city'
      WHEN 7 THEN 'cntl_twr'
      WHEN 8 THEN 'code'
      WHEN 9 THEN 'county'
      WHEN 10 THEN 'cust_intl'
      WHEN 11 THEN 'elevation'
      WHEN 12 THEN 'faa_dist'
      WHEN 13 THEN 'faa_region'
      WHEN 14 THEN 'fac_type'
      WHEN 15 THEN 'fac_use'
      WHEN 16 THEN 'fed_agree'
      WHEN 17 THEN 'full_name'
      WHEN 18 THEN 'id'
      WHEN 19 THEN 'joint_use'
      WHEN 20 THEN 'latitude'
      WHEN 21 THEN 'longitude'
      WHEN 22 THEN 'major'
      WHEN 23 THEN 'mil_rts'
      WHEN 24 THEN 'own_type'
      WHEN 25 THEN 'site_number'
      WHEN 26 THEN 'state'
    END as "fieldPath",
    CASE group_set
      WHEN 0 THEN 'string'
      WHEN 1 THEN 'string'
      WHEN 2 THEN 'string'
      WHEN 3 THEN 'string'
      WHEN 4 THEN 'number'
      WHEN 5 THEN 'string'
      WHEN 6 THEN 'string'
      WHEN 7 THEN 'string'
      WHEN 8 THEN 'string'
      WHEN 9 THEN 'string'
      WHEN 10 THEN 'string'
      WHEN 11 THEN 'number'
      WHEN 12 THEN 'string'
      WHEN 13 THEN 'string'
      WHEN 14 THEN 'string'
      WHEN 15 THEN 'string'
      WHEN 16 THEN 'string'
      WHEN 17 THEN 'string'
      WHEN 18 THEN 'number'
      WHEN 19 THEN 'string'
      WHEN 20 THEN 'number'
      WHEN 21 THEN 'number'
      WHEN 22 THEN 'string'
      WHEN 23 THEN 'string'
      WHEN 24 THEN 'string'
      WHEN 25 THEN 'string'
      WHEN 26 THEN 'string'
    END as "fieldType",  CASE group_set WHEN 99999 THEN CAST(NULL as VARCHAR)
      WHEN 0 THEN base."act_date"
      WHEN 1 THEN base."aero_cht"
      WHEN 2 THEN base."c_ldg_rts"
      WHEN 3 THEN base."cbd_dir"
      WHEN 5 THEN base."cert"
      WHEN 6 THEN base."city"
      WHEN 7 THEN base."cntl_twr"
      WHEN 8 THEN base."code"
      WHEN 9 THEN base."county"
      WHEN 10 THEN base."cust_intl"
      WHEN 12 THEN base."faa_dist"
      WHEN 13 THEN base."faa_region"
      WHEN 14 THEN base."fac_type"
      WHEN 15 THEN base."fac_use"
      WHEN 16 THEN base."fed_agree"
      WHEN 17 THEN base."full_name"
      WHEN 19 THEN base."joint_use"
      WHEN 22 THEN base."major"
      WHEN 23 THEN base."mil_rts"
      WHEN 24 THEN base."own_type"
      WHEN 25 THEN base."site_number"
      WHEN 26 THEN base."state"
    END as "fieldValue",
   COUNT(*) as weight,
    CASE group_set
      WHEN 99999 THEN ''    WHEN 4 THEN MIN(CAST(base."cbd_dist" as VARCHAR)) || ' to ' || CAST(MAX(base."cbd_dist") as VARCHAR)
      WHEN 11 THEN MIN(CAST(base."elevation" as VARCHAR)) || ' to ' || CAST(MAX(base."elevation") as VARCHAR)
      WHEN 18 THEN MIN(CAST(base."id" as VARCHAR)) || ' to ' || CAST(MAX(base."id") as VARCHAR)
      WHEN 20 THEN MIN(CAST(base."latitude" as VARCHAR)) || ' to ' || CAST(MAX(base."latitude") as VARCHAR)
      WHEN 21 THEN MIN(CAST(base."longitude" as VARCHAR)) || ' to ' || CAST(MAX(base."longitude") as VARCHAR)
    END as "fieldRange"
  FROM '../data/airports.parquet' as base
  CROSS JOIN (SELECT UNNEST(GENERATE_SERIES(0,27,1)) as group_set  ) as group_set
  GROUP BY 1,2,3,4,5
)
, __stage1 AS (
  SELECT
    "fieldName",
    "fieldPath",
    "fieldType",
    COALESCE("fieldValue", "fieldRange") as "fieldValue",
    weight
  FROM __stage0
)
SELECT 
   base."fieldName" as "fieldName",
   base."fieldPath" as "fieldPath",
   base."fieldType" as "fieldType",
   base."fieldValue" as "fieldValue",
   base."weight" as "weight"
FROM __stage1 as base
WHERE REGEXP_MATCHES(base."fieldValue", 'SANTA')
ORDER BY 5 desc NULLS LAST
LIMIT 15

We can then write a simple query to show the rows. It turns out that 'SANTA CRUZ' is a county in both California and Arizona.

document
run: duckdb.table('../data/airports.parquet') -> {
  where: county ~ 'SANTA CRUZ'
  select: *
}
QUERY RESULTS
act_​dateaero_​chtc_​ldg_​rtscbd_​dircbd_​distcertcitycntl_​twrcodecountycust_​intlelevationfaa_​distfaa_​regionfac_​typefac_​usefed_​agreefull_​nameidjoint_​uselatitudelongitudemajormil_​rtsown_​typesite_​numberstate
10/1987PHOENIXE1TUBACN2AZ8SANTA CRUZ3,200NONEAWPULTRALIGHTPRTUBAC ULTRALIGHT FLIGHTPARK1,44431.61-111.03NPR00811.*UAZ
PHOENIXNNE7NOGALESNOLSSANTA CRUZY3,955NONEAWPAIRPORTPUNGYNOGALES INTL1,312N31.41-110.84NYPU00739.*AAZ
LOS ANGELES0SAN NICOLAS ISLANDYNSISANTA CRUZ504NONEAWPAIRPORTPRSAN NICOLAS ISLAND NOLF2,28733.23-119.45NYMN02220.*ACA
07/1986SAN FRANCISCONW8SANTA CRUZNCL77SANTA CRUZ2,020SFOAWPAIRPORTPRBONNY DOON VILLAGE2,30737.07-122.12NPR02241.1*ACA
SAN FRANCISCONE3SANTA CRUZNCA37SANTA CRUZ115SFOAWPHELIPORTPRDOMINICAN SANTA CRUZ HOSPITAL2,30836.99-121.98NPR02241.12*HCA
SAN FRANCISCONW6DAVENPORTN6Q6SANTA CRUZ125SFOAWPAIRPORTPRLAS TRANCAS1,693N37.08-122.27NNPR01486.9*ACA
SAN FRANCISCONW5WATSONVILLENCA65SANTA CRUZ480SFOAWPHELIPORTPRALTA VISTA2,441N36.97-121.86NNPR02429.1*HCA
09/1987SAN FRANCISCOE0WATSONVILLENCL99SANTA CRUZ111SFOAWPHELIPORTPRWATSONVILLE COMMUNITY HOSPITAL2,44236.93-121.77NPU02429.11*HCA
SAN FRANCISCOW4WATSONVILLENCA66SANTA CRUZ70SFOAWPAIRPORTPRMONTEREY BAY ACADEMY2,443N36.9-121.84NNPR02429.2*ACA
SAN FRANCISCONNW3WATSONVILLENWVISANTA CRUZN160SFOAWPAIRPORTPUNGPRYWATSONVILLE MUNI2,440N36.93-121.78NYPU02429.*ACA
[
  {
    "act_date": "10/1987",
    "aero_cht": "PHOENIX",
    "c_ldg_rts": null,
    "cbd_dir": "E",
    "cbd_dist": 1,
    "cert": null,
    "city": "TUBAC",
    "cntl_twr": "N",
    "code": "2AZ8",
    "county": "SANTA CRUZ",
    "cust_intl": null,
    "elevation": 3200,
    "faa_dist": "NONE",
    "faa_region": "AWP",
    "fac_type": "ULTRALIGHT",
    "fac_use": "PR",
    "fed_agree": null,
    "full_name": "TUBAC ULTRALIGHT FLIGHTPARK",
    "id": 1444,
    "joint_use": null,
    "latitude": 31.61,
    "longitude": -111.03,
    "major": "N",
    "mil_rts": null,
    "own_type": "PR",
    "site_number": "00811.*U",
    "state": "AZ"
  },
  {
    "act_date": null,
    "aero_cht": "PHOENIX",
    "c_ldg_rts": "N",
    "cbd_dir": "NE",
    "cbd_dist": 7,
    "cert": null,
    "city": "NOGALES",
    "cntl_twr": "N",
    "code": "OLS",
    "county": "SANTA CRUZ",
    "cust_intl": "Y",
    "elevation": 3955,
    "faa_dist": "NONE",
    "faa_region": "AWP",
    "fac_type": "AIRPORT",
    "fac_use": "PU",
    "fed_agree": "NGY",
    "full_name": "NOGALES INTL",
    "id": 1312,
    "joint_use": "N",
    "latitude": 31.41,
    "longitude": -110.84,
    "major": "N",
    "mil_rts": "Y",
    "own_type": "PU",
    "site_number": "00739.*A",
    "state": "AZ"
  },
  {
    "act_date": null,
    "aero_cht": "LOS ANGELES",
    "c_ldg_rts": null,
    "cbd_dir": null,
    "cbd_dist": 0,
    "cert": null,
    "city": "SAN NICOLAS ISLAND",
    "cntl_twr": "Y",
    "code": "NSI",
    "county": "SANTA CRUZ",
    "cust_intl": null,
    "elevation": 504,
    "faa_dist": "NONE",
    "faa_region": "AWP",
    "fac_type": "AIRPORT",
    "fac_use": "PR",
    "fed_agree": null,
    "full_name": "SAN NICOLAS ISLAND NOLF",
    "id": 2287,
    "joint_use": null,
    "latitude": 33.23,
    "longitude": -119.45,
    "major": "N",
    "mil_rts": "Y",
    "own_type": "MN",
    "site_number": "02220.*A",
    "state": "CA"
  },
  {
    "act_date": "07/1986",
    "aero_cht": "SAN FRANCISCO",
    "c_ldg_rts": null,
    "cbd_dir": "NW",
    "cbd_dist": 8,
    "cert": null,
    "city": "SANTA CRUZ",
    "cntl_twr": "N",
    "code": "CL77",
    "county": "SANTA CRUZ",
    "cust_intl": null,
    "elevation": 2020,
    "faa_dist": "SFO",
    "faa_region": "AWP",
    "fac_type": "AIRPORT",
    "fac_use": "PR",
    "fed_agree": null,
    "full_name": "BONNY DOON VILLAGE",
    "id": 2307,
    "joint_use": null,
    "latitude": 37.07,
    "longitude": -122.12,
    "major": "N",
    "mil_rts": null,
    "own_type": "PR",
    "site_number": "02241.1*A",
    "state": "CA"
  },
  {
    "act_date": null,
    "aero_cht": "SAN FRANCISCO",
    "c_ldg_rts": null,
    "cbd_dir": "NE",
    "cbd_dist": 3,
    "cert": null,
    "city": "SANTA CRUZ",
    "cntl_twr": "N",
    "code": "CA37",
    "county": "SANTA CRUZ",
    "cust_intl": null,
    "elevation": 115,
    "faa_dist": "SFO",
    "faa_region": "AWP",
    "fac_type": "HELIPORT",
    "fac_use": "PR",
    "fed_agree": null,
    "full_name": "DOMINICAN SANTA CRUZ HOSPITAL",
    "id": 2308,
    "joint_use": null,
    "latitude": 36.99,
    "longitude": -121.98,
    "major": "N",
    "mil_rts": null,
    "own_type": "PR",
    "site_number": "02241.12*H",
    "state": "CA"
  },
  {
    "act_date": null,
    "aero_cht": "SAN FRANCISCO",
    "c_ldg_rts": null,
    "cbd_dir": "NW",
    "cbd_dist": 6,
    "cert": null,
    "city": "DAVENPORT",
    "cntl_twr": "N",
    "code": "6Q6",
    "county": "SANTA CRUZ",
    "cust_intl": null,
    "elevation": 125,
    "faa_dist": "SFO",
    "faa_region": "AWP",
    "fac_type": "AIRPORT",
    "fac_use": "PR",
    "fed_agree": null,
    "full_name": "LAS TRANCAS",
    "id": 1693,
    "joint_use": "N",
    "latitude": 37.08,
    "longitude": -122.27,
    "major": "N",
    "mil_rts": "N",
    "own_type": "PR",
    "site_number": "01486.9*A",
    "state": "CA"
  },
  {
    "act_date": null,
    "aero_cht": "SAN FRANCISCO",
    "c_ldg_rts": null,
    "cbd_dir": "NW",
    "cbd_dist": 5,
    "cert": null,
    "city": "WATSONVILLE",
    "cntl_twr": "N",
    "code": "CA65",
    "county": "SANTA CRUZ",
    "cust_intl": null,
    "elevation": 480,
    "faa_dist": "SFO",
    "faa_region": "AWP",
    "fac_type": "HELIPORT",
    "fac_use": "PR",
    "fed_agree": null,
    "full_name": "ALTA VISTA",
    "id": 2441,
    "joint_use": "N",
    "latitude": 36.97,
    "longitude": -121.86,
    "major": "N",
    "mil_rts": "N",
    "own_type": "PR",
    "site_number": "02429.1*H",
    "state": "CA"
  },
  {
    "act_date": "09/1987",
    "aero_cht": "SAN FRANCISCO",
    "c_ldg_rts": null,
    "cbd_dir": "E",
    "cbd_dist": 0,
    "cert": null,
    "city": "WATSONVILLE",
    "cntl_twr": "N",
    "code": "CL99",
    "county": "SANTA CRUZ",
    "cust_intl": null,
    "elevation": 111,
    "faa_dist": "SFO",
    "faa_region": "AWP",
    "fac_type": "HELIPORT",
    "fac_use": "PR",
    "fed_agree": null,
    "full_name": "WATSONVILLE COMMUNITY HOSPITAL",
    "id": 2442,
    "joint_use": null,
    "latitude": 36.93,
    "longitude": -121.77,
    "major": "N",
    "mil_rts": null,
    "own_type": "PU",
    "site_number": "02429.11*H",
    "state": "CA"
  },
  {
    "act_date": null,
    "aero_cht": "SAN FRANCISCO",
    "c_ldg_rts": null,
    "cbd_dir": "W",
    "cbd_dist": 4,
    "cert": null,
    "city": "WATSONVILLE",
    "cntl_twr": "N",
    "code": "CA66",
    "county": "SANTA CRUZ",
    "cust_intl": null,
    "elevation": 70,
    "faa_dist": "SFO",
    "faa_region": "AWP",
    "fac_type": "AIRPORT",
    "fac_use": "PR",
    "fed_agree": null,
    "full_name": "MONTEREY BAY ACADEMY",
    "id": 2443,
    "joint_use": "N",
    "latitude": 36.9,
    "longitude": -121.84,
    "major": "N",
    "mil_rts": "N",
    "own_type": "PR",
    "site_number": "02429.2*A",
    "state": "CA"
  },
  {
    "act_date": null,
    "aero_cht": "SAN FRANCISCO",
    "c_ldg_rts": "N",
    "cbd_dir": "NW",
    "cbd_dist": 3,
    "cert": null,
    "city": "WATSONVILLE",
    "cntl_twr": "N",
    "code": "WVI",
    "county": "SANTA CRUZ",
    "cust_intl": "N",
    "elevation": 160,
    "faa_dist": "SFO",
    "faa_region": "AWP",
    "fac_type": "AIRPORT",
    "fac_use": "PU",
    "fed_agree": "NGPRY",
    "full_name": "WATSONVILLE MUNI",
    "id": 2440,
    "joint_use": "N",
    "latitude": 36.93,
    "longitude": -121.78,
    "major": "N",
    "mil_rts": "Y",
    "own_type": "PU",
    "site_number": "02429.*A",
    "state": "CA"
  }
]
SELECT 
   base."act_date" as "act_date",
   base."aero_cht" as "aero_cht",
   base."c_ldg_rts" as "c_ldg_rts",
   base."cbd_dir" as "cbd_dir",
   base."cbd_dist" as "cbd_dist",
   base."cert" as "cert",
   base."city" as "city",
   base."cntl_twr" as "cntl_twr",
   base."code" as "code",
   base."county" as "county",
   base."cust_intl" as "cust_intl",
   base."elevation" as "elevation",
   base."faa_dist" as "faa_dist",
   base."faa_region" as "faa_region",
   base."fac_type" as "fac_type",
   base."fac_use" as "fac_use",
   base."fed_agree" as "fed_agree",
   base."full_name" as "full_name",
   base."id" as "id",
   base."joint_use" as "joint_use",
   base."latitude" as "latitude",
   base."longitude" as "longitude",
   base."major" as "major",
   base."mil_rts" as "mil_rts",
   base."own_type" as "own_type",
   base."site_number" as "site_number",
   base."state" as "state"
FROM '../data/airports.parquet' as base
WHERE base."county" LIKE 'SANTA CRUZ'

Indexing to show top values for each dimension

It is often difficult to approach a new dataset. The index operator provides an intersting way to quickly gain an understanding of the dataset. By piping the results of an index another stage, we can quickly see all the interesting values for each of the interesting dimesions. Again, the weight shows the number of rows for that particular dimension/value.

document
run: duckdb.table('../data/airports.parquet') -> {
  index: *
} -> {
  group_by: fieldName
  nest: values is {
    group_by: fieldValue, weight
    order_by: weight desc
    limit: 10
  }
  order_by: fieldName
}
QUERY RESULTS
fieldNamevalues
act_date
fieldValueweight
12,040
04/1993145
02/1987129
03/1993127
11/1990122
11/1986119
02/1982118
08/1988115
11/1988113
03/1988113
aero_cht
fieldValueweight
NEW YORK1,581
CHICAGO1,480
DETROIT1,262
DALLAS-FT WORTH888
WASHINGTON887
ST LOUIS847
ATLANTA780
HOUSTON765
SEATTLE749
KANSAS CITY713
c_ldg_rts
fieldValueweight
15,145
N4,365
Y283
cbd_dir
fieldValueweight
N3,694
NW2,438
SW2,427
NE2,393
SE2,281
S2,155
E2,127
W2,065
119
SSW20
cbd_dist
fieldValueweight
0 to 7319,793
cert
fieldValueweight
19,142
AS 05/197394
CS 05/197384
BS 05/197381
LU 05/197337
LU 08/199033
DS 05/197326
AU 05/197325
ES 05/197315
LU 11/19749
city
fieldValueweight
HOUSTON108
LOS ANGELES60
COLUMBUS47
SPRINGFIELD45
JACKSON42
GREENVILLE38
WASHINGTON38
PHOENIX37
CLINTON37
PHILADELPHIA35
cntl_twr
fieldValueweight
N19,124
Y669
code
fieldValueweight
ROR1
34AK1
CJX1
AKA1
43AK1
6K81
10AK1
EXI1
5Z21
MLL1
county
fieldValueweight
WASHINGTON214
JEFFERSON199
LOS ANGELES176
MONTGOMERY154
FRANKLIN140
JACKSON140
HARRIS137
MARION127
ORANGE125
MARICOPA117
cust_intl
fieldValueweight
15,145
N4,575
Y73
elevation
fieldValueweight
-1 to 1244219,793
faa_dist
fieldValueweight
NONE7,085
CHI1,528
DET1,240
SEA1,162
MSP1,046
ATL1,029
NYC957
ORL905
HAR846
DEN679
faa_region
fieldValueweight
AGL4,437
ASW3,268
ASO2,924
AEA2,586
ANM2,102
ACE1,579
AWP1,503
ANE763
AAL608
23
fac_type
fieldValueweight
AIRPORT13,925
HELIPORT5,135
SEAPLANE BASE473
ULTRALIGHT125
STOLPORT86
GLIDERPORT37
BALLOONPORT12
fac_use
fieldValueweight
PR14,428
PU5,365
fed_agree
fieldValueweight
16,252
NGY1,682
N515
NGY3219
NGPY171
NY1123
N197
196
NGSY87
NGPY384
full_name
fieldValueweight
MEMORIAL HOSPITAL21
SMITH14
JOHNSON13
ST MARY'S HOSPITAL11
MILLER10
DAVIS FIELD10
HILLTOP10
WILSON9
TAYLOR9
WILLIAMS9
id
fieldValueweight
1 to 1979319,793
joint_use
fieldValueweight
14,804
N4,779
Y210
latitude
fieldValueweight
-14.18 to 71.2819,793
longitude
fieldValueweight
-100.0 to 174.1119,793
major
fieldValueweight
N19,523
Y270
mil_rts
fieldValueweight
14,716
Y2,958
N2,119
own_type
fieldValueweight
PR14,306
PU5,174
MR128
MA107
MN78
site_number
fieldValueweight
51518.6*A1
51541.*A1
50410.13*C1
50720.04*A1
50080.5*A1
50870.21*A1
50530.*A1
50178.01*A1
50427.61*A1
50425.2*H1
state
fieldValueweight
TX1,845
CA984
IL890
FL856
PA804
OH749
IN643
AK608
NY576
WI543
fieldValueweight
19,793
[
  {
    "fieldName": "act_date",
    "values": [
      {
        "fieldValue": null,
        "weight": 12040
      },
      {
        "fieldValue": "04/1993",
        "weight": 145
      },
      {
        "fieldValue": "02/1987",
        "weight": 129
      },
      {
        "fieldValue": "03/1993",
        "weight": 127
      },
      {
        "fieldValue": "11/1990",
        "weight": 122
      },
      {
        "fieldValue": "11/1986",
        "weight": 119
      },
      {
        "fieldValue": "02/1982",
        "weight": 118
      },
      {
        "fieldValue": "08/1988",
        "weight": 115
      },
      {
        "fieldValue": "11/1988",
        "weight": 113
      },
      {
        "fieldValue": "03/1988",
        "weight": 113
      }
    ]
  },
  {
    "fieldName": "aero_cht",
    "values": [
      {
        "fieldValue": "NEW YORK",
        "weight": 1581
      },
      {
        "fieldValue": "CHICAGO",
        "weight": 1480
      },
      {
        "fieldValue": "DETROIT",
        "weight": 1262
      },
      {
        "fieldValue": "DALLAS-FT WORTH",
        "weight": 888
      },
      {
        "fieldValue": "WASHINGTON",
        "weight": 887
      },
      {
        "fieldValue": "ST LOUIS",
        "weight": 847
      },
      {
        "fieldValue": "ATLANTA",
        "weight": 780
      },
      {
        "fieldValue": "HOUSTON",
        "weight": 765
      },
      {
        "fieldValue": "SEATTLE",
        "weight": 749
      },
      {
        "fieldValue": "KANSAS CITY",
        "weight": 713
      }
    ]
  },
  {
    "fieldName": "c_ldg_rts",
    "values": [
      {
        "fieldValue": null,
        "weight": 15145
      },
      {
        "fieldValue": "N",
        "weight": 4365
      },
      {
        "fieldValue": "Y",
        "weight": 283
      }
    ]
  },
  {
    "fieldName": "cbd_dir",
    "values": [
      {
        "fieldValue": "N",
        "weight": 3694
      },
      {
        "fieldValue": "NW",
        "weight": 2438
      },
      {
        "fieldValue": "SW",
        "weight": 2427
      },
      {
        "fieldValue": "NE",
        "weight": 2393
      },
      {
        "fieldValue": "SE",
        "weight": 2281
      },
      {
        "fieldValue": "S",
        "weight": 2155
      },
      {
        "fieldValue": "E",
        "weight": 2127
      },
      {
        "fieldValue": "W",
        "weight": 2065
      },
      {
        "fieldValue": null,
        "weight": 119
      },
      {
        "fieldValue": "SSW",
        "weight": 20
      }
    ]
  },
  {
    "fieldName": "cbd_dist",
    "values": [
      {
        "fieldValue": "0 to 73",
        "weight": 19793
      }
    ]
  },
  {
    "fieldName": "cert",
    "values": [
      {
        "fieldValue": null,
        "weight": 19142
      },
      {
        "fieldValue": "AS 05/1973",
        "weight": 94
      },
      {
        "fieldValue": "CS 05/1973",
        "weight": 84
      },
      {
        "fieldValue": "BS 05/1973",
        "weight": 81
      },
      {
        "fieldValue": "LU 05/1973",
        "weight": 37
      },
      {
        "fieldValue": "LU 08/1990",
        "weight": 33
      },
      {
        "fieldValue": "DS 05/1973",
        "weight": 26
      },
      {
        "fieldValue": "AU 05/1973",
        "weight": 25
      },
      {
        "fieldValue": "ES 05/1973",
        "weight": 15
      },
      {
        "fieldValue": "LU 11/1974",
        "weight": 9
      }
    ]
  },
  {
    "fieldName": "city",
    "values": [
      {
        "fieldValue": "HOUSTON",
        "weight": 108
      },
      {
        "fieldValue": "LOS ANGELES",
        "weight": 60
      },
      {
        "fieldValue": "COLUMBUS",
        "weight": 47
      },
      {
        "fieldValue": "SPRINGFIELD",
        "weight": 45
      },
      {
        "fieldValue": "JACKSON",
        "weight": 42
      },
      {
        "fieldValue": "GREENVILLE",
        "weight": 38
      },
      {
        "fieldValue": "WASHINGTON",
        "weight": 38
      },
      {
        "fieldValue": "PHOENIX",
        "weight": 37
      },
      {
        "fieldValue": "CLINTON",
        "weight": 37
      },
      {
        "fieldValue": "PHILADELPHIA",
        "weight": 35
      }
    ]
  },
  {
    "fieldName": "cntl_twr",
    "values": [
      {
        "fieldValue": "N",
        "weight": 19124
      },
      {
        "fieldValue": "Y",
        "weight": 669
      }
    ]
  },
  {
    "fieldName": "code",
    "values": [
      {
        "fieldValue": "ROR",
        "weight": 1
      },
      {
        "fieldValue": "34AK",
        "weight": 1
      },
      {
        "fieldValue": "CJX",
        "weight": 1
      },
      {
        "fieldValue": "AKA",
        "weight": 1
      },
      {
        "fieldValue": "43AK",
        "weight": 1
      },
      {
        "fieldValue": "6K8",
        "weight": 1
      },
      {
        "fieldValue": "10AK",
        "weight": 1
      },
      {
        "fieldValue": "EXI",
        "weight": 1
      },
      {
        "fieldValue": "5Z2",
        "weight": 1
      },
      {
        "fieldValue": "MLL",
        "weight": 1
      }
    ]
  },
  {
    "fieldName": "county",
    "values": [
      {
        "fieldValue": "WASHINGTON",
        "weight": 214
      },
      {
        "fieldValue": "JEFFERSON",
        "weight": 199
      },
      {
        "fieldValue": "LOS ANGELES",
        "weight": 176
      },
      {
        "fieldValue": "MONTGOMERY",
        "weight": 154
      },
      {
        "fieldValue": "FRANKLIN",
        "weight": 140
      },
      {
        "fieldValue": "JACKSON",
        "weight": 140
      },
      {
        "fieldValue": "HARRIS",
        "weight": 137
      },
      {
        "fieldValue": "MARION",
        "weight": 127
      },
      {
        "fieldValue": "ORANGE",
        "weight": 125
      },
      {
        "fieldValue": "MARICOPA",
        "weight": 117
      }
    ]
  },
  {
    "fieldName": "cust_intl",
    "values": [
      {
        "fieldValue": null,
        "weight": 15145
      },
      {
        "fieldValue": "N",
        "weight": 4575
      },
      {
        "fieldValue": "Y",
        "weight": 73
      }
    ]
  },
  {
    "fieldName": "elevation",
    "values": [
      {
        "fieldValue": "-1 to 12442",
        "weight": 19793
      }
    ]
  },
  {
    "fieldName": "faa_dist",
    "values": [
      {
        "fieldValue": "NONE",
        "weight": 7085
      },
      {
        "fieldValue": "CHI",
        "weight": 1528
      },
      {
        "fieldValue": "DET",
        "weight": 1240
      },
      {
        "fieldValue": "SEA",
        "weight": 1162
      },
      {
        "fieldValue": "MSP",
        "weight": 1046
      },
      {
        "fieldValue": "ATL",
        "weight": 1029
      },
      {
        "fieldValue": "NYC",
        "weight": 957
      },
      {
        "fieldValue": "ORL",
        "weight": 905
      },
      {
        "fieldValue": "HAR",
        "weight": 846
      },
      {
        "fieldValue": "DEN",
        "weight": 679
      }
    ]
  },
  {
    "fieldName": "faa_region",
    "values": [
      {
        "fieldValue": "AGL",
        "weight": 4437
      },
      {
        "fieldValue": "ASW",
        "weight": 3268
      },
      {
        "fieldValue": "ASO",
        "weight": 2924
      },
      {
        "fieldValue": "AEA",
        "weight": 2586
      },
      {
        "fieldValue": "ANM",
        "weight": 2102
      },
      {
        "fieldValue": "ACE",
        "weight": 1579
      },
      {
        "fieldValue": "AWP",
        "weight": 1503
      },
      {
        "fieldValue": "ANE",
        "weight": 763
      },
      {
        "fieldValue": "AAL",
        "weight": 608
      },
      {
        "fieldValue": null,
        "weight": 23
      }
    ]
  },
  {
    "fieldName": "fac_type",
    "values": [
      {
        "fieldValue": "AIRPORT",
        "weight": 13925
      },
      {
        "fieldValue": "HELIPORT",
        "weight": 5135
      },
      {
        "fieldValue": "SEAPLANE BASE",
        "weight": 473
      },
      {
        "fieldValue": "ULTRALIGHT",
        "weight": 125
      },
      {
        "fieldValue": "STOLPORT",
        "weight": 86
      },
      {
        "fieldValue": "GLIDERPORT",
        "weight": 37
      },
      {
        "fieldValue": "BALLOONPORT",
        "weight": 12
      }
    ]
  },
  {
    "fieldName": "fac_use",
    "values": [
      {
        "fieldValue": "PR",
        "weight": 14428
      },
      {
        "fieldValue": "PU",
        "weight": 5365
      }
    ]
  },
  {
    "fieldName": "fed_agree",
    "values": [
      {
        "fieldValue": null,
        "weight": 16252
      },
      {
        "fieldValue": "NGY",
        "weight": 1682
      },
      {
        "fieldValue": "N",
        "weight": 515
      },
      {
        "fieldValue": "NGY3",
        "weight": 219
      },
      {
        "fieldValue": "NGPY",
        "weight": 171
      },
      {
        "fieldValue": "NY1",
        "weight": 123
      },
      {
        "fieldValue": "N1",
        "weight": 97
      },
      {
        "fieldValue": "1",
        "weight": 96
      },
      {
        "fieldValue": "NGSY",
        "weight": 87
      },
      {
        "fieldValue": "NGPY3",
        "weight": 84
      }
    ]
  },
  {
    "fieldName": "full_name",
    "values": [
      {
        "fieldValue": "MEMORIAL HOSPITAL",
        "weight": 21
      },
      {
        "fieldValue": "SMITH",
        "weight": 14
      },
      {
        "fieldValue": "JOHNSON",
        "weight": 13
      },
      {
        "fieldValue": "ST MARY'S HOSPITAL",
        "weight": 11
      },
      {
        "fieldValue": "MILLER",
        "weight": 10
      },
      {
        "fieldValue": "DAVIS FIELD",
        "weight": 10
      },
      {
        "fieldValue": "HILLTOP",
        "weight": 10
      },
      {
        "fieldValue": "WILSON",
        "weight": 9
      },
      {
        "fieldValue": "TAYLOR",
        "weight": 9
      },
      {
        "fieldValue": "WILLIAMS",
        "weight": 9
      }
    ]
  },
  {
    "fieldName": "id",
    "values": [
      {
        "fieldValue": "1 to 19793",
        "weight": 19793
      }
    ]
  },
  {
    "fieldName": "joint_use",
    "values": [
      {
        "fieldValue": null,
        "weight": 14804
      },
      {
        "fieldValue": "N",
        "weight": 4779
      },
      {
        "fieldValue": "Y",
        "weight": 210
      }
    ]
  },
  {
    "fieldName": "latitude",
    "values": [
      {
        "fieldValue": "-14.18 to 71.28",
        "weight": 19793
      }
    ]
  },
  {
    "fieldName": "longitude",
    "values": [
      {
        "fieldValue": "-100.0 to 174.11",
        "weight": 19793
      }
    ]
  },
  {
    "fieldName": "major",
    "values": [
      {
        "fieldValue": "N",
        "weight": 19523
      },
      {
        "fieldValue": "Y",
        "weight": 270
      }
    ]
  },
  {
    "fieldName": "mil_rts",
    "values": [
      {
        "fieldValue": null,
        "weight": 14716
      },
      {
        "fieldValue": "Y",
        "weight": 2958
      },
      {
        "fieldValue": "N",
        "weight": 2119
      }
    ]
  },
  {
    "fieldName": "own_type",
    "values": [
      {
        "fieldValue": "PR",
        "weight": 14306
      },
      {
        "fieldValue": "PU",
        "weight": 5174
      },
      {
        "fieldValue": "MR",
        "weight": 128
      },
      {
        "fieldValue": "MA",
        "weight": 107
      },
      {
        "fieldValue": "MN",
        "weight": 78
      }
    ]
  },
  {
    "fieldName": "site_number",
    "values": [
      {
        "fieldValue": "51518.6*A",
        "weight": 1
      },
      {
        "fieldValue": "51541.*A",
        "weight": 1
      },
      {
        "fieldValue": "50410.13*C",
        "weight": 1
      },
      {
        "fieldValue": "50720.04*A",
        "weight": 1
      },
      {
        "fieldValue": "50080.5*A",
        "weight": 1
      },
      {
        "fieldValue": "50870.21*A",
        "weight": 1
      },
      {
        "fieldValue": "50530.*A",
        "weight": 1
      },
      {
        "fieldValue": "50178.01*A",
        "weight": 1
      },
      {
        "fieldValue": "50427.61*A",
        "weight": 1
      },
      {
        "fieldValue": "50425.2*H",
        "weight": 1
      }
    ]
  },
  {
    "fieldName": "state",
    "values": [
      {
        "fieldValue": "TX",
        "weight": 1845
      },
      {
        "fieldValue": "CA",
        "weight": 984
      },
      {
        "fieldValue": "IL",
        "weight": 890
      },
      {
        "fieldValue": "FL",
        "weight": 856
      },
      {
        "fieldValue": "PA",
        "weight": 804
      },
      {
        "fieldValue": "OH",
        "weight": 749
      },
      {
        "fieldValue": "IN",
        "weight": 643
      },
      {
        "fieldValue": "AK",
        "weight": 608
      },
      {
        "fieldValue": "NY",
        "weight": 576
      },
      {
        "fieldValue": "WI",
        "weight": 543
      }
    ]
  },
  {
    "fieldName": null,
    "values": [
      {
        "fieldValue": null,
        "weight": 19793
      }
    ]
  }
]
WITH __stage0 AS (
  SELECT
    group_set,
    CASE group_set
      WHEN 0 THEN 'act_date'
      WHEN 1 THEN 'aero_cht'
      WHEN 2 THEN 'c_ldg_rts'
      WHEN 3 THEN 'cbd_dir'
      WHEN 4 THEN 'cbd_dist'
      WHEN 5 THEN 'cert'
      WHEN 6 THEN 'city'
      WHEN 7 THEN 'cntl_twr'
      WHEN 8 THEN 'code'
      WHEN 9 THEN 'county'
      WHEN 10 THEN 'cust_intl'
      WHEN 11 THEN 'elevation'
      WHEN 12 THEN 'faa_dist'
      WHEN 13 THEN 'faa_region'
      WHEN 14 THEN 'fac_type'
      WHEN 15 THEN 'fac_use'
      WHEN 16 THEN 'fed_agree'
      WHEN 17 THEN 'full_name'
      WHEN 18 THEN 'id'
      WHEN 19 THEN 'joint_use'
      WHEN 20 THEN 'latitude'
      WHEN 21 THEN 'longitude'
      WHEN 22 THEN 'major'
      WHEN 23 THEN 'mil_rts'
      WHEN 24 THEN 'own_type'
      WHEN 25 THEN 'site_number'
      WHEN 26 THEN 'state'
    END as "fieldName",
    CASE group_set
      WHEN 0 THEN 'act_date'
      WHEN 1 THEN 'aero_cht'
      WHEN 2 THEN 'c_ldg_rts'
      WHEN 3 THEN 'cbd_dir'
      WHEN 4 THEN 'cbd_dist'
      WHEN 5 THEN 'cert'
      WHEN 6 THEN 'city'
      WHEN 7 THEN 'cntl_twr'
      WHEN 8 THEN 'code'
      WHEN 9 THEN 'county'
      WHEN 10 THEN 'cust_intl'
      WHEN 11 THEN 'elevation'
      WHEN 12 THEN 'faa_dist'
      WHEN 13 THEN 'faa_region'
      WHEN 14 THEN 'fac_type'
      WHEN 15 THEN 'fac_use'
      WHEN 16 THEN 'fed_agree'
      WHEN 17 THEN 'full_name'
      WHEN 18 THEN 'id'
      WHEN 19 THEN 'joint_use'
      WHEN 20 THEN 'latitude'
      WHEN 21 THEN 'longitude'
      WHEN 22 THEN 'major'
      WHEN 23 THEN 'mil_rts'
      WHEN 24 THEN 'own_type'
      WHEN 25 THEN 'site_number'
      WHEN 26 THEN 'state'
    END as "fieldPath",
    CASE group_set
      WHEN 0 THEN 'string'
      WHEN 1 THEN 'string'
      WHEN 2 THEN 'string'
      WHEN 3 THEN 'string'
      WHEN 4 THEN 'number'
      WHEN 5 THEN 'string'
      WHEN 6 THEN 'string'
      WHEN 7 THEN 'string'
      WHEN 8 THEN 'string'
      WHEN 9 THEN 'string'
      WHEN 10 THEN 'string'
      WHEN 11 THEN 'number'
      WHEN 12 THEN 'string'
      WHEN 13 THEN 'string'
      WHEN 14 THEN 'string'
      WHEN 15 THEN 'string'
      WHEN 16 THEN 'string'
      WHEN 17 THEN 'string'
      WHEN 18 THEN 'number'
      WHEN 19 THEN 'string'
      WHEN 20 THEN 'number'
      WHEN 21 THEN 'number'
      WHEN 22 THEN 'string'
      WHEN 23 THEN 'string'
      WHEN 24 THEN 'string'
      WHEN 25 THEN 'string'
      WHEN 26 THEN 'string'
    END as "fieldType",  CASE group_set WHEN 99999 THEN CAST(NULL as VARCHAR)
      WHEN 0 THEN base."act_date"
      WHEN 1 THEN base."aero_cht"
      WHEN 2 THEN base."c_ldg_rts"
      WHEN 3 THEN base."cbd_dir"
      WHEN 5 THEN base."cert"
      WHEN 6 THEN base."city"
      WHEN 7 THEN base."cntl_twr"
      WHEN 8 THEN base."code"
      WHEN 9 THEN base."county"
      WHEN 10 THEN base."cust_intl"
      WHEN 12 THEN base."faa_dist"
      WHEN 13 THEN base."faa_region"
      WHEN 14 THEN base."fac_type"
      WHEN 15 THEN base."fac_use"
      WHEN 16 THEN base."fed_agree"
      WHEN 17 THEN base."full_name"
      WHEN 19 THEN base."joint_use"
      WHEN 22 THEN base."major"
      WHEN 23 THEN base."mil_rts"
      WHEN 24 THEN base."own_type"
      WHEN 25 THEN base."site_number"
      WHEN 26 THEN base."state"
    END as "fieldValue",
   COUNT(*) as weight,
    CASE group_set
      WHEN 99999 THEN ''    WHEN 4 THEN MIN(CAST(base."cbd_dist" as VARCHAR)) || ' to ' || CAST(MAX(base."cbd_dist") as VARCHAR)
      WHEN 11 THEN MIN(CAST(base."elevation" as VARCHAR)) || ' to ' || CAST(MAX(base."elevation") as VARCHAR)
      WHEN 18 THEN MIN(CAST(base."id" as VARCHAR)) || ' to ' || CAST(MAX(base."id") as VARCHAR)
      WHEN 20 THEN MIN(CAST(base."latitude" as VARCHAR)) || ' to ' || CAST(MAX(base."latitude") as VARCHAR)
      WHEN 21 THEN MIN(CAST(base."longitude" as VARCHAR)) || ' to ' || CAST(MAX(base."longitude") as VARCHAR)
    END as "fieldRange"
  FROM '../data/airports.parquet' as base
  CROSS JOIN (SELECT UNNEST(GENERATE_SERIES(0,27,1)) as group_set  ) as group_set
  GROUP BY 1,2,3,4,5
)
, __stage1 AS (
  SELECT
    "fieldName",
    "fieldPath",
    "fieldType",
    COALESCE("fieldValue", "fieldRange") as "fieldValue",
    weight
  FROM __stage0
)
, __stage2 AS (
  SELECT
    group_set,
    base."fieldName" as "fieldName__0",
    CASE WHEN group_set=1 THEN
      base."fieldValue"
      END as "fieldValue__1",
    CASE WHEN group_set=1 THEN
      base."weight"
      END as "weight__1"
  FROM __stage1 as base
  CROSS JOIN (SELECT UNNEST(GENERATE_SERIES(0,1,1)) as group_set  ) as group_set
  GROUP BY 1,2,3,4
)
SELECT
  "fieldName__0" as "fieldName",
  COALESCE(LIST({
    "fieldValue": "fieldValue__1", 
    "weight": "weight__1"}  ORDER BY  "weight__1" desc NULLS LAST) FILTER (WHERE group_set=1)[1:10],[]) as "values"
FROM __stage2
GROUP BY 1
ORDER BY 1 ASC NULLS LAST

Sampling

With large datasets, you can also sample a small subsection using the sample: parameter. Sampled indexes are great at identifing the important low cardinality fields.

document
run: duckdb.table('../data/airports.parquet') -> {
  index: *
  sample: 5000  // sample only 5000 rows
} -> {
  group_by: fieldName
  nest: values is  {
    group_by: fieldValue, weight
    order_by: weight desc
    limit: 10
  }
  order_by: fieldName
}
QUERY RESULTS
fieldNamevalues
act_date
fieldValueweight
3,030
02/198240
03/198835
02/198732
11/198632
08/198830
04/199330
03/199329
11/198829
11/199028
aero_cht
fieldValueweight
NEW YORK401
CHICAGO363
DETROIT330
WASHINGTON233
DALLAS-FT WORTH219
HOUSTON214
ST LOUIS214
TWIN CITIES200
SEATTLE197
KANSAS CITY193
c_ldg_rts
fieldValueweight
3,845
N1,077
Y78
cbd_dir
fieldValueweight
N942
SW624
NW605
NE587
SE585
S559
E550
W502
24
NNE6
cbd_dist
fieldValueweight
0 to 605,000
cert
fieldValueweight
4,840
AS 05/197324
BS 05/197322
CS 05/197319
LU 05/197310
LU 08/199010
DS 05/19735
LU 10/19744
AU 05/19733
LU 11/19743
city
fieldValueweight
HOUSTON34
WASHINGTON13
LOS ANGELES13
JACKSON13
JACKSONVILLE13
COLUMBUS12
INDIANAPOLIS12
GREENVILLE11
CLINTON11
ALBANY11
cntl_twr
fieldValueweight
N4,837
Y163
code
fieldValueweight
NK771
12VA1
5TA31
WV651
GGE1
N931
23D1
FDW1
0AK81
WI651
county
fieldValueweight
WASHINGTON61
JACKSON47
JEFFERSON46
HARRIS45
FRANKLIN43
ORANGE42
MONTGOMERY38
LOS ANGELES38
LINCOLN36
MARION35
cust_intl
fieldValueweight
3,845
N1,137
Y18
elevation
fieldValueweight
-1 to 99405,000
faa_dist
fieldValueweight
NONE1,842
CHI361
DET328
SEA306
MSP283
NYC247
ATL228
ORL220
HAR203
DCA173
faa_region
fieldValueweight
AGL1,122
ASW878
ASO705
AEA648
ANM532
ACE420
AWP350
ANE224
AAL114
7
fac_type
fieldValueweight
AIRPORT3,508
HELIPORT1,309
SEAPLANE BASE131
ULTRALIGHT21
STOLPORT20
GLIDERPORT10
BALLOONPORT1
fac_use
fieldValueweight
PR3,665
PU1,335
fed_agree
fieldValueweight
4,111
NGY424
N125
NGY357
NGPY48
NY131
NGSY30
125
NGPY322
N119
full_name
fieldValueweight
JOHNSON7
SMITH5
DAVIS FIELD5
MEMORIAL HOSPITAL4
SKY RANCH4
ST MARY'S HOSPITAL4
BAPTIST MEDICAL CENTER3
ST MARY MEDICAL CENTER3
TENNESSEE GAS3
FLYING S RANCH3
id
fieldValueweight
10001 to 197925,000
joint_use
fieldValueweight
3,780
N1,176
Y44
latitude
fieldValueweight
10.28 to 70.575,000
longitude
fieldValueweight
-100.0 to 171.275,000
major
fieldValueweight
N4,940
Y60
mil_rts
fieldValueweight
3,754
Y741
N505
own_type
fieldValueweight
PR3,615
PU1,309
MR32
MA29
MN15
site_number
fieldValueweight
11898.*A1
07561.53*A1
26424.31*A1
07838.*A1
27534.4*A1
26637.*A1
50308.01*H1
27133.3*A1
12895.1*A1
50593.*A1
state
fieldValueweight
TX494
CA228
IL217
FL211
OH199
PA195
LA151
MN150
IN146
NY142
fieldValueweight
5,000
[
  {
    "fieldName": "act_date",
    "values": [
      {
        "fieldValue": null,
        "weight": 3030
      },
      {
        "fieldValue": "02/1982",
        "weight": 40
      },
      {
        "fieldValue": "03/1988",
        "weight": 35
      },
      {
        "fieldValue": "02/1987",
        "weight": 32
      },
      {
        "fieldValue": "11/1986",
        "weight": 32
      },
      {
        "fieldValue": "08/1988",
        "weight": 30
      },
      {
        "fieldValue": "04/1993",
        "weight": 30
      },
      {
        "fieldValue": "03/1993",
        "weight": 29
      },
      {
        "fieldValue": "11/1988",
        "weight": 29
      },
      {
        "fieldValue": "11/1990",
        "weight": 28
      }
    ]
  },
  {
    "fieldName": "aero_cht",
    "values": [
      {
        "fieldValue": "NEW YORK",
        "weight": 401
      },
      {
        "fieldValue": "CHICAGO",
        "weight": 363
      },
      {
        "fieldValue": "DETROIT",
        "weight": 330
      },
      {
        "fieldValue": "WASHINGTON",
        "weight": 233
      },
      {
        "fieldValue": "DALLAS-FT WORTH",
        "weight": 219
      },
      {
        "fieldValue": "HOUSTON",
        "weight": 214
      },
      {
        "fieldValue": "ST LOUIS",
        "weight": 214
      },
      {
        "fieldValue": "TWIN CITIES",
        "weight": 200
      },
      {
        "fieldValue": "SEATTLE",
        "weight": 197
      },
      {
        "fieldValue": "KANSAS CITY",
        "weight": 193
      }
    ]
  },
  {
    "fieldName": "c_ldg_rts",
    "values": [
      {
        "fieldValue": null,
        "weight": 3845
      },
      {
        "fieldValue": "N",
        "weight": 1077
      },
      {
        "fieldValue": "Y",
        "weight": 78
      }
    ]
  },
  {
    "fieldName": "cbd_dir",
    "values": [
      {
        "fieldValue": "N",
        "weight": 942
      },
      {
        "fieldValue": "SW",
        "weight": 624
      },
      {
        "fieldValue": "NW",
        "weight": 605
      },
      {
        "fieldValue": "NE",
        "weight": 587
      },
      {
        "fieldValue": "SE",
        "weight": 585
      },
      {
        "fieldValue": "S",
        "weight": 559
      },
      {
        "fieldValue": "E",
        "weight": 550
      },
      {
        "fieldValue": "W",
        "weight": 502
      },
      {
        "fieldValue": null,
        "weight": 24
      },
      {
        "fieldValue": "NNE",
        "weight": 6
      }
    ]
  },
  {
    "fieldName": "cbd_dist",
    "values": [
      {
        "fieldValue": "0 to 60",
        "weight": 5000
      }
    ]
  },
  {
    "fieldName": "cert",
    "values": [
      {
        "fieldValue": null,
        "weight": 4840
      },
      {
        "fieldValue": "AS 05/1973",
        "weight": 24
      },
      {
        "fieldValue": "BS 05/1973",
        "weight": 22
      },
      {
        "fieldValue": "CS 05/1973",
        "weight": 19
      },
      {
        "fieldValue": "LU 05/1973",
        "weight": 10
      },
      {
        "fieldValue": "LU 08/1990",
        "weight": 10
      },
      {
        "fieldValue": "DS 05/1973",
        "weight": 5
      },
      {
        "fieldValue": "LU 10/1974",
        "weight": 4
      },
      {
        "fieldValue": "AU 05/1973",
        "weight": 3
      },
      {
        "fieldValue": "LU 11/1974",
        "weight": 3
      }
    ]
  },
  {
    "fieldName": "city",
    "values": [
      {
        "fieldValue": "HOUSTON",
        "weight": 34
      },
      {
        "fieldValue": "WASHINGTON",
        "weight": 13
      },
      {
        "fieldValue": "LOS ANGELES",
        "weight": 13
      },
      {
        "fieldValue": "JACKSON",
        "weight": 13
      },
      {
        "fieldValue": "JACKSONVILLE",
        "weight": 13
      },
      {
        "fieldValue": "COLUMBUS",
        "weight": 12
      },
      {
        "fieldValue": "INDIANAPOLIS",
        "weight": 12
      },
      {
        "fieldValue": "GREENVILLE",
        "weight": 11
      },
      {
        "fieldValue": "CLINTON",
        "weight": 11
      },
      {
        "fieldValue": "ALBANY",
        "weight": 11
      }
    ]
  },
  {
    "fieldName": "cntl_twr",
    "values": [
      {
        "fieldValue": "N",
        "weight": 4837
      },
      {
        "fieldValue": "Y",
        "weight": 163
      }
    ]
  },
  {
    "fieldName": "code",
    "values": [
      {
        "fieldValue": "NK77",
        "weight": 1
      },
      {
        "fieldValue": "12VA",
        "weight": 1
      },
      {
        "fieldValue": "5TA3",
        "weight": 1
      },
      {
        "fieldValue": "WV65",
        "weight": 1
      },
      {
        "fieldValue": "GGE",
        "weight": 1
      },
      {
        "fieldValue": "N93",
        "weight": 1
      },
      {
        "fieldValue": "23D",
        "weight": 1
      },
      {
        "fieldValue": "FDW",
        "weight": 1
      },
      {
        "fieldValue": "0AK8",
        "weight": 1
      },
      {
        "fieldValue": "WI65",
        "weight": 1
      }
    ]
  },
  {
    "fieldName": "county",
    "values": [
      {
        "fieldValue": "WASHINGTON",
        "weight": 61
      },
      {
        "fieldValue": "JACKSON",
        "weight": 47
      },
      {
        "fieldValue": "JEFFERSON",
        "weight": 46
      },
      {
        "fieldValue": "HARRIS",
        "weight": 45
      },
      {
        "fieldValue": "FRANKLIN",
        "weight": 43
      },
      {
        "fieldValue": "ORANGE",
        "weight": 42
      },
      {
        "fieldValue": "MONTGOMERY",
        "weight": 38
      },
      {
        "fieldValue": "LOS ANGELES",
        "weight": 38
      },
      {
        "fieldValue": "LINCOLN",
        "weight": 36
      },
      {
        "fieldValue": "MARION",
        "weight": 35
      }
    ]
  },
  {
    "fieldName": "cust_intl",
    "values": [
      {
        "fieldValue": null,
        "weight": 3845
      },
      {
        "fieldValue": "N",
        "weight": 1137
      },
      {
        "fieldValue": "Y",
        "weight": 18
      }
    ]
  },
  {
    "fieldName": "elevation",
    "values": [
      {
        "fieldValue": "-1 to 9940",
        "weight": 5000
      }
    ]
  },
  {
    "fieldName": "faa_dist",
    "values": [
      {
        "fieldValue": "NONE",
        "weight": 1842
      },
      {
        "fieldValue": "CHI",
        "weight": 361
      },
      {
        "fieldValue": "DET",
        "weight": 328
      },
      {
        "fieldValue": "SEA",
        "weight": 306
      },
      {
        "fieldValue": "MSP",
        "weight": 283
      },
      {
        "fieldValue": "NYC",
        "weight": 247
      },
      {
        "fieldValue": "ATL",
        "weight": 228
      },
      {
        "fieldValue": "ORL",
        "weight": 220
      },
      {
        "fieldValue": "HAR",
        "weight": 203
      },
      {
        "fieldValue": "DCA",
        "weight": 173
      }
    ]
  },
  {
    "fieldName": "faa_region",
    "values": [
      {
        "fieldValue": "AGL",
        "weight": 1122
      },
      {
        "fieldValue": "ASW",
        "weight": 878
      },
      {
        "fieldValue": "ASO",
        "weight": 705
      },
      {
        "fieldValue": "AEA",
        "weight": 648
      },
      {
        "fieldValue": "ANM",
        "weight": 532
      },
      {
        "fieldValue": "ACE",
        "weight": 420
      },
      {
        "fieldValue": "AWP",
        "weight": 350
      },
      {
        "fieldValue": "ANE",
        "weight": 224
      },
      {
        "fieldValue": "AAL",
        "weight": 114
      },
      {
        "fieldValue": null,
        "weight": 7
      }
    ]
  },
  {
    "fieldName": "fac_type",
    "values": [
      {
        "fieldValue": "AIRPORT",
        "weight": 3508
      },
      {
        "fieldValue": "HELIPORT",
        "weight": 1309
      },
      {
        "fieldValue": "SEAPLANE BASE",
        "weight": 131
      },
      {
        "fieldValue": "ULTRALIGHT",
        "weight": 21
      },
      {
        "fieldValue": "STOLPORT",
        "weight": 20
      },
      {
        "fieldValue": "GLIDERPORT",
        "weight": 10
      },
      {
        "fieldValue": "BALLOONPORT",
        "weight": 1
      }
    ]
  },
  {
    "fieldName": "fac_use",
    "values": [
      {
        "fieldValue": "PR",
        "weight": 3665
      },
      {
        "fieldValue": "PU",
        "weight": 1335
      }
    ]
  },
  {
    "fieldName": "fed_agree",
    "values": [
      {
        "fieldValue": null,
        "weight": 4111
      },
      {
        "fieldValue": "NGY",
        "weight": 424
      },
      {
        "fieldValue": "N",
        "weight": 125
      },
      {
        "fieldValue": "NGY3",
        "weight": 57
      },
      {
        "fieldValue": "NGPY",
        "weight": 48
      },
      {
        "fieldValue": "NY1",
        "weight": 31
      },
      {
        "fieldValue": "NGSY",
        "weight": 30
      },
      {
        "fieldValue": "1",
        "weight": 25
      },
      {
        "fieldValue": "NGPY3",
        "weight": 22
      },
      {
        "fieldValue": "N1",
        "weight": 19
      }
    ]
  },
  {
    "fieldName": "full_name",
    "values": [
      {
        "fieldValue": "JOHNSON",
        "weight": 7
      },
      {
        "fieldValue": "SMITH",
        "weight": 5
      },
      {
        "fieldValue": "DAVIS FIELD",
        "weight": 5
      },
      {
        "fieldValue": "MEMORIAL HOSPITAL",
        "weight": 4
      },
      {
        "fieldValue": "SKY RANCH",
        "weight": 4
      },
      {
        "fieldValue": "ST MARY'S HOSPITAL",
        "weight": 4
      },
      {
        "fieldValue": "BAPTIST MEDICAL CENTER",
        "weight": 3
      },
      {
        "fieldValue": "ST MARY MEDICAL CENTER",
        "weight": 3
      },
      {
        "fieldValue": "TENNESSEE GAS",
        "weight": 3
      },
      {
        "fieldValue": "FLYING S RANCH",
        "weight": 3
      }
    ]
  },
  {
    "fieldName": "id",
    "values": [
      {
        "fieldValue": "10001 to 19792",
        "weight": 5000
      }
    ]
  },
  {
    "fieldName": "joint_use",
    "values": [
      {
        "fieldValue": null,
        "weight": 3780
      },
      {
        "fieldValue": "N",
        "weight": 1176
      },
      {
        "fieldValue": "Y",
        "weight": 44
      }
    ]
  },
  {
    "fieldName": "latitude",
    "values": [
      {
        "fieldValue": "10.28 to 70.57",
        "weight": 5000
      }
    ]
  },
  {
    "fieldName": "longitude",
    "values": [
      {
        "fieldValue": "-100.0 to 171.27",
        "weight": 5000
      }
    ]
  },
  {
    "fieldName": "major",
    "values": [
      {
        "fieldValue": "N",
        "weight": 4940
      },
      {
        "fieldValue": "Y",
        "weight": 60
      }
    ]
  },
  {
    "fieldName": "mil_rts",
    "values": [
      {
        "fieldValue": null,
        "weight": 3754
      },
      {
        "fieldValue": "Y",
        "weight": 741
      },
      {
        "fieldValue": "N",
        "weight": 505
      }
    ]
  },
  {
    "fieldName": "own_type",
    "values": [
      {
        "fieldValue": "PR",
        "weight": 3615
      },
      {
        "fieldValue": "PU",
        "weight": 1309
      },
      {
        "fieldValue": "MR",
        "weight": 32
      },
      {
        "fieldValue": "MA",
        "weight": 29
      },
      {
        "fieldValue": "MN",
        "weight": 15
      }
    ]
  },
  {
    "fieldName": "site_number",
    "values": [
      {
        "fieldValue": "11898.*A",
        "weight": 1
      },
      {
        "fieldValue": "07561.53*A",
        "weight": 1
      },
      {
        "fieldValue": "26424.31*A",
        "weight": 1
      },
      {
        "fieldValue": "07838.*A",
        "weight": 1
      },
      {
        "fieldValue": "27534.4*A",
        "weight": 1
      },
      {
        "fieldValue": "26637.*A",
        "weight": 1
      },
      {
        "fieldValue": "50308.01*H",
        "weight": 1
      },
      {
        "fieldValue": "27133.3*A",
        "weight": 1
      },
      {
        "fieldValue": "12895.1*A",
        "weight": 1
      },
      {
        "fieldValue": "50593.*A",
        "weight": 1
      }
    ]
  },
  {
    "fieldName": "state",
    "values": [
      {
        "fieldValue": "TX",
        "weight": 494
      },
      {
        "fieldValue": "CA",
        "weight": 228
      },
      {
        "fieldValue": "IL",
        "weight": 217
      },
      {
        "fieldValue": "FL",
        "weight": 211
      },
      {
        "fieldValue": "OH",
        "weight": 199
      },
      {
        "fieldValue": "PA",
        "weight": 195
      },
      {
        "fieldValue": "LA",
        "weight": 151
      },
      {
        "fieldValue": "MN",
        "weight": 150
      },
      {
        "fieldValue": "IN",
        "weight": 146
      },
      {
        "fieldValue": "NY",
        "weight": 142
      }
    ]
  },
  {
    "fieldName": null,
    "values": [
      {
        "fieldValue": null,
        "weight": 5000
      }
    ]
  }
]
WITH __stage0 AS (
  SELECT * from (SELECT * FROM '../data/airports.parquet' USING SAMPLE 5000) as x limit 100000 )
, __stage1 AS (
  SELECT
    group_set,
    CASE group_set
      WHEN 0 THEN 'act_date'
      WHEN 1 THEN 'aero_cht'
      WHEN 2 THEN 'c_ldg_rts'
      WHEN 3 THEN 'cbd_dir'
      WHEN 4 THEN 'cbd_dist'
      WHEN 5 THEN 'cert'
      WHEN 6 THEN 'city'
      WHEN 7 THEN 'cntl_twr'
      WHEN 8 THEN 'code'
      WHEN 9 THEN 'county'
      WHEN 10 THEN 'cust_intl'
      WHEN 11 THEN 'elevation'
      WHEN 12 THEN 'faa_dist'
      WHEN 13 THEN 'faa_region'
      WHEN 14 THEN 'fac_type'
      WHEN 15 THEN 'fac_use'
      WHEN 16 THEN 'fed_agree'
      WHEN 17 THEN 'full_name'
      WHEN 18 THEN 'id'
      WHEN 19 THEN 'joint_use'
      WHEN 20 THEN 'latitude'
      WHEN 21 THEN 'longitude'
      WHEN 22 THEN 'major'
      WHEN 23 THEN 'mil_rts'
      WHEN 24 THEN 'own_type'
      WHEN 25 THEN 'site_number'
      WHEN 26 THEN 'state'
    END as "fieldName",
    CASE group_set
      WHEN 0 THEN 'act_date'
      WHEN 1 THEN 'aero_cht'
      WHEN 2 THEN 'c_ldg_rts'
      WHEN 3 THEN 'cbd_dir'
      WHEN 4 THEN 'cbd_dist'
      WHEN 5 THEN 'cert'
      WHEN 6 THEN 'city'
      WHEN 7 THEN 'cntl_twr'
      WHEN 8 THEN 'code'
      WHEN 9 THEN 'county'
      WHEN 10 THEN 'cust_intl'
      WHEN 11 THEN 'elevation'
      WHEN 12 THEN 'faa_dist'
      WHEN 13 THEN 'faa_region'
      WHEN 14 THEN 'fac_type'
      WHEN 15 THEN 'fac_use'
      WHEN 16 THEN 'fed_agree'
      WHEN 17 THEN 'full_name'
      WHEN 18 THEN 'id'
      WHEN 19 THEN 'joint_use'
      WHEN 20 THEN 'latitude'
      WHEN 21 THEN 'longitude'
      WHEN 22 THEN 'major'
      WHEN 23 THEN 'mil_rts'
      WHEN 24 THEN 'own_type'
      WHEN 25 THEN 'site_number'
      WHEN 26 THEN 'state'
    END as "fieldPath",
    CASE group_set
      WHEN 0 THEN 'string'
      WHEN 1 THEN 'string'
      WHEN 2 THEN 'string'
      WHEN 3 THEN 'string'
      WHEN 4 THEN 'number'
      WHEN 5 THEN 'string'
      WHEN 6 THEN 'string'
      WHEN 7 THEN 'string'
      WHEN 8 THEN 'string'
      WHEN 9 THEN 'string'
      WHEN 10 THEN 'string'
      WHEN 11 THEN 'number'
      WHEN 12 THEN 'string'
      WHEN 13 THEN 'string'
      WHEN 14 THEN 'string'
      WHEN 15 THEN 'string'
      WHEN 16 THEN 'string'
      WHEN 17 THEN 'string'
      WHEN 18 THEN 'number'
      WHEN 19 THEN 'string'
      WHEN 20 THEN 'number'
      WHEN 21 THEN 'number'
      WHEN 22 THEN 'string'
      WHEN 23 THEN 'string'
      WHEN 24 THEN 'string'
      WHEN 25 THEN 'string'
      WHEN 26 THEN 'string'
    END as "fieldType",  CASE group_set WHEN 99999 THEN CAST(NULL as VARCHAR)
      WHEN 0 THEN base."act_date"
      WHEN 1 THEN base."aero_cht"
      WHEN 2 THEN base."c_ldg_rts"
      WHEN 3 THEN base."cbd_dir"
      WHEN 5 THEN base."cert"
      WHEN 6 THEN base."city"
      WHEN 7 THEN base."cntl_twr"
      WHEN 8 THEN base."code"
      WHEN 9 THEN base."county"
      WHEN 10 THEN base."cust_intl"
      WHEN 12 THEN base."faa_dist"
      WHEN 13 THEN base."faa_region"
      WHEN 14 THEN base."fac_type"
      WHEN 15 THEN base."fac_use"
      WHEN 16 THEN base."fed_agree"
      WHEN 17 THEN base."full_name"
      WHEN 19 THEN base."joint_use"
      WHEN 22 THEN base."major"
      WHEN 23 THEN base."mil_rts"
      WHEN 24 THEN base."own_type"
      WHEN 25 THEN base."site_number"
      WHEN 26 THEN base."state"
    END as "fieldValue",
   COUNT(*) as weight,
    CASE group_set
      WHEN 99999 THEN ''    WHEN 4 THEN MIN(CAST(base."cbd_dist" as VARCHAR)) || ' to ' || CAST(MAX(base."cbd_dist") as VARCHAR)
      WHEN 11 THEN MIN(CAST(base."elevation" as VARCHAR)) || ' to ' || CAST(MAX(base."elevation") as VARCHAR)
      WHEN 18 THEN MIN(CAST(base."id" as VARCHAR)) || ' to ' || CAST(MAX(base."id") as VARCHAR)
      WHEN 20 THEN MIN(CAST(base."latitude" as VARCHAR)) || ' to ' || CAST(MAX(base."latitude") as VARCHAR)
      WHEN 21 THEN MIN(CAST(base."longitude" as VARCHAR)) || ' to ' || CAST(MAX(base."longitude") as VARCHAR)
    END as "fieldRange"
  FROM __stage0 as base
  CROSS JOIN (SELECT UNNEST(GENERATE_SERIES(0,27,1)) as group_set  ) as group_set
  GROUP BY 1,2,3,4,5
)
, __stage2 AS (
  SELECT
    "fieldName",
    "fieldPath",
    "fieldType",
    COALESCE("fieldValue", "fieldRange") as "fieldValue",
    weight
  FROM __stage1
)
, __stage3 AS (
  SELECT
    group_set,
    base."fieldName" as "fieldName__0",
    CASE WHEN group_set=1 THEN
      base."fieldValue"
      END as "fieldValue__1",
    CASE WHEN group_set=1 THEN
      base."weight"
      END as "weight__1"
  FROM __stage2 as base
  CROSS JOIN (SELECT UNNEST(GENERATE_SERIES(0,1,1)) as group_set  ) as group_set
  GROUP BY 1,2,3,4
)
SELECT
  "fieldName__0" as "fieldName",
  COALESCE(LIST({
    "fieldValue": "fieldValue__1", 
    "weight": "weight__1"}  ORDER BY  "weight__1" desc NULLS LAST) FILTER (WHERE group_set=1)[1:10],[]) as "values"
FROM __stage3
GROUP BY 1
ORDER BY 1 ASC NULLS LAST

A More Complex Example

The rest of this pages uses the model below. The data is an excerpt from the IMDB. The Malloy schema for this model is shown on the right. The core value is movies, but joined at the principals (the people that worked on the movie) and the people (the actual data about the individuals).

We use the measure total_ratings to determin a movie's popularity. An individual's popularity is determined by the some of all the ratings of the movies a person has worked on.

document
source: movies is duckdb.table('../data/titles.parquet') extend {
  join_many: principals is duckdb.table('../data/principals.parquet') extend {
    join_one: people is duckdb.table('../data/names.parquet') 
      on nconst = people.nconst
  } on tconst = principals.tconst
  measure: total_ratings is numVotes.sum()
}

Weights can be any measure

Often a row count will work nicely as a weight, but sometimes there is something better. In movies, for example the sum of the number of votes will not only find the interesting most interesting movies but will also find the most interesting people. For example the most interesting people in the dataset.

document
run: movies -> {
  group_by: principals.people.primaryName
  aggregate: total_ratings
} 
QUERY RESULTS
primaryNametotal_​ratings
Brad Pitt18,269,386
Stan Lee18,229,893
John Williams17,651,379
Leonardo DiCaprio17,032,662
Tom Hanks16,650,835
Christopher Nolan15,368,415
Steven Spielberg15,069,082
Robert De Niro14,629,861
Christian Bale13,730,681
Samuel L. Jackson13,423,134
Robert Downey Jr.12,685,331
George Lucas12,584,331
Matt Damon12,509,393
Quentin Tarantino12,348,394
Bruce Willis12,045,753
Jack Kirby11,901,244
Johnny Depp11,755,228
Morgan Freeman11,435,905
Tom Cruise11,290,573
Thomas Newman11,056,371
Hans Zimmer10,957,053
Scott Rudin10,793,692
Charles Roven10,778,794
Bob Kane10,685,405
Ian McKellen10,552,024
Chris Evans10,497,785
Harrison Ford10,449,365
Scarlett Johansson10,128,373
David S. Goyer10,022,517
Jonathan Nolan9,823,211
Martin Scorsese9,692,050
Peter Jackson9,612,306
Orlando Bloom9,482,690
James Newton Howard9,473,293
Stephen King9,454,020
Hugh Jackman9,409,702
Kevin Feige9,408,976
Ridley Scott9,334,292
Natalie Portman9,206,903
Liam Neeson9,185,450
David Heyman9,174,472
Mark Ruffalo9,171,115
Bradley Cooper8,980,668
Will Smith8,960,562
Al Pacino8,933,776
Emma Thomas8,773,124
Tim Bevan8,756,327
Roger Deakins8,737,852
Fran Walsh8,594,296
Michael Caine8,533,028
Lorne Orleans8,518,672
Lawrence Bender8,503,500
Keanu Reeves8,480,149
David Fincher8,427,910
Mark Wahlberg8,393,193
Joel Silver8,360,819
Robert Richardson8,351,268
Philippa Boyens8,336,233
Kathleen Kennedy8,278,785
Matthew McConaughey8,271,368
Ben Affleck8,268,036
James Horner8,253,828
Alan Silvestri8,072,953
Chris Hemsworth8,058,188
Carter Burwell7,997,536
Simon Kinberg7,846,138
Eric Fellner7,845,245
J.R.R. Tolkien7,798,667
Jake Gyllenhaal7,762,048
Jerry Bruckheimer7,721,877
Edward Norton7,713,816
Woody Harrelson7,711,063
Ewan McGregor7,655,458
George Clooney7,653,368
David Benioff7,637,309
Kevin Spacey7,603,094
Brian Grazer7,570,625
Anne Hathaway7,509,220
Arnon Milchan7,494,607
Jim Carrey7,421,247
Robert Zemeckis7,371,523
Danny Elfman7,340,555
Ryan Reynolds7,319,537
Jason Blum7,308,653
James Cameron7,306,015
Sally Menke7,239,769
Tom Hardy7,213,428
Clint Eastwood7,209,434
Russell Crowe7,166,573
Akiva Goldsman7,094,797
Nicolas Cage7,053,952
Michael Giacchino7,047,025
Gary Oldman7,036,991
Cate Blanchett7,017,425
Michael Bay7,016,200
J.J. Abrams6,991,513
Willem Dafoe6,924,815
Christopher Markus6,886,318
Stephen McFeely6,886,318
Neal H. Moritz6,870,329
Alexandre Desplat6,867,309
Jennifer Lawrence6,855,625
Rachel McAdams6,777,091
Lena Headey6,742,472
Elijah Wood6,734,358
Dwayne Johnson6,584,416
Jason Statham6,582,293
Steve Kloves6,559,963
Denzel Washington6,556,554
Sigourney Weaver6,515,096
Arnold Schwarzenegger6,482,925
Tim Burton6,467,281
Steve Carell6,436,581
Terry Rossio6,423,369
Ceán Chaffin6,415,865
Amy Adams6,401,556
Daniel Radcliffe6,393,663
J.K. Rowling6,392,020
Mel Gibson6,322,650
Anthony Hopkins6,315,913
Emma Watson6,304,351
6,300,267
Rick McCallum6,211,607
Jack Nicholson6,180,622
Ted Elliott6,136,354
Adam Sandler6,094,935
Ed Harris6,077,615
Chris Columbus6,076,896
Cameron Diaz6,042,333
Joseph Gordon-Levitt6,034,397
Emilia Clarke5,995,245
D.B. Weiss5,972,128
Joaquin Phoenix5,967,875
Daniel Craig5,967,704
Luc Besson5,961,182
Ryan Gosling5,956,376
Vin Diesel5,944,056
Andrew Stanton5,942,167
John Goodman5,940,986
Ralph Fiennes5,906,715
Peter Dinklage5,906,118
David Koepp5,894,926
Pete Docter5,862,141
Sylvester Stallone5,861,981
Angelina Jolie5,857,481
Ian Bryce5,848,379
Hugo Weaving5,841,890
Frank Darabont5,826,908
Ben Kingsley5,825,798
Viggo Mortensen5,823,719
Richard Francis-Bruce5,798,818
Colin Farrell5,788,835
Charlize Theron5,765,794
Joss Whedon5,757,097
Nikolaj Coster-Waldau5,749,486
Julianne Moore5,744,632
Jonah Hill5,718,674
Joel Coen5,700,458
Zack Snyder5,695,090
Ben Stiller5,685,709
Bryan Cranston5,685,238
Kate Winslet5,682,918
Ethan Coen5,663,547
Walter F. Parkes5,657,162
Howard Shore5,638,214
Jeremy Renner5,623,966
Marco Beltrami5,590,317
Bryan Singer5,590,237
Emma Stone5,583,422
Guillermo del Toro5,570,240
Owen Wilson5,556,539
Rupert Grint5,552,590
Jude Law5,538,884
Matthew Vaughn5,524,297
Alex Kurtzman5,522,344
Lana Wachowski5,518,169
Keira Knightley5,512,152
Lilly Wachowski5,444,217
Judd Apatow5,443,590
Chris Pratt5,439,043
Francis Ford Coppola5,436,313
Will Ferrell5,420,626
Seth Rogen5,419,570
Sandra Bullock5,405,221
Steve Ditko5,371,488
Frank Marshall5,363,210
John Logan5,353,165
Ken Watanabe5,352,344
Sam Raimi5,334,765
Carrie-Anne Moss5,305,827
Benedict Cumberbatch5,273,615
Robin Williams5,224,218
Jennifer Connelly5,222,568
Ron Howard5,215,903
John Travolta5,206,564
Laurence Fishburne5,187,514
Ethan Hawke5,186,955
Jamie Foxx5,180,837
Lawrence Kasdan5,173,484
Gerard Butler5,156,049
[
  {
    "primaryName": "Brad Pitt",
    "total_ratings": 18269386
  },
  {
    "primaryName": "Stan Lee",
    "total_ratings": 18229893
  },
  {
    "primaryName": "John Williams",
    "total_ratings": 17651379
  },
  {
    "primaryName": "Leonardo DiCaprio",
    "total_ratings": 17032662
  },
  {
    "primaryName": "Tom Hanks",
    "total_ratings": 16650835
  },
  {
    "primaryName": "Christopher Nolan",
    "total_ratings": 15368415
  },
  {
    "primaryName": "Steven Spielberg",
    "total_ratings": 15069082
  },
  {
    "primaryName": "Robert De Niro",
    "total_ratings": 14629861
  },
  {
    "primaryName": "Christian Bale",
    "total_ratings": 13730681
  },
  {
    "primaryName": "Samuel L. Jackson",
    "total_ratings": 13423134
  },
  {
    "primaryName": "Robert Downey Jr.",
    "total_ratings": 12685331
  },
  {
    "primaryName": "George Lucas",
    "total_ratings": 12584331
  },
  {
    "primaryName": "Matt Damon",
    "total_ratings": 12509393
  },
  {
    "primaryName": "Quentin Tarantino",
    "total_ratings": 12348394
  },
  {
    "primaryName": "Bruce Willis",
    "total_ratings": 12045753
  },
  {
    "primaryName": "Jack Kirby",
    "total_ratings": 11901244
  },
  {
    "primaryName": "Johnny Depp",
    "total_ratings": 11755228
  },
  {
    "primaryName": "Morgan Freeman",
    "total_ratings": 11435905
  },
  {
    "primaryName": "Tom Cruise",
    "total_ratings": 11290573
  },
  {
    "primaryName": "Thomas Newman",
    "total_ratings": 11056371
  },
  {
    "primaryName": "Hans Zimmer",
    "total_ratings": 10957053
  },
  {
    "primaryName": "Scott Rudin",
    "total_ratings": 10793692
  },
  {
    "primaryName": "Charles Roven",
    "total_ratings": 10778794
  },
  {
    "primaryName": "Bob Kane",
    "total_ratings": 10685405
  },
  {
    "primaryName": "Ian McKellen",
    "total_ratings": 10552024
  },
  {
    "primaryName": "Chris Evans",
    "total_ratings": 10497785
  },
  {
    "primaryName": "Harrison Ford",
    "total_ratings": 10449365
  },
  {
    "primaryName": "Scarlett Johansson",
    "total_ratings": 10128373
  },
  {
    "primaryName": "David S. Goyer",
    "total_ratings": 10022517
  },
  {
    "primaryName": "Jonathan Nolan",
    "total_ratings": 9823211
  },
  {
    "primaryName": "Martin Scorsese",
    "total_ratings": 9692050
  },
  {
    "primaryName": "Peter Jackson",
    "total_ratings": 9612306
  },
  {
    "primaryName": "Orlando Bloom",
    "total_ratings": 9482690
  },
  {
    "primaryName": "James Newton Howard",
    "total_ratings": 9473293
  },
  {
    "primaryName": "Stephen King",
    "total_ratings": 9454020
  },
  {
    "primaryName": "Hugh Jackman",
    "total_ratings": 9409702
  },
  {
    "primaryName": "Kevin Feige",
    "total_ratings": 9408976
  },
  {
    "primaryName": "Ridley Scott",
    "total_ratings": 9334292
  },
  {
    "primaryName": "Natalie Portman",
    "total_ratings": 9206903
  },
  {
    "primaryName": "Liam Neeson",
    "total_ratings": 9185450
  },
  {
    "primaryName": "David Heyman",
    "total_ratings": 9174472
  },
  {
    "primaryName": "Mark Ruffalo",
    "total_ratings": 9171115
  },
  {
    "primaryName": "Bradley Cooper",
    "total_ratings": 8980668
  },
  {
    "primaryName": "Will Smith",
    "total_ratings": 8960562
  },
  {
    "primaryName": "Al Pacino",
    "total_ratings": 8933776
  },
  {
    "primaryName": "Emma Thomas",
    "total_ratings": 8773124
  },
  {
    "primaryName": "Tim Bevan",
    "total_ratings": 8756327
  },
  {
    "primaryName": "Roger Deakins",
    "total_ratings": 8737852
  },
  {
    "primaryName": "Fran Walsh",
    "total_ratings": 8594296
  },
  {
    "primaryName": "Michael Caine",
    "total_ratings": 8533028
  },
  {
    "primaryName": "Lorne Orleans",
    "total_ratings": 8518672
  },
  {
    "primaryName": "Lawrence Bender",
    "total_ratings": 8503500
  },
  {
    "primaryName": "Keanu Reeves",
    "total_ratings": 8480149
  },
  {
    "primaryName": "David Fincher",
    "total_ratings": 8427910
  },
  {
    "primaryName": "Mark Wahlberg",
    "total_ratings": 8393193
  },
  {
    "primaryName": "Joel Silver",
    "total_ratings": 8360819
  },
  {
    "primaryName": "Robert Richardson",
    "total_ratings": 8351268
  },
  {
    "primaryName": "Philippa Boyens",
    "total_ratings": 8336233
  },
  {
    "primaryName": "Kathleen Kennedy",
    "total_ratings": 8278785
  },
  {
    "primaryName": "Matthew McConaughey",
    "total_ratings": 8271368
  },
  {
    "primaryName": "Ben Affleck",
    "total_ratings": 8268036
  },
  {
    "primaryName": "James Horner",
    "total_ratings": 8253828
  },
  {
    "primaryName": "Alan Silvestri",
    "total_ratings": 8072953
  },
  {
    "primaryName": "Chris Hemsworth",
    "total_ratings": 8058188
  },
  {
    "primaryName": "Carter Burwell",
    "total_ratings": 7997536
  },
  {
    "primaryName": "Simon Kinberg",
    "total_ratings": 7846138
  },
  {
    "primaryName": "Eric Fellner",
    "total_ratings": 7845245
  },
  {
    "primaryName": "J.R.R. Tolkien",
    "total_ratings": 7798667
  },
  {
    "primaryName": "Jake Gyllenhaal",
    "total_ratings": 7762048
  },
  {
    "primaryName": "Jerry Bruckheimer",
    "total_ratings": 7721877
  },
  {
    "primaryName": "Edward Norton",
    "total_ratings": 7713816
  },
  {
    "primaryName": "Woody Harrelson",
    "total_ratings": 7711063
  },
  {
    "primaryName": "Ewan McGregor",
    "total_ratings": 7655458
  },
  {
    "primaryName": "George Clooney",
    "total_ratings": 7653368
  },
  {
    "primaryName": "David Benioff",
    "total_ratings": 7637309
  },
  {
    "primaryName": "Kevin Spacey",
    "total_ratings": 7603094
  },
  {
    "primaryName": "Brian Grazer",
    "total_ratings": 7570625
  },
  {
    "primaryName": "Anne Hathaway",
    "total_ratings": 7509220
  },
  {
    "primaryName": "Arnon Milchan",
    "total_ratings": 7494607
  },
  {
    "primaryName": "Jim Carrey",
    "total_ratings": 7421247
  },
  {
    "primaryName": "Robert Zemeckis",
    "total_ratings": 7371523
  },
  {
    "primaryName": "Danny Elfman",
    "total_ratings": 7340555
  },
  {
    "primaryName": "Ryan Reynolds",
    "total_ratings": 7319537
  },
  {
    "primaryName": "Jason Blum",
    "total_ratings": 7308653
  },
  {
    "primaryName": "James Cameron",
    "total_ratings": 7306015
  },
  {
    "primaryName": "Sally Menke",
    "total_ratings": 7239769
  },
  {
    "primaryName": "Tom Hardy",
    "total_ratings": 7213428
  },
  {
    "primaryName": "Clint Eastwood",
    "total_ratings": 7209434
  },
  {
    "primaryName": "Russell Crowe",
    "total_ratings": 7166573
  },
  {
    "primaryName": "Akiva Goldsman",
    "total_ratings": 7094797
  },
  {
    "primaryName": "Nicolas Cage",
    "total_ratings": 7053952
  },
  {
    "primaryName": "Michael Giacchino",
    "total_ratings": 7047025
  },
  {
    "primaryName": "Gary Oldman",
    "total_ratings": 7036991
  },
  {
    "primaryName": "Cate Blanchett",
    "total_ratings": 7017425
  },
  {
    "primaryName": "Michael Bay",
    "total_ratings": 7016200
  },
  {
    "primaryName": "J.J. Abrams",
    "total_ratings": 6991513
  },
  {
    "primaryName": "Willem Dafoe",
    "total_ratings": 6924815
  },
  {
    "primaryName": "Christopher Markus",
    "total_ratings": 6886318
  },
  {
    "primaryName": "Stephen McFeely",
    "total_ratings": 6886318
  },
  {
    "primaryName": "Neal H. Moritz",
    "total_ratings": 6870329
  },
  {
    "primaryName": "Alexandre Desplat",
    "total_ratings": 6867309
  },
  {
    "primaryName": "Jennifer Lawrence",
    "total_ratings": 6855625
  },
  {
    "primaryName": "Rachel McAdams",
    "total_ratings": 6777091
  },
  {
    "primaryName": "Lena Headey",
    "total_ratings": 6742472
  },
  {
    "primaryName": "Elijah Wood",
    "total_ratings": 6734358
  },
  {
    "primaryName": "Dwayne Johnson",
    "total_ratings": 6584416
  },
  {
    "primaryName": "Jason Statham",
    "total_ratings": 6582293
  },
  {
    "primaryName": "Steve Kloves",
    "total_ratings": 6559963
  },
  {
    "primaryName": "Denzel Washington",
    "total_ratings": 6556554
  },
  {
    "primaryName": "Sigourney Weaver",
    "total_ratings": 6515096
  },
  {
    "primaryName": "Arnold Schwarzenegger",
    "total_ratings": 6482925
  },
  {
    "primaryName": "Tim Burton",
    "total_ratings": 6467281
  },
  {
    "primaryName": "Steve Carell",
    "total_ratings": 6436581
  },
  {
    "primaryName": "Terry Rossio",
    "total_ratings": 6423369
  },
  {
    "primaryName": "Ceán Chaffin",
    "total_ratings": 6415865
  },
  {
    "primaryName": "Amy Adams",
    "total_ratings": 6401556
  },
  {
    "primaryName": "Daniel Radcliffe",
    "total_ratings": 6393663
  },
  {
    "primaryName": "J.K. Rowling",
    "total_ratings": 6392020
  },
  {
    "primaryName": "Mel Gibson",
    "total_ratings": 6322650
  },
  {
    "primaryName": "Anthony Hopkins",
    "total_ratings": 6315913
  },
  {
    "primaryName": "Emma Watson",
    "total_ratings": 6304351
  },
  {
    "primaryName": null,
    "total_ratings": 6300267
  },
  {
    "primaryName": "Rick McCallum",
    "total_ratings": 6211607
  },
  {
    "primaryName": "Jack Nicholson",
    "total_ratings": 6180622
  },
  {
    "primaryName": "Ted Elliott",
    "total_ratings": 6136354
  },
  {
    "primaryName": "Adam Sandler",
    "total_ratings": 6094935
  },
  {
    "primaryName": "Ed Harris",
    "total_ratings": 6077615
  },
  {
    "primaryName": "Chris Columbus",
    "total_ratings": 6076896
  },
  {
    "primaryName": "Cameron Diaz",
    "total_ratings": 6042333
  },
  {
    "primaryName": "Joseph Gordon-Levitt",
    "total_ratings": 6034397
  },
  {
    "primaryName": "Emilia Clarke",
    "total_ratings": 5995245
  },
  {
    "primaryName": "D.B. Weiss",
    "total_ratings": 5972128
  },
  {
    "primaryName": "Joaquin Phoenix",
    "total_ratings": 5967875
  },
  {
    "primaryName": "Daniel Craig",
    "total_ratings": 5967704
  },
  {
    "primaryName": "Luc Besson",
    "total_ratings": 5961182
  },
  {
    "primaryName": "Ryan Gosling",
    "total_ratings": 5956376
  },
  {
    "primaryName": "Vin Diesel",
    "total_ratings": 5944056
  },
  {
    "primaryName": "Andrew Stanton",
    "total_ratings": 5942167
  },
  {
    "primaryName": "John Goodman",
    "total_ratings": 5940986
  },
  {
    "primaryName": "Ralph Fiennes",
    "total_ratings": 5906715
  },
  {
    "primaryName": "Peter Dinklage",
    "total_ratings": 5906118
  },
  {
    "primaryName": "David Koepp",
    "total_ratings": 5894926
  },
  {
    "primaryName": "Pete Docter",
    "total_ratings": 5862141
  },
  {
    "primaryName": "Sylvester Stallone",
    "total_ratings": 5861981
  },
  {
    "primaryName": "Angelina Jolie",
    "total_ratings": 5857481
  },
  {
    "primaryName": "Ian Bryce",
    "total_ratings": 5848379
  },
  {
    "primaryName": "Hugo Weaving",
    "total_ratings": 5841890
  },
  {
    "primaryName": "Frank Darabont",
    "total_ratings": 5826908
  },
  {
    "primaryName": "Ben Kingsley",
    "total_ratings": 5825798
  },
  {
    "primaryName": "Viggo Mortensen",
    "total_ratings": 5823719
  },
  {
    "primaryName": "Richard Francis-Bruce",
    "total_ratings": 5798818
  },
  {
    "primaryName": "Colin Farrell",
    "total_ratings": 5788835
  },
  {
    "primaryName": "Charlize Theron",
    "total_ratings": 5765794
  },
  {
    "primaryName": "Joss Whedon",
    "total_ratings": 5757097
  },
  {
    "primaryName": "Nikolaj Coster-Waldau",
    "total_ratings": 5749486
  },
  {
    "primaryName": "Julianne Moore",
    "total_ratings": 5744632
  },
  {
    "primaryName": "Jonah Hill",
    "total_ratings": 5718674
  },
  {
    "primaryName": "Joel Coen",
    "total_ratings": 5700458
  },
  {
    "primaryName": "Zack Snyder",
    "total_ratings": 5695090
  },
  {
    "primaryName": "Ben Stiller",
    "total_ratings": 5685709
  },
  {
    "primaryName": "Bryan Cranston",
    "total_ratings": 5685238
  },
  {
    "primaryName": "Kate Winslet",
    "total_ratings": 5682918
  },
  {
    "primaryName": "Ethan Coen",
    "total_ratings": 5663547
  },
  {
    "primaryName": "Walter F. Parkes",
    "total_ratings": 5657162
  },
  {
    "primaryName": "Howard Shore",
    "total_ratings": 5638214
  },
  {
    "primaryName": "Jeremy Renner",
    "total_ratings": 5623966
  },
  {
    "primaryName": "Marco Beltrami",
    "total_ratings": 5590317
  },
  {
    "primaryName": "Bryan Singer",
    "total_ratings": 5590237
  },
  {
    "primaryName": "Emma Stone",
    "total_ratings": 5583422
  },
  {
    "primaryName": "Guillermo del Toro",
    "total_ratings": 5570240
  },
  {
    "primaryName": "Owen Wilson",
    "total_ratings": 5556539
  },
  {
    "primaryName": "Rupert Grint",
    "total_ratings": 5552590
  },
  {
    "primaryName": "Jude Law",
    "total_ratings": 5538884
  },
  {
    "primaryName": "Matthew Vaughn",
    "total_ratings": 5524297
  },
  {
    "primaryName": "Alex Kurtzman",
    "total_ratings": 5522344
  },
  {
    "primaryName": "Lana Wachowski",
    "total_ratings": 5518169
  },
  {
    "primaryName": "Keira Knightley",
    "total_ratings": 5512152
  },
  {
    "primaryName": "Lilly Wachowski",
    "total_ratings": 5444217
  },
  {
    "primaryName": "Judd Apatow",
    "total_ratings": 5443590
  },
  {
    "primaryName": "Chris Pratt",
    "total_ratings": 5439043
  },
  {
    "primaryName": "Francis Ford Coppola",
    "total_ratings": 5436313
  },
  {
    "primaryName": "Will Ferrell",
    "total_ratings": 5420626
  },
  {
    "primaryName": "Seth Rogen",
    "total_ratings": 5419570
  },
  {
    "primaryName": "Sandra Bullock",
    "total_ratings": 5405221
  },
  {
    "primaryName": "Steve Ditko",
    "total_ratings": 5371488
  },
  {
    "primaryName": "Frank Marshall",
    "total_ratings": 5363210
  },
  {
    "primaryName": "John Logan",
    "total_ratings": 5353165
  },
  {
    "primaryName": "Ken Watanabe",
    "total_ratings": 5352344
  },
  {
    "primaryName": "Sam Raimi",
    "total_ratings": 5334765
  },
  {
    "primaryName": "Carrie-Anne Moss",
    "total_ratings": 5305827
  },
  {
    "primaryName": "Benedict Cumberbatch",
    "total_ratings": 5273615
  },
  {
    "primaryName": "Robin Williams",
    "total_ratings": 5224218
  },
  {
    "primaryName": "Jennifer Connelly",
    "total_ratings": 5222568
  },
  {
    "primaryName": "Ron Howard",
    "total_ratings": 5215903
  },
  {
    "primaryName": "John Travolta",
    "total_ratings": 5206564
  },
  {
    "primaryName": "Laurence Fishburne",
    "total_ratings": 5187514
  },
  {
    "primaryName": "Ethan Hawke",
    "total_ratings": 5186955
  },
  {
    "primaryName": "Jamie Foxx",
    "total_ratings": 5180837
  },
  {
    "primaryName": "Lawrence Kasdan",
    "total_ratings": 5173484
  },
  {
    "primaryName": "Gerard Butler",
    "total_ratings": 5156049
  }
]
SELECT 
   people_0."primaryName" as "primaryName",
   COALESCE((
        SELECT SUM(a.val) as value
        FROM (
          SELECT UNNEST(list(distinct {key:movies."__distinct_key", val: movies."numVotes"})) a
        )
      ),0) as "total_ratings"
FROM (SELECT GEN_RANDOM_UUID() as __distinct_key, x.*  FROM '../data/titles.parquet' as x) as movies
 LEFT JOIN '../data/principals.parquet' AS principals_0
  ON movies."tconst"=principals_0."tconst"
 LEFT JOIN '../data/names.parquet' AS people_0
  ON principals_0."nconst"=people_0."nconst"
GROUP BY 1
ORDER BY 2 desc NULLS LAST

Index the entire graph

Indexing can work across an entire network of joins and can be selective.

document
run: movies -> {
  index:
    *
    genres.*
    principals.category, principals.job
    principals.characters.*
    principals.people.primaryName
  by total_ratings
  sample: 5000
} -> {
  select: *
  order_by: weight desc
}
QUERY RESULTS
fieldNamefieldPathfieldTypefieldValueweight
averageRatingaverageRatingnumber1.0 to 10.0713,412,305
endYearendYearnumber1964.0 to 2024.0713,412,305
isAdultisAdultstring0713,412,305
numVotesnumVotesnumber100038.0 to 2755400.0713,412,305
runtimeMinutesruntimeMinutesnumber100.0 to 780.0713,412,305
startYearstartYearnumber1902.0 to 2023.0713,412,305
713,412,305
principals.jobprincipals/jobstring\N708,992,234
principals.characters.valueprincipals/characters/valuestring\N700,768,445
principals.categoryprincipals/categorystringactor699,183,314
principals.categoryprincipals/categorystringdirector618,349,991
principals.categoryprincipals/categorystringwriter605,802,222
principals.categoryprincipals/categorystringactress603,119,288
principals.categoryprincipals/categorystringproducer535,359,219
principals.jobprincipals/jobstringproducer533,039,158
genres.valuegenres/valuestringDrama369,491,232
principals.categoryprincipals/categorystringcomposer322,100,121
genres.valuegenres/valuestringAction257,083,861
principals.categoryprincipals/categorystringcinematographer218,605,262
genres.valuegenres/valuestringAdventure211,856,074
genres.valuegenres/valuestringComedy202,130,232
principals.jobprincipals/jobstringwritten by170,630,049
principals.jobprincipals/jobstringscreenplay170,444,517
principals.jobprincipals/jobstringdirector of photography161,989,333
genres.valuegenres/valuestringCrime149,725,589
principals.categoryprincipals/categorystringeditor123,990,484
genres.valuegenres/valuestringThriller122,437,077
principals.jobprincipals/jobstringscreenplay by106,282,343
genres.valuegenres/valuestringSci-Fi95,214,735
genres.valuegenres/valuestringMystery87,075,217
genres.valuegenres/valuestringRomance70,753,795
genres.valuegenres/valuestringFantasy67,751,049
genres.valuegenres/valuestringHorror63,004,222
principals.jobprincipals/jobstringstory57,160,031
genres.valuegenres/valuestringAnimation48,915,737
genres.valuegenres/valuestringBiography45,994,693
principals.jobprincipals/jobstringcreated by44,140,628
principals.categoryprincipals/categorystringproduction_designer36,589,602
principals.jobprincipals/jobstringnovel32,811,023
genres.valuegenres/valuestringFamily30,814,736
principals.jobprincipals/jobstringstory by30,794,392
principals.jobprincipals/jobstringcharacters25,259,112
genres.valuegenres/valuestringHistory18,632,607
principals.jobprincipals/jobstringbased on the novel by16,816,181
principals.people.primaryNameprincipals/people/primaryNamestringJohn Williams15,069,031
principals.people.primaryNameprincipals/people/primaryNamestringBrad Pitt13,738,414
principals.people.primaryNameprincipals/people/primaryNamestringTom Hanks13,605,801
principals.people.primaryNameprincipals/people/primaryNamestringStan Lee13,522,620
principals.people.primaryNameprincipals/people/primaryNamestringSteven Spielberg13,026,220
principals.jobprincipals/jobstringbook12,992,689
principals.jobprincipals/jobstringbased on characters created by12,836,985
genres.valuegenres/valuestringWar12,766,741
genres.valuegenres/valuestringMusic11,425,366
principals.people.primaryNameprincipals/people/primaryNamestringMatt Damon11,199,816
principals.people.primaryNameprincipals/people/primaryNamestringGeorge Lucas11,068,023
principals.people.primaryNameprincipals/people/primaryNamestringChristian Bale10,645,032
principals.jobprincipals/jobstringfilm editor10,549,323
principals.jobprincipals/jobstringco-director10,201,160
genres.valuegenres/valuestringSport9,991,294
principals.people.primaryNameprincipals/people/primaryNamestringRobert De Niro9,958,088
principals.people.primaryNameprincipals/people/primaryNamestringJonathan Nolan9,823,211
principals.people.primaryNameprincipals/people/primaryNamestringRobert Downey Jr.9,663,572
principals.people.primaryNameprincipals/people/primaryNamestringChristopher Nolan9,662,066
principals.jobprincipals/jobstringdeveloped by9,347,457
principals.people.primaryNameprincipals/people/primaryNamestringTom Cruise9,345,657
principals.people.primaryNameprincipals/people/primaryNamestringSamuel L. Jackson9,307,508
principals.people.primaryNameprincipals/people/primaryNamestringScott Rudin9,303,560
principals.people.primaryNameprincipals/people/primaryNamestringHarrison Ford9,058,701
principals.people.primaryNameprincipals/people/primaryNamestringQuentin Tarantino8,741,484
principals.people.primaryNameprincipals/people/primaryNamestringMorgan Freeman8,624,640
principals.people.primaryNameprincipals/people/primaryNamestringRoger Deakins8,607,840
principals.people.primaryNameprincipals/people/primaryNamestringRidley Scott8,600,047
principals.people.primaryNameprincipals/people/primaryNamestringBob Kane8,391,526
principals.people.primaryNameprincipals/people/primaryNamestringBruce Willis8,197,142
principals.people.primaryNameprincipals/people/primaryNamestringThomas Newman8,109,370
principals.people.primaryNameprincipals/people/primaryNamestringChris Evans8,085,780
principals.people.primaryNameprincipals/people/primaryNamestringIan McKellen8,045,112
principals.people.primaryNameprincipals/people/primaryNamestringLeonardo DiCaprio7,916,449
principals.people.primaryNameprincipals/people/primaryNamestringScarlett Johansson7,906,484
principals.people.primaryNameprincipals/people/primaryNamestringPeter Jackson7,904,306
principals.people.primaryNameprincipals/people/primaryNamestringDavid Fincher7,702,759
principals.people.primaryNameprincipals/people/primaryNamestringKathleen Kennedy7,662,013
principals.jobprincipals/jobstringbased on the book by7,539,137
principals.people.primaryNameprincipals/people/primaryNamestringJames Newton Howard7,517,793
principals.people.primaryNameprincipals/people/primaryNamestringStephen King7,468,924
principals.people.primaryNameprincipals/people/primaryNamestringJack Kirby7,346,095
principals.characters.valueprincipals/characters/valuestringBruce Wayne7,280,383
principals.people.primaryNameprincipals/people/primaryNamestringGeorge Clooney7,044,988
principals.people.primaryNameprincipals/people/primaryNamestringHans Zimmer7,032,934
principals.people.primaryNameprincipals/people/primaryNamestringDavid Benioff7,026,424
principals.jobprincipals/jobstringbased on the Marvel comics by6,953,795
genres.valuegenres/valuestringWestern6,907,326
principals.people.primaryNameprincipals/people/primaryNamestringFran Walsh6,886,296
principals.characters.valueprincipals/characters/valuestringBatman6,843,554
principals.people.primaryNameprincipals/people/primaryNamestringBrian Grazer6,727,510
principals.people.primaryNameprincipals/people/primaryNamestringCharles Roven6,724,064
principals.people.primaryNameprincipals/people/primaryNamestringDavid S. Goyer6,700,259
principals.people.primaryNameprincipals/people/primaryNamestringWillem Dafoe6,652,533
principals.people.primaryNameprincipals/people/primaryNamestringPhilippa Boyens6,628,233
principals.jobprincipals/jobstringoriginal story by6,612,504
principals.people.primaryNameprincipals/people/primaryNamestringRyan Reynolds6,603,104
principals.people.primaryNameprincipals/people/primaryNamestringHugh Jackman6,580,292
principals.people.primaryNameprincipals/people/primaryNamestringBen Affleck6,472,409
principals.people.primaryNameprincipals/people/primaryNamestringMichael Bay6,454,981
principals.people.primaryNameprincipals/people/primaryNamestringMark Ruffalo6,410,822
principals.characters.valueprincipals/characters/valuestringTony Stark6,376,595
principals.people.primaryNameprincipals/people/primaryNamestringLiam Neeson6,368,475
principals.people.primaryNameprincipals/people/primaryNamestringJames Horner6,346,657
principals.people.primaryNameprincipals/people/primaryNamestringSimon Kinberg6,345,804
principals.people.primaryNameprincipals/people/primaryNamestringRussell Crowe6,286,871
principals.people.primaryNameprincipals/people/primaryNamestringDavid Heyman6,190,765
principals.people.primaryNameprincipals/people/primaryNamestringTim Bevan6,143,130
principals.people.primaryNameprincipals/people/primaryNamestringMark Wahlberg6,128,463
principals.people.primaryNameprincipals/people/primaryNamestringLena Headey6,053,266
principals.people.primaryNameprincipals/people/primaryNamestringJake Gyllenhaal6,036,981
principals.people.primaryNameprincipals/people/primaryNamestringAlan Silvestri6,027,718
principals.people.primaryNameprincipals/people/primaryNamestringJ.R.R. Tolkien6,022,586
principals.people.primaryNameprincipals/people/primaryNamestringArnon Milchan6,014,552
principals.people.primaryNameprincipals/people/primaryNamestringNatalie Portman6,013,851
principals.people.primaryNameprincipals/people/primaryNamestringAnne Hathaway5,979,537
principals.people.primaryNameprincipals/people/primaryNamestringMatthew McConaughey5,966,433
principals.people.primaryNameprincipals/people/primaryNamestringMartin Scorsese5,965,414
principals.people.primaryNameprincipals/people/primaryNamestringEdward Norton5,957,019
principals.characters.valueprincipals/characters/valuestringGandalf5,923,041
principals.people.primaryNameprincipals/people/primaryNamestringSteve Carell5,912,945
principals.people.primaryNameprincipals/people/primaryNamestringChris Hemsworth5,909,740
principals.people.primaryNameprincipals/people/primaryNamestringMichael Caine5,871,920
principals.people.primaryNameprincipals/people/primaryNamestringOrlando Bloom5,871,401
principals.people.primaryNameprincipals/people/primaryNamestringStephen McFeely5,854,040
principals.people.primaryNameprincipals/people/primaryNamestringChristopher Markus5,854,040
principals.people.primaryNameprincipals/people/primaryNamestringAndrew Stanton5,827,281
principals.people.primaryNameprincipals/people/primaryNamestringRachel McAdams5,819,261
principals.people.primaryNameprincipals/people/primaryNamestringNeal H. Moritz5,796,407
principals.people.primaryNameprincipals/people/primaryNamestringEwan McGregor5,766,592
principals.people.primaryNameprincipals/people/primaryNamestringWill Smith5,762,034
principals.people.primaryNameprincipals/people/primaryNamestringJ.J. Abrams5,760,887
principals.people.primaryNameprincipals/people/primaryNamestringGary Oldman5,759,266
principals.characters.valueprincipals/characters/valuestringNarrator5,749,700
principals.people.primaryNameprincipals/people/primaryNamestringKevin Feige5,742,904
principals.people.primaryNameprincipals/people/primaryNamestringEric Fellner5,737,444
principals.characters.valueprincipals/characters/valuestringCaptain America5,707,245
principals.people.primaryNameprincipals/people/primaryNamestringCeán Chaffin5,690,714
principals.people.primaryNameprincipals/people/primaryNamestringEmma Thomas5,666,891
principals.people.primaryNameprincipals/people/primaryNamestringMel Gibson5,659,939
principals.people.primaryNameprincipals/people/primaryNamestringJohnny Depp5,642,498
principals.people.primaryNameprincipals/people/primaryNamestringEd Harris5,631,567
principals.people.primaryNameprincipals/people/primaryNamestringRyan Gosling5,629,440
principals.people.primaryNameprincipals/people/primaryNamestringJoel Coen5,617,443
principals.people.primaryNameprincipals/people/primaryNamestringAkiva Goldsman5,608,535
principals.people.primaryNameprincipals/people/primaryNamestringJeremy Renner5,584,773
principals.people.primaryNameprincipals/people/primaryNamestringEthan Coen5,580,532
principals.people.primaryNameprincipals/people/primaryNamestringNicolas Cage5,553,255
principals.people.primaryNameprincipals/people/primaryNamestringCarter Burwell5,552,802
principals.people.primaryNameprincipals/people/primaryNamestringKevin Spacey5,551,554
principals.people.primaryNameprincipals/people/primaryNamestringRobert Richardson5,550,036
principals.jobprincipals/jobstringscreen story5,549,684
principals.people.primaryNameprincipals/people/primaryNamestringJoaquin Phoenix5,525,746
principals.people.primaryNameprincipals/people/primaryNamestringEmilia Clarke5,501,831
principals.characters.valueprincipals/characters/valuestringSteve Rogers5,472,223
principals.people.primaryNameprincipals/people/primaryNamestringAlexandre Desplat5,451,704
principals.people.primaryNameprincipals/people/primaryNamestringIan Bryce5,447,770
principals.people.primaryNameprincipals/people/primaryNamestringRick McCallum5,397,561
principals.people.primaryNameprincipals/people/primaryNamestringD.B. Weiss5,361,243
principals.people.primaryNameprincipals/people/primaryNamestringPeter Dinklage5,310,182
principals.people.primaryNameprincipals/people/primaryNamestringSigourney Weaver5,276,356
principals.people.primaryNameprincipals/people/primaryNamestringBryan Cranston5,218,252
principals.people.primaryNameprincipals/people/primaryNamestringWoody Harrelson5,205,583
principals.people.primaryNameprincipals/people/primaryNamestringJohn Goodman5,203,881
principals.people.primaryNameprincipals/people/primaryNamestringJudd Apatow5,185,765
principals.people.primaryNameprincipals/people/primaryNamestringRobert Zemeckis5,178,545
principals.people.primaryNameprincipals/people/primaryNamestringNikolaj Coster-Waldau5,169,230
principals.people.primaryNameprincipals/people/primaryNamestringJim Carrey5,162,127
principals.people.primaryNameprincipals/people/primaryNamestringAdam Sandler5,142,370
principals.people.primaryNameprincipals/people/primaryNamestringJerry Bruckheimer5,136,116
principals.people.primaryNameprincipals/people/primaryNamestringLawrence Kasdan5,121,888
principals.people.primaryNameprincipals/people/primaryNamestringTom Hardy5,115,341
principals.characters.valueprincipals/characters/valuestringJack5,094,328
principals.people.primaryNameprincipals/people/primaryNamestringAmy Adams5,074,168
principals.people.primaryNameprincipals/people/primaryNamestringRobin Wright5,032,891
principals.jobprincipals/jobstringcreator5,004,603
principals.people.primaryNameprincipals/people/primaryNamestringAl Pacino5,002,731
principals.people.primaryNameprincipals/people/primaryNamestringAnthony Hopkins4,986,085
principals.people.primaryNameprincipals/people/primaryNamestringEmma Watson4,953,767
principals.people.primaryNameprincipals/people/primaryNamestringOwen Wilson4,953,404
principals.people.primaryNameprincipals/people/primaryNamestringSteve Kloves4,935,821
principals.people.primaryNameprincipals/people/primaryNamestringHoward Shore4,911,631
principals.people.primaryNameprincipals/people/primaryNamestringDenzel Washington4,867,886
principals.people.primaryNameprincipals/people/primaryNamestringFrank Marshall4,848,595
principals.characters.valueprincipals/characters/valuestringThor4,843,702
principals.characters.valueprincipals/characters/valuestringSpider-Man4,840,293
principals.characters.valueprincipals/characters/valuestringPeter Parker4,840,293
principals.people.primaryNameprincipals/people/primaryNamestring4,820,837
principals.characters.valueprincipals/characters/valuestringTyrion Lannister4,818,993
principals.people.primaryNameprincipals/people/primaryNamestringLawrence Bender4,817,351
principals.people.primaryNameprincipals/people/primaryNamestringGuillermo del Toro4,810,864
principals.people.primaryNameprincipals/people/primaryNamestringPaul Rudd4,807,253
principals.people.primaryNameprincipals/people/primaryNamestringRon Howard4,759,799
principals.categoryprincipals/categorystringself4,678,213
principals.people.primaryNameprincipals/people/primaryNamestringLuc Besson4,665,178
principals.people.primaryNameprincipals/people/primaryNamestringEmma Stone4,653,426
[
  {
    "fieldName": "averageRating",
    "fieldPath": "averageRating",
    "fieldType": "number",
    "fieldValue": "1.0 to 10.0",
    "weight": 713412305
  },
  {
    "fieldName": "endYear",
    "fieldPath": "endYear",
    "fieldType": "number",
    "fieldValue": "1964.0 to 2024.0",
    "weight": 713412305
  },
  {
    "fieldName": "isAdult",
    "fieldPath": "isAdult",
    "fieldType": "string",
    "fieldValue": "0",
    "weight": 713412305
  },
  {
    "fieldName": "numVotes",
    "fieldPath": "numVotes",
    "fieldType": "number",
    "fieldValue": "100038.0 to 2755400.0",
    "weight": 713412305
  },
  {
    "fieldName": "runtimeMinutes",
    "fieldPath": "runtimeMinutes",
    "fieldType": "number",
    "fieldValue": "100.0 to 780.0",
    "weight": 713412305
  },
  {
    "fieldName": "startYear",
    "fieldPath": "startYear",
    "fieldType": "number",
    "fieldValue": "1902.0 to 2023.0",
    "weight": 713412305
  },
  {
    "fieldName": null,
    "fieldPath": null,
    "fieldType": null,
    "fieldValue": null,
    "weight": 713412305
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "\\N",
    "weight": 708992234
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "\\N",
    "weight": 700768445
  },
  {
    "fieldName": "principals.category",
    "fieldPath": "principals/category",
    "fieldType": "string",
    "fieldValue": "actor",
    "weight": 699183314
  },
  {
    "fieldName": "principals.category",
    "fieldPath": "principals/category",
    "fieldType": "string",
    "fieldValue": "director",
    "weight": 618349991
  },
  {
    "fieldName": "principals.category",
    "fieldPath": "principals/category",
    "fieldType": "string",
    "fieldValue": "writer",
    "weight": 605802222
  },
  {
    "fieldName": "principals.category",
    "fieldPath": "principals/category",
    "fieldType": "string",
    "fieldValue": "actress",
    "weight": 603119288
  },
  {
    "fieldName": "principals.category",
    "fieldPath": "principals/category",
    "fieldType": "string",
    "fieldValue": "producer",
    "weight": 535359219
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "producer",
    "weight": 533039158
  },
  {
    "fieldName": "genres.value",
    "fieldPath": "genres/value",
    "fieldType": "string",
    "fieldValue": "Drama",
    "weight": 369491232
  },
  {
    "fieldName": "principals.category",
    "fieldPath": "principals/category",
    "fieldType": "string",
    "fieldValue": "composer",
    "weight": 322100121
  },
  {
    "fieldName": "genres.value",
    "fieldPath": "genres/value",
    "fieldType": "string",
    "fieldValue": "Action",
    "weight": 257083861
  },
  {
    "fieldName": "principals.category",
    "fieldPath": "principals/category",
    "fieldType": "string",
    "fieldValue": "cinematographer",
    "weight": 218605262
  },
  {
    "fieldName": "genres.value",
    "fieldPath": "genres/value",
    "fieldType": "string",
    "fieldValue": "Adventure",
    "weight": 211856074
  },
  {
    "fieldName": "genres.value",
    "fieldPath": "genres/value",
    "fieldType": "string",
    "fieldValue": "Comedy",
    "weight": 202130232
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "written by",
    "weight": 170630049
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "screenplay",
    "weight": 170444517
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "director of photography",
    "weight": 161989333
  },
  {
    "fieldName": "genres.value",
    "fieldPath": "genres/value",
    "fieldType": "string",
    "fieldValue": "Crime",
    "weight": 149725589
  },
  {
    "fieldName": "principals.category",
    "fieldPath": "principals/category",
    "fieldType": "string",
    "fieldValue": "editor",
    "weight": 123990484
  },
  {
    "fieldName": "genres.value",
    "fieldPath": "genres/value",
    "fieldType": "string",
    "fieldValue": "Thriller",
    "weight": 122437077
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "screenplay by",
    "weight": 106282343
  },
  {
    "fieldName": "genres.value",
    "fieldPath": "genres/value",
    "fieldType": "string",
    "fieldValue": "Sci-Fi",
    "weight": 95214735
  },
  {
    "fieldName": "genres.value",
    "fieldPath": "genres/value",
    "fieldType": "string",
    "fieldValue": "Mystery",
    "weight": 87075217
  },
  {
    "fieldName": "genres.value",
    "fieldPath": "genres/value",
    "fieldType": "string",
    "fieldValue": "Romance",
    "weight": 70753795
  },
  {
    "fieldName": "genres.value",
    "fieldPath": "genres/value",
    "fieldType": "string",
    "fieldValue": "Fantasy",
    "weight": 67751049
  },
  {
    "fieldName": "genres.value",
    "fieldPath": "genres/value",
    "fieldType": "string",
    "fieldValue": "Horror",
    "weight": 63004222
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "story",
    "weight": 57160031
  },
  {
    "fieldName": "genres.value",
    "fieldPath": "genres/value",
    "fieldType": "string",
    "fieldValue": "Animation",
    "weight": 48915737
  },
  {
    "fieldName": "genres.value",
    "fieldPath": "genres/value",
    "fieldType": "string",
    "fieldValue": "Biography",
    "weight": 45994693
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "created by",
    "weight": 44140628
  },
  {
    "fieldName": "principals.category",
    "fieldPath": "principals/category",
    "fieldType": "string",
    "fieldValue": "production_designer",
    "weight": 36589602
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "novel",
    "weight": 32811023
  },
  {
    "fieldName": "genres.value",
    "fieldPath": "genres/value",
    "fieldType": "string",
    "fieldValue": "Family",
    "weight": 30814736
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "story by",
    "weight": 30794392
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "characters",
    "weight": 25259112
  },
  {
    "fieldName": "genres.value",
    "fieldPath": "genres/value",
    "fieldType": "string",
    "fieldValue": "History",
    "weight": 18632607
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "based on the novel by",
    "weight": 16816181
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "John Williams",
    "weight": 15069031
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Pitt",
    "weight": 13738414
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Tom Hanks",
    "weight": 13605801
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Stan Lee",
    "weight": 13522620
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Steven Spielberg",
    "weight": 13026220
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "book",
    "weight": 12992689
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "based on characters created by",
    "weight": 12836985
  },
  {
    "fieldName": "genres.value",
    "fieldPath": "genres/value",
    "fieldType": "string",
    "fieldValue": "War",
    "weight": 12766741
  },
  {
    "fieldName": "genres.value",
    "fieldPath": "genres/value",
    "fieldType": "string",
    "fieldValue": "Music",
    "weight": 11425366
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Matt Damon",
    "weight": 11199816
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "George Lucas",
    "weight": 11068023
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Christian Bale",
    "weight": 10645032
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "film editor",
    "weight": 10549323
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "co-director",
    "weight": 10201160
  },
  {
    "fieldName": "genres.value",
    "fieldPath": "genres/value",
    "fieldType": "string",
    "fieldValue": "Sport",
    "weight": 9991294
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Robert De Niro",
    "weight": 9958088
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Jonathan Nolan",
    "weight": 9823211
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Robert Downey Jr.",
    "weight": 9663572
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Christopher Nolan",
    "weight": 9662066
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "developed by",
    "weight": 9347457
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Tom Cruise",
    "weight": 9345657
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Samuel L. Jackson",
    "weight": 9307508
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Scott Rudin",
    "weight": 9303560
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Harrison Ford",
    "weight": 9058701
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Quentin Tarantino",
    "weight": 8741484
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Morgan Freeman",
    "weight": 8624640
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Roger Deakins",
    "weight": 8607840
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Ridley Scott",
    "weight": 8600047
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bob Kane",
    "weight": 8391526
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bruce Willis",
    "weight": 8197142
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Thomas Newman",
    "weight": 8109370
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Chris Evans",
    "weight": 8085780
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Ian McKellen",
    "weight": 8045112
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Leonardo DiCaprio",
    "weight": 7916449
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Scarlett Johansson",
    "weight": 7906484
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Peter Jackson",
    "weight": 7904306
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "David Fincher",
    "weight": 7702759
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Kathleen Kennedy",
    "weight": 7662013
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "based on the book by",
    "weight": 7539137
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "James Newton Howard",
    "weight": 7517793
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Stephen King",
    "weight": 7468924
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Jack Kirby",
    "weight": 7346095
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Bruce Wayne",
    "weight": 7280383
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "George Clooney",
    "weight": 7044988
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Hans Zimmer",
    "weight": 7032934
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "David Benioff",
    "weight": 7026424
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "based on the Marvel comics by",
    "weight": 6953795
  },
  {
    "fieldName": "genres.value",
    "fieldPath": "genres/value",
    "fieldType": "string",
    "fieldValue": "Western",
    "weight": 6907326
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Fran Walsh",
    "weight": 6886296
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Batman",
    "weight": 6843554
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brian Grazer",
    "weight": 6727510
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Charles Roven",
    "weight": 6724064
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "David S. Goyer",
    "weight": 6700259
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Willem Dafoe",
    "weight": 6652533
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Philippa Boyens",
    "weight": 6628233
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "original story by",
    "weight": 6612504
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Ryan Reynolds",
    "weight": 6603104
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Hugh Jackman",
    "weight": 6580292
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Ben Affleck",
    "weight": 6472409
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Michael Bay",
    "weight": 6454981
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Mark Ruffalo",
    "weight": 6410822
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Tony Stark",
    "weight": 6376595
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Liam Neeson",
    "weight": 6368475
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "James Horner",
    "weight": 6346657
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Simon Kinberg",
    "weight": 6345804
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Russell Crowe",
    "weight": 6286871
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "David Heyman",
    "weight": 6190765
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Tim Bevan",
    "weight": 6143130
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Mark Wahlberg",
    "weight": 6128463
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Lena Headey",
    "weight": 6053266
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Jake Gyllenhaal",
    "weight": 6036981
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Alan Silvestri",
    "weight": 6027718
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "J.R.R. Tolkien",
    "weight": 6022586
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Arnon Milchan",
    "weight": 6014552
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Natalie Portman",
    "weight": 6013851
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Anne Hathaway",
    "weight": 5979537
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Matthew McConaughey",
    "weight": 5966433
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Martin Scorsese",
    "weight": 5965414
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Edward Norton",
    "weight": 5957019
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Gandalf",
    "weight": 5923041
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Steve Carell",
    "weight": 5912945
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Chris Hemsworth",
    "weight": 5909740
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Michael Caine",
    "weight": 5871920
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Orlando Bloom",
    "weight": 5871401
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Stephen McFeely",
    "weight": 5854040
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Christopher Markus",
    "weight": 5854040
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Andrew Stanton",
    "weight": 5827281
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Rachel McAdams",
    "weight": 5819261
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Neal H. Moritz",
    "weight": 5796407
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Ewan McGregor",
    "weight": 5766592
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Will Smith",
    "weight": 5762034
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "J.J. Abrams",
    "weight": 5760887
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Gary Oldman",
    "weight": 5759266
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Narrator",
    "weight": 5749700
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Kevin Feige",
    "weight": 5742904
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Eric Fellner",
    "weight": 5737444
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Captain America",
    "weight": 5707245
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Ceán Chaffin",
    "weight": 5690714
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Emma Thomas",
    "weight": 5666891
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Mel Gibson",
    "weight": 5659939
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Johnny Depp",
    "weight": 5642498
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Ed Harris",
    "weight": 5631567
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Ryan Gosling",
    "weight": 5629440
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Joel Coen",
    "weight": 5617443
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Akiva Goldsman",
    "weight": 5608535
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Jeremy Renner",
    "weight": 5584773
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Ethan Coen",
    "weight": 5580532
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Nicolas Cage",
    "weight": 5553255
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Carter Burwell",
    "weight": 5552802
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Kevin Spacey",
    "weight": 5551554
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Robert Richardson",
    "weight": 5550036
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "screen story",
    "weight": 5549684
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Joaquin Phoenix",
    "weight": 5525746
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Emilia Clarke",
    "weight": 5501831
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Steve Rogers",
    "weight": 5472223
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Alexandre Desplat",
    "weight": 5451704
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Ian Bryce",
    "weight": 5447770
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Rick McCallum",
    "weight": 5397561
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "D.B. Weiss",
    "weight": 5361243
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Peter Dinklage",
    "weight": 5310182
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Sigourney Weaver",
    "weight": 5276356
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bryan Cranston",
    "weight": 5218252
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Woody Harrelson",
    "weight": 5205583
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "John Goodman",
    "weight": 5203881
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Judd Apatow",
    "weight": 5185765
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Robert Zemeckis",
    "weight": 5178545
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Nikolaj Coster-Waldau",
    "weight": 5169230
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Jim Carrey",
    "weight": 5162127
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Adam Sandler",
    "weight": 5142370
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Jerry Bruckheimer",
    "weight": 5136116
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Lawrence Kasdan",
    "weight": 5121888
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Tom Hardy",
    "weight": 5115341
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Jack",
    "weight": 5094328
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Amy Adams",
    "weight": 5074168
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Robin Wright",
    "weight": 5032891
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "creator",
    "weight": 5004603
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Al Pacino",
    "weight": 5002731
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Anthony Hopkins",
    "weight": 4986085
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Emma Watson",
    "weight": 4953767
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Owen Wilson",
    "weight": 4953404
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Steve Kloves",
    "weight": 4935821
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Howard Shore",
    "weight": 4911631
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Denzel Washington",
    "weight": 4867886
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Frank Marshall",
    "weight": 4848595
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Thor",
    "weight": 4843702
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Spider-Man",
    "weight": 4840293
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Peter Parker",
    "weight": 4840293
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": null,
    "weight": 4820837
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Tyrion Lannister",
    "weight": 4818993
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Lawrence Bender",
    "weight": 4817351
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Guillermo del Toro",
    "weight": 4810864
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Paul Rudd",
    "weight": 4807253
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Ron Howard",
    "weight": 4759799
  },
  {
    "fieldName": "principals.category",
    "fieldPath": "principals/category",
    "fieldType": "string",
    "fieldValue": "self",
    "weight": 4678213
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Luc Besson",
    "weight": 4665178
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Emma Stone",
    "weight": 4653426
  }
]
WITH __stage0 AS (
  SELECT * from (SELECT * FROM '../data/titles.parquet' USING SAMPLE 5000) as x limit 100000 )
, __stage1 AS (
  SELECT
    group_set,
    CASE group_set
      WHEN 0 THEN 'averageRating'
      WHEN 1 THEN 'endYear'
      WHEN 2 THEN 'isAdult'
      WHEN 3 THEN 'numVotes'
      WHEN 4 THEN 'originalTitle'
      WHEN 5 THEN 'primaryTitle'
      WHEN 6 THEN 'runtimeMinutes'
      WHEN 7 THEN 'startYear'
      WHEN 8 THEN 'tconst'
      WHEN 9 THEN 'genres.value'
      WHEN 10 THEN 'principals.category'
      WHEN 11 THEN 'principals.job'
      WHEN 12 THEN 'principals.characters.value'
      WHEN 13 THEN 'principals.people.primaryName'
    END as "fieldName",
    CASE group_set
      WHEN 0 THEN 'averageRating'
      WHEN 1 THEN 'endYear'
      WHEN 2 THEN 'isAdult'
      WHEN 3 THEN 'numVotes'
      WHEN 4 THEN 'originalTitle'
      WHEN 5 THEN 'primaryTitle'
      WHEN 6 THEN 'runtimeMinutes'
      WHEN 7 THEN 'startYear'
      WHEN 8 THEN 'tconst'
      WHEN 9 THEN 'genres/value'
      WHEN 10 THEN 'principals/category'
      WHEN 11 THEN 'principals/job'
      WHEN 12 THEN 'principals/characters/value'
      WHEN 13 THEN 'principals/people/primaryName'
    END as "fieldPath",
    CASE group_set
      WHEN 0 THEN 'number'
      WHEN 1 THEN 'number'
      WHEN 2 THEN 'string'
      WHEN 3 THEN 'number'
      WHEN 4 THEN 'string'
      WHEN 5 THEN 'string'
      WHEN 6 THEN 'number'
      WHEN 7 THEN 'number'
      WHEN 8 THEN 'string'
      WHEN 9 THEN 'string'
      WHEN 10 THEN 'string'
      WHEN 11 THEN 'string'
      WHEN 12 THEN 'string'
      WHEN 13 THEN 'string'
    END as "fieldType",  CASE group_set WHEN 99999 THEN CAST(NULL as VARCHAR)
      WHEN 2 THEN movies."isAdult"
      WHEN 4 THEN movies."originalTitle"
      WHEN 5 THEN movies."primaryTitle"
      WHEN 8 THEN movies."tconst"
      WHEN 9 THEN genres_0
      WHEN 10 THEN principals_0."category"
      WHEN 11 THEN principals_0."job"
      WHEN 12 THEN characters_0
      WHEN 13 THEN people_0."primaryName"
    END as "fieldValue",
   COALESCE((
        SELECT SUM(a.val) as value
        FROM (
          SELECT UNNEST(list(distinct {key:movies."__distinct_key", val: movies."numVotes"})) a
        )
      ),0) as weight,
    CASE group_set
      WHEN 99999 THEN ''    WHEN 0 THEN MIN(CAST(movies."averageRating" as VARCHAR)) || ' to ' || CAST(MAX(movies."averageRating") as VARCHAR)
      WHEN 1 THEN MIN(CAST(movies."endYear" as VARCHAR)) || ' to ' || CAST(MAX(movies."endYear") as VARCHAR)
      WHEN 3 THEN MIN(CAST(movies."numVotes" as VARCHAR)) || ' to ' || CAST(MAX(movies."numVotes") as VARCHAR)
      WHEN 6 THEN MIN(CAST(movies."runtimeMinutes" as VARCHAR)) || ' to ' || CAST(MAX(movies."runtimeMinutes") as VARCHAR)
      WHEN 7 THEN MIN(CAST(movies."startYear" as VARCHAR)) || ' to ' || CAST(MAX(movies."startYear") as VARCHAR)
    END as "fieldRange"
  FROM (SELECT GEN_RANDOM_UUID() as __distinct_key, x.*  FROM __stage0 as x) as movies
  LEFT JOIN LATERAL (SELECT UNNEST(movies."genres"), 1 as ignoreme) as genres_0_outer(genres_0,ignoreme) ON genres_0_outer.ignoreme=1
   LEFT JOIN '../data/principals.parquet' AS principals_0
    ON movies."tconst"=principals_0."tconst"
  LEFT JOIN LATERAL (SELECT UNNEST(principals_0."characters"), 1 as ignoreme) as characters_0_outer(characters_0,ignoreme) ON characters_0_outer.ignoreme=1
   LEFT JOIN '../data/names.parquet' AS people_0
    ON principals_0."nconst"=people_0."nconst"
  CROSS JOIN (SELECT UNNEST(GENERATE_SERIES(0,14,1)) as group_set  ) as group_set
  GROUP BY 1,2,3,4,5
)
, __stage2 AS (
  SELECT
    "fieldName",
    "fieldPath",
    "fieldType",
    COALESCE("fieldValue", "fieldRange") as "fieldValue",
    weight
  FROM __stage1
)
SELECT 
   base."fieldName" as "fieldName",
   base."fieldPath" as "fieldPath",
   base."fieldType" as "fieldType",
   base."fieldValue" as "fieldValue",
   base."weight" as "weight"
FROM __stage2 as base
ORDER BY 5 desc NULLS LAST

Search Index Naming Convention

By convention indexes in sources are named search_index.

document
source: movies2 is duckdb.table('../data/titles.parquet') extend {
  join_many: principals is duckdb.table('../data/principals.parquet') extend {
    join_one: people is duckdb.table('../data/names.parquet') 
      on nconst = people.nconst
  } on tconst = principals.tconst

  measure: total_ratings is numVotes.sum()

  view: search_index is {
    index:
      *
      genres.*
      principals.category, principals.job
      principals.characters.*
      principals.people.primaryName
    by total_ratings
  }
}

So to look for 'Brad'

document
run: movies2 -> search_index -> { 
  select: *
  where: fieldValue ~ 'Brad%'
  order_by: weight desc
}
QUERY RESULTS
fieldNamefieldPathfieldTypefieldValueweight
principals.people.primaryNameprincipals/people/primaryNamestringBrad Pitt18,269,386
principals.people.primaryNameprincipals/people/primaryNamestringBradley Cooper8,980,668
principals.people.primaryNameprincipals/people/primaryNamestringBrad Bird2,783,448
principals.people.primaryNameprincipals/people/primaryNamestringBradley J. Fischer2,582,567
principals.people.primaryNameprincipals/people/primaryNamestringBrad Fiedel2,516,157
principals.people.primaryNameprincipals/people/primaryNamestringBrad Grey1,858,689
principals.people.primaryNameprincipals/people/primaryNamestringBrad Fuller1,589,845
principals.people.primaryNameprincipals/people/primaryNamestringBrad Garrett989,180
principals.people.primaryNameprincipals/people/primaryNamestringBradley Whitford908,639
principals.people.primaryNameprincipals/people/primaryNamestringBrad Anderson785,214
principals.people.primaryNameprincipals/people/primaryNamestringBradley Thomas672,907
principals.people.primaryNameprincipals/people/primaryNamestringBrad Dourif595,034
principals.people.primaryNameprincipals/people/primaryNamestringBrad Falchuk594,475
principals.people.primaryNameprincipals/people/primaryNamestringBrad Krevoy593,257
principals.people.primaryNameprincipals/people/primaryNamestringBradford Lewis566,153
principals.people.primaryNameprincipals/people/primaryNamestringBrad Peyton565,084
principals.characters.valueprincipals/characters/valuestringBrad Bellick553,782
principals.people.primaryNameprincipals/people/primaryNamestringBrad Silberling552,092
principals.characters.valueprincipals/characters/valuestringBrad Gurdlinger466,826
principals.people.primaryNameprincipals/people/primaryNamestringBrad Ingelsby452,543
principals.people.primaryNameprincipals/people/primaryNamestringBrad Segal402,692
principals.people.primaryNameprincipals/people/primaryNamestringBrad Furman385,968
principals.people.primaryNameprincipals/people/primaryNamestringBrad Mann384,595
principals.people.primaryNameprincipals/people/primaryNamestringBraden Aftergood374,772
principals.people.primaryNameprincipals/people/primaryNamestringBrad Winderbaum366,995
principals.people.primaryNameprincipals/people/primaryNamestringBrad Swaile345,759
principals.people.primaryNameprincipals/people/primaryNamestringBrad Wright278,557
principals.people.primaryNameprincipals/people/primaryNamestringBrad Renfro273,848
principals.characters.valueprincipals/characters/valuestringBradley Fine250,952
principals.people.primaryNameprincipals/people/primaryNamestringBrad Greenquist250,909
principals.characters.valueprincipals/characters/valuestringBrad245,925
principals.people.primaryNameprincipals/people/primaryNamestringBrad Copeland234,415
principals.characters.valueprincipals/characters/valuestringBrad Whitaker226,799
principals.people.primaryNameprincipals/people/primaryNamestringBrad Epstein197,059
principals.people.primaryNameprincipals/people/primaryNamestringBradley Gallo184,654
principals.people.primaryNameprincipals/people/primaryNamestringBrady Corbet173,307
principals.characters.valueprincipals/characters/valuestringBrad Majors - A Hero158,457
principals.people.primaryNameprincipals/people/primaryNamestringBrad Wyman156,357
principals.people.primaryNameprincipals/people/primaryNamestringBrad Davis150,273
principals.people.primaryNameprincipals/people/primaryNamestringBradford Dillman131,412
principals.characters.valueprincipals/characters/valuestringBrad Adamson113,849
principals.characters.valueprincipals/characters/valuestringBradley Martin112,103
principals.characters.valueprincipals/characters/valuestringBradley Jackson110,209
principals.characters.valueprincipals/characters/valuestringBrad Hamilton110,039
principals.people.primaryNameprincipals/people/primaryNamestringBrad Kane86,923
principals.people.primaryNameprincipals/people/primaryNamestringBrad Halvorson85,643
principals.people.primaryNameprincipals/people/primaryNamestringBradley James84,478
principals.characters.valueprincipals/characters/valuestringBrad Cage82,655
principals.characters.valueprincipals/characters/valuestringBrad Wesley80,561
principals.people.primaryNameprincipals/people/primaryNamestringBradford Lipson78,284
principals.people.primaryNameprincipals/people/primaryNamestringBrady Noon77,389
principals.people.primaryNameprincipals/people/primaryNamestringBrad Ableson75,588
principals.people.primaryNameprincipals/people/primaryNamestringBradford Young75,006
principals.people.primaryNameprincipals/people/primaryNamestringBrad Booker74,354
principals.people.primaryNameprincipals/people/primaryNamestringBrad Riddell73,922
principals.people.primaryNameprincipals/people/primaryNamestringBrad Gann73,337
principals.people.primaryNameprincipals/people/primaryNamestringBradley Stonesifer71,122
principals.characters.valueprincipals/characters/valuestringBradley Thomas71,027
principals.people.primaryNameprincipals/people/primaryNamestringBrad Leland69,259
principals.characters.valueprincipals/characters/valuestringBrad Lewis68,518
principals.characters.valueprincipals/characters/valuestringBrad Gregory67,955
principals.people.primaryNameprincipals/people/primaryNamestringBradley Parker67,355
principals.characters.valueprincipals/characters/valuestringBrad Stand65,526
principals.characters.valueprincipals/characters/valuestringBrad (segment \Tape 56\)65,431
principals.people.primaryNameprincipals/people/primaryNamestringBrady Coleman61,797
principals.characters.valueprincipals/characters/valuestringBrad Chang59,267
principals.people.primaryNameprincipals/people/primaryNamestringBrad Beyer57,584
principals.people.primaryNameprincipals/people/primaryNamestringBrad Weston51,673
principals.characters.valueprincipals/characters/valuestringBrad Bottig51,451
principals.characters.valueprincipals/characters/valuestringBrad Chase48,224
principals.people.primaryNameprincipals/people/primaryNamestringBradley King47,442
principals.people.primaryNameprincipals/people/primaryNamestringBrad Loree46,958
principals.characters.valueprincipals/characters/valuestringBrad Harris46,640
principals.people.primaryNameprincipals/people/primaryNamestringBrad Morris46,105
principals.characters.valueprincipals/characters/valuestringBrad Taylor46,084
principals.people.primaryNameprincipals/people/primaryNamestringBradley Raymond43,731
principals.people.primaryNameprincipals/people/primaryNamestringBradley Jenkel42,784
principals.people.primaryNameprincipals/people/primaryNamestringBrad M. Gilbert39,777
principals.people.primaryNameprincipals/people/primaryNamestringBrad Baruh39,491
principals.characters.valueprincipals/characters/valuestringBrad Williams39,300
principals.characters.valueprincipals/characters/valuestringBradley38,412
principals.characters.valueprincipals/characters/valuestringBrad Brown37,424
principals.people.primaryNameprincipals/people/primaryNamestringBradford L. Schlei35,007
principals.people.primaryNameprincipals/people/primaryNamestringBrad Silverman34,490
principals.people.primaryNameprincipals/people/primaryNamestringBrad Simpson33,880
principals.people.primaryNameprincipals/people/primaryNamestringBradford May33,729
principals.people.primaryNameprincipals/people/primaryNamestringBrad Johnson31,763
[
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Pitt",
    "weight": 18269386
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bradley Cooper",
    "weight": 8980668
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Bird",
    "weight": 2783448
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bradley J. Fischer",
    "weight": 2582567
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Fiedel",
    "weight": 2516157
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Grey",
    "weight": 1858689
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Fuller",
    "weight": 1589845
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Garrett",
    "weight": 989180
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bradley Whitford",
    "weight": 908639
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Anderson",
    "weight": 785214
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bradley Thomas",
    "weight": 672907
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Dourif",
    "weight": 595034
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Falchuk",
    "weight": 594475
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Krevoy",
    "weight": 593257
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bradford Lewis",
    "weight": 566153
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Peyton",
    "weight": 565084
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Brad Bellick",
    "weight": 553782
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Silberling",
    "weight": 552092
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Brad Gurdlinger",
    "weight": 466826
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Ingelsby",
    "weight": 452543
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Segal",
    "weight": 402692
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Furman",
    "weight": 385968
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Mann",
    "weight": 384595
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Braden Aftergood",
    "weight": 374772
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Winderbaum",
    "weight": 366995
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Swaile",
    "weight": 345759
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Wright",
    "weight": 278557
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Renfro",
    "weight": 273848
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Bradley Fine",
    "weight": 250952
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Greenquist",
    "weight": 250909
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Brad",
    "weight": 245925
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Copeland",
    "weight": 234415
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Brad Whitaker",
    "weight": 226799
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Epstein",
    "weight": 197059
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bradley Gallo",
    "weight": 184654
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brady Corbet",
    "weight": 173307
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Brad Majors - A Hero",
    "weight": 158457
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Wyman",
    "weight": 156357
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Davis",
    "weight": 150273
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bradford Dillman",
    "weight": 131412
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Brad Adamson",
    "weight": 113849
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Bradley Martin",
    "weight": 112103
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Bradley Jackson",
    "weight": 110209
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Brad Hamilton",
    "weight": 110039
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Kane",
    "weight": 86923
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Halvorson",
    "weight": 85643
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bradley James",
    "weight": 84478
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Brad Cage",
    "weight": 82655
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Brad Wesley",
    "weight": 80561
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bradford Lipson",
    "weight": 78284
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brady Noon",
    "weight": 77389
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Ableson",
    "weight": 75588
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bradford Young",
    "weight": 75006
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Booker",
    "weight": 74354
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Riddell",
    "weight": 73922
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Gann",
    "weight": 73337
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bradley Stonesifer",
    "weight": 71122
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Bradley Thomas",
    "weight": 71027
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Leland",
    "weight": 69259
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Brad Lewis",
    "weight": 68518
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Brad Gregory",
    "weight": 67955
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bradley Parker",
    "weight": 67355
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Brad Stand",
    "weight": 65526
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Brad (segment \\Tape 56\\)",
    "weight": 65431
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brady Coleman",
    "weight": 61797
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Brad Chang",
    "weight": 59267
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Beyer",
    "weight": 57584
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Weston",
    "weight": 51673
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Brad Bottig",
    "weight": 51451
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Brad Chase",
    "weight": 48224
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bradley King",
    "weight": 47442
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Loree",
    "weight": 46958
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Brad Harris",
    "weight": 46640
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Morris",
    "weight": 46105
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Brad Taylor",
    "weight": 46084
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bradley Raymond",
    "weight": 43731
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bradley Jenkel",
    "weight": 42784
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad M. Gilbert",
    "weight": 39777
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Baruh",
    "weight": 39491
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Brad Williams",
    "weight": 39300
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Bradley",
    "weight": 38412
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Brad Brown",
    "weight": 37424
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bradford L. Schlei",
    "weight": 35007
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Silverman",
    "weight": 34490
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Simpson",
    "weight": 33880
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bradford May",
    "weight": 33729
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Brad Johnson",
    "weight": 31763
  }
]
WITH __stage0 AS (
  SELECT
    group_set,
    CASE group_set
      WHEN 0 THEN 'averageRating'
      WHEN 1 THEN 'endYear'
      WHEN 2 THEN 'isAdult'
      WHEN 3 THEN 'numVotes'
      WHEN 4 THEN 'originalTitle'
      WHEN 5 THEN 'primaryTitle'
      WHEN 6 THEN 'runtimeMinutes'
      WHEN 7 THEN 'startYear'
      WHEN 8 THEN 'tconst'
      WHEN 9 THEN 'genres.value'
      WHEN 10 THEN 'principals.category'
      WHEN 11 THEN 'principals.job'
      WHEN 12 THEN 'principals.characters.value'
      WHEN 13 THEN 'principals.people.primaryName'
    END as "fieldName",
    CASE group_set
      WHEN 0 THEN 'averageRating'
      WHEN 1 THEN 'endYear'
      WHEN 2 THEN 'isAdult'
      WHEN 3 THEN 'numVotes'
      WHEN 4 THEN 'originalTitle'
      WHEN 5 THEN 'primaryTitle'
      WHEN 6 THEN 'runtimeMinutes'
      WHEN 7 THEN 'startYear'
      WHEN 8 THEN 'tconst'
      WHEN 9 THEN 'genres/value'
      WHEN 10 THEN 'principals/category'
      WHEN 11 THEN 'principals/job'
      WHEN 12 THEN 'principals/characters/value'
      WHEN 13 THEN 'principals/people/primaryName'
    END as "fieldPath",
    CASE group_set
      WHEN 0 THEN 'number'
      WHEN 1 THEN 'number'
      WHEN 2 THEN 'string'
      WHEN 3 THEN 'number'
      WHEN 4 THEN 'string'
      WHEN 5 THEN 'string'
      WHEN 6 THEN 'number'
      WHEN 7 THEN 'number'
      WHEN 8 THEN 'string'
      WHEN 9 THEN 'string'
      WHEN 10 THEN 'string'
      WHEN 11 THEN 'string'
      WHEN 12 THEN 'string'
      WHEN 13 THEN 'string'
    END as "fieldType",  CASE group_set WHEN 99999 THEN CAST(NULL as VARCHAR)
      WHEN 2 THEN movies2."isAdult"
      WHEN 4 THEN movies2."originalTitle"
      WHEN 5 THEN movies2."primaryTitle"
      WHEN 8 THEN movies2."tconst"
      WHEN 9 THEN genres_0
      WHEN 10 THEN principals_0."category"
      WHEN 11 THEN principals_0."job"
      WHEN 12 THEN characters_0
      WHEN 13 THEN people_0."primaryName"
    END as "fieldValue",
   COALESCE((
        SELECT SUM(a.val) as value
        FROM (
          SELECT UNNEST(list(distinct {key:movies2."__distinct_key", val: movies2."numVotes"})) a
        )
      ),0) as weight,
    CASE group_set
      WHEN 99999 THEN ''    WHEN 0 THEN MIN(CAST(movies2."averageRating" as VARCHAR)) || ' to ' || CAST(MAX(movies2."averageRating") as VARCHAR)
      WHEN 1 THEN MIN(CAST(movies2."endYear" as VARCHAR)) || ' to ' || CAST(MAX(movies2."endYear") as VARCHAR)
      WHEN 3 THEN MIN(CAST(movies2."numVotes" as VARCHAR)) || ' to ' || CAST(MAX(movies2."numVotes") as VARCHAR)
      WHEN 6 THEN MIN(CAST(movies2."runtimeMinutes" as VARCHAR)) || ' to ' || CAST(MAX(movies2."runtimeMinutes") as VARCHAR)
      WHEN 7 THEN MIN(CAST(movies2."startYear" as VARCHAR)) || ' to ' || CAST(MAX(movies2."startYear") as VARCHAR)
    END as "fieldRange"
  FROM (SELECT GEN_RANDOM_UUID() as __distinct_key, x.*  FROM '../data/titles.parquet' as x) as movies2
  LEFT JOIN LATERAL (SELECT UNNEST(movies2."genres"), 1 as ignoreme) as genres_0_outer(genres_0,ignoreme) ON genres_0_outer.ignoreme=1
   LEFT JOIN '../data/principals.parquet' AS principals_0
    ON movies2."tconst"=principals_0."tconst"
  LEFT JOIN LATERAL (SELECT UNNEST(principals_0."characters"), 1 as ignoreme) as characters_0_outer(characters_0,ignoreme) ON characters_0_outer.ignoreme=1
   LEFT JOIN '../data/names.parquet' AS people_0
    ON principals_0."nconst"=people_0."nconst"
  CROSS JOIN (SELECT UNNEST(GENERATE_SERIES(0,14,1)) as group_set  ) as group_set
  GROUP BY 1,2,3,4,5
)
, __stage1 AS (
  SELECT
    "fieldName",
    "fieldPath",
    "fieldType",
    COALESCE("fieldValue", "fieldRange") as "fieldValue",
    weight
  FROM __stage0
)
SELECT 
   base."fieldName" as "fieldName",
   base."fieldPath" as "fieldPath",
   base."fieldType" as "fieldType",
   base."fieldValue" as "fieldValue",
   base."weight" as "weight"
FROM __stage1 as base
WHERE base."fieldValue" LIKE 'Brad%'
ORDER BY 5 desc NULLS LAST

So to look for 'Bat'

document
run: movies2 -> search_index -> { 
  select: *
  where: fieldValue ~ 'Bat%'
  order_by: weight desc
}
QUERY RESULTS
fieldNamefieldPathfieldTypefieldValueweight
principals.characters.valueprincipals/characters/valuestringBatman10,424,082
primaryTitleprimaryTitlestringBatman Begins1,507,854
originalTitleoriginalTitlestringBatman Begins1,507,854
principals.jobprincipals/jobstringBatman created by1,020,989
principals.jobprincipals/jobstringBatman characters964,899
principals.characters.valueprincipals/characters/valuestringBatty790,162
originalTitleoriginalTitlestringBatman v Superman: Dawn of Justice713,914
primaryTitleprimaryTitlestringBatman v Superman: Dawn of Justice713,914
primaryTitleprimaryTitlestringBatman389,337
originalTitleoriginalTitlestringBatman389,337
originalTitleoriginalTitlestringBatman Returns315,132
primaryTitleprimaryTitlestringBatman Returns315,132
principals.characters.valueprincipals/characters/valuestringBatou260,600
primaryTitleprimaryTitlestringBatman & Robin260,430
originalTitleoriginalTitlestringBatman & Robin260,430
originalTitleoriginalTitlestringBatman Forever259,315
primaryTitleprimaryTitlestringBatman Forever259,315
primaryTitleprimaryTitlestringBattleship252,642
originalTitleoriginalTitlestringBattleship252,642
primaryTitleprimaryTitlestringBattlestar Galactica248,435
originalTitleoriginalTitlestringBattlestar Galactica248,435
principals.characters.valueprincipals/characters/valuestringBatgirl221,004
originalTitleoriginalTitlestringBattle of the Bastards217,000
primaryTitleprimaryTitlestringBattle of the Bastards217,000
originalTitleoriginalTitlestringBatoru rowaiaru188,692
primaryTitleprimaryTitlestringBattle Royale188,692
originalTitleoriginalTitlestringBattle: Los Angeles182,720
primaryTitleprimaryTitlestringBattle Los Angeles182,720
principals.characters.valueprincipals/characters/valuestringBatô148,975
principals.characters.valueprincipals/characters/valuestringBatiatus141,304
principals.characters.valueprincipals/characters/valuestringBattera112,813
primaryTitleprimaryTitlestringBates Motel112,103
originalTitleoriginalTitlestringBates Motel112,103
primaryTitleprimaryTitlestringBatman: The Animated Series109,143
originalTitleoriginalTitlestringBatman: The Animated Series109,143
principals.characters.valueprincipals/characters/valuestringBattle Droids107,847
originalTitleoriginalTitlestringBattlefield Earth81,723
primaryTitleprimaryTitlestringBattlefield Earth81,723
principals.people.primaryNameprincipals/people/primaryNamestringBathsheba Doran76,412
principals.people.primaryNameprincipals/people/primaryNamestringBate Khalil73,385
primaryTitleprimaryTitlestringBatman v Superman: Dawn of Justice (Ultimate Edition)68,865
originalTitleoriginalTitlestringBatman v Superman: Dawn of Justice (Ultimate Edition)68,865
originalTitleoriginalTitlestringBatman: Under the Red Hood65,192
primaryTitleprimaryTitlestringBatman: Under the Red Hood65,192
originalTitleoriginalTitlestringBatman: The Dark Knight Returns, Part 161,312
primaryTitleprimaryTitlestringBatman: The Dark Knight Returns, Part 161,312
primaryTitleprimaryTitlestringBattleship Potemkin59,629
primaryTitleprimaryTitlestringBatman: The Killing Joke59,389
originalTitleoriginalTitlestringBatman: The Killing Joke59,389
originalTitleoriginalTitlestringBattle of the Sexes57,648
primaryTitleprimaryTitlestringBattle of the Sexes57,648
principals.characters.valueprincipals/characters/valuestringBathurst 202055,709
primaryTitleprimaryTitlestringBatman: The Dark Knight Returns, Part 253,960
originalTitleoriginalTitlestringBatman: The Dark Knight Returns, Part 253,960
primaryTitleprimaryTitlestringBatman: Mask of the Phantasm53,743
originalTitleoriginalTitlestringBatman: Mask of the Phantasm53,743
principals.characters.valueprincipals/characters/valuestringBatu51,728
principals.characters.valueprincipals/characters/valuestringBathsheba Everdene51,291
originalTitleoriginalTitlestringBatwoman45,279
principals.characters.valueprincipals/characters/valuestringBatwoman45,279
primaryTitleprimaryTitlestringBatwoman45,279
principals.characters.valueprincipals/characters/valuestringBatwing45,279
principals.characters.valueprincipals/characters/valuestringBatukeshwar 'Bittu' Tiwari41,416
primaryTitleprimaryTitlestringBatman: Year One36,891
originalTitleoriginalTitlestringBatman: Year One36,891
primaryTitleprimaryTitlestringBatman: Assault on Arkham36,460
originalTitleoriginalTitlestringBatman: Assault on Arkham36,460
principals.characters.valueprincipals/characters/valuestringBattal35,502
primaryTitleprimaryTitlestringBatman: The Movie34,606
originalTitleoriginalTitlestringBatman: The Movie34,606
principals.people.primaryNameprincipals/people/primaryNamestringBattle Davis33,046
principals.characters.valueprincipals/characters/valuestringBathroom Attendant33,012
primaryTitleprimaryTitlestringBatman: Arkham City32,852
originalTitleoriginalTitlestringBatman: Arkham City32,852
originalTitleoriginalTitlestringBattle for the Planet of the Apes32,287
primaryTitleprimaryTitlestringBattle for the Planet of the Apes32,287
principals.characters.valueprincipals/characters/valuestringBatty Koda32,170
[
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Batman",
    "weight": 10424082
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Batman Begins",
    "weight": 1507854
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Batman Begins",
    "weight": 1507854
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "Batman created by",
    "weight": 1020989
  },
  {
    "fieldName": "principals.job",
    "fieldPath": "principals/job",
    "fieldType": "string",
    "fieldValue": "Batman characters",
    "weight": 964899
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Batty",
    "weight": 790162
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Batman v Superman: Dawn of Justice",
    "weight": 713914
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Batman v Superman: Dawn of Justice",
    "weight": 713914
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Batman",
    "weight": 389337
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Batman",
    "weight": 389337
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Batman Returns",
    "weight": 315132
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Batman Returns",
    "weight": 315132
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Batou",
    "weight": 260600
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Batman & Robin",
    "weight": 260430
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Batman & Robin",
    "weight": 260430
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Batman Forever",
    "weight": 259315
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Batman Forever",
    "weight": 259315
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Battleship",
    "weight": 252642
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Battleship",
    "weight": 252642
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Battlestar Galactica",
    "weight": 248435
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Battlestar Galactica",
    "weight": 248435
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Batgirl",
    "weight": 221004
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Battle of the Bastards",
    "weight": 217000
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Battle of the Bastards",
    "weight": 217000
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Batoru rowaiaru",
    "weight": 188692
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Battle Royale",
    "weight": 188692
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Battle: Los Angeles",
    "weight": 182720
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Battle Los Angeles",
    "weight": 182720
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Batô",
    "weight": 148975
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Batiatus",
    "weight": 141304
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Battera",
    "weight": 112813
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Bates Motel",
    "weight": 112103
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Bates Motel",
    "weight": 112103
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Batman: The Animated Series",
    "weight": 109143
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Batman: The Animated Series",
    "weight": 109143
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Battle Droids",
    "weight": 107847
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Battlefield Earth",
    "weight": 81723
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Battlefield Earth",
    "weight": 81723
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bathsheba Doran",
    "weight": 76412
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Bate Khalil",
    "weight": 73385
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Batman v Superman: Dawn of Justice (Ultimate Edition)",
    "weight": 68865
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Batman v Superman: Dawn of Justice (Ultimate Edition)",
    "weight": 68865
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Batman: Under the Red Hood",
    "weight": 65192
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Batman: Under the Red Hood",
    "weight": 65192
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Batman: The Dark Knight Returns, Part 1",
    "weight": 61312
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Batman: The Dark Knight Returns, Part 1",
    "weight": 61312
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Battleship Potemkin",
    "weight": 59629
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Batman: The Killing Joke",
    "weight": 59389
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Batman: The Killing Joke",
    "weight": 59389
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Battle of the Sexes",
    "weight": 57648
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Battle of the Sexes",
    "weight": 57648
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Bathurst 2020",
    "weight": 55709
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Batman: The Dark Knight Returns, Part 2",
    "weight": 53960
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Batman: The Dark Knight Returns, Part 2",
    "weight": 53960
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Batman: Mask of the Phantasm",
    "weight": 53743
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Batman: Mask of the Phantasm",
    "weight": 53743
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Batu",
    "weight": 51728
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Bathsheba Everdene",
    "weight": 51291
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Batwoman",
    "weight": 45279
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Batwoman",
    "weight": 45279
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Batwoman",
    "weight": 45279
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Batwing",
    "weight": 45279
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Batukeshwar 'Bittu' Tiwari",
    "weight": 41416
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Batman: Year One",
    "weight": 36891
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Batman: Year One",
    "weight": 36891
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Batman: Assault on Arkham",
    "weight": 36460
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Batman: Assault on Arkham",
    "weight": 36460
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Battal",
    "weight": 35502
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Batman: The Movie",
    "weight": 34606
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Batman: The Movie",
    "weight": 34606
  },
  {
    "fieldName": "principals.people.primaryName",
    "fieldPath": "principals/people/primaryName",
    "fieldType": "string",
    "fieldValue": "Battle Davis",
    "weight": 33046
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Bathroom Attendant",
    "weight": 33012
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Batman: Arkham City",
    "weight": 32852
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Batman: Arkham City",
    "weight": 32852
  },
  {
    "fieldName": "originalTitle",
    "fieldPath": "originalTitle",
    "fieldType": "string",
    "fieldValue": "Battle for the Planet of the Apes",
    "weight": 32287
  },
  {
    "fieldName": "primaryTitle",
    "fieldPath": "primaryTitle",
    "fieldType": "string",
    "fieldValue": "Battle for the Planet of the Apes",
    "weight": 32287
  },
  {
    "fieldName": "principals.characters.value",
    "fieldPath": "principals/characters/value",
    "fieldType": "string",
    "fieldValue": "Batty Koda",
    "weight": 32170
  }
]
WITH __stage0 AS (
  SELECT
    group_set,
    CASE group_set
      WHEN 0 THEN 'averageRating'
      WHEN 1 THEN 'endYear'
      WHEN 2 THEN 'isAdult'
      WHEN 3 THEN 'numVotes'
      WHEN 4 THEN 'originalTitle'
      WHEN 5 THEN 'primaryTitle'
      WHEN 6 THEN 'runtimeMinutes'
      WHEN 7 THEN 'startYear'
      WHEN 8 THEN 'tconst'
      WHEN 9 THEN 'genres.value'
      WHEN 10 THEN 'principals.category'
      WHEN 11 THEN 'principals.job'
      WHEN 12 THEN 'principals.characters.value'
      WHEN 13 THEN 'principals.people.primaryName'
    END as "fieldName",
    CASE group_set
      WHEN 0 THEN 'averageRating'
      WHEN 1 THEN 'endYear'
      WHEN 2 THEN 'isAdult'
      WHEN 3 THEN 'numVotes'
      WHEN 4 THEN 'originalTitle'
      WHEN 5 THEN 'primaryTitle'
      WHEN 6 THEN 'runtimeMinutes'
      WHEN 7 THEN 'startYear'
      WHEN 8 THEN 'tconst'
      WHEN 9 THEN 'genres/value'
      WHEN 10 THEN 'principals/category'
      WHEN 11 THEN 'principals/job'
      WHEN 12 THEN 'principals/characters/value'
      WHEN 13 THEN 'principals/people/primaryName'
    END as "fieldPath",
    CASE group_set
      WHEN 0 THEN 'number'
      WHEN 1 THEN 'number'
      WHEN 2 THEN 'string'
      WHEN 3 THEN 'number'
      WHEN 4 THEN 'string'
      WHEN 5 THEN 'string'
      WHEN 6 THEN 'number'
      WHEN 7 THEN 'number'
      WHEN 8 THEN 'string'
      WHEN 9 THEN 'string'
      WHEN 10 THEN 'string'
      WHEN 11 THEN 'string'
      WHEN 12 THEN 'string'
      WHEN 13 THEN 'string'
    END as "fieldType",  CASE group_set WHEN 99999 THEN CAST(NULL as VARCHAR)
      WHEN 2 THEN movies2."isAdult"
      WHEN 4 THEN movies2."originalTitle"
      WHEN 5 THEN movies2."primaryTitle"
      WHEN 8 THEN movies2."tconst"
      WHEN 9 THEN genres_0
      WHEN 10 THEN principals_0."category"
      WHEN 11 THEN principals_0."job"
      WHEN 12 THEN characters_0
      WHEN 13 THEN people_0."primaryName"
    END as "fieldValue",
   COALESCE((
        SELECT SUM(a.val) as value
        FROM (
          SELECT UNNEST(list(distinct {key:movies2."__distinct_key", val: movies2."numVotes"})) a
        )
      ),0) as weight,
    CASE group_set
      WHEN 99999 THEN ''    WHEN 0 THEN MIN(CAST(movies2."averageRating" as VARCHAR)) || ' to ' || CAST(MAX(movies2."averageRating") as VARCHAR)
      WHEN 1 THEN MIN(CAST(movies2."endYear" as VARCHAR)) || ' to ' || CAST(MAX(movies2."endYear") as VARCHAR)
      WHEN 3 THEN MIN(CAST(movies2."numVotes" as VARCHAR)) || ' to ' || CAST(MAX(movies2."numVotes") as VARCHAR)
      WHEN 6 THEN MIN(CAST(movies2."runtimeMinutes" as VARCHAR)) || ' to ' || CAST(MAX(movies2."runtimeMinutes") as VARCHAR)
      WHEN 7 THEN MIN(CAST(movies2."startYear" as VARCHAR)) || ' to ' || CAST(MAX(movies2."startYear") as VARCHAR)
    END as "fieldRange"
  FROM (SELECT GEN_RANDOM_UUID() as __distinct_key, x.*  FROM '../data/titles.parquet' as x) as movies2
  LEFT JOIN LATERAL (SELECT UNNEST(movies2."genres"), 1 as ignoreme) as genres_0_outer(genres_0,ignoreme) ON genres_0_outer.ignoreme=1
   LEFT JOIN '../data/principals.parquet' AS principals_0
    ON movies2."tconst"=principals_0."tconst"
  LEFT JOIN LATERAL (SELECT UNNEST(principals_0."characters"), 1 as ignoreme) as characters_0_outer(characters_0,ignoreme) ON characters_0_outer.ignoreme=1
   LEFT JOIN '../data/names.parquet' AS people_0
    ON principals_0."nconst"=people_0."nconst"
  CROSS JOIN (SELECT UNNEST(GENERATE_SERIES(0,14,1)) as group_set  ) as group_set
  GROUP BY 1,2,3,4,5
)
, __stage1 AS (
  SELECT
    "fieldName",
    "fieldPath",
    "fieldType",
    COALESCE("fieldValue", "fieldRange") as "fieldValue",
    weight
  FROM __stage0
)
SELECT 
   base."fieldName" as "fieldName",
   base."fieldPath" as "fieldPath",
   base."fieldType" as "fieldType",
   base."fieldValue" as "fieldValue",
   base."weight" as "weight"
FROM __stage1 as base
WHERE base."fieldValue" LIKE 'Bat%'
ORDER BY 5 desc NULLS LAST