Spaces:
Running
Running
File size: 125,435 Bytes
d8d4856 1104031 3ba9557 1104031 ca28f70 1104031 d8d4856 3ba9557 d8d4856 1104031 d8d4856 1104031 d8d4856 1104031 d8d4856 1104031 d8d4856 1104031 8364f3c cb256f8 8364f3c 1104031 d8d4856 1104031 d8d4856 1104031 8364f3c a5fd57d 1104031 d8d4856 1104031 ca28f70 3ba9557 ca28f70 a5fd57d ca28f70 a5fd57d ca28f70 a5fd57d 3ba9557 ca28f70 1104031 d8d4856 1104031 8364f3c a5fd57d 1104031 d8d4856 1104031 d8d4856 1104031 8364f3c 1104031 8364f3c cb256f8 8364f3c a5fd57d 3ba9557 1104031 d8d4856 1104031 d8d4856 1104031 dfb9466 1104031 8364f3c a5fd57d 1104031 d8d4856 1104031 ca28f70 3ba9557 ca28f70 3ba9557 ca28f70 d8d4856 3ba9557 d8d4856 3ba9557 1104031 3ba9557 1104031 3ba9557 1104031 d8d4856 1104031 d8d4856 3ba9557 d8d4856 3ba9557 d8d4856 1104031 3ba9557 1104031 3ba9557 1104031 3ba9557 1104031 3ba9557 1104031 d8d4856 1104031 d8d4856 3ba9557 d8d4856 1104031 3ba9557 1104031 d8d4856 1104031 d8d4856 3ba9557 d8d4856 3ba9557 1104031 3ba9557 1104031 3ba9557 1104031 d8d4856 1104031 3ba9557 1104031 d8d4856 3ba9557 d8d4856 3ba9557 1104031 3ba9557 1104031 3ba9557 1104031 3ba9557 1104031 d8d4856 1104031 d8d4856 3ba9557 d8d4856 1104031 3ba9557 1104031 3ba9557 1104031 3ba9557 1104031 3ba9557 1104031 3ba9557 1104031 3ba9557 1104031 3ba9557 1104031 3ba9557 1104031 3ba9557 1104031 3ba9557 1104031 3ba9557 a5fd57d 3ba9557 a5fd57d 3ba9557 a5fd57d 3ba9557 1104031 3ba9557 1104031 8364f3c 1104031 8364f3c 1104031 8364f3c a5fd57d 3ba9557 1104031 3ba9557 1104031 8364f3c 1104031 cb256f8 8364f3c a5fd57d 3ba9557 1104031 3ba9557 1104031 3ba9557 1104031 3ba9557 1104031 3ba9557 1104031 a5fd57d 1104031 cb256f8 8364f3c a5fd57d 3ba9557 1104031 8364f3c 1104031 8364f3c 1104031 8364f3c a5fd57d 1104031 8364f3c 1104031 8364f3c cb256f8 8364f3c a5fd57d 1104031 d8d4856 1104031 8364f3c 1104031 8364f3c a5fd57d 1104031 d8d4856 1104031 d8d4856 1104031 8364f3c 1104031 8364f3c 1104031 3ba9557 1104031 8364f3c a5fd57d 3ba9557 1104031 3ba9557 1104031 d8d4856 1104031 8364f3c a5fd57d 1104031 d8d4856 1104031 d8d4856 1104031 8364f3c a5fd57d 1104031 d8d4856 1104031 d8d4856 1104031 d8d4856 1104031 8364f3c a5fd57d 1104031 d8d4856 1104031 d8d4856 1104031 d8d4856 1104031 8364f3c a5fd57d 1104031 d8d4856 1104031 d8d4856 1104031 d8d4856 1104031 8364f3c 1104031 8364f3c a5fd57d 1104031 d8d4856 1104031 d8d4856 3ba9557 d8d4856 1104031 8364f3c 1104031 8364f3c a5fd57d 1104031 d8d4856 1104031 d8d4856 3ba9557 d8d4856 1104031 8364f3c 1104031 8364f3c a5fd57d 1104031 d8d4856 1104031 d8d4856 3ba9557 d8d4856 1104031 8364f3c 1104031 8364f3c a5fd57d 1104031 d8d4856 1104031 d8d4856 3ba9557 1104031 8364f3c 1104031 8364f3c a5fd57d 1104031 3ba9557 d8d4856 1104031 8364f3c a5fd57d 3ba9557 1104031 d8d4856 1104031 d8d4856 1104031 d8d4856 3ba9557 d8d4856 1104031 8364f3c a5fd57d 3ba9557 1104031 3ba9557 1104031 dfb9466 3ba9557 1104031 3ba9557 cb256f8 3ba9557 cb256f8 3ba9557 a5fd57d 3ba9557 a5fd57d 3ba9557 a5fd57d 3ba9557 a5fd57d 3ba9557 a5fd57d 3ba9557 a5fd57d 3ba9557 a5fd57d 3ba9557 a5fd57d 3ba9557 a5fd57d 3ba9557 a5fd57d 3ba9557 cb256f8 3ba9557 cb256f8 3ba9557 cb256f8 3ba9557 cb256f8 3ba9557 cb256f8 3ba9557 cb256f8 3ba9557 a5fd57d 3ba9557 a5fd57d 3ba9557 a5fd57d 3ba9557 a5fd57d 3ba9557 cb256f8 3ba9557 cb256f8 a5fd57d cb256f8 8364f3c cb256f8 8364f3c cb256f8 8364f3c a5fd57d 3ba9557 cb256f8 3ba9557 cb256f8 a5fd57d cb256f8 8364f3c cb256f8 8364f3c cb256f8 a5fd57d 3ba9557 cb256f8 8364f3c cb256f8 8364f3c cb256f8 8364f3c a5fd57d cb256f8 8364f3c cb256f8 8364f3c a5fd57d cb256f8 a5fd57d cb256f8 8364f3c cb256f8 8364f3c cb256f8 8364f3c a5fd57d cb256f8 a5fd57d cb256f8 8364f3c cb256f8 8364f3c cb256f8 8364f3c a5fd57d cb256f8 ca28f70 a5fd57d 3ba9557 ca28f70 a5fd57d 3ba9557 ca28f70 3ba9557 cb256f8 3ba9557 cb256f8 3ba9557 cb256f8 3ba9557 cb256f8 3ba9557 cb256f8 3ba9557 cb256f8 3ba9557 cb256f8 3ba9557 cb256f8 3ba9557 cb256f8 3ba9557 cb256f8 3ba9557 cb256f8 3ba9557 cb256f8 3ba9557 d8d4856 1104031 d8d4856 1104031 d8d4856 1104031 d8d4856 1104031 d8d4856 1104031 d8d4856 1104031 d8d4856 1104031 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 | """
SQL template definitions for synthetic data generation.
Geometry output convention
--------------------------
Every final SELECT wraps geometry with ST_AsGeoJSON():
ST_AsGeoJSON(geometry) AS geometry
This returns a GeoJSON string instead of raw WKB bytes, which is directly
JSON-serialisable and matches what the serving stack expects.
CTEs that compute intermediate geometries (used only for spatial predicates
or ST_Area) keep the column as raw GEOMETRY so DuckDB spatial functions work.
Buffer distance convention
--------------------------
All buffer templates use {buffer_m} (metres) in SQL: geometry / 111_320.
Question hints use {buffer_label} β a human-readable string like "50 km" or
"500 m" β generated by the handler from a combined (metres, label) choice list.
This keeps km and metre queries in a single template instead of separate ones.
Mixed-source candidates
-----------------------
generate_samples.py pads every candidate list with 50 % cross-source
distractors so the model always sees both source values and learns the
correct parquet path from the candidates table.
Template families
-----------------
direct_lookup Simple single-feature fetch by ID.
disambiguation "Place, Container" queries like "Puri, Odisha" β lookup by
ID after resolving an ambiguous name via containing region
or country mentioned in the query.
adjacency ST_Touches β features sharing a border.
multi_adjacency Features that simultaneously touch TWO anchors.
containment ST_Within / ST_Contains β hierarchical nesting.
intersection ST_Intersects β overlapping or crossing features.
buffer ST_Buffer β proximity zones in km or metres.
chained Containment + EXISTS/NOT EXISTS sea predicate.
difference ST_Difference β geometry subtraction.
border_corridor Buffered ST_Intersection of a shared border.
set_operations ST_Union_Agg β merging multiple geometries.
partial_selection Bbox clipping β directional halves or feature clips.
aggregation TOP-N by area with ORDER BY.
window_function ROW_NUMBER() OVER (PARTITION BY) β per-group ranking.
attribute_filter Pure attribute predicates: is_land, country, etc.
"""
from dataclasses import dataclass
from typing import List, Literal
_SUBTYPE_ALIASES = {
"country": ["countries", "nations"],
"region": ["states", "provinces", "oblasts", "departments", "prefectures", "cantons"],
"county": ["districts", "municipalities", "boroughs", "communes", "parishes"],
}
def _join_anchor_exprs(num_anchors: int) -> str:
"""Join anchor placeholders into a natural-language list."""
names = [f"{{anchor_{i}_name}}" for i in range(1, num_anchors + 1)]
if num_anchors == 1:
return names[0]
if num_anchors == 2:
return f"{names[0]} or {names[1]}"
return ", ".join(names[:-1]) + f", or {names[-1]}"
def _buffer_question_hints(target_subtype: str, anchor_name_expr: str) -> List[str]:
"""Build varied buffer question hints for one target subtype."""
aliases = _SUBTYPE_ALIASES[target_subtype]
return [
f"which {aliases[0]} are within {{buffer_label}} of {anchor_name_expr}?",
f"{aliases[0]} within {{buffer_label}} of {anchor_name_expr}",
f"find {aliases[0]} within a {{buffer_label}} radius of {anchor_name_expr}",
f"which {aliases[1]} are within {{buffer_label}} of {anchor_name_expr}?",
f"show {aliases[0]} within {{buffer_label}} of {anchor_name_expr}",
f"what {aliases[0]} fall within {{buffer_label}} of {anchor_name_expr}?",
f"areas close to {anchor_name_expr} within {{buffer_label}}",
]
def _make_buffer_templates() -> List["SQLTemplate"]:
"""Generate subtype-specific and multi-anchor buffer templates."""
templates: List[SQLTemplate] = []
for template_id, target_subtype in (
("buffer_04", "country"),
("buffer_05", "region"),
("buffer_06", "county"),
):
templates.append(
SQLTemplate(
template_id=template_id,
family="buffer",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype=target_subtype,
requires_buffer=True,
sql_template=(
"WITH a AS ("
" SELECT ST_Buffer(geometry, {buffer_m} / 111320.0) AS geom"
" FROM read_parquet('divisions_area')"
" WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.id != '{anchor_id}'"
" AND b.subtype = '{target_subtype}'"
" AND ST_Intersects(b.geometry, a.geom)"
),
question_hints=_buffer_question_hints(target_subtype, "{anchor_name}"),
)
)
for template_id, num_anchors, target_subtype in (
("buffer_07", 2, "region"),
("buffer_08", 3, "country"),
("buffer_09", 4, "region"),
("buffer_10", 5, "county"),
):
anchor_ids = ", ".join(f"'{{anchor_id_{i}}}'" for i in range(1, num_anchors + 1))
name_expr = _join_anchor_exprs(num_anchors)
templates.append(
SQLTemplate(
template_id=template_id,
family="buffer",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=num_anchors,
target_subtype=target_subtype,
requires_buffer=True,
sql_template=(
"WITH buf AS ("
" SELECT ST_Union_Agg(ST_Buffer(geometry, {buffer_m} / 111320.0)) AS geom"
" FROM read_parquet('divisions_area')"
f" WHERE id IN ({anchor_ids})"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, buf"
f" WHERE b.id NOT IN ({anchor_ids})"
" AND b.subtype = '{target_subtype}'"
" AND ST_Intersects(b.geometry, buf.geom)"
),
question_hints=_buffer_question_hints(target_subtype, name_expr),
)
)
return templates
def _make_country_in_templates() -> List["SQLTemplate"]:
"""Generate repeated country-IN set-operation templates."""
specs = (
("contain_multi_01", 2, "region"),
("contain_multi_02", 3, "region"),
("contain_multi_03", 2, "county"),
)
templates: List[SQLTemplate] = []
for template_id, num_anchors, target_subtype in specs:
countries = ", ".join(f"'{{country_{i}}}'" for i in range(1, num_anchors + 1))
anchor_names = _join_anchor_exprs(num_anchors).replace(" or ", " and ")
aliases = _SUBTYPE_ALIASES[target_subtype]
question_hints = [
f"{aliases[0]} of {anchor_names}",
f"all {aliases[0]} in {anchor_names}",
f"show {aliases[0]} across {anchor_names}",
f"find {aliases[0]} across {anchor_names}",
f"list {aliases[0]} in {anchor_names}",
f"areas of {anchor_names}",
]
if len(aliases) > 1:
question_hints.extend(
[
f"{aliases[1]} of {anchor_names}",
f"all {aliases[1]} in {anchor_names}",
]
)
templates.append(
SQLTemplate(
template_id=template_id,
family="set_operations",
sql_difficulty="medium-hard",
anchor_source="divisions_area",
num_anchors=num_anchors,
target_subtype=target_subtype,
sql_template=(
"SELECT id, names.\"primary\" AS name, subtype, country,"
" ST_AsGeoJSON(geometry) AS geometry"
" FROM read_parquet('divisions_area')"
f" WHERE country IN ({countries})"
" AND subtype = '{target_subtype}'"
),
question_hints=question_hints,
)
)
return templates
@dataclass
class SQLTemplate:
"""SQL template for synthetic data generation."""
template_id: str
family: str
sql_difficulty: Literal["easy", "medium", "medium-hard", "hard"]
anchor_source: Literal["divisions_area", "natural_earth", "mixed"]
num_anchors: int
sql_template: str
question_hints: List[str]
target_subtype: str = None
requires_buffer: bool = False
requires_aggregation: bool = False
# ---------------------------------------------------------------------------
# Template catalog
# ---------------------------------------------------------------------------
TEMPLATES = [
# ββ DIRECT LOOKUP ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
SQLTemplate(
template_id="lookup_01",
family="direct_lookup",
sql_difficulty="easy",
anchor_source="divisions_area",
num_anchors=1,
sql_template=(
"SELECT ST_AsGeoJSON(geometry) AS geometry,"
" names.\"primary\" AS name, id, subtype, country"
" FROM read_parquet('divisions_area')"
" WHERE id = '{anchor_id}'"
),
question_hints=[
"show me {anchor_name}",
"get the boundary of {anchor_name}",
"find {anchor_name}",
"where is {anchor_name}?",
"outline of {anchor_name}",
"map {anchor_name}",
"what does {anchor_name} look like",
"i need the shape of {anchor_name}",
"pull up {anchor_name}",
"can you show {anchor_name}",
"map of {anchor_name}",
"{anchor_name} boundary",
"locate {anchor_name}",
],
),
SQLTemplate(
template_id="lookup_02",
family="direct_lookup",
sql_difficulty="easy",
anchor_source="natural_earth",
num_anchors=1,
sql_template=(
"SELECT ST_AsGeoJSON(geometry) AS geometry,"
" names.\"primary\" AS name, id, subtype"
" FROM read_parquet('natural_earth')"
" WHERE id = '{anchor_id}'"
),
question_hints=[
"show me the {anchor_name}",
"get the {anchor_name}",
"find the {anchor_name}",
"where is the {anchor_name}?",
"extent of the {anchor_name}",
"geometry of the {anchor_name}",
"display the {anchor_name}",
"pull up the {anchor_name}",
"i want to see the {anchor_name}",
"map the {anchor_name}",
"how big is the {anchor_name}?",
"outline of the {anchor_name}",
"show the shape of the {anchor_name}",
"trace the {anchor_name}",
"map out the {anchor_name}",
"where exactly is the {anchor_name}",
],
),
# ββ DISAMBIGUATION ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# "Puri, Odisha", "Lisbon, Portugal", "Goa, India" β a common real-world
# query pattern where users give a place plus its containing region or
# country to disambiguate same-name localities.
# SQL is a plain lookup by id (disambiguation happens at candidate-pick
# time). Candidates include same-name localities in other regions plus
# the container, so the model must read the CSV to choose correctly.
#
# disambiguate_01: county scoped by its region / country
# disambiguate_02: county scoped by its country
# disambiguate_03: region scoped by its country
SQLTemplate(
template_id="disambiguate_01",
family="disambiguation",
sql_difficulty="easy",
anchor_source="divisions_area",
num_anchors=1,
sql_template=(
"SELECT ST_AsGeoJSON(geometry) AS geometry,"
" names.\"primary\" AS name, id, subtype, country, region"
" FROM read_parquet('divisions_area')"
" WHERE id = '{anchor_id}'"
),
question_hints=[
"{anchor_name}, {container_name}",
"{anchor_name} in {container_name}",
"the {anchor_name} that's in {container_name}",
"show me {anchor_name}, {container_name}",
"where is {anchor_name}, {container_name}?",
"map of {anchor_name} ({container_name})",
"{anchor_name} ({container_name})",
"{anchor_name} {container_name}",
"pull up {anchor_name} in {container_name}",
"find {anchor_name} in {container_name}",
"locate {anchor_name} in {container_name}",
"need {anchor_name} from {container_name}",
"show {anchor_name} under {container_name}",
"{anchor_name} near {container_name}",
],
),
SQLTemplate(
template_id="disambiguate_02",
family="disambiguation",
sql_difficulty="easy",
anchor_source="divisions_area",
num_anchors=1,
sql_template=(
"SELECT ST_AsGeoJSON(geometry) AS geometry,"
" names.\"primary\" AS name, id, subtype, country"
" FROM read_parquet('divisions_area')"
" WHERE id = '{anchor_id}'"
),
question_hints=[
"{anchor_name}, {container_name}",
"{anchor_name} in {container_name}",
"{anchor_name}, {container_name}.",
"show me {anchor_name}, {container_name}",
"where is {anchor_name} in {container_name}?",
"the {anchor_name} that's in {container_name}",
"map of {anchor_name}, {container_name}",
"pull up {anchor_name} ({container_name})",
"find {anchor_name} in {container_name}",
"{anchor_name} {container_name}",
"locate {anchor_name} in {container_name}",
"need the {anchor_name} in {container_name}",
"show {anchor_name} from {container_name}",
"bring up {anchor_name}, {container_name}",
],
),
SQLTemplate(
template_id="disambiguate_03",
family="disambiguation",
sql_difficulty="easy",
anchor_source="divisions_area",
num_anchors=1,
sql_template=(
"SELECT ST_AsGeoJSON(geometry) AS geometry,"
" names.\"primary\" AS name, id, subtype, country"
" FROM read_parquet('divisions_area')"
" WHERE id = '{anchor_id}'"
),
question_hints=[
"{anchor_name}, {container_name}",
"{anchor_name} state of {container_name}",
"the {anchor_name} region in {container_name}",
"show me {anchor_name}, {container_name}",
"where is {anchor_name} in {container_name}?",
"map of {anchor_name}, {container_name}",
"{anchor_name} ({container_name})",
"{anchor_name} province of {container_name}",
"pull up {anchor_name} in {container_name}",
"find {anchor_name} {container_name}",
"locate {anchor_name} within {container_name}",
"show the {anchor_name} part of {container_name}",
"need {anchor_name} from {container_name}",
"bring up {anchor_name} in {container_name}",
"{anchor_name} prefecture of {container_name}",
"{anchor_name} oblast of {container_name}",
"{anchor_name} department of {container_name}",
"{anchor_name} canton in {container_name}",
],
),
# ββ ADJACENCY ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
SQLTemplate(
template_id="adj_01",
family="adjacency",
sql_difficulty="medium",
anchor_source="divisions_area",
num_anchors=1,
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.id != '{anchor_id}'"
" AND ST_Touches(a.geometry, b.geometry)"
),
question_hints=[
"what places touch {anchor_name}",
"list everything adjacent to {anchor_name}",
"what shares a border with {anchor_name}",
"neighbours of {anchor_name}",
"what's next to {anchor_name}",
"what surrounds {anchor_name}?",
"places next to {anchor_name}",
"everything bordering {anchor_name}",
"show adjacent places to {anchor_name}",
"areas touching {anchor_name}",
"find the neighbours of {anchor_name}",
"bordering places for {anchor_name}",
"places that meet {anchor_name}",
],
),
SQLTemplate(
template_id="adj_02",
family="adjacency",
sql_difficulty="medium",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="region",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.id != '{anchor_id}'"
" AND b.subtype = '{target_subtype}'"
" AND ST_Touches(a.geometry, b.geometry)"
),
question_hints=[
"which {target_subtype}s border {anchor_name}?",
"what {target_subtype}s share a border with {anchor_name}",
"{target_subtype}s that touch {anchor_name}",
"neighbouring {target_subtype}s of {anchor_name}",
"which {target_subtype}s are adjacent to {anchor_name}?",
"{target_subtype}s along the {anchor_name} border",
"find {target_subtype}s next to {anchor_name}",
"show {target_subtype}s bordering {anchor_name}",
"{target_subtype}s beside {anchor_name}",
"all {target_subtype}s touching {anchor_name}",
"{target_subtype}s meeting {anchor_name}",
"which states border {anchor_name}?",
"which provinces share a border with {anchor_name}?",
"states adjacent to {anchor_name}",
"neighbouring provinces of {anchor_name}",
"which prefectures border {anchor_name}?",
"oblasts bordering {anchor_name}",
"departments that touch {anchor_name}",
"cantons adjacent to {anchor_name}",
],
),
SQLTemplate(
template_id="adj_03",
family="adjacency",
sql_difficulty="medium",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="sea",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT n.id, n.names.\"primary\" AS name, n.subtype,"
" ST_AsGeoJSON(n.geometry) AS geometry"
" FROM read_parquet('natural_earth') AS n, a"
" WHERE n.subtype IN ('ocean', 'sea')"
" AND ST_Intersects(a.geometry, n.geometry)"
),
question_hints=[
"which seas touch {anchor_name}?",
"what seas border {anchor_name}?",
"which bodies of water is {anchor_name} next to?",
"what ocean or sea borders {anchor_name}",
"which oceans touch {anchor_name}?",
"what coastline does {anchor_name} have?",
"which water bodies does {anchor_name} border?",
"does {anchor_name} have sea access?",
"what ocean is {anchor_name} on?",
"is {anchor_name} on the coast?",
"what sea is off the coast of {anchor_name}?",
"which ocean lies off {anchor_name}?",
"what water is {anchor_name} on the shore of?",
"which sea or ocean is {anchor_name} along?",
],
),
SQLTemplate(
template_id="adj_04",
family="adjacency",
sql_difficulty="medium",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="county",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.id != '{anchor_id}'"
" AND b.subtype = '{target_subtype}'"
" AND ST_Touches(a.geometry, b.geometry)"
),
question_hints=[
"neighbouring counties of {anchor_name}",
"neighbouring districts of {anchor_name}",
"which counties border {anchor_name}?",
"which districts border {anchor_name}?",
"counties adjacent to {anchor_name}",
"districts next to {anchor_name}",
"counties sharing a border with {anchor_name}",
"what counties touch {anchor_name}?",
"nearby counties of {anchor_name}",
"counties along the {anchor_name} boundary",
"municipalities bordering {anchor_name}",
"which boroughs are adjacent to {anchor_name}?",
"communes that touch {anchor_name}",
"parishes next to {anchor_name}",
"neighbouring municipalities of {anchor_name}",
],
),
SQLTemplate(
template_id="adj_05",
family="adjacency",
sql_difficulty="medium",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="country",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.id != '{anchor_id}'"
" AND b.subtype = '{target_subtype}'"
" AND ST_Touches(a.geometry, b.geometry)"
),
question_hints=[
"which countries border {anchor_name}?",
"what countries share a border with {anchor_name}?",
"countries adjacent to {anchor_name}",
"neighbouring countries of {anchor_name}",
"which nations border {anchor_name}?",
"what nations are next to {anchor_name}?",
"nations sharing a border with {anchor_name}",
"countries that touch {anchor_name}",
"find countries bordering {anchor_name}",
"show countries adjacent to {anchor_name}",
"all countries touching {anchor_name}",
"which nations are {anchor_name}'s neighbours?",
],
),
SQLTemplate(
template_id="adj_06",
family="adjacency",
sql_difficulty="medium",
anchor_source="natural_earth",
num_anchors=1,
target_subtype="country",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('natural_earth') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Intersects(b.geometry, a.geometry)"
),
question_hints=[
"which countries border the {anchor_name}?",
"what countries are next to the {anchor_name}?",
"countries along the {anchor_name}",
"which nations touch the {anchor_name}?",
"countries adjacent to the {anchor_name}",
"which countries lie on the {anchor_name}?",
],
),
SQLTemplate(
template_id="adj_07",
family="adjacency",
sql_difficulty="medium",
anchor_source="natural_earth",
num_anchors=1,
target_subtype="region",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('natural_earth') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Intersects(b.geometry, a.geometry)"
),
question_hints=[
"which regions border the {anchor_name}?",
"what regions are next to the {anchor_name}?",
"regions along the {anchor_name}",
"which states touch the {anchor_name}?",
"provinces adjacent to the {anchor_name}",
"which regions lie on the {anchor_name}?",
],
),
SQLTemplate(
template_id="adj_08",
family="adjacency",
sql_difficulty="medium",
anchor_source="natural_earth",
num_anchors=1,
target_subtype="county",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('natural_earth') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Intersects(b.geometry, a.geometry)"
),
question_hints=[
"which counties border the {anchor_name}?",
"what districts are next to the {anchor_name}?",
"counties along the {anchor_name}",
"which districts touch the {anchor_name}?",
"municipalities adjacent to the {anchor_name}",
"which counties lie on the {anchor_name}?",
],
),
# ββ NATURAL EARTH ADJACENCY βββββββββββββββββββββββββββββββββββββββββββββ
# Division anchor, natural_earth targets. Handler formats anchor_id and
# target_subtype but the SQL hardcodes NE subtypes (like adj_03).
SQLTemplate(
template_id="adj_09",
family="adjacency",
sql_difficulty="medium",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="river",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT n.id, n.names.\"primary\" AS name, n.subtype,"
" ST_AsGeoJSON(n.geometry) AS geometry"
" FROM read_parquet('natural_earth') AS n, a"
" WHERE n.subtype IN ('river', 'lake', 'basin')"
" AND ST_Intersects(a.geometry, n.geometry)"
),
question_hints=[
"what rivers or lakes are in {anchor_name}?",
"natural water features of {anchor_name}",
"which rivers flow through {anchor_name}?",
"lakes and rivers within {anchor_name}",
"water features inside {anchor_name}",
"what bodies of water cross {anchor_name}?",
"rivers of {anchor_name}",
"show me the lakes in {anchor_name}",
"what rivers run through {anchor_name}?",
"which lakes lie in {anchor_name}?",
"what waterways are in {anchor_name}?",
"which basins, lakes, or rivers are in {anchor_name}?",
],
),
SQLTemplate(
template_id="adj_10",
family="adjacency",
sql_difficulty="medium",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="range/mtn",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT n.id, n.names.\"primary\" AS name, n.subtype,"
" ST_AsGeoJSON(n.geometry) AS geometry"
" FROM read_parquet('natural_earth') AS n, a"
" WHERE n.subtype = 'range/mtn'"
" AND ST_Intersects(a.geometry, n.geometry)"
),
question_hints=[
"what mountain ranges are in {anchor_name}?",
"which mountain ranges cross {anchor_name}?",
"mountains of {anchor_name}",
"mountain regions in {anchor_name}",
"what hills are in {anchor_name}?",
"which hills cross {anchor_name}?",
"ghats of {anchor_name}",
"what ghats are in {anchor_name}?",
"highlands in {anchor_name}",
"mountain belts within {anchor_name}",
],
),
SQLTemplate(
template_id="adj_11",
family="adjacency",
sql_difficulty="medium",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="plateau",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT n.id, n.names.\"primary\" AS name, n.subtype,"
" ST_AsGeoJSON(n.geometry) AS geometry"
" FROM read_parquet('natural_earth') AS n, a"
" WHERE n.subtype = 'plateau'"
" AND ST_Intersects(a.geometry, n.geometry)"
),
question_hints=[
"what plateaus are in {anchor_name}?",
"which plateaus cross {anchor_name}?",
"uplands in {anchor_name}",
"what uplands are in {anchor_name}?",
"tablelands of {anchor_name}",
"plateau regions within {anchor_name}",
"show plateaus in {anchor_name}",
"find uplands of {anchor_name}",
"give me plateau areas in {anchor_name}",
"{anchor_name} plateaus and uplands",
"what tablelands are there in {anchor_name}?",
],
),
SQLTemplate(
template_id="adj_12",
family="adjacency",
sql_difficulty="medium",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="landform",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT n.id, n.names.\"primary\" AS name, n.subtype,"
" ST_AsGeoJSON(n.geometry) AS geometry"
" FROM read_parquet('natural_earth') AS n, a"
" WHERE n.subtype IN ('plain', 'lowland', 'basin', 'valley', 'depression', 'gorge')"
" AND ST_Intersects(a.geometry, n.geometry)"
),
question_hints=[
"what plains are in {anchor_name}?",
"basins and valleys of {anchor_name}",
"which basins are in {anchor_name}?",
"what valleys cross {anchor_name}?",
"lowlands in {anchor_name}",
"major landforms in {anchor_name}",
"plains, basins, and valleys within {anchor_name}",
"show me the main landforms in {anchor_name}",
"landforms of {anchor_name}",
"find plains and basins in {anchor_name}",
"{anchor_name} valleys and lowlands",
],
),
# ββ MULTI-ADJACENCY ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
SQLTemplate(
template_id="multi_adj_01",
family="multi_adjacency",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=2,
target_subtype="region",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id_1}'"
"),"
" b AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id_2}'"
")"
" SELECT c.id, c.names.\"primary\" AS name, c.subtype, c.country,"
" ST_AsGeoJSON(c.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS c, a, b"
" WHERE c.id NOT IN ('{anchor_id_1}', '{anchor_id_2}')"
" AND c.subtype = '{target_subtype}'"
" AND ST_Touches(c.geometry, a.geometry)"
" AND ST_Touches(c.geometry, b.geometry)"
),
question_hints=[
"which {target_subtype}s border both {anchor_1_name} and {anchor_2_name}?",
"what {target_subtype}s touch both {anchor_1_name} and {anchor_2_name}?",
"{target_subtype}s adjacent to both {anchor_1_name} and {anchor_2_name}",
"common {target_subtype} neighbours of {anchor_1_name} and {anchor_2_name}",
"show {target_subtype}s touching both {anchor_1_name} and {anchor_2_name}",
"{target_subtype}s bordering both {anchor_1_name} and {anchor_2_name}",
"shared {target_subtype} neighbours of {anchor_1_name} and {anchor_2_name}",
"find {target_subtype}s adjacent to both {anchor_1_name} and {anchor_2_name}",
"which states border both {anchor_1_name} and {anchor_2_name}?",
"which provinces are adjacent to both {anchor_1_name} and {anchor_2_name}?",
"states touching both {anchor_1_name} and {anchor_2_name}",
],
),
SQLTemplate(
template_id="multi_adj_02",
family="multi_adjacency",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=2,
target_subtype="country",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id_1}'"
"),"
" b AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id_2}'"
")"
" SELECT c.id, c.names.\"primary\" AS name, c.subtype, c.country,"
" ST_AsGeoJSON(c.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS c, a, b"
" WHERE c.id NOT IN ('{anchor_id_1}', '{anchor_id_2}')"
" AND c.subtype = '{target_subtype}'"
" AND ST_Touches(c.geometry, a.geometry)"
" AND ST_Touches(c.geometry, b.geometry)"
),
question_hints=[
"which countries border both {anchor_1_name} and {anchor_2_name}?",
"what nations share a border with both {anchor_1_name} and {anchor_2_name}?",
"countries adjacent to both {anchor_1_name} and {anchor_2_name}",
"which country touches both {anchor_1_name} and {anchor_2_name}?",
"nations bordering both {anchor_1_name} and {anchor_2_name}",
"show countries neighbouring both {anchor_1_name} and {anchor_2_name}",
"find countries that border both {anchor_1_name} and {anchor_2_name}",
"common country neighbours of {anchor_1_name} and {anchor_2_name}",
"which nation lies between {anchor_1_name} and {anchor_2_name}?",
"countries sharing a border with both {anchor_1_name} and {anchor_2_name}",
],
),
SQLTemplate(
template_id="multi_adj_03",
family="multi_adjacency",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=2,
target_subtype="county",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id_1}'"
"),"
" b AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id_2}'"
")"
" SELECT c.id, c.names.\"primary\" AS name, c.subtype, c.country,"
" ST_AsGeoJSON(c.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS c, a, b"
" WHERE c.id NOT IN ('{anchor_id_1}', '{anchor_id_2}')"
" AND c.subtype = '{target_subtype}'"
" AND ST_Touches(c.geometry, a.geometry)"
" AND ST_Touches(c.geometry, b.geometry)"
),
question_hints=[
"which {target_subtype}s border both {anchor_1_name} and {anchor_2_name}?",
"what {target_subtype}s touch both {anchor_1_name} and {anchor_2_name}?",
"{target_subtype}s adjacent to both {anchor_1_name} and {anchor_2_name}",
"common {target_subtype} neighbours of {anchor_1_name} and {anchor_2_name}",
"show {target_subtype}s touching both {anchor_1_name} and {anchor_2_name}",
"which districts border both {anchor_1_name} and {anchor_2_name}?",
"districts lying between {anchor_1_name} and {anchor_2_name}",
"find districts adjacent to both {anchor_1_name} and {anchor_2_name}",
"municipalities bordering both {anchor_1_name} and {anchor_2_name}",
"which boroughs touch both {anchor_1_name} and {anchor_2_name}?",
],
),
# ββ CONTAINMENT ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
SQLTemplate(
template_id="contain_01",
family="containment",
sql_difficulty="medium",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="county",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.id != '{anchor_id}'"
" AND b.subtype = '{target_subtype}'"
" AND ST_Within(b.geometry, a.geometry)"
),
question_hints=[
"what {target_subtype}s are in {anchor_name}?",
"which {target_subtype}s fall within {anchor_name}?",
"list all {target_subtype}s inside {anchor_name}",
"{target_subtype}s contained by {anchor_name}",
"all {target_subtype}s within {anchor_name}",
"{target_subtype}s of {anchor_name}",
"show every {target_subtype} in {anchor_name}",
"show {target_subtype}s inside {anchor_name}",
"find {target_subtype}s in {anchor_name}",
"give me the {target_subtype}s in {anchor_name}",
"{anchor_name} {target_subtype}s",
"which {target_subtype}s does {anchor_name} contain?",
"what all {target_subtype}s are there in {anchor_name}?",
"{target_subtype}s under {anchor_name}",
"what districts are in {anchor_name}?",
"which districts fall within {anchor_name}?",
"districts of {anchor_name}",
"show all districts inside {anchor_name}",
"list municipalities in {anchor_name}",
"boroughs of {anchor_name}",
"communes inside {anchor_name}",
"parishes in {anchor_name}",
],
),
SQLTemplate(
template_id="contain_02",
family="containment",
sql_difficulty="medium",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="country",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.id != '{anchor_id}'"
" AND b.subtype = '{target_subtype}'"
" AND ST_Contains(b.geometry, a.geometry)"
),
question_hints=[
"what country contains {anchor_name}?",
"which country is {anchor_name} in?",
"what country does {anchor_name} belong to?",
"which nation contains {anchor_name}?",
"{anchor_name} is part of which country?",
"where is {anchor_name}",
"what country is {anchor_name} in",
"{anchor_name} belongs to which country?",
"show country for {anchor_name}",
"find the country of {anchor_name}",
"which country does {anchor_name} fall in?",
"{anchor_name} under which country",
"tell me the country for {anchor_name}",
"which nation does {anchor_name} belong to?",
"what nation is {anchor_name} in?",
],
),
SQLTemplate(
template_id="contain_03",
family="containment",
sql_difficulty="medium",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="region",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Within(b.geometry, a.geometry)"
),
question_hints=[
"what {target_subtype}s are in {anchor_name}?",
"list all {target_subtype}s in {anchor_name}",
"which {target_subtype}s does {anchor_name} have?",
"show {target_subtype}s of {anchor_name}",
"all {target_subtype}s within {anchor_name}",
"{anchor_name} {target_subtype}s",
"give me the {target_subtype}s of {anchor_name}",
"what states are in {anchor_name}?",
"list all states of {anchor_name}",
"which provinces does {anchor_name} have?",
"show the provinces of {anchor_name}",
"all states within {anchor_name}",
"provinces of {anchor_name}",
"what oblasts are in {anchor_name}?",
"departments of {anchor_name}",
"prefectures in {anchor_name}",
"cantons of {anchor_name}",
],
),
SQLTemplate(
template_id="contain_04",
family="containment",
sql_difficulty="medium",
anchor_source="natural_earth",
num_anchors=1,
target_subtype="region",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('natural_earth') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Within(b.geometry, a.geometry)"
),
question_hints=[
"which {target_subtype}s are in the {anchor_name}?",
"what {target_subtype}s fall within the {anchor_name}?",
"{target_subtype}s inside the {anchor_name}",
"admin {target_subtype}s within the {anchor_name}",
"all regions inside the {anchor_name}",
"what {target_subtype}s does the {anchor_name} contain?",
"{target_subtype}s covered by the {anchor_name}",
"which regions are in the {anchor_name} basin?",
"what admin regions lie within the {anchor_name}?",
"which provinces are inside the {anchor_name}?",
"show the regions in the {anchor_name}",
"find provinces inside the {anchor_name}",
"give me admin regions within the {anchor_name}",
"regions belonging to the {anchor_name}",
"areas contained in the {anchor_name}",
"which states are in the {anchor_name}?",
"states inside the {anchor_name}",
"which prefectures lie within the {anchor_name}?",
"oblasts in the {anchor_name}",
"departments inside the {anchor_name}",
],
),
# ββ NATURAL EARTH CONTAINMENT βββββββββββββββββββββββββββββββββββββββββββ
# contain_05: NE anchor (sea/gulf/bay), find countries that touch it.
# Uses containment handler via containment_pairs.
SQLTemplate(
template_id="contain_05",
family="containment",
sql_difficulty="medium",
anchor_source="natural_earth",
num_anchors=1,
target_subtype="country",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('natural_earth') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Intersects(b.geometry, a.geometry)"
),
question_hints=[
"which countries border the {anchor_name}?",
"what countries are along the {anchor_name}?",
"countries surrounding the {anchor_name}",
"nations on the {anchor_name}",
"which countries touch the {anchor_name}?",
"countries with coastline on the {anchor_name}",
"what nations lie on the {anchor_name}?",
"which countries are on the coast of the {anchor_name}?",
"what countries lie around the {anchor_name}?",
"which nations have shores on the {anchor_name}?",
"what countries front the {anchor_name}?",
],
),
# ββ INTERSECTION βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
SQLTemplate(
template_id="intersect_01",
family="intersection",
sql_difficulty="medium-hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="region",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.id != '{anchor_id}'"
" AND b.subtype = '{target_subtype}'"
" AND ST_Intersects(b.geometry, a.geometry)"
),
question_hints=[
"which {target_subtype}s intersect {anchor_name}?",
"what {target_subtype}s overlap with {anchor_name}?",
"{target_subtype}s that cross into {anchor_name}",
"which {target_subtype}s overlap {anchor_name}?",
"{target_subtype}s partially inside {anchor_name}",
"what {target_subtype}s extend into {anchor_name}?",
"show {target_subtype}s overlapping {anchor_name}",
"find {target_subtype}s crossing {anchor_name}",
"{target_subtype}s meeting {anchor_name}",
"areas intersecting {anchor_name}",
"{anchor_name} overlapping {target_subtype}s",
"which {target_subtype}s are partly in {anchor_name}?",
"which states intersect {anchor_name}?",
"which provinces overlap {anchor_name}?",
"states crossing into {anchor_name}",
"provinces partly inside {anchor_name}",
],
),
SQLTemplate(
template_id="intersect_02",
family="intersection",
sql_difficulty="medium-hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="county",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.id != '{anchor_id}'"
" AND b.subtype = '{target_subtype}'"
" AND ST_Intersects(b.geometry, a.geometry)"
),
question_hints=[
"which {target_subtype}s intersect {anchor_name}?",
"what {target_subtype}s overlap with {anchor_name}?",
"{target_subtype}s crossing into {anchor_name}",
"which {target_subtype}s are partly in {anchor_name}?",
"show {target_subtype}s overlapping {anchor_name}",
"find {target_subtype}s crossing {anchor_name}",
"{target_subtype}s that overlap {anchor_name}",
"which districts intersect {anchor_name}?",
"what districts overlap with {anchor_name}?",
"districts crossing into {anchor_name}",
"which municipalities are partly in {anchor_name}?",
"boroughs overlapping {anchor_name}",
"communes crossing {anchor_name}",
],
),
SQLTemplate(
template_id="intersect_03",
family="intersection",
sql_difficulty="medium-hard",
anchor_source="natural_earth",
num_anchors=1,
target_subtype="country",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('natural_earth') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Intersects(b.geometry, a.geometry)"
),
question_hints=[
"which countries does the {anchor_name} pass through?",
"what countries does the {anchor_name} cross?",
"countries that overlap the {anchor_name}",
"which countries touch the {anchor_name}?",
"nations intersected by the {anchor_name}",
"which nations does the {anchor_name} cross?",
"countries along the {anchor_name}",
"what countries does the {anchor_name} cover?",
"countries the {anchor_name} spans across",
"what countries is the {anchor_name} in?",
"which countries lie along the {anchor_name}?",
"what countries does the {anchor_name} run through?",
"which countries border the {anchor_name}?",
],
),
# ββ NATURAL EARTH INTERSECTION ββββββββββββββββββββββββββββββββββββββββββ
# intersect_04: NE anchor, finding overlapping regions (vs countries in
# intersect_03). Uses cross_source_relations handler.
# intersect_05: division anchor, finding NE features that overlap it.
# Uses intersection_pairs handler (extra NE subtypes ignored in SQL).
SQLTemplate(
template_id="intersect_04",
family="intersection",
sql_difficulty="medium-hard",
anchor_source="natural_earth",
num_anchors=1,
target_subtype="region",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('natural_earth') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Intersects(b.geometry, a.geometry)"
),
question_hints=[
"which regions does the {anchor_name} pass through?",
"what admin regions overlap with the {anchor_name}?",
"regions that the {anchor_name} crosses",
"admin areas intersected by the {anchor_name}",
"what provinces does the {anchor_name} span?",
"regions along the {anchor_name}",
"which provinces overlap the {anchor_name}?",
"which regions is the {anchor_name} in?",
"what states does the {anchor_name} run through?",
"which provinces lie along the {anchor_name}?",
"show regions crossed by the {anchor_name}",
"find administrative regions along the {anchor_name}",
"give me the regions touched by the {anchor_name}",
"regions of the {anchor_name}",
"which states does the {anchor_name} pass through?",
"what oblasts does the {anchor_name} cross?",
"which departments does the {anchor_name} run through?",
"prefectures along the {anchor_name}",
],
),
SQLTemplate(
template_id="intersect_05",
family="intersection",
sql_difficulty="medium-hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="region",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT n.id, n.names.\"primary\" AS name, n.subtype,"
" ST_AsGeoJSON(n.geometry) AS geometry"
" FROM read_parquet('natural_earth') AS n, a"
" WHERE ST_Intersects(n.geometry, a.geometry)"
),
question_hints=[
"what natural features intersect {anchor_name}?",
"natural features that overlap {anchor_name}",
"which geographic features cross {anchor_name}?",
"everything natural that touches {anchor_name}",
"what geographic features does {anchor_name} contain?",
"natural features within or crossing {anchor_name}",
"show natural features overlapping {anchor_name}",
"find the natural features in or across {anchor_name}",
"{anchor_name} intersecting natural features",
"what physical features are associated with {anchor_name}?",
],
),
SQLTemplate(
template_id="intersect_06",
family="intersection",
sql_difficulty="medium-hard",
anchor_source="natural_earth",
num_anchors=1,
target_subtype="county",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('natural_earth') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Intersects(b.geometry, a.geometry)"
),
question_hints=[
"which districts does the {anchor_name} pass through?",
"what districts does the {anchor_name} cross?",
"districts intersected by the {anchor_name}",
"which counties does the {anchor_name} flow through?",
"what counties overlap the {anchor_name}?",
"districts along the {anchor_name}",
"which districts are crossed by the {anchor_name}?",
"what districts is the {anchor_name} in?",
"which counties lie along the {anchor_name}?",
"what districts does the {anchor_name} run through?",
"show districts crossed by the {anchor_name}",
"find counties along the {anchor_name}",
"give me the districts touched by the {anchor_name}",
"districts of the {anchor_name}",
"which municipalities does the {anchor_name} pass through?",
"boroughs along the {anchor_name}",
"communes crossed by the {anchor_name}",
"parishes the {anchor_name} runs through",
],
),
# ββ BUFFER βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# CTE computes the buffered geometry (raw) for the spatial join.
# Final SELECT wraps the result features with ST_AsGeoJSON.
SQLTemplate(
template_id="buffer_01",
family="buffer",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
requires_buffer=True,
sql_template=(
"WITH a AS ("
" SELECT ST_Buffer(geometry, {buffer_m} / 111320.0) AS geom"
" FROM read_parquet('divisions_area')"
" WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.id != '{anchor_id}'"
" AND ST_Intersects(b.geometry, a.geom)"
),
question_hints=[
"what's within {buffer_label} of {anchor_name}?",
"admin units within {buffer_label} of {anchor_name}",
"features within a {buffer_label} radius of {anchor_name}",
"places within {buffer_label} of {anchor_name}",
"{buffer_label} buffer around {anchor_name}",
"what falls within {buffer_label} of {anchor_name}?",
"everything within {buffer_label} of {anchor_name}",
],
),
SQLTemplate(
template_id="buffer_02",
family="buffer",
sql_difficulty="hard",
anchor_source="natural_earth",
num_anchors=1,
requires_buffer=True,
sql_template=(
"WITH a AS ("
" SELECT ST_Buffer(geometry, {buffer_m} / 111320.0) AS geom"
" FROM read_parquet('natural_earth')"
" WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE ST_Intersects(b.geometry, a.geom)"
),
question_hints=[
"what admin units are within {buffer_label} of the {anchor_name}?",
"countries within {buffer_label} of the {anchor_name}",
"regions within {buffer_label} of the {anchor_name}",
"what falls within {buffer_label} of the {anchor_name}?",
"admin divisions within a {buffer_label} radius of the {anchor_name}",
"places within {buffer_label} of the {anchor_name}",
"what places are near the {anchor_name}?",
"what admin areas are close to the {anchor_name}?",
"which regions are around the {anchor_name}?",
"what lies within {buffer_label} of the shoreline of the {anchor_name}?",
"show places around the {anchor_name}",
"find areas near the {anchor_name}",
"admin units close to the {anchor_name}",
"what is around the {anchor_name} within {buffer_label}",
"give me nearby admin regions for the {anchor_name}",
],
),
SQLTemplate(
template_id="buffer_03",
family="buffer",
sql_difficulty="medium",
anchor_source="divisions_area",
num_anchors=1,
requires_buffer=True,
sql_template=(
"SELECT ST_AsGeoJSON(ST_Buffer(geometry, {buffer_m} / 111320.0)) AS geometry"
" FROM read_parquet('divisions_area')"
" WHERE id = '{anchor_id}'"
),
question_hints=[
"{buffer_label} buffer around {anchor_name}",
"draw a {buffer_label} buffer around {anchor_name}",
"show the {buffer_label} buffer around {anchor_name}",
"create a {buffer_label} radius around {anchor_name}",
"map a {buffer_label} zone around {anchor_name}",
"outline the {buffer_label} buffer around {anchor_name}",
"buffer {anchor_name} by {buffer_label}",
"show radius {buffer_label} from {anchor_name}",
"{anchor_name} with a {buffer_label} buffer",
],
),
# Subtype-specific and multi-anchor buffer templates are generated by helper
# functions to keep the catalog compact while preserving template IDs.
*_make_buffer_templates(),
# ββ NATURAL EARTH BUFFER ββββββββββββββββββββββββββββββββββββββββββββββββ
# buffer_11: NE anchor, find other NE features within a buffer distance.
# Uses buffer handler for natural_earth.
SQLTemplate(
template_id="buffer_11",
family="buffer",
sql_difficulty="hard",
anchor_source="natural_earth",
num_anchors=1,
requires_buffer=True,
sql_template=(
"WITH a AS ("
" SELECT ST_Buffer(geometry, {buffer_m} / 111320.0) AS geom"
" FROM read_parquet('natural_earth')"
" WHERE id = '{anchor_id}'"
")"
" SELECT n.id, n.names.\"primary\" AS name, n.subtype,"
" ST_AsGeoJSON(n.geometry) AS geometry"
" FROM read_parquet('natural_earth') AS n, a"
" WHERE ST_Intersects(n.geometry, a.geom)"
),
question_hints=[
"natural features within {buffer_label} of the {anchor_name}",
"what's within {buffer_label} of the {anchor_name}?",
"geographic features near the {anchor_name} within {buffer_label}",
"everything within {buffer_label} of the {anchor_name}",
"what natural features are close to the {anchor_name}?",
"{buffer_label} radius around the {anchor_name}",
"what natural features are around the {anchor_name}?",
"what lies near the {anchor_name}?",
"which features are close to the {anchor_name}?",
"what natural features are near the shoreline of the {anchor_name}?",
"show nearby natural features for the {anchor_name}",
"find features around the {anchor_name}",
"give me natural features near the {anchor_name}",
"features around the {anchor_name}",
"what is close to the {anchor_name} within {buffer_label}",
],
),
# ββ CHAINED ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Containment + EXISTS/NOT EXISTS ocean/sea.
# CTE holds raw geometry for ST_Within; final SELECT wraps with ST_AsGeoJSON.
SQLTemplate(
template_id="chained_01",
family="chained",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="county",
sql_template=(
"WITH region AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, region"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Within(b.geometry, region.geometry)"
" AND EXISTS ("
" SELECT 1 FROM read_parquet('natural_earth') AS n"
" WHERE n.subtype IN ('ocean', 'sea')"
" AND ST_Intersects(b.geometry, n.geometry)"
" )"
),
question_hints=[
"coastal {target_subtype}s of {anchor_name}",
"{target_subtype}s in {anchor_name} with sea access",
"which {target_subtype}s in {anchor_name} are on the coast?",
"seaside {target_subtype}s within {anchor_name}",
"{target_subtype}s in {anchor_name} bordering the sea",
"oceanfront {target_subtype}s in {anchor_name}",
"which {target_subtype}s in {anchor_name} have a coastline?",
"show coastal {target_subtype}s in {anchor_name}",
"find {target_subtype}s of {anchor_name} on the shore",
"{target_subtype}s of {anchor_name} by the sea",
"which {target_subtype}s of {anchor_name} touch the ocean?",
"coastline {target_subtype}s in {anchor_name}",
"coastal districts of {anchor_name}",
"which districts of {anchor_name} are on the coast?",
"seaside municipalities of {anchor_name}",
"coastal boroughs in {anchor_name}",
],
),
SQLTemplate(
template_id="chained_02",
family="chained",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="county",
sql_template=(
"WITH region AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, region"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Intersects(b.geometry, region.geometry)"
" AND NOT EXISTS ("
" SELECT 1 FROM read_parquet('natural_earth') AS n"
" WHERE n.subtype IN ('ocean', 'sea')"
" AND ST_Intersects(b.geometry, n.geometry)"
" )"
),
question_hints=[
"landlocked {target_subtype}s in {anchor_name}",
"which {target_subtype}s in {anchor_name} have no sea access?",
"{target_subtype}s in {anchor_name} that are landlocked",
"{target_subtype}s in {anchor_name} with no coastline",
"which {target_subtype}s within {anchor_name} are landlocked?",
"interior {target_subtype}s of {anchor_name} with no ocean border",
"show inland {target_subtype}s in {anchor_name}",
"find non-coastal {target_subtype}s of {anchor_name}",
"{target_subtype}s of {anchor_name} away from the sea",
"which {target_subtype}s in {anchor_name} are not coastal?",
"inner {target_subtype}s of {anchor_name}",
"inland districts of {anchor_name}",
"which districts in {anchor_name} are not on the coast?",
"non-coastal municipalities of {anchor_name}",
"interior boroughs of {anchor_name}",
],
),
SQLTemplate(
template_id="chained_03",
family="chained",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="region",
sql_template=(
"WITH country AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, country"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Within(b.geometry, country.geometry)"
" AND EXISTS ("
" SELECT 1 FROM read_parquet('natural_earth') AS n"
" WHERE n.subtype IN ('range/mtn', 'island group', 'peninsula', 'depression')"
" AND ST_Intersects(b.geometry, n.geometry)"
" )"
),
question_hints=[
"{target_subtype}s in {anchor_name} on a terrain feature or island",
"{target_subtype}s of {anchor_name} on a peninsula or island group",
"{target_subtype}s within {anchor_name} on notable landforms",
"island and peninsula {target_subtype}s of {anchor_name}",
"show {target_subtype}s in {anchor_name} on major landforms",
"find {target_subtype}s of {anchor_name} on islands or peninsulas",
"{target_subtype}s in {anchor_name} on terrain regions",
"states of {anchor_name} on a peninsula or island",
"island states of {anchor_name}",
"provinces of {anchor_name} on major landforms",
"which regions of {anchor_name} are on a peninsula?",
],
),
# ββ DIFFERENCE βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# CTEs hold raw geometry; ST_Difference result wrapped with ST_AsGeoJSON.
SQLTemplate(
template_id="diff_01",
family="difference",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=2,
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id_1}'"
"),"
" b AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id_2}'"
")"
" SELECT ST_AsGeoJSON(ST_Difference(a.geometry, b.geometry)) AS geometry"
" FROM a, b"
" WHERE ST_Intersects(a.geometry, b.geometry)"
),
question_hints=[
"{anchor_1_name} excluding {anchor_2_name}",
"{anchor_1_name} minus {anchor_2_name}",
"the part of {anchor_1_name} that is not in {anchor_2_name}",
"{anchor_1_name} without the {anchor_2_name} area",
"remove {anchor_2_name} from {anchor_1_name}",
"{anchor_1_name} with {anchor_2_name} cut out",
"subtract {anchor_2_name} from {anchor_1_name}",
"what's left of {anchor_1_name} after removing {anchor_2_name}?",
"difference between {anchor_1_name} and {anchor_2_name}",
"keep only {anchor_1_name} outside {anchor_2_name}",
"cut {anchor_2_name} out of {anchor_1_name}",
"show {anchor_1_name} without {anchor_2_name}",
],
),
SQLTemplate(
template_id="diff_02",
family="difference",
sql_difficulty="hard",
anchor_source="mixed",
num_anchors=2,
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
"),"
" b AS ("
" SELECT geometry FROM read_parquet('natural_earth') WHERE id = '{clip_feature_id}'"
")"
" SELECT ST_AsGeoJSON(ST_Difference(a.geometry, b.geometry)) AS geometry"
" FROM a, b"
" WHERE ST_Intersects(a.geometry, b.geometry)"
),
question_hints=[
"the part of {anchor_name} outside the {clip_feature_name}",
"{anchor_name} excluding the {clip_feature_name}",
"{anchor_name} minus the {clip_feature_name}",
"parts of {anchor_name} not covered by the {clip_feature_name}",
"{anchor_name} with the {clip_feature_name} removed",
"what's left of {anchor_name} after removing the {clip_feature_name}?",
"show me {anchor_name} excluding the {clip_feature_name}",
"keep only the part of {anchor_name} outside the {clip_feature_name}",
"cut the {clip_feature_name} out of {anchor_name}",
"difference of {anchor_name} and the {clip_feature_name}",
"{anchor_name} after subtracting the {clip_feature_name}",
],
),
# ββ BORDER CORRIDOR ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Intermediate intersection kept raw; final buffer wrapped with ST_AsGeoJSON.
SQLTemplate(
template_id="corridor_01",
family="border_corridor",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=2,
requires_buffer=True,
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id_1}'"
"),"
" b AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id_2}'"
"),"
" border AS ("
" SELECT ST_Intersection(a.geometry, b.geometry) AS line"
" FROM a, b"
" WHERE ST_Intersects(a.geometry, b.geometry)"
")"
" SELECT ST_AsGeoJSON(ST_Buffer(border.line, {buffer_km} * 1000.0 / 111320.0)) AS geometry"
" FROM border"
" WHERE border.line IS NOT NULL"
),
question_hints=[
"{buffer_km} km zone along the border between {anchor_1_name} and {anchor_2_name}",
"the {buffer_km} km border corridor between {anchor_1_name} and {anchor_2_name}",
"area within {buffer_km} km of the {anchor_1_name}-{anchor_2_name} border",
"the region straddling the border of {anchor_1_name} and {anchor_2_name} within {buffer_km} km",
"{buffer_km} km on either side of the {anchor_1_name} and {anchor_2_name} border",
"buffer the {anchor_1_name}-{anchor_2_name} boundary by {buffer_km} km",
"show the border zone between {anchor_1_name} and {anchor_2_name}",
"map the corridor along the {anchor_1_name}-{anchor_2_name} border",
"find the area near the border of {anchor_1_name} and {anchor_2_name}",
"give me the border buffer for {anchor_1_name} and {anchor_2_name}",
"border area of {anchor_1_name} and {anchor_2_name} within {buffer_km} km",
],
),
# ββ SET OPERATIONS βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# union_01 / union_02: 2-anchor and filtered-containment unions.
# union_03: 3-anchor union β trains the model on IN-clause with 3 IDs.
# contain_multi: subtype within multiple countries via country IN clause.
SQLTemplate(
template_id="union_01",
family="set_operations",
sql_difficulty="medium-hard",
anchor_source="divisions_area",
num_anchors=2,
sql_template=(
"SELECT ST_AsGeoJSON(ST_Union_Agg(geometry)) AS geometry,"
" array_agg(names.\"primary\") AS names"
" FROM read_parquet('divisions_area')"
" WHERE id IN ('{anchor_id_1}', '{anchor_id_2}')"
),
question_hints=[
"the combined area of {anchor_1_name} and {anchor_2_name}",
"union of {anchor_1_name} and {anchor_2_name}",
"merge {anchor_1_name} and {anchor_2_name}",
"{anchor_1_name} and {anchor_2_name} together",
"combined geometry of {anchor_1_name} and {anchor_2_name}",
],
),
SQLTemplate(
template_id="union_02",
family="set_operations",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="county",
requires_aggregation=True,
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT ST_AsGeoJSON(ST_Union_Agg(b.geometry)) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Within(b.geometry, a.geometry)"
),
question_hints=[
"merge all {target_subtype}s in {anchor_name} into one geometry",
"combined geometry of all {target_subtype}s in {anchor_name}",
"union of all {target_subtype}s within {anchor_name}",
"all {target_subtype}s of {anchor_name} merged together",
"the overall extent of {target_subtype}s in {anchor_name}",
"show one merged shape for all {target_subtype}s in {anchor_name}",
"dissolve all {target_subtype}s in {anchor_name}",
"make one geometry from all {target_subtype}s in {anchor_name}",
"single outline of all {target_subtype}s in {anchor_name}",
"combine the {target_subtype}s of {anchor_name} into one area",
"merge all districts in {anchor_name} into one shape",
"dissolve all municipalities in {anchor_name}",
"combine all boroughs of {anchor_name} into one geometry",
],
),
SQLTemplate(
template_id="union_03",
family="set_operations",
sql_difficulty="medium-hard",
anchor_source="divisions_area",
num_anchors=3,
sql_template=(
"SELECT ST_AsGeoJSON(ST_Union_Agg(geometry)) AS geometry,"
" array_agg(names.\"primary\") AS names"
" FROM read_parquet('divisions_area')"
" WHERE id IN ('{anchor_id_1}', '{anchor_id_2}', '{anchor_id_3}')"
),
question_hints=[
"show me {anchor_1_name}, {anchor_2_name} and {anchor_3_name}",
"the combined area of {anchor_1_name}, {anchor_2_name} and {anchor_3_name}",
"union of {anchor_1_name}, {anchor_2_name} and {anchor_3_name}",
"merge {anchor_1_name}, {anchor_2_name} and {anchor_3_name}",
"{anchor_1_name}, {anchor_2_name} and {anchor_3_name} together",
"display {anchor_1_name}, {anchor_2_name} and {anchor_3_name}",
],
),
*_make_country_in_templates(),
# ββ PARTIAL SELECTION ββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Bbox clip CTEs use raw geometry; ST_Intersection result wrapped.
SQLTemplate(
template_id="partial_01",
family="partial_selection",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
"),"
" bbox AS ("
" SELECT ST_XMin(geometry) AS xmin, ST_XMax(geometry) AS xmax,"
" ST_YMin(geometry) AS ymin, ST_YMax(geometry) AS ymax FROM a"
"),"
" clip AS ("
" SELECT ST_MakeEnvelope(xmin, (ymin + ymax) / 2.0, xmax, ymax) AS half_geom FROM bbox"
")"
" SELECT ST_AsGeoJSON(ST_Intersection(a.geometry, clip.half_geom)) AS geometry"
" FROM a, clip"
),
question_hints=[
"the northern half of {anchor_name}",
"northern part of {anchor_name}",
"the top half of {anchor_name}",
"northern portion of {anchor_name}",
"upper half of {anchor_name}",
"top side of {anchor_name}",
"show north half of {anchor_name}",
"cut {anchor_name} to the north half",
"only the northern side of {anchor_name}",
"north part of {anchor_name}",
],
),
SQLTemplate(
template_id="partial_02",
family="partial_selection",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
"),"
" bbox AS ("
" SELECT ST_XMin(geometry) AS xmin, ST_XMax(geometry) AS xmax,"
" ST_YMin(geometry) AS ymin, ST_YMax(geometry) AS ymax FROM a"
"),"
" clip AS ("
" SELECT ST_MakeEnvelope(xmin, ymin, xmax, (ymin + ymax) / 2.0) AS half_geom FROM bbox"
")"
" SELECT ST_AsGeoJSON(ST_Intersection(a.geometry, clip.half_geom)) AS geometry"
" FROM a, clip"
),
question_hints=[
"the southern half of {anchor_name}",
"southern part of {anchor_name}",
"the bottom half of {anchor_name}",
"southern portion of {anchor_name}",
"lower half of {anchor_name}",
"bottom side of {anchor_name}",
"show south half of {anchor_name}",
"cut {anchor_name} to the south half",
"only the southern side of {anchor_name}",
"south part of {anchor_name}",
],
),
SQLTemplate(
template_id="partial_03",
family="partial_selection",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
"),"
" bbox AS ("
" SELECT ST_XMin(geometry) AS xmin, ST_XMax(geometry) AS xmax,"
" ST_YMin(geometry) AS ymin, ST_YMax(geometry) AS ymax FROM a"
"),"
" clip AS ("
" SELECT ST_MakeEnvelope((xmin + xmax) / 2.0, ymin, xmax, ymax) AS half_geom FROM bbox"
")"
" SELECT ST_AsGeoJSON(ST_Intersection(a.geometry, clip.half_geom)) AS geometry"
" FROM a, clip"
),
question_hints=[
"the eastern half of {anchor_name}",
"eastern part of {anchor_name}",
"the right half of {anchor_name}",
"eastern portion of {anchor_name}",
"east side of {anchor_name}",
"show east half of {anchor_name}",
"cut {anchor_name} to the east half",
"only the eastern side of {anchor_name}",
"right side of {anchor_name}",
],
),
SQLTemplate(
template_id="partial_04",
family="partial_selection",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
"),"
" bbox AS ("
" SELECT ST_XMin(geometry) AS xmin, ST_XMax(geometry) AS xmax,"
" ST_YMin(geometry) AS ymin, ST_YMax(geometry) AS ymax FROM a"
"),"
" clip AS ("
" SELECT ST_MakeEnvelope(xmin, ymin, (xmin + xmax) / 2.0, ymax) AS half_geom FROM bbox"
")"
" SELECT ST_AsGeoJSON(ST_Intersection(a.geometry, clip.half_geom)) AS geometry"
" FROM a, clip"
),
question_hints=[
"the western half of {anchor_name}",
"western part of {anchor_name}",
"the left half of {anchor_name}",
"western portion of {anchor_name}",
"west side of {anchor_name}",
"show west half of {anchor_name}",
"cut {anchor_name} to the west half",
"only the western side of {anchor_name}",
"left side of {anchor_name}",
],
),
SQLTemplate(
template_id="partial_05",
family="partial_selection",
sql_difficulty="hard",
anchor_source="mixed",
num_anchors=2,
sql_template=(
"WITH a AS ("
" SELECT geometry AS g1 FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
"),"
" b AS ("
" SELECT geometry AS g2 FROM read_parquet('natural_earth') WHERE id = '{clip_feature_id}'"
")"
" SELECT ST_AsGeoJSON(ST_Intersection(a.g1, b.g2)) AS geometry"
" FROM a, b"
" WHERE ST_Intersects(a.g1, b.g2)"
),
question_hints=[
"the part of {anchor_name} that overlaps the {clip_feature_name}",
"{anchor_name} within the {clip_feature_name}",
"the portion of {anchor_name} inside the {clip_feature_name}",
"part of the {clip_feature_name} in {anchor_name}",
"part of {anchor_name} in the {clip_feature_name}",
"clip {anchor_name} to the {clip_feature_name}",
"{anchor_name} clipped to the {clip_feature_name}",
"{clip_feature_name} inside {anchor_name}",
"parts of {anchor_name} covered by the {clip_feature_name}",
"show me where {anchor_name} and the {clip_feature_name} overlap",
"keep only the part of {anchor_name} in the {clip_feature_name}",
"intersection of {anchor_name} and the {clip_feature_name}",
"give me the overlap between {anchor_name} and the {clip_feature_name}",
"only the shared area of {anchor_name} and the {clip_feature_name}",
],
),
# ββ AGGREGATION ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# ST_Area uses raw geometry in the ORDER BY; final SELECT wraps output.
SQLTemplate(
template_id="agg_01",
family="aggregation",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype=None, # filled at generation time: county or region
requires_aggregation=True,
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name,"
" ST_AsGeoJSON(b.geometry) AS geometry,"
" ST_Area(b.geometry) AS area"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE ST_Within(b.geometry, a.geometry)"
" AND b.subtype = '{target_subtype}'"
" ORDER BY area DESC"
" LIMIT {top_n}"
),
question_hints=[
"top {top_n} largest {target_subtype}s in {anchor_name}",
"biggest {top_n} {target_subtype}s in {anchor_name}",
"{top_n} largest {target_subtype}s inside {anchor_name}",
"the {top_n} biggest {target_subtype}s within {anchor_name}",
"largest {target_subtype} in {anchor_name}",
"which {target_subtype} in {anchor_name} has the most area?",
"show the biggest {target_subtype}s in {anchor_name}",
"list the largest {target_subtype}s for {anchor_name}",
"give me the biggest {target_subtype}s in {anchor_name}",
"{anchor_name} largest {target_subtype}s",
],
),
SQLTemplate(
template_id="agg_02",
family="aggregation",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype=None, # filled at generation time: county or region
requires_aggregation=True,
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name,"
" ST_AsGeoJSON(b.geometry) AS geometry,"
" ST_Area(b.geometry) AS area"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE ST_Within(b.geometry, a.geometry)"
" AND b.subtype = '{target_subtype}'"
" ORDER BY area ASC"
" LIMIT {top_n}"
),
question_hints=[
"top {top_n} smallest {target_subtype}s in {anchor_name}",
"smallest {top_n} {target_subtype}s in {anchor_name}",
"{top_n} smallest {target_subtype}s inside {anchor_name}",
"the {top_n} tiniest {target_subtype}s within {anchor_name}",
"smallest {target_subtype} in {anchor_name}",
"which {target_subtype} in {anchor_name} has the least area?",
"show the smallest {target_subtype}s in {anchor_name}",
"list the smallest {target_subtype}s for {anchor_name}",
"give me the tiniest {target_subtype}s in {anchor_name}",
"{anchor_name} smallest {target_subtype}s",
],
),
SQLTemplate(
template_id="agg_03",
family="aggregation",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype=None, # filled at generation time: county or region
requires_aggregation=True,
sql_template=(
"SELECT id, names.\"primary\" AS name,"
" ST_AsGeoJSON(geometry) AS geometry,"
" ST_Area(geometry) AS area"
" FROM read_parquet('divisions_area')"
" WHERE country = '{country}'"
" AND subtype = '{target_subtype}'"
" ORDER BY area DESC"
" LIMIT {top_n}"
),
question_hints=[
"top {top_n} largest {target_subtype}s in {anchor_name}",
"{top_n} biggest {target_subtype}s in {anchor_name}",
"largest {top_n} {target_subtype}s in {anchor_name}",
"the {top_n} largest {target_subtype}s in {anchor_name}",
"biggest {target_subtype} in {anchor_name}",
"which {target_subtype} in {anchor_name} is the largest?",
"show the largest {target_subtype}s in {anchor_name}",
"list the biggest {target_subtype}s in {anchor_name}",
"give me the largest {target_subtype}s for {anchor_name}",
"{anchor_name} biggest {target_subtype}s",
],
),
SQLTemplate(
template_id="agg_04",
family="aggregation",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype=None, # filled at generation time: county or region
requires_aggregation=True,
sql_template=(
"SELECT id, names.\"primary\" AS name,"
" ST_AsGeoJSON(geometry) AS geometry,"
" ST_Area(geometry) AS area"
" FROM read_parquet('divisions_area')"
" WHERE country = '{country}'"
" AND subtype = '{target_subtype}'"
" ORDER BY area ASC"
" LIMIT {top_n}"
),
question_hints=[
"top {top_n} smallest {target_subtype}s in {anchor_name}",
"{top_n} smallest {target_subtype}s in {anchor_name}",
"smallest {top_n} {target_subtype}s in {anchor_name}",
"the {top_n} smallest {target_subtype}s in {anchor_name}",
"smallest {target_subtype} in {anchor_name}",
"which {target_subtype} in {anchor_name} is the smallest?",
"show the smallest {target_subtype}s in {anchor_name}",
"list the smallest {target_subtype}s in {anchor_name}",
"give me the smallest {target_subtype}s for {anchor_name}",
"{anchor_name} tiniest {target_subtype}s",
],
),
# ββ WINDOW FUNCTION ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# CTE keeps raw geometry for ST_Area; final SELECT wraps with ST_AsGeoJSON.
SQLTemplate(
template_id="window_01",
family="window_function",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="county",
requires_aggregation=True,
sql_template=(
"WITH ranked AS ("
" SELECT id, names.\"primary\" AS name, subtype, country, region, geometry,"
" ST_Area(geometry) AS area,"
" ROW_NUMBER() OVER (PARTITION BY region ORDER BY ST_Area(geometry) DESC) AS rn"
" FROM read_parquet('divisions_area')"
" WHERE country = '{country}'"
" AND subtype = '{target_subtype}'"
")"
" SELECT id, name, subtype, country, region,"
" ST_AsGeoJSON(geometry) AS geometry, area"
" FROM ranked"
" WHERE rn = 1"
),
question_hints=[
"the largest {target_subtype} in each region of {anchor_name}",
"biggest {target_subtype} per region in {anchor_name}",
"largest {target_subtype} for every region of {anchor_name}",
"the biggest {target_subtype} in each province of {anchor_name}",
"show the largest {target_subtype} in every region of {anchor_name}",
"list biggest {target_subtype} by region in {anchor_name}",
"for each region in {anchor_name}, give the largest {target_subtype}",
"largest {target_subtype}s grouped by region in {anchor_name}",
"one biggest {target_subtype} for each region of {anchor_name}",
"the largest district in each state of {anchor_name}",
"biggest district per province in {anchor_name}",
"the largest municipality in each region of {anchor_name}",
"biggest borough per state in {anchor_name}",
],
),
SQLTemplate(
template_id="window_02",
family="window_function",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="county",
requires_aggregation=True,
sql_template=(
"WITH ranked AS ("
" SELECT id, names.\"primary\" AS name, subtype, country, region, geometry,"
" ST_Area(geometry) AS area,"
" ROW_NUMBER() OVER (PARTITION BY region ORDER BY ST_Area(geometry) ASC) AS rn"
" FROM read_parquet('divisions_area')"
" WHERE country = '{country}'"
" AND subtype = '{target_subtype}'"
")"
" SELECT id, name, subtype, country, region,"
" ST_AsGeoJSON(geometry) AS geometry, area"
" FROM ranked"
" WHERE rn = 1"
),
question_hints=[
"the smallest {target_subtype} in each region of {anchor_name}",
"smallest {target_subtype} per region in {anchor_name}",
"tiniest {target_subtype} for every region of {anchor_name}",
"the smallest {target_subtype} in each province of {anchor_name}",
"show the smallest {target_subtype} in every region of {anchor_name}",
"list smallest {target_subtype} by region in {anchor_name}",
"for each region in {anchor_name}, give the smallest {target_subtype}",
"smallest {target_subtype}s grouped by region in {anchor_name}",
"one tiniest {target_subtype} for each region of {anchor_name}",
"the smallest district in each state of {anchor_name}",
"smallest district per province in {anchor_name}",
"the smallest municipality in each region of {anchor_name}",
"tiniest borough per state in {anchor_name}",
],
),
SQLTemplate(
template_id="window_03",
family="window_function",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="region",
requires_aggregation=True,
sql_template=(
"WITH ranked AS ("
" SELECT id, names.\"primary\" AS name, subtype, country, geometry,"
" ST_Area(geometry) AS area,"
" ROW_NUMBER() OVER (PARTITION BY country ORDER BY ST_Area(geometry) DESC) AS rn"
" FROM read_parquet('divisions_area')"
" WHERE country = '{country}'"
" AND subtype = '{target_subtype}'"
")"
" SELECT id, name, subtype, country,"
" ST_AsGeoJSON(geometry) AS geometry, area"
" FROM ranked"
" WHERE rn = 1"
),
question_hints=[
"the largest {target_subtype} in {anchor_name}",
"which {target_subtype} of {anchor_name} has the most area?",
"biggest {target_subtype} in {anchor_name}",
"what is the largest {target_subtype} of {anchor_name}?",
"show the biggest {target_subtype} of {anchor_name}",
"the largest state in {anchor_name}",
"which state of {anchor_name} is the biggest?",
"the largest province in {anchor_name}",
"biggest state of {anchor_name}",
"what is the largest province of {anchor_name}?",
"the largest oblast in {anchor_name}",
"biggest department of {anchor_name}",
"which prefecture of {anchor_name} has the most area?",
],
),
SQLTemplate(
template_id="window_04",
family="window_function",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="region",
requires_aggregation=True,
sql_template=(
"WITH ranked AS ("
" SELECT id, names.\"primary\" AS name, subtype, country, geometry,"
" ST_Area(geometry) AS area,"
" ROW_NUMBER() OVER (PARTITION BY country ORDER BY ST_Area(geometry) ASC) AS rn"
" FROM read_parquet('divisions_area')"
" WHERE country = '{country}'"
" AND subtype = '{target_subtype}'"
")"
" SELECT id, name, subtype, country,"
" ST_AsGeoJSON(geometry) AS geometry, area"
" FROM ranked"
" WHERE rn = 1"
),
question_hints=[
"the smallest {target_subtype} in {anchor_name}",
"which {target_subtype} of {anchor_name} has the least area?",
"tiniest {target_subtype} in {anchor_name}",
"what is the smallest {target_subtype} of {anchor_name}?",
"show the smallest {target_subtype} of {anchor_name}",
"the smallest state in {anchor_name}",
"which state of {anchor_name} is the smallest?",
"the smallest province in {anchor_name}",
"tiniest state of {anchor_name}",
"what is the smallest province of {anchor_name}?",
"the smallest oblast in {anchor_name}",
"smallest department of {anchor_name}",
"which prefecture of {anchor_name} has the least area?",
],
),
# ββ ATTRIBUTE FILTER βββββββββββββββββββββββββββββββββββββββββββββββββββββ
# No spatial op β pure WHERE on is_land / is_territorial / country.
SQLTemplate(
template_id="attr_01",
family="attribute_filter",
sql_difficulty="medium",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="county",
sql_template=(
"SELECT id, names.\"primary\" AS name, subtype, country,"
" ST_AsGeoJSON(geometry) AS geometry"
" FROM read_parquet('divisions_area')"
" WHERE country = '{country}'"
" AND is_land = TRUE"
" AND subtype = '{target_subtype}'"
),
question_hints=[
"land {target_subtype}s of {anchor_name}",
"which {target_subtype}s of {anchor_name} are on land?",
"{anchor_name}'s land-based {target_subtype}s",
"show the land {target_subtype}s of {anchor_name}",
"find land {target_subtype}s of {anchor_name}",
"give me land-based {target_subtype}s in {anchor_name}",
"which {target_subtype}s of {anchor_name} are land-based?",
"non-island {target_subtype}s of {anchor_name}",
"land districts of {anchor_name}",
"which districts of {anchor_name} are on land?",
"land-based municipalities of {anchor_name}",
"mainland boroughs of {anchor_name}",
],
),
SQLTemplate(
template_id="attr_02",
family="attribute_filter",
sql_difficulty="medium",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="region",
sql_template=(
"SELECT id, names.\"primary\" AS name, subtype, country,"
" ST_AsGeoJSON(geometry) AS geometry"
" FROM read_parquet('divisions_area')"
" WHERE country = '{country}'"
" AND is_territorial = TRUE"
" AND subtype = '{target_subtype}'"
),
question_hints=[
"territorial {target_subtype}s of {anchor_name}",
"official territorial divisions of {anchor_name}",
"recognised territorial {target_subtype}s belonging to {anchor_name}",
"which territorial regions does {anchor_name} have?",
"show territorial {target_subtype}s of {anchor_name}",
"find official territorial regions of {anchor_name}",
"give me recognised territorial {target_subtype}s of {anchor_name}",
"territorial regions under {anchor_name}",
"{anchor_name} official territorial {target_subtype}s",
"official states of {anchor_name}",
"recognised provinces of {anchor_name}",
"territorial provinces of {anchor_name}",
"official oblasts of {anchor_name}",
"recognised departments of {anchor_name}",
],
),
SQLTemplate(
template_id="attr_03",
family="attribute_filter",
sql_difficulty="medium",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="region",
sql_template=(
"SELECT id, names.\"primary\" AS name, subtype, country,"
" ST_AsGeoJSON(geometry) AS geometry"
" FROM read_parquet('divisions_area')"
" WHERE country = '{country}'"
" AND subtype = '{target_subtype}'"
" AND is_land = FALSE"
),
question_hints=[
"offshore {target_subtype}s of {anchor_name}",
"{target_subtype}s of {anchor_name} that are not on land",
"water-associated {target_subtype}s of {anchor_name}",
"marine or offshore {target_subtype}s of {anchor_name}",
"show offshore {target_subtype}s of {anchor_name}",
"find {target_subtype}s of {anchor_name} in water",
"give me non-land {target_subtype}s of {anchor_name}",
"water-side {target_subtype}s of {anchor_name}",
"{anchor_name} {target_subtype}s not on land",
"offshore states of {anchor_name}",
"island provinces of {anchor_name}",
"non-land regions of {anchor_name}",
],
),
SQLTemplate(
template_id="attr_04",
family="attribute_filter",
sql_difficulty="medium",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="country",
sql_template=(
"SELECT id, names.\"primary\" AS name, subtype, country,"
" ST_AsGeoJSON(geometry) AS geometry"
" FROM read_parquet('divisions_area')"
" WHERE country = '{country}'"
" AND subtype = '{target_subtype}'"
" AND is_territorial = TRUE"
),
question_hints=[
"show the recognised boundary of {anchor_name}",
"find the official territorial extent of {anchor_name}",
"get the internationally recognised boundary of {anchor_name}",
"map the sovereign boundary of {anchor_name}",
"show the official country geometry for {anchor_name}",
"display the territorial country entry for {anchor_name}",
"give me the recognised country outline of {anchor_name}",
"official boundary of {anchor_name}",
],
),
# ββ NATURAL EARTH CHAINED βββββββββββββββββββββββββββββββββββββββββββββββ
# chained_04: localities in a region that intersect a river or lake.
# chained_05: localities in a region that lie on a mountain range.
SQLTemplate(
template_id="chained_04",
family="chained",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="region",
sql_template=(
"WITH region AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, region"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Within(b.geometry, region.geometry)"
" AND EXISTS ("
" SELECT 1 FROM read_parquet('natural_earth') AS n"
" WHERE n.subtype IN ('river', 'lake', 'basin')"
" AND ST_Intersects(b.geometry, n.geometry)"
" )"
),
question_hints=[
"riverside {target_subtype}s in {anchor_name}",
"{target_subtype}s in {anchor_name} near a river or lake",
"which {target_subtype}s in {anchor_name} are on a waterway?",
"lakeside or riverside {target_subtype}s within {anchor_name}",
"{target_subtype}s in {anchor_name} that touch a river",
"which {target_subtype}s in {anchor_name} are on a lake?",
"waterfront {target_subtype}s of {anchor_name}",
"show water-side {target_subtype}s in {anchor_name}",
"find {target_subtype}s of {anchor_name} by rivers or lakes",
"{target_subtype}s of {anchor_name} on the water",
"riverside states of {anchor_name}",
"states of {anchor_name} near a river or lake",
"provinces of {anchor_name} along a waterway",
"which regions of {anchor_name} have a major river?",
],
),
SQLTemplate(
template_id="chained_05",
family="chained",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="region",
sql_template=(
"WITH region AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, region"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Within(b.geometry, region.geometry)"
" AND EXISTS ("
" SELECT 1 FROM read_parquet('natural_earth') AS n"
" WHERE n.subtype IN ('range/mtn', 'depression')"
" AND ST_Intersects(b.geometry, n.geometry)"
" )"
),
question_hints=[
"mountain {target_subtype}s in {anchor_name}",
"{target_subtype}s in {anchor_name} on a mountain range",
"which {target_subtype}s in {anchor_name} are in the mountains?",
"highland {target_subtype}s within {anchor_name}",
"{target_subtype}s of {anchor_name} in mountainous terrain",
"{target_subtype}s in {anchor_name} near a mountain range",
"show mountain {target_subtype}s in {anchor_name}",
"find {target_subtype}s of {anchor_name} in hilly terrain",
"{target_subtype}s of {anchor_name} by the mountains",
"mountain states of {anchor_name}",
"states of {anchor_name} in mountainous terrain",
"highland provinces of {anchor_name}",
"which regions of {anchor_name} have a mountain range?",
],
),
# ββ CHAINED (county-level) ββββββββββββββββββββββββββββββββββββββββββββββ
# Same spatial patterns as chained_01..05 but targeting counties/districts
# so the model learns "coastal districts of X", "riverside counties", etc.
SQLTemplate(
template_id="chained_06",
family="chained",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="county",
sql_template=(
"WITH region AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, region"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Within(b.geometry, region.geometry)"
" AND EXISTS ("
" SELECT 1 FROM read_parquet('natural_earth') AS n"
" WHERE n.subtype IN ('ocean', 'sea')"
" AND ST_Intersects(b.geometry, n.geometry)"
" )"
),
question_hints=[
"coastal {target_subtype}s of {anchor_name}",
"which districts of {anchor_name} are on the coast?",
"{target_subtype}s in {anchor_name} that border the sea",
"seaside {target_subtype}s within {anchor_name}",
"{target_subtype}s of {anchor_name} with ocean access",
"which {target_subtype}s in {anchor_name} touch the sea?",
"maritime {target_subtype}s of {anchor_name}",
"show coastal districts of {anchor_name}",
"find {target_subtype}s of {anchor_name} by the sea",
"give me shoreline {target_subtype}s in {anchor_name}",
"{target_subtype}s of {anchor_name} on the coast",
],
),
SQLTemplate(
template_id="chained_07",
family="chained",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="county",
sql_template=(
"WITH region AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, region"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Within(b.geometry, region.geometry)"
" AND NOT EXISTS ("
" SELECT 1 FROM read_parquet('natural_earth') AS n"
" WHERE n.subtype IN ('ocean', 'sea')"
" AND ST_Intersects(b.geometry, n.geometry)"
" )"
),
question_hints=[
"landlocked {target_subtype}s of {anchor_name}",
"which districts of {anchor_name} have no coastline?",
"interior {target_subtype}s within {anchor_name}",
"{target_subtype}s in {anchor_name} with no sea access",
"non-coastal {target_subtype}s of {anchor_name}",
"inland {target_subtype}s of {anchor_name}",
"show inland districts of {anchor_name}",
"find non-coastal {target_subtype}s in {anchor_name}",
"give me inner {target_subtype}s of {anchor_name}",
"{target_subtype}s of {anchor_name} away from the coast",
],
),
SQLTemplate(
template_id="chained_08",
family="chained",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="county",
sql_template=(
"WITH region AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, region"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Within(b.geometry, region.geometry)"
" AND EXISTS ("
" SELECT 1 FROM read_parquet('natural_earth') AS n"
" WHERE n.subtype IN ('river', 'lake', 'basin')"
" AND ST_Intersects(b.geometry, n.geometry)"
" )"
),
question_hints=[
"riverside {target_subtype}s of {anchor_name}",
"which districts of {anchor_name} have a river or lake?",
"{target_subtype}s in {anchor_name} on a waterway",
"lakeside {target_subtype}s within {anchor_name}",
"{target_subtype}s of {anchor_name} along a river",
"which {target_subtype}s in {anchor_name} border a lake?",
"show water-side {target_subtype}s of {anchor_name}",
"find {target_subtype}s in {anchor_name} near rivers and lakes",
"give me riverside districts of {anchor_name}",
"{target_subtype}s of {anchor_name} by the water",
],
),
SQLTemplate(
template_id="chained_09",
family="chained",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="county",
sql_template=(
"WITH region AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, region"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Within(b.geometry, region.geometry)"
" AND EXISTS ("
" SELECT 1 FROM read_parquet('natural_earth') AS n"
" WHERE n.subtype IN ('range/mtn', 'depression')"
" AND ST_Intersects(b.geometry, n.geometry)"
" )"
),
question_hints=[
"mountain {target_subtype}s of {anchor_name}",
"which districts of {anchor_name} are in the mountains?",
"{target_subtype}s in {anchor_name} on a mountain range",
"highland {target_subtype}s within {anchor_name}",
"{target_subtype}s of {anchor_name} in mountainous terrain",
"which {target_subtype}s in {anchor_name} have mountain ranges?",
"show mountain districts of {anchor_name}",
"find {target_subtype}s of {anchor_name} in hilly areas",
"give me highland {target_subtype}s in {anchor_name}",
"{target_subtype}s of {anchor_name} by the mountains",
],
),
# chained_10 / chained_11: coastal and inland REGIONS of a country.
# Same pattern as chained_06/07 but with target_subtype='region' and
# container forced to a country so phrasings like "coastal states of
# India" / "inland provinces of Kenya" work correctly.
SQLTemplate(
template_id="chained_10",
family="chained",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="region",
sql_template=(
"WITH country AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, country"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Within(b.geometry, country.geometry)"
" AND EXISTS ("
" SELECT 1 FROM read_parquet('natural_earth') AS n"
" WHERE n.subtype IN ('ocean', 'sea')"
" AND ST_Intersects(b.geometry, n.geometry)"
" )"
),
question_hints=[
"coastal states of {anchor_name}",
"coastal regions of {anchor_name}",
"coastal provinces of {anchor_name}",
"which states of {anchor_name} are on the coast?",
"regions of {anchor_name} with sea access",
"states of {anchor_name} that border the ocean",
"maritime states of {anchor_name}",
"seaside regions of {anchor_name}",
"which provinces of {anchor_name} touch the sea?",
"states of {anchor_name} along the coast",
"show coastal regions of {anchor_name}",
"find seaside states of {anchor_name}",
"give me provinces of {anchor_name} on the coast",
"{anchor_name} regions by the sea",
"which oblasts of {anchor_name} are on the coast?",
"coastal departments of {anchor_name}",
"coastal prefectures of {anchor_name}",
"which cantons of {anchor_name} have sea access?",
],
),
SQLTemplate(
template_id="chained_11",
family="chained",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="region",
sql_template=(
"WITH country AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, country"
" WHERE b.subtype = '{target_subtype}'"
" AND ST_Within(b.geometry, country.geometry)"
" AND NOT EXISTS ("
" SELECT 1 FROM read_parquet('natural_earth') AS n"
" WHERE n.subtype IN ('ocean', 'sea')"
" AND ST_Intersects(b.geometry, n.geometry)"
" )"
),
question_hints=[
"landlocked states of {anchor_name}",
"inland regions of {anchor_name}",
"non-coastal states of {anchor_name}",
"which states of {anchor_name} have no coast?",
"inland provinces of {anchor_name}",
"regions of {anchor_name} without sea access",
"interior states of {anchor_name}",
"states of {anchor_name} that don't border the ocean",
"show inland regions of {anchor_name}",
"find non-coastal states of {anchor_name}",
"give me inner provinces of {anchor_name}",
"{anchor_name} regions away from the sea",
"landlocked oblasts of {anchor_name}",
"inland departments of {anchor_name}",
"interior prefectures of {anchor_name}",
"inland cantons of {anchor_name}",
],
),
# chained_12 / chained_13: coastal and landlocked COUNTRIES adjacent to anchor.
# Anchor is any country; finds its neighbours that are coastal / landlocked.
SQLTemplate(
template_id="chained_12",
family="chained",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="country",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.subtype = 'country'"
" AND b.id != '{anchor_id}'"
" AND ST_Touches(a.geometry, b.geometry)"
" AND EXISTS ("
" SELECT 1 FROM read_parquet('natural_earth') AS n"
" WHERE n.subtype IN ('ocean', 'sea')"
" AND ST_Intersects(b.geometry, n.geometry)"
" )"
),
question_hints=[
"which countries bordering {anchor_name} are coastal?",
"coastal countries adjacent to {anchor_name}",
"which neighboring countries of {anchor_name} have sea access?",
"countries that touch {anchor_name} and border the ocean",
"which nations next to {anchor_name} are on the coast?",
"find coastal nations bordering {anchor_name}",
"countries neighboring {anchor_name} with a coastline",
"which countries near {anchor_name} touch the sea?",
],
),
SQLTemplate(
template_id="chained_13",
family="chained",
sql_difficulty="hard",
anchor_source="divisions_area",
num_anchors=1,
target_subtype="country",
sql_template=(
"WITH a AS ("
" SELECT geometry FROM read_parquet('divisions_area') WHERE id = '{anchor_id}'"
")"
" SELECT b.id, b.names.\"primary\" AS name, b.subtype, b.country,"
" ST_AsGeoJSON(b.geometry) AS geometry"
" FROM read_parquet('divisions_area') AS b, a"
" WHERE b.subtype = 'country'"
" AND b.id != '{anchor_id}'"
" AND ST_Touches(a.geometry, b.geometry)"
" AND NOT EXISTS ("
" SELECT 1 FROM read_parquet('natural_earth') AS n"
" WHERE n.subtype IN ('ocean', 'sea')"
" AND ST_Intersects(b.geometry, n.geometry)"
" )"
),
question_hints=[
"which countries bordering {anchor_name} are landlocked?",
"landlocked countries adjacent to {anchor_name}",
"which neighboring countries of {anchor_name} have no sea access?",
"countries that touch {anchor_name} and are landlocked",
"which nations next to {anchor_name} have no coastline?",
"find landlocked nations bordering {anchor_name}",
"countries neighboring {anchor_name} with no ocean access",
"which countries near {anchor_name} are inland?",
],
),
]
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
def get_templates_by_family(family: str) -> List[SQLTemplate]:
"""Return all templates for a specific task family."""
return [t for t in TEMPLATES if t.family == family]
def get_template_by_id(template_id: str) -> SQLTemplate:
"""Return a template by its ID, raising ValueError if not found."""
for t in TEMPLATES:
if t.template_id == template_id:
return t
raise ValueError(f"Template '{template_id}' not found")
if __name__ == "__main__":
families: dict = {}
for t in TEMPLATES:
families[t.family] = families.get(t.family, 0) + 1
print("SQL Template Catalog")
print("=" * 60)
for family, count in sorted(families.items()):
print(f"{family:20s}: {count:2d} templates")
print(f"{'TOTAL':20s}: {len(TEMPLATES):2d} templates")
# Verify every template's final SELECT wraps geometry with ST_AsGeoJSON
print()
print("Geometry output check (all should show ST_AsGeoJSON)")
print("=" * 60)
for t in TEMPLATES:
has_geojson = "ST_AsGeoJSON" in t.sql_template
status = "OK" if has_geojson else "MISSING"
print(f" {t.template_id:20s}: {status}")
|