File size: 233,957 Bytes
5a9e79d | 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 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 | diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/BoolWatermark.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/BoolWatermark.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/BoolWatermark.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+
+import java.util.Objects;
+
+/**
+ * The {@link BoolWatermark} represents a watermark with a boolean value and an associated
+ * identifier.
+ */
+@Experimental
+public class BoolWatermark implements Watermark {
+
+ private static final long serialVersionUID = 1L;
+
+ private final boolean value;
+
+ private final String identifier;
+
+ public BoolWatermark(boolean value, String identifier) {
+ this.value = value;
+ this.identifier = identifier;
+ }
+
+ public boolean getValue() {
+ return value;
+ }
+
+ @Override
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ BoolWatermark that = (BoolWatermark) o;
+ return value == that.value && Objects.equals(identifier, that.identifier);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(value, identifier);
+ }
+
+ @Override
+ public String toString() {
+ return "BoolWatermark{" + "value=" + value + ", identifier='" + identifier + '\'' + '}';
+ }
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/BoolWatermarkDeclaration.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/BoolWatermarkDeclaration.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/BoolWatermarkDeclaration.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+
+import java.util.Objects;
+
+/**
+ * The {@link BoolWatermarkDeclaration} class implements the {@link WatermarkDeclaration} interface
+ * and provides additional functionality specific to boolean-type watermarks. It includes methods
+ * for obtaining combination semantics and creating new bool watermarks.
+ */
+@Experimental
+public class BoolWatermarkDeclaration implements WatermarkDeclaration {
+
+ private final String identifier;
+
+ private final WatermarkCombinationPolicy combinationPolicy;
+
+ private final WatermarkHandlingStrategy defaultHandlingStrategy;
+
+ public BoolWatermarkDeclaration(
+ String identifier,
+ WatermarkCombinationPolicy combinationPolicy,
+ WatermarkHandlingStrategy defaultHandlingStrategy) {
+ this.identifier = identifier;
+ this.combinationPolicy = combinationPolicy;
+ this.defaultHandlingStrategy = defaultHandlingStrategy;
+ }
+
+ @Override
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ /** Creates a new {@link BoolWatermark} with the specified boolean value. */
+ public BoolWatermark newWatermark(boolean val) {
+ return new BoolWatermark(val, identifier);
+ }
+
+ public WatermarkCombinationPolicy getCombinationPolicy() {
+ return combinationPolicy;
+ }
+
+ public WatermarkHandlingStrategy getDefaultHandlingStrategy() {
+ return defaultHandlingStrategy;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ BoolWatermarkDeclaration that = (BoolWatermarkDeclaration) o;
+ return Objects.equals(identifier, that.identifier)
+ && Objects.equals(combinationPolicy, that.combinationPolicy)
+ && defaultHandlingStrategy == that.defaultHandlingStrategy;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(identifier, combinationPolicy, defaultHandlingStrategy);
+ }
+
+ @Override
+ public String toString() {
+ return "BoolWatermarkDeclaration{"
+ + "identifier='"
+ + identifier
+ + '\''
+ + ", combinationPolicy="
+ + combinationPolicy
+ + ", defaultHandlingStrategy="
+ + defaultHandlingStrategy
+ + '}';
+ }
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/LongWatermark.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/LongWatermark.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/LongWatermark.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+
+import java.util.Objects;
+
+/**
+ * The {@link LongWatermark} represents a watermark with a long value and an associated identifier.
+ */
+@Experimental
+public class LongWatermark implements Watermark {
+
+ private static final long serialVersionUID = 1L;
+
+ private final long value;
+
+ private final String identifier;
+
+ public LongWatermark(long value, String identifier) {
+ this.value = value;
+ this.identifier = identifier;
+ }
+
+ public long getValue() {
+ return value;
+ }
+
+ @Override
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ LongWatermark that = (LongWatermark) o;
+ return value == that.value && Objects.equals(identifier, that.identifier);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(value, identifier);
+ }
+
+ @Override
+ public String toString() {
+ return "LongWatermark{" + "value=" + value + ", identifier='" + identifier + '\'' + '}';
+ }
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/LongWatermarkDeclaration.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/LongWatermarkDeclaration.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/LongWatermarkDeclaration.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+
+import java.util.Objects;
+
+/**
+ * The {@link LongWatermarkDeclaration} class implements the {@link WatermarkDeclaration} interface
+ * and provides additional functionality specific to long-type watermarks. It includes methods for
+ * obtaining combination semantics and creating new long watermarks.
+ */
+@Experimental
+public class LongWatermarkDeclaration implements WatermarkDeclaration {
+
+ protected static final long serialVersionUID = 1L;
+
+ protected final String identifier;
+
+ protected final WatermarkCombinationPolicy combinationPolicy;
+
+ protected final WatermarkHandlingStrategy defaultHandlingStrategy;
+
+ public LongWatermarkDeclaration(
+ String identifier,
+ WatermarkCombinationPolicy combinationPolicy,
+ WatermarkHandlingStrategy defaultHandlingStrategy) {
+ this.identifier = identifier;
+ this.combinationPolicy = combinationPolicy;
+ this.defaultHandlingStrategy = defaultHandlingStrategy;
+ }
+
+ @Override
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ /** Creates a new {@link LongWatermark} with the specified long value. */
+ public LongWatermark newWatermark(long val) {
+ return new LongWatermark(val, identifier);
+ }
+
+ public WatermarkCombinationPolicy getCombinationPolicy() {
+ return combinationPolicy;
+ }
+
+ public WatermarkHandlingStrategy getDefaultHandlingStrategy() {
+ return defaultHandlingStrategy;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ LongWatermarkDeclaration that = (LongWatermarkDeclaration) o;
+ return Objects.equals(identifier, that.identifier)
+ && Objects.equals(combinationPolicy, that.combinationPolicy)
+ && defaultHandlingStrategy == that.defaultHandlingStrategy;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(identifier, combinationPolicy, defaultHandlingStrategy);
+ }
+
+ @Override
+ public String toString() {
+ return "LongWatermarkDeclaration{"
+ + "identifier='"
+ + identifier
+ + '\''
+ + ", combinationPolicy="
+ + combinationPolicy
+ + ", defaultHandlingStrategy="
+ + defaultHandlingStrategy
+ + '}';
+ }
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/Watermark.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/Watermark.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/Watermark.java
@@ -0,0 +1,34 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package org.apache.flink.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+
+import java.io.Serializable;
+
+/* * This interface represents a watermark. It will provide a unified triggering and
+ * combination mechanism for user-defined event-like things.
+ */
+@Experimental
+public interface Watermark extends Serializable {
+ /**
+ * Returns the unique identifier for this watermark.
+ *
+ * @return a {@code String} representing the unique identifier of the watermark
+ */
+ String getIdentifier();
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkCombinationFunction.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkCombinationFunction.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkCombinationFunction.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.functions.Function;
+
+/**
+ * The {@link WatermarkCombinationFunction} defines the watermark's comparison/combination semantics
+ * among multiple input channels.
+ */
+@Experimental
+public interface WatermarkCombinationFunction extends Function {
+ /**
+ * The {@link BoolWatermarkCombinationFunction} enum defines the combination semantics for
+ * boolean watermarks. It includes logical operations such as {@code OR} and {@code AND}.
+ */
+ @Experimental
+ enum BoolWatermarkCombinationFunction implements WatermarkCombinationFunction {
+ /** Logical OR combination for boolean watermarks. */
+ OR,
+
+ /** Logical AND combination for boolean watermarks. */
+ AND
+ }
+
+ /**
+ * The {@link NumericWatermarkCombinationFunction} enum defines the combination semantics for
+ * numeric watermarks. It includes operations such as {@code MIN} and {@code MAX}.
+ */
+ @Experimental
+ enum NumericWatermarkCombinationFunction implements WatermarkCombinationFunction {
+ /** Minimum value combination for numeric watermarks. */
+ MIN,
+
+ /** Maximum value combination for numeric watermarks. */
+ MAX
+ }
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkCombinationPolicy.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkCombinationPolicy.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkCombinationPolicy.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+/**
+ * The {@link WatermarkCombinationPolicy} defines when and how to the combine {@link Watermark}s.
+ *
+ * <p>The watermark combination process will first check the setting of {@link
+ * #combineWaitForAllChannels}. If it is set to true, the ProcessFunction must receive watermarks
+ * from all input channels before it can proceed with the combination.
+ *
+ * <p>The actual combination of watermarks will then be executed using the specified {@link
+ * #watermarkCombinationFunction}.
+ */
+@Experimental
+public class WatermarkCombinationPolicy implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private final WatermarkCombinationFunction watermarkCombinationFunction;
+
+ // Whether the combine process should be executed after the process function receives watermarks
+ // from both upstream channels.
+ private final boolean combineWaitForAllChannels;
+
+ public WatermarkCombinationPolicy(
+ WatermarkCombinationFunction watermarkCombinationFunction,
+ boolean combineWaitForAllChannels) {
+ this.watermarkCombinationFunction = watermarkCombinationFunction;
+ this.combineWaitForAllChannels = combineWaitForAllChannels;
+ }
+
+ public WatermarkCombinationFunction getWatermarkCombinationFunction() {
+ return watermarkCombinationFunction;
+ }
+
+ public boolean isCombineWaitForAllChannels() {
+ return combineWaitForAllChannels;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ WatermarkCombinationPolicy that = (WatermarkCombinationPolicy) o;
+ return combineWaitForAllChannels == that.combineWaitForAllChannels
+ && Objects.equals(watermarkCombinationFunction, that.watermarkCombinationFunction);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(watermarkCombinationFunction, combineWaitForAllChannels);
+ }
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkDeclaration.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkDeclaration.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkDeclaration.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+
+import java.io.Serializable;
+
+/** This class represents the watermark creation and handling policy defined by the user. */
+@Experimental
+public interface WatermarkDeclaration extends Serializable {
+ /**
+ * Returns the unique identifier for this watermark.
+ *
+ * @return a {@code String} representing the unique identifier of the watermark
+ */
+ String getIdentifier();
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkDeclarations.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkDeclarations.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkDeclarations.java
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.watermark.WatermarkCombinationFunction.BoolWatermarkCombinationFunction;
+import org.apache.flink.api.common.watermark.WatermarkCombinationFunction.NumericWatermarkCombinationFunction;
+
+/** The Utils class is used to create {@link WatermarkDeclaration}. */
+@Experimental
+public class WatermarkDeclarations {
+
+ public static WatermarkDeclarationBuilder newBuilder(String identifier) {
+ return new WatermarkDeclarationBuilder(identifier);
+ }
+
+ /** Builder class for {@link WatermarkDeclaration}s. */
+ @Experimental
+ public static class WatermarkDeclarationBuilder {
+
+ protected final String identifier;
+
+ WatermarkDeclarationBuilder(String identifier) {
+ this.identifier = identifier;
+ }
+
+ public LongWatermarkDeclarationBuilder typeLong() {
+ return new LongWatermarkDeclarationBuilder(identifier);
+ }
+
+ public BoolWatermarkDeclarationBuilder typeBool() {
+ return new BoolWatermarkDeclarationBuilder(identifier);
+ }
+
+ @Experimental
+ public static class LongWatermarkDeclarationBuilder {
+ private final String identifier;
+ private boolean combineWaitForAllChannels = false;
+ private WatermarkCombinationFunction combinationFunction =
+ NumericWatermarkCombinationFunction.MIN;
+ private WatermarkHandlingStrategy defaultHandlingStrategy =
+ WatermarkHandlingStrategy.FORWARD;
+
+ public LongWatermarkDeclarationBuilder(String identifier) {
+ this.identifier = identifier;
+ }
+
+ /** Combine and propagate the maximum watermark to downstream. */
+ public LongWatermarkDeclarationBuilder combineFunctionMax() {
+ this.combinationFunction = NumericWatermarkCombinationFunction.MAX;
+ return this;
+ }
+
+ /** Combine and propagate the minimum watermark to downstream. */
+ public LongWatermarkDeclarationBuilder combineFunctionMin() {
+ this.combinationFunction = NumericWatermarkCombinationFunction.MIN;
+ return this;
+ }
+
+ /**
+ * Define whether the framework should send the {@link Watermark} to downstream tasks
+ * when the user-defined {@link Watermark} process method returns {@link
+ * WatermarkHandlingResult#PEEK}. If set to {@link WatermarkHandlingStrategy#FORWARD},
+ * the framework will send the watermark to downstream tasks. If set to {@link
+ * WatermarkHandlingStrategy#IGNORE}, the framework will not take any action.
+ */
+ public LongWatermarkDeclarationBuilder defaultHandlingStrategy(
+ WatermarkHandlingStrategy strategy) {
+ this.defaultHandlingStrategy = strategy;
+ return this;
+ }
+
+ public LongWatermarkDeclarationBuilder defaultHandlingStrategyForward() {
+ this.defaultHandlingStrategy = WatermarkHandlingStrategy.FORWARD;
+ return this;
+ }
+
+ public LongWatermarkDeclarationBuilder defaultHandlingStrategyIgnore() {
+ this.defaultHandlingStrategy = WatermarkHandlingStrategy.IGNORE;
+ return this;
+ }
+
+ /**
+ * Whether the combine process should be executed after the process function receives
+ * watermarks from both upstream channels.
+ */
+ public LongWatermarkDeclarationBuilder combineWaitForAllChannels(
+ boolean combineWaitForAllChannels) {
+ this.combineWaitForAllChannels = combineWaitForAllChannels;
+ return this;
+ }
+
+ public LongWatermarkDeclaration build() {
+ return new LongWatermarkDeclaration(
+ identifier,
+ new WatermarkCombinationPolicy(
+ this.combinationFunction, this.combineWaitForAllChannels),
+ this.defaultHandlingStrategy);
+ }
+ }
+
+ @Experimental
+ public static class BoolWatermarkDeclarationBuilder {
+ private final String identifier;
+ private boolean combineWaitForAllChannels = false;
+ private WatermarkCombinationFunction combinationFunction =
+ BoolWatermarkCombinationFunction.AND;
+ private WatermarkHandlingStrategy defaultHandlingStrategy =
+ WatermarkHandlingStrategy.FORWARD;
+
+ public BoolWatermarkDeclarationBuilder(String identifier) {
+ this.identifier = identifier;
+ }
+
+ /** Propagate the logical OR combination result of boolean watermarks downstream. */
+ public BoolWatermarkDeclarationBuilder combineFunctionOR() {
+ this.combinationFunction = BoolWatermarkCombinationFunction.OR;
+ return this;
+ }
+
+ /** Propagate the logical AND combination result of boolean watermarks downstream. */
+ public BoolWatermarkDeclarationBuilder combineFunctionAND() {
+ this.combinationFunction = BoolWatermarkCombinationFunction.AND;
+ return this;
+ }
+
+ /**
+ * Define whether the framework should send the {@link Watermark} to downstream tasks
+ * when the user-defined {@link Watermark} process method returns {@link
+ * WatermarkHandlingResult#PEEK}. If set to {@link WatermarkHandlingStrategy#FORWARD},
+ * the framework will send the watermark to downstream tasks. If set to {@link
+ * WatermarkHandlingStrategy#IGNORE}, the framework will not take any action.
+ */
+ public BoolWatermarkDeclarationBuilder defaultHandlingStrategy(
+ WatermarkHandlingStrategy strategy) {
+ this.defaultHandlingStrategy = strategy;
+ return this;
+ }
+
+ public BoolWatermarkDeclarationBuilder defaultHandlingStrategyForward() {
+ this.defaultHandlingStrategy = WatermarkHandlingStrategy.FORWARD;
+ return this;
+ }
+
+ public BoolWatermarkDeclarationBuilder defaultHandlingStrategyIgnore() {
+ this.defaultHandlingStrategy = WatermarkHandlingStrategy.IGNORE;
+ return this;
+ }
+
+ /**
+ * Whether the combine process should be executed after the process function receives
+ * watermarks from both upstream channels.
+ */
+ public BoolWatermarkDeclarationBuilder combineWaitForAllChannels(
+ boolean combineWaitForAllChannels) {
+ this.combineWaitForAllChannels = combineWaitForAllChannels;
+ return this;
+ }
+
+ public BoolWatermarkDeclaration build() {
+ return new BoolWatermarkDeclaration(
+ identifier,
+ new WatermarkCombinationPolicy(
+ this.combinationFunction, this.combineWaitForAllChannels),
+ this.defaultHandlingStrategy);
+ }
+ }
+ }
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkHandlingResult.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkHandlingResult.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkHandlingResult.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+
+/** This class defines watermark handling result for user-defined process function. */
+@Experimental
+public enum WatermarkHandlingResult {
+ /**
+ * Process function only peek the watermark, and it's framework's responsibility to handle this
+ * watermark.
+ */
+ PEEK,
+
+ /**
+ * This watermark should be sent to downstream by process function itself. The framework does no
+ * additional processing.
+ */
+ POLL,
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkHandlingStrategy.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkHandlingStrategy.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkHandlingStrategy.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+
+/**
+ * This class defines the framework's behavior when the user-defined {@link Watermark} process
+ * method returns {@link WatermarkHandlingResult#PEEK}.
+ */
+@Experimental
+public enum WatermarkHandlingStrategy {
+ /** The framework shouldn't take any action. */
+ IGNORE,
+
+ /** The framework should send the watermark to downstream. */
+ FORWARD,
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkManager.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkManager.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkManager.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+
+/**
+ * The {@link WatermarkManager} interface provides a mechanism to emit watermarks from a process
+ * function.
+ */
+@Experimental
+public interface WatermarkManager {
+
+ /**
+ * Emits a watermark from the process function.
+ *
+ * @param watermark the {@link Watermark} to emit.
+ */
+ void emitWatermark(Watermark watermark);
+}
diff --git a/flink-core/src/main/java/org/apache/flink/api/connector/source/Source.java b/flink-core/src/main/java/org/apache/flink/api/connector/source/Source.java
--- a/flink-core/src/main/java/org/apache/flink/api/connector/source/Source.java
+++ b/flink-core/src/main/java/org/apache/flink/api/connector/source/Source.java
@@ -19,8 +19,12 @@
package org.apache.flink.api.connector.source;
import org.apache.flink.annotation.Public;
+import org.apache.flink.api.common.watermark.WatermarkDeclaration;
import org.apache.flink.core.io.SimpleVersionedSerializer;
+import java.util.Collections;
+import java.util.Set;
+
/**
* The interface for Source. It acts like a factory class that helps construct the {@link
* SplitEnumerator} and {@link SourceReader} and corresponding serializers.
@@ -83,4 +87,14 @@ SplitEnumerator<SplitT, EnumChkT> restoreEnumerator(
* @return The serializer for the SplitEnumerator checkpoint.
*/
SimpleVersionedSerializer<EnumChkT> getEnumeratorCheckpointSerializer();
+
+ /**
+ * Explicitly declare watermarks upfront. Each specific watermark must be declared in this
+ * method before it can be used.
+ *
+ * @return all watermark declarations used by this application.
+ */
+ default Set<? extends WatermarkDeclaration> declareWatermarks() {
+ return Collections.emptySet();
+ }
}
diff --git a/flink-core/src/main/java/org/apache/flink/api/connector/source/SourceReaderContext.java b/flink-core/src/main/java/org/apache/flink/api/connector/source/SourceReaderContext.java
--- a/flink-core/src/main/java/org/apache/flink/api/connector/source/SourceReaderContext.java
+++ b/flink-core/src/main/java/org/apache/flink/api/connector/source/SourceReaderContext.java
@@ -19,6 +19,7 @@
package org.apache.flink.api.connector.source;
import org.apache.flink.annotation.Public;
+import org.apache.flink.api.common.watermark.Watermark;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.metrics.groups.SourceReaderMetricGroup;
import org.apache.flink.util.UserCodeClassLoader;
@@ -76,4 +77,13 @@ public interface SourceReaderContext {
default int currentParallelism() {
throw new UnsupportedOperationException();
}
+
+ /**
+ * Send the watermark to source output.
+ *
+ * <p>This should only be used for datastream v2.
+ */
+ default void emitWatermark(Watermark watermark) {
+ throw new UnsupportedOperationException();
+ }
}
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/BasePartitionedContext.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/BasePartitionedContext.java
new file mode 100644
--- /dev/null
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/BasePartitionedContext.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.datastream.api.context;
+
+import org.apache.flink.annotation.Experimental;
+
+/**
+ * On the base of {@link RuntimeContext}, {@link BasePartitionedContext} also contains all
+ * partition-wise execution information, such as getting state, registering timer, etc.
+ */
+@Experimental
+public interface BasePartitionedContext extends RuntimeContext {
+ /** Get the {@link StateManager} of this process function. */
+ StateManager getStateManager();
+
+ /** Get the {@link ProcessingTimeManager} of this process function. */
+ ProcessingTimeManager getProcessingTimeManager();
+}
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/NonPartitionedContext.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/NonPartitionedContext.java
--- a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/NonPartitionedContext.java
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/NonPartitionedContext.java
@@ -19,6 +19,8 @@
package org.apache.flink.datastream.api.context;
import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.watermark.Watermark;
+import org.apache.flink.api.common.watermark.WatermarkManager;
import org.apache.flink.datastream.api.function.ApplyPartitionFunction;
/**
@@ -32,4 +34,10 @@ public interface NonPartitionedContext<OUT> extends RuntimeContext {
* non-keyed stream, it will apply to single partition.
*/
void applyToAllPartitions(ApplyPartitionFunction<OUT> applyPartitionFunction) throws Exception;
+
+ /**
+ * Get {@link WatermarkManager} instance, which allow emitting a {@link Watermark} from the
+ * process function.
+ */
+ WatermarkManager getWatermarkManager();
}
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/PartitionedContext.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/PartitionedContext.java
--- a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/PartitionedContext.java
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/PartitionedContext.java
@@ -20,15 +20,9 @@
import org.apache.flink.annotation.Experimental;
-/**
- * On the base of {@link RuntimeContext}, {@link PartitionedContext} also contains all
- * partition-wise execution information, such as getting state, registering timer, etc.
- */
+/** A {@link BasePartitionedContext} used in one output process functions. */
@Experimental
-public interface PartitionedContext extends RuntimeContext {
- /** Get the {@link StateManager} of this process function. */
- StateManager getStateManager();
-
- /** Get the {@link ProcessingTimeManager} of this process function. */
- ProcessingTimeManager getProcessingTimeManager();
+public interface PartitionedContext<OUT> extends BasePartitionedContext {
+ /** Get the non-partitioned context of this process function. */
+ NonPartitionedContext<OUT> getNonPartitionedContext();
}
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/TwoOutputNonPartitionedContext.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/TwoOutputNonPartitionedContext.java
--- a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/TwoOutputNonPartitionedContext.java
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/TwoOutputNonPartitionedContext.java
@@ -19,6 +19,8 @@
package org.apache.flink.datastream.api.context;
import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.watermark.Watermark;
+import org.apache.flink.api.common.watermark.WatermarkManager;
import org.apache.flink.datastream.api.function.TwoOutputApplyPartitionFunction;
/**
@@ -33,4 +35,10 @@ public interface TwoOutputNonPartitionedContext<OUT1, OUT2> extends RuntimeConte
*/
void applyToAllPartitions(TwoOutputApplyPartitionFunction<OUT1, OUT2> applyPartitionFunction)
throws Exception;
+
+ /**
+ * Get {@link WatermarkManager} instance, which allow emitting a {@link Watermark} from the
+ * process function.
+ */
+ WatermarkManager getWatermarkManager();
}
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/TwoOutputPartitionedContext.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/TwoOutputPartitionedContext.java
new file mode 100644
--- /dev/null
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/TwoOutputPartitionedContext.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.datastream.api.context;
+
+import org.apache.flink.annotation.Experimental;
+
+/** A special {@link BasePartitionedContext} used in two output process functions. */
+@Experimental
+public interface TwoOutputPartitionedContext<OUT1, OUT2> extends BasePartitionedContext {
+ TwoOutputNonPartitionedContext<OUT1, OUT2> getNonPartitionedContext();
+}
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/OneInputStreamProcessFunction.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/OneInputStreamProcessFunction.java
--- a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/OneInputStreamProcessFunction.java
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/OneInputStreamProcessFunction.java
@@ -19,6 +19,8 @@
package org.apache.flink.datastream.api.function;
import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.watermark.Watermark;
+import org.apache.flink.api.common.watermark.WatermarkHandlingResult;
import org.apache.flink.datastream.api.common.Collector;
import org.apache.flink.datastream.api.context.NonPartitionedContext;
import org.apache.flink.datastream.api.context.PartitionedContext;
@@ -63,4 +65,10 @@ default void endInput(NonPartitionedContext<OUT> ctx) {}
* @param ctx runtime context in which this function is executed.
*/
default void onProcessingTimer(long timestamp, Collector<OUT> output, PartitionedContext ctx) {}
+
+ /** Callback function when receive watermark. */
+ default WatermarkHandlingResult onWatermark(
+ Watermark watermark, Collector<OUT> output, NonPartitionedContext<OUT> ctx) {
+ return WatermarkHandlingResult.PEEK;
+ }
}
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/ProcessFunction.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/ProcessFunction.java
--- a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/ProcessFunction.java
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/ProcessFunction.java
@@ -21,6 +21,7 @@
import org.apache.flink.annotation.Experimental;
import org.apache.flink.api.common.functions.Function;
import org.apache.flink.api.common.state.StateDeclaration;
+import org.apache.flink.api.common.watermark.WatermarkDeclaration;
import java.util.Collections;
import java.util.Set;
@@ -38,6 +39,16 @@ default Set<StateDeclaration> usesStates() {
return Collections.emptySet();
}
+ /**
+ * Explicitly declare watermarks upfront. Each specific watermark must be declared in this
+ * method before it can be used.
+ *
+ * @return all watermark declarations used by this application.
+ */
+ default Set<? extends WatermarkDeclaration> declareWatermarks() {
+ return Collections.emptySet();
+ }
+
/**
* Tear-down method for the user code. It is called after the last call to the main working
* methods (e.g. processRecord).
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoInputBroadcastStreamProcessFunction.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoInputBroadcastStreamProcessFunction.java
--- a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoInputBroadcastStreamProcessFunction.java
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoInputBroadcastStreamProcessFunction.java
@@ -19,6 +19,8 @@
package org.apache.flink.datastream.api.function;
import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.watermark.Watermark;
+import org.apache.flink.api.common.watermark.WatermarkHandlingResult;
import org.apache.flink.datastream.api.common.Collector;
import org.apache.flink.datastream.api.context.NonPartitionedContext;
import org.apache.flink.datastream.api.context.PartitionedContext;
@@ -86,4 +88,28 @@ default void endBroadcastInput(NonPartitionedContext<OUT> ctx) {}
* @param ctx runtime context in which this function is executed.
*/
default void onProcessingTimer(long timestamp, Collector<OUT> output, PartitionedContext ctx) {}
+
+ /**
+ * Callback function when receive the watermark from broadcast input.
+ *
+ * @param watermark to process.
+ * @param output to emit record.
+ * @param ctx runtime context in which this function is executed.
+ */
+ default WatermarkHandlingResult onWatermarkFromBroadcastInput(
+ Watermark watermark, Collector<OUT> output, NonPartitionedContext<OUT> ctx) {
+ return WatermarkHandlingResult.PEEK;
+ }
+
+ /**
+ * Callback function when receive the watermark from non-broadcast input.
+ *
+ * @param watermark to process.
+ * @param output to emit record.
+ * @param ctx runtime context in which this function is executed.
+ */
+ default WatermarkHandlingResult onWatermarkFromNonBroadcastInput(
+ Watermark watermark, Collector<OUT> output, NonPartitionedContext<OUT> ctx) {
+ return WatermarkHandlingResult.PEEK;
+ }
}
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoInputNonBroadcastStreamProcessFunction.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoInputNonBroadcastStreamProcessFunction.java
--- a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoInputNonBroadcastStreamProcessFunction.java
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoInputNonBroadcastStreamProcessFunction.java
@@ -19,6 +19,8 @@
package org.apache.flink.datastream.api.function;
import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.watermark.Watermark;
+import org.apache.flink.api.common.watermark.WatermarkHandlingResult;
import org.apache.flink.datastream.api.common.Collector;
import org.apache.flink.datastream.api.context.NonPartitionedContext;
import org.apache.flink.datastream.api.context.PartitionedContext;
@@ -82,4 +84,28 @@ default void endSecondInput(NonPartitionedContext<OUT> ctx) {}
* @param ctx runtime context in which this function is executed.
*/
default void onProcessingTimer(long timestamp, Collector<OUT> output, PartitionedContext ctx) {}
+
+ /**
+ * Callback function when receive the watermark from the first input.
+ *
+ * @param watermark to process.
+ * @param output to emit record.
+ * @param ctx runtime context in which this function is executed.
+ */
+ default WatermarkHandlingResult onWatermarkFromFirstInput(
+ Watermark watermark, Collector<OUT> output, NonPartitionedContext<OUT> ctx) {
+ return WatermarkHandlingResult.PEEK;
+ }
+
+ /**
+ * Callback function when receive the watermark from the second input.
+ *
+ * @param watermark to process.
+ * @param output to emit record.
+ * @param ctx runtime context in which this function is executed.
+ */
+ default WatermarkHandlingResult onWatermarkFromSecondInput(
+ Watermark watermark, Collector<OUT> output, NonPartitionedContext<OUT> ctx) {
+ return WatermarkHandlingResult.PEEK;
+ }
}
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoOutputApplyPartitionFunction.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoOutputApplyPartitionFunction.java
--- a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoOutputApplyPartitionFunction.java
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoOutputApplyPartitionFunction.java
@@ -21,7 +21,7 @@
import org.apache.flink.annotation.Experimental;
import org.apache.flink.api.common.functions.Function;
import org.apache.flink.datastream.api.common.Collector;
-import org.apache.flink.datastream.api.context.PartitionedContext;
+import org.apache.flink.datastream.api.context.TwoOutputPartitionedContext;
/** A function to be applied to all partitions with two outputs. */
@FunctionalInterface
@@ -34,6 +34,9 @@ public interface TwoOutputApplyPartitionFunction<OUT1, OUT2> extends Function {
* @param secondOutput to emit record to second output.
* @param ctx runtime context in which this function is executed.
*/
- void apply(Collector<OUT1> firstOutput, Collector<OUT2> secondOutput, PartitionedContext ctx)
+ void apply(
+ Collector<OUT1> firstOutput,
+ Collector<OUT2> secondOutput,
+ TwoOutputPartitionedContext ctx)
throws Exception;
}
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoOutputStreamProcessFunction.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoOutputStreamProcessFunction.java
--- a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoOutputStreamProcessFunction.java
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoOutputStreamProcessFunction.java
@@ -19,9 +19,11 @@
package org.apache.flink.datastream.api.function;
import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.watermark.Watermark;
+import org.apache.flink.api.common.watermark.WatermarkHandlingResult;
import org.apache.flink.datastream.api.common.Collector;
-import org.apache.flink.datastream.api.context.PartitionedContext;
import org.apache.flink.datastream.api.context.TwoOutputNonPartitionedContext;
+import org.apache.flink.datastream.api.context.TwoOutputPartitionedContext;
/** This contains all logical related to process and emit records to two output streams. */
@Experimental
@@ -47,7 +49,10 @@ default void open(TwoOutputNonPartitionedContext<OUT1, OUT2> ctx) throws Excepti
* @param ctx runtime context in which this function is executed.
*/
void processRecord(
- IN record, Collector<OUT1> output1, Collector<OUT2> output2, PartitionedContext ctx)
+ IN record,
+ Collector<OUT1> output1,
+ Collector<OUT2> output2,
+ TwoOutputPartitionedContext ctx)
throws Exception;
/**
@@ -70,5 +75,21 @@ default void onProcessingTimer(
long timestamp,
Collector<OUT1> output1,
Collector<OUT2> output2,
- PartitionedContext ctx) {}
+ TwoOutputPartitionedContext ctx) {}
+
+ /**
+ * Callback function when receive the watermark from the input.
+ *
+ * @param watermark to process.
+ * @param output1 to emit data to the first output.
+ * @param output2 to emit data to the second output.
+ * @param ctx runtime context in which this function is executed.
+ */
+ default WatermarkHandlingResult onWatermark(
+ Watermark watermark,
+ Collector<OUT1> output1,
+ Collector<OUT2> output2,
+ TwoOutputNonPartitionedContext<OUT1, OUT2> ctx) {
+ return WatermarkHandlingResult.PEEK;
+ }
}
diff --git a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/ExecutionEnvironmentImpl.java b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/ExecutionEnvironmentImpl.java
--- a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/ExecutionEnvironmentImpl.java
+++ b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/ExecutionEnvironmentImpl.java
@@ -193,7 +193,7 @@ public <OUT> ProcessConfigurableAndNonKeyedPartitionStream<OUT> fromSource(
return fromSource(new WrappedSource<>(generatorSource), "Collection Source");
} else {
throw new UnsupportedOperationException(
- "Unsupported type of sink, you could use DataStreamV2SourceUtils to wrap a FLIP-27 based source.");
+ "Unsupported type of source, you could use DataStreamV2SourceUtils to wrap a FLIP-27 based source.");
}
}
diff --git a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/AbstractPartitionedContext.java b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/AbstractPartitionedContext.java
new file mode 100644
--- /dev/null
+++ b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/AbstractPartitionedContext.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.datastream.impl.context;
+
+import org.apache.flink.datastream.api.context.BasePartitionedContext;
+import org.apache.flink.datastream.api.context.JobInfo;
+import org.apache.flink.datastream.api.context.ProcessingTimeManager;
+import org.apache.flink.datastream.api.context.RuntimeContext;
+import org.apache.flink.datastream.api.context.TaskInfo;
+import org.apache.flink.metrics.MetricGroup;
+import org.apache.flink.runtime.state.v2.OperatorStateStore;
+import org.apache.flink.streaming.api.operators.StreamingRuntimeContext;
+
+import java.util.function.BiConsumer;
+import java.util.function.Supplier;
+
+/** Abstract implementation class of {@link BasePartitionedContext}. */
+public abstract class AbstractPartitionedContext implements BasePartitionedContext {
+ protected final RuntimeContext context;
+
+ protected final DefaultStateManager stateManager;
+
+ protected final ProcessingTimeManager processingTimeManager;
+
+ public AbstractPartitionedContext(
+ RuntimeContext context,
+ Supplier<Object> currentKeySupplier,
+ BiConsumer<Runnable, Object> processorWithKey,
+ ProcessingTimeManager processingTimeManager,
+ StreamingRuntimeContext operatorContext,
+ OperatorStateStore operatorStateStore) {
+ this.context = context;
+ this.stateManager =
+ new DefaultStateManager(
+ currentKeySupplier, processorWithKey, operatorContext, operatorStateStore);
+ this.processingTimeManager = processingTimeManager;
+ }
+
+ @Override
+ public JobInfo getJobInfo() {
+ return context.getJobInfo();
+ }
+
+ @Override
+ public TaskInfo getTaskInfo() {
+ return context.getTaskInfo();
+ }
+
+ @Override
+ public DefaultStateManager getStateManager() {
+ return stateManager;
+ }
+
+ @Override
+ public ProcessingTimeManager getProcessingTimeManager() {
+ return processingTimeManager;
+ }
+
+ @Override
+ public MetricGroup getMetricGroup() {
+ return context.getMetricGroup();
+ }
+}
diff --git a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/DefaultNonPartitionedContext.java b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/DefaultNonPartitionedContext.java
--- a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/DefaultNonPartitionedContext.java
+++ b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/DefaultNonPartitionedContext.java
@@ -18,38 +18,49 @@
package org.apache.flink.datastream.impl.context;
+import org.apache.flink.api.common.watermark.WatermarkManager;
import org.apache.flink.datastream.api.common.Collector;
import org.apache.flink.datastream.api.context.JobInfo;
import org.apache.flink.datastream.api.context.NonPartitionedContext;
import org.apache.flink.datastream.api.context.TaskInfo;
import org.apache.flink.datastream.api.function.ApplyPartitionFunction;
+import org.apache.flink.datastream.impl.watermark.DefaultWatermarkManager;
import org.apache.flink.metrics.MetricGroup;
+import org.apache.flink.streaming.api.operators.Output;
+import org.apache.flink.streaming.runtime.watermark.AbstractInternalWatermarkDeclaration;
+import java.util.Map;
import java.util.Set;
/** The default implementation of {@link NonPartitionedContext}. */
public class DefaultNonPartitionedContext<OUT> implements NonPartitionedContext<OUT> {
private final DefaultRuntimeContext context;
- private final DefaultPartitionedContext partitionedContext;
+ private final DefaultPartitionedContext<OUT> partitionedContext;
private final Collector<OUT> collector;
private final boolean isKeyed;
private final Set<Object> keySet;
+ private final WatermarkManager watermarkManager;
+
public DefaultNonPartitionedContext(
DefaultRuntimeContext context,
- DefaultPartitionedContext partitionedContext,
+ DefaultPartitionedContext<OUT> partitionedContext,
Collector<OUT> collector,
boolean isKeyed,
- Set<Object> keySet) {
+ Set<Object> keySet,
+ Output<?> streamRecordOutput,
+ Map<String, AbstractInternalWatermarkDeclaration<?>> watermarkDeclarationMap) {
this.context = context;
this.partitionedContext = partitionedContext;
this.collector = collector;
this.isKeyed = isKeyed;
this.keySet = keySet;
+ this.watermarkManager =
+ new DefaultWatermarkManager(streamRecordOutput, watermarkDeclarationMap);
}
@Override
@@ -75,6 +86,11 @@ public void applyToAllPartitions(ApplyPartitionFunction<OUT> applyPartitionFunct
}
}
+ @Override
+ public WatermarkManager getWatermarkManager() {
+ return watermarkManager;
+ }
+
@Override
public JobInfo getJobInfo() {
return context.getJobInfo();
diff --git a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/DefaultPartitionedContext.java b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/DefaultPartitionedContext.java
--- a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/DefaultPartitionedContext.java
+++ b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/DefaultPartitionedContext.java
@@ -18,25 +18,28 @@
package org.apache.flink.datastream.impl.context;
-import org.apache.flink.datastream.api.context.JobInfo;
+import org.apache.flink.datastream.api.context.NonPartitionedContext;
import org.apache.flink.datastream.api.context.PartitionedContext;
import org.apache.flink.datastream.api.context.ProcessingTimeManager;
import org.apache.flink.datastream.api.context.RuntimeContext;
-import org.apache.flink.datastream.api.context.TaskInfo;
-import org.apache.flink.metrics.MetricGroup;
import org.apache.flink.runtime.state.v2.OperatorStateStore;
import org.apache.flink.streaming.api.operators.StreamingRuntimeContext;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
/** The default implementation of {@link PartitionedContext}. */
-public class DefaultPartitionedContext implements PartitionedContext {
- private final RuntimeContext context;
+public class DefaultPartitionedContext<OUT> extends AbstractPartitionedContext
+ implements PartitionedContext<OUT> {
- private final DefaultStateManager stateManager;
-
- private final ProcessingTimeManager processingTimeManager;
+ /**
+ * The {@link DefaultNonPartitionedContext} and {@link DefaultPartitionedContext} create a
+ * circular reference, so the {@code nonPartitionedContext} field of {@link
+ * DefaultPartitionedContext} should be set in a separate method, {@link
+ * DefaultPartitionedContext#setNonPartitionedContext(NonPartitionedContext)}, rather than in
+ * the constructor.
+ */
+ private NonPartitionedContext<OUT> nonPartitionedContext;
public DefaultPartitionedContext(
RuntimeContext context,
@@ -45,35 +48,21 @@ public DefaultPartitionedContext(
ProcessingTimeManager processingTimeManager,
StreamingRuntimeContext operatorContext,
OperatorStateStore operatorStateStore) {
- this.context = context;
- this.stateManager =
- new DefaultStateManager(
- currentKeySupplier, processorWithKey, operatorContext, operatorStateStore);
- this.processingTimeManager = processingTimeManager;
- }
-
- @Override
- public JobInfo getJobInfo() {
- return context.getJobInfo();
+ super(
+ context,
+ currentKeySupplier,
+ processorWithKey,
+ processingTimeManager,
+ operatorContext,
+ operatorStateStore);
}
- @Override
- public TaskInfo getTaskInfo() {
- return context.getTaskInfo();
- }
-
- @Override
- public DefaultStateManager getStateManager() {
- return stateManager;
- }
-
- @Override
- public ProcessingTimeManager getProcessingTimeManager() {
- return processingTimeManager;
+ public void setNonPartitionedContext(NonPartitionedContext<OUT> nonPartitionedContext) {
+ this.nonPartitionedContext = nonPartitionedContext;
}
@Override
- public MetricGroup getMetricGroup() {
- return context.getMetricGroup();
+ public NonPartitionedContext<OUT> getNonPartitionedContext() {
+ return nonPartitionedContext;
}
}
diff --git a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/DefaultTwoOutputNonPartitionedContext.java b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/DefaultTwoOutputNonPartitionedContext.java
--- a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/DefaultTwoOutputNonPartitionedContext.java
+++ b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/DefaultTwoOutputNonPartitionedContext.java
@@ -18,21 +18,26 @@
package org.apache.flink.datastream.impl.context;
+import org.apache.flink.api.common.watermark.WatermarkManager;
import org.apache.flink.datastream.api.common.Collector;
import org.apache.flink.datastream.api.context.JobInfo;
import org.apache.flink.datastream.api.context.TaskInfo;
import org.apache.flink.datastream.api.context.TwoOutputNonPartitionedContext;
import org.apache.flink.datastream.api.function.TwoOutputApplyPartitionFunction;
+import org.apache.flink.datastream.impl.watermark.DefaultWatermarkManager;
import org.apache.flink.metrics.MetricGroup;
+import org.apache.flink.streaming.api.operators.Output;
+import org.apache.flink.streaming.runtime.watermark.AbstractInternalWatermarkDeclaration;
+import java.util.Map;
import java.util.Set;
/** The default implementation of {@link TwoOutputNonPartitionedContext}. */
public class DefaultTwoOutputNonPartitionedContext<OUT1, OUT2>
implements TwoOutputNonPartitionedContext<OUT1, OUT2> {
protected final DefaultRuntimeContext context;
- private final DefaultPartitionedContext partitionedContext;
+ private final DefaultTwoOutputPartitionedContext<OUT1, OUT2> partitionedContext;
protected final Collector<OUT1> firstCollector;
@@ -42,19 +47,25 @@ public class DefaultTwoOutputNonPartitionedContext<OUT1, OUT2>
private final Set<Object> keySet;
+ private final WatermarkManager watermarkManager;
+
public DefaultTwoOutputNonPartitionedContext(
DefaultRuntimeContext context,
- DefaultPartitionedContext partitionedContext,
+ DefaultTwoOutputPartitionedContext<OUT1, OUT2> partitionedContext,
Collector<OUT1> firstCollector,
Collector<OUT2> secondCollector,
boolean isKeyed,
- Set<Object> keySet) {
+ Set<Object> keySet,
+ Output<?> streamRecordOutput,
+ Map<String, AbstractInternalWatermarkDeclaration<?>> watermarkDeclarationMap) {
this.context = context;
this.partitionedContext = partitionedContext;
this.firstCollector = firstCollector;
this.secondCollector = secondCollector;
this.isKeyed = isKeyed;
this.keySet = keySet;
+ this.watermarkManager =
+ new DefaultWatermarkManager(streamRecordOutput, watermarkDeclarationMap);
}
@Override
@@ -83,6 +94,11 @@ public void applyToAllPartitions(
}
}
+ @Override
+ public WatermarkManager getWatermarkManager() {
+ return watermarkManager;
+ }
+
@Override
public JobInfo getJobInfo() {
return context.getJobInfo();
diff --git a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/DefaultTwoOutputPartitionedContext.java b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/DefaultTwoOutputPartitionedContext.java
new file mode 100644
--- /dev/null
+++ b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/DefaultTwoOutputPartitionedContext.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.datastream.impl.context;
+
+import org.apache.flink.datastream.api.context.ProcessingTimeManager;
+import org.apache.flink.datastream.api.context.RuntimeContext;
+import org.apache.flink.datastream.api.context.TwoOutputNonPartitionedContext;
+import org.apache.flink.datastream.api.context.TwoOutputPartitionedContext;
+import org.apache.flink.runtime.state.v2.OperatorStateStore;
+import org.apache.flink.streaming.api.operators.StreamingRuntimeContext;
+
+import java.util.function.BiConsumer;
+import java.util.function.Supplier;
+
+/** The default implementation of {@link TwoOutputPartitionedContext}. */
+public class DefaultTwoOutputPartitionedContext<OUT1, OUT2> extends AbstractPartitionedContext
+ implements TwoOutputPartitionedContext<OUT1, OUT2> {
+
+ /**
+ * The {@link DefaultTwoOutputNonPartitionedContext} and {@link
+ * DefaultTwoOutputPartitionedContext} create a circular reference, so the {@code
+ * nonPartitionedContext} field of {@link DefaultTwoOutputPartitionedContext} should be set in a
+ * separate method, {@link DefaultTwoOutputPartitionedContext#setNonPartitionedContext}, rather
+ * than in the constructor.
+ */
+ protected TwoOutputNonPartitionedContext<OUT1, OUT2> nonPartitionedContext;
+
+ public DefaultTwoOutputPartitionedContext(
+ RuntimeContext context,
+ Supplier<Object> currentKeySupplier,
+ BiConsumer<Runnable, Object> processorWithKey,
+ ProcessingTimeManager processingTimeManager,
+ StreamingRuntimeContext operatorContext,
+ OperatorStateStore operatorStateStore) {
+ super(
+ context,
+ currentKeySupplier,
+ processorWithKey,
+ processingTimeManager,
+ operatorContext,
+ operatorStateStore);
+ }
+
+ public void setNonPartitionedContext(
+ TwoOutputNonPartitionedContext<OUT1, OUT2> nonPartitionedContext) {
+ this.nonPartitionedContext = nonPartitionedContext;
+ }
+
+ @Override
+ public TwoOutputNonPartitionedContext<OUT1, OUT2> getNonPartitionedContext() {
+ return nonPartitionedContext;
+ }
+}
diff --git a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedProcessOperator.java b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedProcessOperator.java
--- a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedProcessOperator.java
+++ b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedProcessOperator.java
@@ -101,7 +101,13 @@ protected ProcessingTimeManager getProcessingTimeManager() {
@Override
protected NonPartitionedContext<OUT> getNonPartitionedContext() {
return new DefaultNonPartitionedContext<>(
- context, partitionedContext, outputCollector, true, keySet);
+ context,
+ partitionedContext,
+ outputCollector,
+ true,
+ keySet,
+ output,
+ watermarkDeclarationMap);
}
@Override
diff --git a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedTwoInputBroadcastProcessOperator.java b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedTwoInputBroadcastProcessOperator.java
--- a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedTwoInputBroadcastProcessOperator.java
+++ b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedTwoInputBroadcastProcessOperator.java
@@ -102,7 +102,13 @@ public void onProcessingTime(InternalTimer<KEY, VoidNamespace> timer) throws Exc
@Override
protected NonPartitionedContext<OUT> getNonPartitionedContext() {
return new DefaultNonPartitionedContext<>(
- context, partitionedContext, collector, true, keySet);
+ context,
+ partitionedContext,
+ collector,
+ true,
+ keySet,
+ output,
+ watermarkDeclarationMap);
}
@Override
diff --git a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedTwoInputNonBroadcastProcessOperator.java b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedTwoInputNonBroadcastProcessOperator.java
--- a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedTwoInputNonBroadcastProcessOperator.java
+++ b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedTwoInputNonBroadcastProcessOperator.java
@@ -104,7 +104,13 @@ public void onProcessingTime(InternalTimer<KEY, VoidNamespace> timer) throws Exc
@Override
protected NonPartitionedContext<OUT> getNonPartitionedContext() {
return new DefaultNonPartitionedContext<>(
- context, partitionedContext, collector, true, keySet);
+ context,
+ partitionedContext,
+ collector,
+ true,
+ keySet,
+ output,
+ watermarkDeclarationMap);
}
@Override
diff --git a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedTwoOutputProcessOperator.java b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedTwoOutputProcessOperator.java
--- a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedTwoOutputProcessOperator.java
+++ b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedTwoOutputProcessOperator.java
@@ -125,7 +125,14 @@ public void onProcessingTime(InternalTimer<KEY, VoidNamespace> timer) throws Exc
@Override
protected TwoOutputNonPartitionedContext<OUT_MAIN, OUT_SIDE> getNonPartitionedContext() {
return new DefaultTwoOutputNonPartitionedContext<>(
- context, partitionedContext, mainCollector, sideCollector, true, keySet);
+ context,
+ partitionedContext,
+ mainCollector,
+ sideCollector,
+ true,
+ keySet,
+ output,
+ watermarkDeclarationMap);
}
@Override
diff --git a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/ProcessOperator.java b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/ProcessOperator.java
--- a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/ProcessOperator.java
+++ b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/ProcessOperator.java
@@ -19,6 +19,8 @@
package org.apache.flink.datastream.impl.operators;
import org.apache.flink.api.common.TaskInfo;
+import org.apache.flink.api.common.watermark.WatermarkHandlingResult;
+import org.apache.flink.api.common.watermark.WatermarkHandlingStrategy;
import org.apache.flink.datastream.api.context.NonPartitionedContext;
import org.apache.flink.datastream.api.context.ProcessingTimeManager;
import org.apache.flink.datastream.api.function.OneInputStreamProcessFunction;
@@ -29,12 +31,17 @@
import org.apache.flink.datastream.impl.context.DefaultRuntimeContext;
import org.apache.flink.datastream.impl.context.UnsupportedProcessingTimeManager;
import org.apache.flink.runtime.asyncprocessing.operators.AbstractAsyncStateUdfStreamOperator;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.streaming.api.operators.BoundedOneInput;
import org.apache.flink.streaming.api.operators.OneInputStreamOperator;
import org.apache.flink.streaming.api.operators.StreamingRuntimeContext;
import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.streaming.runtime.watermark.AbstractInternalWatermarkDeclaration;
+import java.util.Map;
import java.util.function.BiConsumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
/** Operator for {@link OneInputStreamProcessFunction}. */
public class ProcessOperator<IN, OUT>
@@ -43,12 +50,15 @@ public class ProcessOperator<IN, OUT>
protected transient DefaultRuntimeContext context;
- protected transient DefaultPartitionedContext partitionedContext;
+ protected transient DefaultPartitionedContext<OUT> partitionedContext;
protected transient NonPartitionedContext<OUT> nonPartitionedContext;
protected transient TimestampCollector<OUT> outputCollector;
+ protected transient Map<String, AbstractInternalWatermarkDeclaration<?>>
+ watermarkDeclarationMap;
+
public ProcessOperator(OneInputStreamProcessFunction<IN, OUT> userFunction) {
super(userFunction);
}
@@ -68,8 +78,17 @@ public void open() throws Exception {
taskInfo.getIndexOfThisSubtask(),
taskInfo.getAttemptNumber(),
operatorContext.getMetricGroup());
+
+ outputCollector = getOutputCollector();
+ watermarkDeclarationMap =
+ config.getWatermarkDeclarations(getUserCodeClassloader()).stream()
+ .collect(
+ Collectors.toMap(
+ AbstractInternalWatermarkDeclaration::getIdentifier,
+ Function.identity()));
+
partitionedContext =
- new DefaultPartitionedContext(
+ new DefaultPartitionedContext<>(
context,
this::currentKey,
getProcessorWithKey(),
@@ -78,6 +97,7 @@ public void open() throws Exception {
getOperatorStateBackend());
outputCollector = getOutputCollector();
nonPartitionedContext = getNonPartitionedContext();
+ partitionedContext.setNonPartitionedContext(nonPartitionedContext);
userFunction.open(nonPartitionedContext);
}
@@ -87,6 +107,20 @@ public void processElement(StreamRecord<IN> element) throws Exception {
userFunction.processRecord(element.getValue(), outputCollector, partitionedContext);
}
+ @Override
+ public void processWatermarkInternal(WatermarkEvent watermark) throws Exception {
+ WatermarkHandlingResult watermarkHandlingResultByUserFunction =
+ userFunction.onWatermark(
+ watermark.getWatermark(), outputCollector, nonPartitionedContext);
+ if (watermarkHandlingResultByUserFunction == WatermarkHandlingResult.PEEK
+ && watermarkDeclarationMap
+ .get(watermark.getWatermark().getIdentifier())
+ .getDefaultHandlingStrategy()
+ == WatermarkHandlingStrategy.FORWARD) {
+ output.emitWatermark(watermark);
+ }
+ }
+
protected TimestampCollector<OUT> getOutputCollector() {
return new OutputCollector<>(output);
}
@@ -121,7 +155,13 @@ protected ProcessingTimeManager getProcessingTimeManager() {
protected NonPartitionedContext<OUT> getNonPartitionedContext() {
return new DefaultNonPartitionedContext<>(
- context, partitionedContext, outputCollector, false, null);
+ context,
+ partitionedContext,
+ outputCollector,
+ false,
+ null,
+ output,
+ watermarkDeclarationMap);
}
@Override
diff --git a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/TwoInputBroadcastProcessOperator.java b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/TwoInputBroadcastProcessOperator.java
--- a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/TwoInputBroadcastProcessOperator.java
+++ b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/TwoInputBroadcastProcessOperator.java
@@ -19,6 +19,8 @@
package org.apache.flink.datastream.impl.operators;
import org.apache.flink.api.common.TaskInfo;
+import org.apache.flink.api.common.watermark.WatermarkHandlingResult;
+import org.apache.flink.api.common.watermark.WatermarkHandlingStrategy;
import org.apache.flink.datastream.api.context.NonPartitionedContext;
import org.apache.flink.datastream.api.context.ProcessingTimeManager;
import org.apache.flink.datastream.api.function.TwoInputBroadcastStreamProcessFunction;
@@ -29,12 +31,17 @@
import org.apache.flink.datastream.impl.context.DefaultRuntimeContext;
import org.apache.flink.datastream.impl.context.UnsupportedProcessingTimeManager;
import org.apache.flink.runtime.asyncprocessing.operators.AbstractAsyncStateUdfStreamOperator;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.streaming.api.operators.BoundedMultiInput;
import org.apache.flink.streaming.api.operators.StreamingRuntimeContext;
import org.apache.flink.streaming.api.operators.TwoInputStreamOperator;
import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.streaming.runtime.watermark.AbstractInternalWatermarkDeclaration;
+import java.util.Map;
import java.util.function.BiConsumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import static org.apache.flink.util.Preconditions.checkState;
@@ -48,10 +55,13 @@ public class TwoInputBroadcastProcessOperator<IN1, IN2, OUT>
protected transient DefaultRuntimeContext context;
- protected transient DefaultPartitionedContext partitionedContext;
+ protected transient DefaultPartitionedContext<OUT> partitionedContext;
protected transient NonPartitionedContext<OUT> nonPartitionedContext;
+ protected transient Map<String, AbstractInternalWatermarkDeclaration<?>>
+ watermarkDeclarationMap;
+
public TwoInputBroadcastProcessOperator(
TwoInputBroadcastStreamProcessFunction<IN1, IN2, OUT> userFunction) {
super(userFunction);
@@ -73,15 +83,23 @@ public void open() throws Exception {
taskInfo.getIndexOfThisSubtask(),
taskInfo.getAttemptNumber(),
operatorContext.getMetricGroup());
+
+ watermarkDeclarationMap =
+ config.getWatermarkDeclarations(getUserCodeClassloader()).stream()
+ .collect(
+ Collectors.toMap(
+ AbstractInternalWatermarkDeclaration::getIdentifier,
+ Function.identity()));
this.partitionedContext =
- new DefaultPartitionedContext(
+ new DefaultPartitionedContext<>(
context,
this::currentKey,
getProcessorWithKey(),
getProcessingTimeManager(),
operatorContext,
getOperatorStateBackend());
this.nonPartitionedContext = getNonPartitionedContext();
+ this.partitionedContext.setNonPartitionedContext(this.nonPartitionedContext);
this.userFunction.open(this.nonPartitionedContext);
}
@@ -98,13 +116,47 @@ public void processElement2(StreamRecord<IN2> element) throws Exception {
userFunction.processRecordFromBroadcastInput(element.getValue(), nonPartitionedContext);
}
+ @Override
+ public void processWatermark1Internal(WatermarkEvent watermark) throws Exception {
+ WatermarkHandlingResult watermarkHandlingResultByUserFunction =
+ userFunction.onWatermarkFromNonBroadcastInput(
+ watermark.getWatermark(), collector, nonPartitionedContext);
+ if (watermarkHandlingResultByUserFunction == WatermarkHandlingResult.PEEK
+ && watermarkDeclarationMap
+ .get(watermark.getWatermark().getIdentifier())
+ .getDefaultHandlingStrategy()
+ == WatermarkHandlingStrategy.FORWARD) {
+ output.emitWatermark(watermark);
+ }
+ }
+
+ @Override
+ public void processWatermark2Internal(WatermarkEvent watermark) throws Exception {
+ WatermarkHandlingResult watermarkHandlingResultByUserFunction =
+ userFunction.onWatermarkFromBroadcastInput(
+ watermark.getWatermark(), collector, nonPartitionedContext);
+ if (watermarkHandlingResultByUserFunction == WatermarkHandlingResult.PEEK
+ && watermarkDeclarationMap
+ .get(watermark.getWatermark().getIdentifier())
+ .getDefaultHandlingStrategy()
+ == WatermarkHandlingStrategy.FORWARD) {
+ output.emitWatermark(watermark);
+ }
+ }
+
protected TimestampCollector<OUT> getOutputCollector() {
return new OutputCollector<>(output);
}
protected NonPartitionedContext<OUT> getNonPartitionedContext() {
return new DefaultNonPartitionedContext<>(
- context, partitionedContext, collector, false, null);
+ context,
+ partitionedContext,
+ collector,
+ false,
+ null,
+ output,
+ watermarkDeclarationMap);
}
@Override
diff --git a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/TwoInputNonBroadcastProcessOperator.java b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/TwoInputNonBroadcastProcessOperator.java
--- a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/TwoInputNonBroadcastProcessOperator.java
+++ b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/TwoInputNonBroadcastProcessOperator.java
@@ -19,6 +19,8 @@
package org.apache.flink.datastream.impl.operators;
import org.apache.flink.api.common.TaskInfo;
+import org.apache.flink.api.common.watermark.WatermarkHandlingResult;
+import org.apache.flink.api.common.watermark.WatermarkHandlingStrategy;
import org.apache.flink.datastream.api.context.NonPartitionedContext;
import org.apache.flink.datastream.api.context.ProcessingTimeManager;
import org.apache.flink.datastream.api.function.TwoInputNonBroadcastStreamProcessFunction;
@@ -29,13 +31,18 @@
import org.apache.flink.datastream.impl.context.DefaultRuntimeContext;
import org.apache.flink.datastream.impl.context.UnsupportedProcessingTimeManager;
import org.apache.flink.runtime.asyncprocessing.operators.AbstractAsyncStateUdfStreamOperator;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.runtime.state.OperatorStateBackend;
import org.apache.flink.streaming.api.operators.BoundedMultiInput;
import org.apache.flink.streaming.api.operators.StreamingRuntimeContext;
import org.apache.flink.streaming.api.operators.TwoInputStreamOperator;
import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.streaming.runtime.watermark.AbstractInternalWatermarkDeclaration;
+import java.util.Map;
import java.util.function.BiConsumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import static org.apache.flink.util.Preconditions.checkState;
@@ -49,10 +56,13 @@ public class TwoInputNonBroadcastProcessOperator<IN1, IN2, OUT>
protected transient DefaultRuntimeContext context;
- protected transient DefaultPartitionedContext partitionedContext;
+ protected transient DefaultPartitionedContext<OUT> partitionedContext;
protected transient NonPartitionedContext<OUT> nonPartitionedContext;
+ protected transient Map<String, AbstractInternalWatermarkDeclaration<?>>
+ watermarkDeclarationMap;
+
public TwoInputNonBroadcastProcessOperator(
TwoInputNonBroadcastStreamProcessFunction<IN1, IN2, OUT> userFunction) {
super(userFunction);
@@ -76,15 +86,23 @@ public void open() throws Exception {
taskInfo.getIndexOfThisSubtask(),
taskInfo.getAttemptNumber(),
operatorContext.getMetricGroup());
+
+ watermarkDeclarationMap =
+ config.getWatermarkDeclarations(getUserCodeClassloader()).stream()
+ .collect(
+ Collectors.toMap(
+ AbstractInternalWatermarkDeclaration::getIdentifier,
+ Function.identity()));
this.partitionedContext =
- new DefaultPartitionedContext(
+ new DefaultPartitionedContext<>(
context,
this::currentKey,
getProcessorWithKey(),
getProcessingTimeManager(),
operatorContext,
operatorStateBackend);
this.nonPartitionedContext = getNonPartitionedContext();
+ this.partitionedContext.setNonPartitionedContext(this.nonPartitionedContext);
this.userFunction.open(this.nonPartitionedContext);
}
@@ -101,13 +119,47 @@ public void processElement2(StreamRecord<IN2> element) throws Exception {
element.getValue(), collector, partitionedContext);
}
+ @Override
+ public void processWatermark1Internal(WatermarkEvent watermark) throws Exception {
+ WatermarkHandlingResult watermarkHandlingResultByUserFunction =
+ userFunction.onWatermarkFromFirstInput(
+ watermark.getWatermark(), collector, nonPartitionedContext);
+ if (watermarkHandlingResultByUserFunction == WatermarkHandlingResult.PEEK
+ && watermarkDeclarationMap
+ .get(watermark.getWatermark().getIdentifier())
+ .getDefaultHandlingStrategy()
+ == WatermarkHandlingStrategy.FORWARD) {
+ output.emitWatermark(watermark);
+ }
+ }
+
+ @Override
+ public void processWatermark2Internal(WatermarkEvent watermark) throws Exception {
+ WatermarkHandlingResult watermarkHandlingResultByUserFunction =
+ userFunction.onWatermarkFromSecondInput(
+ watermark.getWatermark(), collector, nonPartitionedContext);
+ if (watermarkHandlingResultByUserFunction == WatermarkHandlingResult.PEEK
+ && watermarkDeclarationMap
+ .get(watermark.getWatermark().getIdentifier())
+ .getDefaultHandlingStrategy()
+ == WatermarkHandlingStrategy.FORWARD) {
+ output.emitWatermark(watermark);
+ }
+ }
+
protected TimestampCollector<OUT> getOutputCollector() {
return new OutputCollector<>(output);
}
protected NonPartitionedContext<OUT> getNonPartitionedContext() {
return new DefaultNonPartitionedContext<>(
- context, partitionedContext, collector, false, null);
+ context,
+ partitionedContext,
+ collector,
+ false,
+ null,
+ output,
+ watermarkDeclarationMap);
}
@Override
diff --git a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/TwoOutputProcessOperator.java b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/TwoOutputProcessOperator.java
--- a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/TwoOutputProcessOperator.java
+++ b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/TwoOutputProcessOperator.java
@@ -19,25 +19,32 @@
package org.apache.flink.datastream.impl.operators;
import org.apache.flink.api.common.TaskInfo;
+import org.apache.flink.api.common.watermark.WatermarkHandlingResult;
+import org.apache.flink.api.common.watermark.WatermarkHandlingStrategy;
import org.apache.flink.datastream.api.context.ProcessingTimeManager;
import org.apache.flink.datastream.api.context.TwoOutputNonPartitionedContext;
import org.apache.flink.datastream.api.function.TwoOutputStreamProcessFunction;
import org.apache.flink.datastream.impl.common.OutputCollector;
import org.apache.flink.datastream.impl.common.TimestampCollector;
-import org.apache.flink.datastream.impl.context.DefaultPartitionedContext;
import org.apache.flink.datastream.impl.context.DefaultRuntimeContext;
import org.apache.flink.datastream.impl.context.DefaultTwoOutputNonPartitionedContext;
+import org.apache.flink.datastream.impl.context.DefaultTwoOutputPartitionedContext;
import org.apache.flink.datastream.impl.context.UnsupportedProcessingTimeManager;
import org.apache.flink.runtime.asyncprocessing.operators.AbstractAsyncStateUdfStreamOperator;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.runtime.state.v2.OperatorStateStore;
import org.apache.flink.streaming.api.operators.BoundedOneInput;
import org.apache.flink.streaming.api.operators.OneInputStreamOperator;
import org.apache.flink.streaming.api.operators.Output;
import org.apache.flink.streaming.api.operators.StreamingRuntimeContext;
import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.streaming.runtime.watermark.AbstractInternalWatermarkDeclaration;
import org.apache.flink.util.OutputTag;
+import java.util.Map;
import java.util.function.BiConsumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
/**
* Operator for {@link TwoOutputStreamProcessFunction}.
@@ -54,12 +61,15 @@ public class TwoOutputProcessOperator<IN, OUT_MAIN, OUT_SIDE>
protected transient DefaultRuntimeContext context;
- protected transient DefaultPartitionedContext partitionedContext;
+ protected transient DefaultTwoOutputPartitionedContext<OUT_MAIN, OUT_SIDE> partitionedContext;
protected transient TwoOutputNonPartitionedContext<OUT_MAIN, OUT_SIDE> nonPartitionedContext;
protected OutputTag<OUT_SIDE> outputTag;
+ protected transient Map<String, AbstractInternalWatermarkDeclaration<?>>
+ watermarkDeclarationMap;
+
public TwoOutputProcessOperator(
TwoOutputStreamProcessFunction<IN, OUT_MAIN, OUT_SIDE> userFunction,
OutputTag<OUT_SIDE> outputTag) {
@@ -85,15 +95,23 @@ public void open() throws Exception {
taskInfo.getIndexOfThisSubtask(),
taskInfo.getAttemptNumber(),
operatorContext.getMetricGroup());
+
+ watermarkDeclarationMap =
+ config.getWatermarkDeclarations(getUserCodeClassloader()).stream()
+ .collect(
+ Collectors.toMap(
+ AbstractInternalWatermarkDeclaration::getIdentifier,
+ Function.identity()));
this.partitionedContext =
- new DefaultPartitionedContext(
+ new DefaultTwoOutputPartitionedContext<>(
context,
this::currentKey,
getProcessorWithKey(),
getProcessingTimeManager(),
operatorContext,
operatorStateStore);
this.nonPartitionedContext = getNonPartitionedContext();
+ this.partitionedContext.setNonPartitionedContext(nonPartitionedContext);
this.userFunction.open(this.nonPartitionedContext);
}
@@ -105,6 +123,23 @@ public void processElement(StreamRecord<IN> element) throws Exception {
element.getValue(), mainCollector, sideCollector, partitionedContext);
}
+ @Override
+ public void processWatermarkInternal(WatermarkEvent watermark) throws Exception {
+ WatermarkHandlingResult watermarkHandlingResultByUserFunction =
+ userFunction.onWatermark(
+ watermark.getWatermark(),
+ mainCollector,
+ sideCollector,
+ nonPartitionedContext);
+ if (watermarkHandlingResultByUserFunction == WatermarkHandlingResult.PEEK
+ && watermarkDeclarationMap
+ .get(watermark.getWatermark().getIdentifier())
+ .getDefaultHandlingStrategy()
+ == WatermarkHandlingStrategy.FORWARD) {
+ output.emitWatermark(watermark);
+ }
+ }
+
@Override
public void endInput() throws Exception {
userFunction.endInput(nonPartitionedContext);
@@ -139,7 +174,14 @@ protected BiConsumer<Runnable, Object> getProcessorWithKey() {
protected TwoOutputNonPartitionedContext<OUT_MAIN, OUT_SIDE> getNonPartitionedContext() {
return new DefaultTwoOutputNonPartitionedContext<>(
- context, partitionedContext, mainCollector, sideCollector, false, null);
+ context,
+ partitionedContext,
+ mainCollector,
+ sideCollector,
+ false,
+ null,
+ output,
+ watermarkDeclarationMap);
}
protected ProcessingTimeManager getProcessingTimeManager() {
diff --git a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/watermark/DefaultWatermarkManager.java b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/watermark/DefaultWatermarkManager.java
new file mode 100644
--- /dev/null
+++ b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/watermark/DefaultWatermarkManager.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.datastream.impl.watermark;
+
+import org.apache.flink.api.common.watermark.Watermark;
+import org.apache.flink.api.common.watermark.WatermarkManager;
+import org.apache.flink.runtime.event.WatermarkEvent;
+import org.apache.flink.streaming.api.operators.Output;
+import org.apache.flink.streaming.runtime.watermark.AbstractInternalWatermarkDeclaration;
+import org.apache.flink.util.Preconditions;
+
+import java.util.Map;
+
+/** A default implementation of {@link WatermarkManager}. */
+public class DefaultWatermarkManager implements WatermarkManager {
+
+ private final Output<?> streamRecordOutput;
+
+ private final Map<String, AbstractInternalWatermarkDeclaration<?>> watermarkDeclarationMap;
+
+ public DefaultWatermarkManager(
+ Output<?> streamRecordOutput,
+ Map<String, AbstractInternalWatermarkDeclaration<?>> watermarkDeclarationMap) {
+ this.streamRecordOutput = streamRecordOutput;
+ this.watermarkDeclarationMap = watermarkDeclarationMap;
+ }
+
+ @Override
+ public void emitWatermark(Watermark watermark) {
+ Preconditions.checkState(
+ watermarkDeclarationMap.containsKey(watermark.getIdentifier()),
+ "Watermark identifier "
+ + watermark.getIdentifier()
+ + " does not exist, please declare it.");
+
+ streamRecordOutput.emitWatermark(
+ new WatermarkEvent(
+ watermark,
+ watermarkDeclarationMap.get(watermark.getIdentifier()).isAligned()));
+ }
+}
diff --git a/flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/output/operators/StateBootstrapWrapperOperator.java b/flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/output/operators/StateBootstrapWrapperOperator.java
--- a/flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/output/operators/StateBootstrapWrapperOperator.java
+++ b/flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/output/operators/StateBootstrapWrapperOperator.java
@@ -22,6 +22,7 @@
import org.apache.flink.core.fs.Path;
import org.apache.flink.metrics.groups.OperatorMetricGroup;
import org.apache.flink.runtime.checkpoint.CheckpointOptions;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.runtime.jobgraph.OperatorID;
import org.apache.flink.runtime.state.CheckpointStreamFactory;
import org.apache.flink.state.api.output.SnapshotUtils;
@@ -206,6 +207,9 @@ public void emitLatencyMarker(LatencyMarker latencyMarker) {}
@Override
public void emitRecordAttributes(RecordAttributes recordAttributes) {}
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) {}
+
@Override
public void collect(T record) {}
diff --git a/flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/output/operators/StateBootstrapWrapperOperatorFactory.java b/flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/output/operators/StateBootstrapWrapperOperatorFactory.java
--- a/flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/output/operators/StateBootstrapWrapperOperatorFactory.java
+++ b/flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/output/operators/StateBootstrapWrapperOperatorFactory.java
@@ -19,6 +19,7 @@
package org.apache.flink.state.api.output.operators;
import org.apache.flink.core.fs.Path;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.state.api.output.TaggedOperatorSubtaskState;
import org.apache.flink.streaming.api.operators.AbstractStreamOperator;
import org.apache.flink.streaming.api.operators.AbstractStreamOperatorFactory;
@@ -96,6 +97,9 @@ public void emitLatencyMarker(LatencyMarker latencyMarker) {}
@Override
public void emitRecordAttributes(RecordAttributes recordAttributes) {}
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) {}
+
@Override
public void collect(T record) {}
diff --git a/flink-runtime/pom.xml b/flink-runtime/pom.xml
--- a/flink-runtime/pom.xml
+++ b/flink-runtime/pom.xml
@@ -56,6 +56,12 @@ under the License.
<dependencies>
+ <dependency>
+ <groupId>org.apache.flink</groupId>
+ <artifactId>flink-datastream-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
<!-- core dependencies -->
<dependency>
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/asyncprocessing/operators/AbstractAsyncStateStreamOperator.java b/flink-runtime/src/main/java/org/apache/flink/runtime/asyncprocessing/operators/AbstractAsyncStateStreamOperator.java
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/asyncprocessing/operators/AbstractAsyncStateStreamOperator.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/asyncprocessing/operators/AbstractAsyncStateStreamOperator.java
@@ -29,6 +29,7 @@
import org.apache.flink.runtime.asyncprocessing.AsyncStateException;
import org.apache.flink.runtime.asyncprocessing.RecordContext;
import org.apache.flink.runtime.asyncprocessing.declare.DeclarationManager;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.runtime.execution.Environment;
import org.apache.flink.runtime.state.AsyncKeyedStateBackend;
import org.apache.flink.runtime.state.v2.StateDescriptor;
@@ -480,6 +481,48 @@ public void processRecordAttributes2(RecordAttributes recordAttributes) {
null, () -> super.processRecordAttributes2(recordAttributes));
}
+ public void processWatermarkInternal(WatermarkEvent watermark) throws Exception {
+ super.processWatermark(watermark);
+ }
+
+ public void processWatermark1Internal(WatermarkEvent watermark) throws Exception {
+ super.processWatermark1(watermark);
+ }
+
+ public void processWatermark2Internal(WatermarkEvent watermark) throws Exception {
+ super.processWatermark2(watermark);
+ }
+
+ @Override
+ public void processWatermark(WatermarkEvent watermark) throws Exception {
+ if (!isAsyncStateProcessingEnabled()) {
+ this.processWatermarkInternal(watermark);
+ return;
+ }
+ asyncExecutionController.processNonRecord(
+ null, () -> this.processWatermarkInternal(watermark));
+ }
+
+ @Override
+ public void processWatermark1(WatermarkEvent watermark) throws Exception {
+ if (!isAsyncStateProcessingEnabled()) {
+ this.processWatermark1Internal(watermark);
+ return;
+ }
+ asyncExecutionController.processNonRecord(
+ null, () -> this.processWatermark1Internal(watermark));
+ }
+
+ @Override
+ public void processWatermark2(WatermarkEvent watermark) throws Exception {
+ if (!isAsyncStateProcessingEnabled()) {
+ this.processWatermark2Internal(watermark);
+ return;
+ }
+ asyncExecutionController.processNonRecord(
+ null, () -> this.processWatermark2Internal(watermark));
+ }
+
@VisibleForTesting
AsyncExecutionController<?> getAsyncExecutionController() {
return asyncExecutionController;
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/asyncprocessing/operators/TimestampedCollectorWithDeclaredVariable.java b/flink-runtime/src/main/java/org/apache/flink/runtime/asyncprocessing/operators/TimestampedCollectorWithDeclaredVariable.java
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/asyncprocessing/operators/TimestampedCollectorWithDeclaredVariable.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/asyncprocessing/operators/TimestampedCollectorWithDeclaredVariable.java
@@ -22,6 +22,7 @@
import org.apache.flink.api.common.typeutils.base.LongSerializer;
import org.apache.flink.runtime.asyncprocessing.declare.DeclarationContext;
import org.apache.flink.runtime.asyncprocessing.declare.DeclaredVariable;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.streaming.api.operators.Output;
import org.apache.flink.streaming.api.watermark.Watermark;
import org.apache.flink.streaming.runtime.streamrecord.LatencyMarker;
@@ -126,4 +127,9 @@ public void emitLatencyMarker(LatencyMarker latencyMarker) {
public void emitRecordAttributes(RecordAttributes recordAttributes) {
output.emitRecordAttributes(recordAttributes);
}
+
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) {
+ output.emitWatermark(watermark);
+ }
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/event/WatermarkEvent.java b/flink-runtime/src/main/java/org/apache/flink/runtime/event/WatermarkEvent.java
new file mode 100644
--- /dev/null
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/event/WatermarkEvent.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.event;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.watermark.BoolWatermark;
+import org.apache.flink.api.common.watermark.LongWatermark;
+import org.apache.flink.api.common.watermark.Watermark;
+import org.apache.flink.core.memory.DataInputView;
+import org.apache.flink.core.memory.DataOutputView;
+
+import java.io.IOException;
+import java.util.Objects;
+
+/**
+ * This event wraps the {@link Watermark}, it is used in propagate {@link Watermark} between shuffle
+ * components, and should not be visible to operators and functions.
+ */
+@Internal
+public class WatermarkEvent extends RuntimeEvent {
+
+ private static final int TAG_LONG_GENERALIZED_WATERMARK = 0;
+ private static final int TAG_BOOL_GENERALIZED_WATERMARK = 1;
+
+ private Watermark watermark;
+ private boolean isAligned = false;
+
+ public WatermarkEvent() {}
+
+ public WatermarkEvent(Watermark watermark, boolean isAligned) {
+ this.watermark = watermark;
+ this.isAligned = isAligned;
+ }
+
+ @Override
+ public void write(DataOutputView out) throws IOException {
+ // write watermark identifier
+ out.writeUTF(watermark.getIdentifier());
+ // write align flag
+ out.writeBoolean(isAligned);
+ // write watermark class tag
+ // write watermark value
+ if (watermark instanceof LongWatermark) {
+ out.writeInt(TAG_LONG_GENERALIZED_WATERMARK);
+ out.writeLong(((LongWatermark) watermark).getValue());
+ } else if (watermark instanceof BoolWatermark) {
+ out.writeInt(TAG_BOOL_GENERALIZED_WATERMARK);
+ out.writeBoolean(((BoolWatermark) watermark).getValue());
+ } else {
+ throw new IllegalArgumentException(
+ "Unsupported watermark type: " + watermark.getClass());
+ }
+ }
+
+ @Override
+ public void read(DataInputView in) throws IOException {
+ // read watermark identifier
+ String identifier = in.readUTF();
+ // read align flag
+ this.isAligned = in.readBoolean();
+
+ // read watermark class tag
+ int watermarkTypeTag = in.readInt();
+
+ // read watermark value
+ if (watermarkTypeTag == TAG_LONG_GENERALIZED_WATERMARK) {
+ long value = in.readLong();
+ this.watermark = new LongWatermark(value, identifier);
+ } else if (watermarkTypeTag == TAG_BOOL_GENERALIZED_WATERMARK) {
+ boolean value = in.readBoolean();
+ this.watermark = new BoolWatermark(value, identifier);
+ } else {
+ throw new IllegalArgumentException("Unknown watermark class tag: " + watermarkTypeTag);
+ }
+ }
+
+ public Watermark getWatermark() {
+ return watermark;
+ }
+
+ public boolean isAligned() {
+ return isAligned;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ WatermarkEvent that = (WatermarkEvent) o;
+ return isAligned == that.isAligned && Objects.equals(watermark, that.watermark);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(watermark, isAligned);
+ }
+
+ @Override
+ public String toString() {
+ return "WatermarkEvent{"
+ + "watermarkElement="
+ + watermark
+ + ", isAligned="
+ + isAligned
+ + '}';
+ }
+}
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/api/serialization/EventSerializer.java b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/api/serialization/EventSerializer.java
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/api/serialization/EventSerializer.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/api/serialization/EventSerializer.java
@@ -28,6 +28,7 @@
import org.apache.flink.runtime.checkpoint.SavepointType;
import org.apache.flink.runtime.checkpoint.SnapshotType;
import org.apache.flink.runtime.event.AbstractEvent;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.runtime.io.network.api.CancelCheckpointMarker;
import org.apache.flink.runtime.io.network.api.CheckpointBarrier;
import org.apache.flink.runtime.io.network.api.EndOfData;
@@ -81,6 +82,8 @@ public class EventSerializer {
private static final int RECOVERY_METADATA = 10;
+ private static final int GENERALIZED_WATERMARK_EVENT = 11;
+
private static final byte CHECKPOINT_TYPE_CHECKPOINT = 0;
private static final byte CHECKPOINT_TYPE_SAVEPOINT = 1;
@@ -154,6 +157,15 @@ public static ByteBuffer toSerializedEvent(AbstractEvent event) throws IOExcepti
buf.putInt(0, RECOVERY_METADATA);
buf.putInt(4, recoveryMetadata.getFinalBufferSubpartitionId());
return buf;
+ } else if (eventClass == WatermarkEvent.class) {
+ try {
+ final DataOutputSerializer serializer = new DataOutputSerializer(128);
+ serializer.writeInt(GENERALIZED_WATERMARK_EVENT);
+ event.write(serializer);
+ return serializer.wrapAsByteBuffer();
+ } catch (IOException e) {
+ throw new IOException("Error while serializing event.", e);
+ }
} else {
try {
final DataOutputSerializer serializer = new DataOutputSerializer(128);
@@ -203,6 +215,11 @@ public static AbstractEvent fromSerializedEvent(ByteBuffer buffer, ClassLoader c
} else if (type == RECOVERY_METADATA) {
int subpartitionId = buffer.getInt();
return new RecoveryMetadata(subpartitionId);
+ } else if (type == GENERALIZED_WATERMARK_EVENT) {
+ final DataInputDeserializer deserializer = new DataInputDeserializer(buffer);
+ WatermarkEvent watermarkEvent = new WatermarkEvent();
+ watermarkEvent.read(deserializer);
+ return watermarkEvent;
} else if (type == OTHER_EVENT) {
try {
final DataInputDeserializer deserializer = new DataInputDeserializer(buffer);
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/buffer/Buffer.java b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/buffer/Buffer.java
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/buffer/Buffer.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/buffer/Buffer.java
@@ -20,6 +20,7 @@
import org.apache.flink.core.memory.MemorySegment;
import org.apache.flink.runtime.event.AbstractEvent;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.runtime.io.network.api.CheckpointBarrier;
import org.apache.flink.runtime.io.network.api.EndOfData;
import org.apache.flink.runtime.io.network.api.EndOfPartitionEvent;
@@ -328,7 +329,19 @@ enum DataType {
END_OF_PARTITION(false, true, false, false, false, false),
/** Contains the metadata used during a recovery process. */
- RECOVERY_METADATA(false, true, false, false, false, false);
+ RECOVERY_METADATA(false, true, false, false, false, false),
+
+ /**
+ * {@link #ALIGNED_WATERMARK_EVENT} indicates that this buffer represents a serialized
+ * {@link WatermarkEvent}, which needs to be aligned.
+ */
+ ALIGNED_WATERMARK_EVENT(false, true, true, false, false, false),
+
+ /**
+ * {@link #UNALIGNED_WATERMARK_EVENT} indicates that this buffer represents a serialized
+ * {@link WatermarkEvent}, which does not need to be aligned.
+ */
+ UNALIGNED_WATERMARK_EVENT(false, true, false, false, false, false);
private final boolean isBuffer;
private final boolean isEvent;
@@ -401,6 +414,12 @@ public static DataType getDataType(AbstractEvent event, boolean hasPriority) {
return END_OF_DATA;
} else if (event instanceof EndOfPartitionEvent) {
return END_OF_PARTITION;
+ } else if (event instanceof WatermarkEvent) {
+ if (((WatermarkEvent) event).isAligned()) {
+ return ALIGNED_WATERMARK_EVENT;
+ } else {
+ return UNALIGNED_WATERMARK_EVENT;
+ }
} else if (!(event instanceof CheckpointBarrier)) {
return EVENT_BUFFER;
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/InputGate.java b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/InputGate.java
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/InputGate.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/InputGate.java
@@ -131,6 +131,8 @@ public CompletableFuture<?> getAvailableFuture() {
return availabilityHelper.getAvailableFuture();
}
+ public abstract void resumeGateConsumption() throws IOException;
+
public abstract void resumeConsumption(InputChannelInfo channelInfo) throws IOException;
public abstract void acknowledgeAllRecordsProcessed(InputChannelInfo channelInfo)
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/SingleInputGate.java b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/SingleInputGate.java
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/SingleInputGate.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/SingleInputGate.java
@@ -1130,6 +1130,13 @@ public void sendTaskEvent(TaskEvent event) throws IOException {
}
}
+ public void resumeGateConsumption() throws IOException {
+ checkState(!isFinished(), "InputGate already finished.");
+ for (InputChannel inputChannel : channels) {
+ inputChannel.resumeConsumption();
+ }
+ }
+
@Override
public void resumeConsumption(InputChannelInfo channelInfo) throws IOException {
checkState(!isFinished(), "InputGate already finished.");
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/UnionInputGate.java b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/UnionInputGate.java
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/UnionInputGate.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/UnionInputGate.java
@@ -320,6 +320,12 @@ public void sendTaskEvent(TaskEvent event) throws IOException {
}
}
+ public void resumeGateConsumption() throws IOException {
+ for (Map.Entry<Integer, InputGate> entry : inputGatesByGateIndex.entrySet()) {
+ entry.getValue().resumeGateConsumption();
+ }
+ }
+
@Override
public void resumeConsumption(InputChannelInfo channelInfo) throws IOException {
inputGatesByGateIndex.get(channelInfo.getGateIdx()).resumeConsumption(channelInfo);
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/taskmanager/InputGateWithMetrics.java b/flink-runtime/src/main/java/org/apache/flink/runtime/taskmanager/InputGateWithMetrics.java
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/taskmanager/InputGateWithMetrics.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/taskmanager/InputGateWithMetrics.java
@@ -55,6 +55,10 @@ public CompletableFuture<?> getAvailableFuture() {
return inputGate.getAvailableFuture();
}
+ public void resumeGateConsumption() throws IOException {
+ inputGate.resumeGateConsumption();
+ }
+
@Override
public void resumeConsumption(InputChannelInfo channelInfo) throws IOException {
inputGate.resumeConsumption(channelInfo);
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamConfig.java b/flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamConfig.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamConfig.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamConfig.java
@@ -38,6 +38,7 @@
import org.apache.flink.streaming.api.operators.StreamOperator;
import org.apache.flink.streaming.api.operators.StreamOperatorFactory;
import org.apache.flink.streaming.runtime.tasks.StreamTaskException;
+import org.apache.flink.streaming.runtime.watermark.AbstractInternalWatermarkDeclaration;
import org.apache.flink.util.ClassLoaderUtil;
import org.apache.flink.util.InstantiationUtil;
import org.apache.flink.util.OutputTag;
@@ -49,6 +50,7 @@
import java.io.Serializable;
import java.time.Duration;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -133,6 +135,15 @@ public class StreamConfig implements Serializable {
private static final String ATTRIBUTE = "attribute";
+ private static final String WATERMARK_DECLARATIONS = "watermarkDeclarations";
+
+ /**
+ * To reduce the deserialization overhead of reading the WatermarkDeclaration, we'll store the
+ * result after the first deserialization, and return it directly in subsequent reading
+ * requests.
+ */
+ private Set<AbstractInternalWatermarkDeclaration<?>> deserializedWatermarkDeclarations;
+
private static final ConfigOption<Boolean> STATE_BACKEND_USE_MANAGED_MEMORY =
ConfigOptions.key("statebackend.useManagedMemory")
.booleanType()
@@ -331,6 +342,28 @@ public <T> TypeSerializer<T> getTypeSerializerSideOut(OutputTag<?> outputTag, Cl
}
}
+ public void setWatermarkDeclarations(byte[] serializedWatermarkDeclarations) {
+ if (serializedWatermarkDeclarations != null) {
+ config.setBytes(WATERMARK_DECLARATIONS, serializedWatermarkDeclarations);
+ }
+ }
+
+ public Set<AbstractInternalWatermarkDeclaration<?>> getWatermarkDeclarations(ClassLoader cl) {
+ if (deserializedWatermarkDeclarations != null) {
+ return deserializedWatermarkDeclarations;
+ }
+
+ try {
+ Set<AbstractInternalWatermarkDeclaration<?>> watermarkDeclarations =
+ InstantiationUtil.readObjectFromConfig(this.config, WATERMARK_DECLARATIONS, cl);
+ deserializedWatermarkDeclarations =
+ watermarkDeclarations == null ? Collections.emptySet() : watermarkDeclarations;
+ return deserializedWatermarkDeclarations;
+ } catch (Exception e) {
+ throw new StreamTaskException("Could not instantiate serializer.", e);
+ }
+ }
+
public void setupNetworkInputs(TypeSerializer<?>... serializers) {
InputConfig[] inputs = new InputConfig[serializers.length];
for (int i = 0; i < serializers.length; i++) {
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamGraph.java b/flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamGraph.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamGraph.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamGraph.java
@@ -75,7 +75,9 @@
import org.apache.flink.streaming.runtime.tasks.OneInputStreamTask;
import org.apache.flink.streaming.runtime.tasks.SourceOperatorStreamTask;
import org.apache.flink.streaming.runtime.tasks.SourceStreamTask;
+import org.apache.flink.streaming.runtime.tasks.StreamTaskException;
import org.apache.flink.streaming.runtime.tasks.TwoInputStreamTask;
+import org.apache.flink.streaming.runtime.watermark.AbstractInternalWatermarkDeclaration;
import org.apache.flink.util.FlinkRuntimeException;
import org.apache.flink.util.InstantiationUtil;
import org.apache.flink.util.OutputTag;
@@ -110,6 +112,7 @@
import java.util.stream.Collectors;
import static org.apache.flink.runtime.jobgraph.tasks.CheckpointCoordinatorConfiguration.MINIMAL_CHECKPOINT_TIME;
+import static org.apache.flink.streaming.util.watermark.WatermarkUtils.getInternalWatermarkDeclarationsFromStreamGraph;
import static org.apache.flink.util.Preconditions.checkArgument;
import static org.apache.flink.util.Preconditions.checkNotNull;
@@ -191,6 +194,10 @@ public class StreamGraph implements Pipeline, ExecutionPlan {
private final Map<Integer, ResourceSpec> streamNodeMinResources = new HashMap<>();
+ // Serialized watermark declarations of the StreamGraph, which may be null if no watermark is
+ // declared
+ private byte[] serializedWatermarkDeclarations;
+
public StreamGraph(
Configuration jobConfiguration,
ExecutionConfig executionConfig,
@@ -1491,6 +1498,24 @@ private void addNodesThatHaveNoNewPredecessors(
}
}
+ public void serializeAndSaveWatermarkDeclarations() {
+ Set<AbstractInternalWatermarkDeclaration<?>> watermarkDeclarations =
+ getInternalWatermarkDeclarationsFromStreamGraph(this);
+ if (!watermarkDeclarations.isEmpty()) {
+ try {
+ this.serializedWatermarkDeclarations =
+ InstantiationUtil.serializeObject(watermarkDeclarations);
+ } catch (IOException e) {
+ throw new StreamTaskException("Could not serialize watermark declarations.", e);
+ }
+ }
+ }
+
+ /** Get serialized watermark declarations, note that it may be null. */
+ public byte[] getSerializedWatermarkDeclarations() {
+ return serializedWatermarkDeclarations;
+ }
+
@Override
public String toString() {
return "StreamGraph(jobId: " + jobId + ")";
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamGraphGenerator.java b/flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamGraphGenerator.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamGraphGenerator.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamGraphGenerator.java
@@ -289,6 +289,8 @@ public StreamGraph generate() {
streamGraph.addUserArtifact(entry.getKey(), entry.getValue());
}
+ streamGraph.serializeAndSaveWatermarkDeclarations();
+
final StreamGraph builtStreamGraph = streamGraph;
alreadyTransformed.clear();
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamNode.java b/flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamNode.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamNode.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamNode.java
@@ -274,7 +274,6 @@ public void setBufferTimeout(Long bufferTimeout) {
this.bufferTimeout = bufferTimeout;
}
- @VisibleForTesting
public StreamOperator<?> getOperator() {
assert operatorFactory != null && operatorFactory instanceof SimpleOperatorFactory;
return (StreamOperator<?>) ((SimpleOperatorFactory) operatorFactory).getOperator();
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamingJobGraphGenerator.java b/flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamingJobGraphGenerator.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamingJobGraphGenerator.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamingJobGraphGenerator.java
@@ -754,6 +754,7 @@ public static List<StreamEdge> createChain(
tryConvertPartitionerForDynamicGraph(
chainableOutputs, nonChainableOutputs, jobVertexBuildContext);
config.setAttribute(currentNodeAttribute);
+ config.setWatermarkDeclarations(streamGraph.getSerializedWatermarkDeclarations());
setOperatorConfig(currentNodeId, config, chainInfo, jobVertexBuildContext);
setOperatorChainedOutputsConfig(config, chainableOutputs, jobVertexBuildContext);
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/AbstractStreamOperator.java b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/AbstractStreamOperator.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/AbstractStreamOperator.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/AbstractStreamOperator.java
@@ -37,6 +37,7 @@
import org.apache.flink.metrics.MetricGroup;
import org.apache.flink.metrics.groups.OperatorMetricGroup;
import org.apache.flink.runtime.checkpoint.CheckpointOptions;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.runtime.execution.Environment;
import org.apache.flink.runtime.jobgraph.OperatorID;
import org.apache.flink.runtime.metrics.groups.InternalOperatorMetricGroup;
@@ -751,4 +752,19 @@ public void processRecordAttributes2(RecordAttributes recordAttributes) {
Arrays.asList(lastRecordAttributes1, lastRecordAttributes2))
.build());
}
+
+ @Experimental
+ public void processWatermark(WatermarkEvent watermark) throws Exception {
+ output.emitWatermark(watermark);
+ }
+
+ @Experimental
+ public void processWatermark1(WatermarkEvent watermark) throws Exception {
+ output.emitWatermark(watermark);
+ }
+
+ @Experimental
+ public void processWatermark2(WatermarkEvent watermark) throws Exception {
+ output.emitWatermark(watermark);
+ }
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/CountingOutput.java b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/CountingOutput.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/CountingOutput.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/CountingOutput.java
@@ -20,6 +20,7 @@
import org.apache.flink.metrics.Counter;
import org.apache.flink.metrics.Gauge;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.streaming.api.watermark.Watermark;
import org.apache.flink.streaming.runtime.streamrecord.LatencyMarker;
import org.apache.flink.streaming.runtime.streamrecord.RecordAttributes;
@@ -80,4 +81,9 @@ public Gauge<Long> getWatermarkGauge() {
public void emitRecordAttributes(RecordAttributes recordAttributes) {
output.emitRecordAttributes(recordAttributes);
}
+
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) {
+ output.emitWatermark(watermark);
+ }
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/Input.java b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/Input.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/Input.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/Input.java
@@ -20,6 +20,7 @@
import org.apache.flink.annotation.Experimental;
import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.streaming.api.watermark.Watermark;
import org.apache.flink.streaming.runtime.streamrecord.LatencyMarker;
import org.apache.flink.streaming.runtime.streamrecord.RecordAttributes;
@@ -78,4 +79,11 @@ public interface Input<IN> {
*/
@Experimental
default void processRecordAttributes(RecordAttributes recordAttributes) throws Exception {}
+
+ /**
+ * Processes a {@link org.apache.flink.api.common.watermark.Watermark} that arrived at this
+ * input, wrapped in a {@link WatermarkEvent}.
+ */
+ @Experimental
+ default void processWatermark(WatermarkEvent watermark) throws Exception {}
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/KeyedProcessOperator.java b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/KeyedProcessOperator.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/KeyedProcessOperator.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/KeyedProcessOperator.java
@@ -18,6 +18,7 @@
package org.apache.flink.streaming.api.operators;
import org.apache.flink.annotation.Internal;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.runtime.state.VoidNamespace;
import org.apache.flink.runtime.state.VoidNamespaceSerializer;
import org.apache.flink.streaming.api.SimpleTimerService;
@@ -68,6 +69,11 @@ public void onEventTime(InternalTimer<K, VoidNamespace> timer) throws Exception
invokeUserFunction(TimeDomain.EVENT_TIME, timer);
}
+ @Override
+ public void processWatermark(WatermarkEvent watermark) throws Exception {
+ output.emitWatermark(watermark);
+ }
+
@Override
public void onProcessingTime(InternalTimer<K, VoidNamespace> timer) throws Exception {
collector.eraseTimestamp();
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/Output.java b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/Output.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/Output.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/Output.java
@@ -20,6 +20,7 @@
import org.apache.flink.annotation.Experimental;
import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.streaming.api.watermark.Watermark;
import org.apache.flink.streaming.runtime.streamrecord.LatencyMarker;
import org.apache.flink.streaming.runtime.streamrecord.RecordAttributes;
@@ -64,4 +65,11 @@ public interface Output<T> extends Collector<T> {
*/
@Experimental
void emitRecordAttributes(RecordAttributes recordAttributes);
+
+ /**
+ * Emits a {@link org.apache.flink.api.common.watermark.Watermark} from an operator, wrapped in
+ * a {@link WatermarkEvent}.
+ */
+ @Experimental
+ void emitWatermark(WatermarkEvent watermark);
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/SourceOperator.java b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/SourceOperator.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/SourceOperator.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/SourceOperator.java
@@ -34,6 +34,7 @@
import org.apache.flink.core.io.InputStatus;
import org.apache.flink.core.io.SimpleVersionedSerializer;
import org.apache.flink.metrics.groups.SourceReaderMetricGroup;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.runtime.io.AvailabilityProvider;
import org.apache.flink.runtime.io.network.api.StopMode;
import org.apache.flink.runtime.metrics.groups.InternalSourceReaderMetricGroup;
@@ -205,6 +206,9 @@ private enum OperatingMode {
*/
private transient PausableRelativeClock mainInputActivityClock;
+ /** Watermark identifier to whether the watermark are aligned. */
+ private final Map<String, Boolean> watermarkIsAlignedMap;
+
public SourceOperator(
StreamOperatorParameters<OUT> parameters,
FunctionWithException<SourceReaderContext, SourceReader<OUT, SplitT>, Exception>
@@ -216,7 +220,8 @@ public SourceOperator(
Configuration configuration,
String localHostname,
boolean emitProgressiveWatermarks,
- CanEmitBatchOfRecordsChecker canEmitBatchOfRecords) {
+ CanEmitBatchOfRecordsChecker canEmitBatchOfRecords,
+ Map<String, Boolean> watermarkIsAlignedMap) {
super(parameters);
this.readerFactory = checkNotNull(readerFactory);
this.operatorEventGateway = checkNotNull(operatorEventGateway);
@@ -230,6 +235,7 @@ public SourceOperator(
this.watermarkAlignmentParams = watermarkStrategy.getAlignmentParameters();
this.allowUnalignedSourceSplits = configuration.get(ALLOW_UNALIGNED_SOURCE_SPLITS);
this.canEmitBatchOfRecords = checkNotNull(canEmitBatchOfRecords);
+ this.watermarkIsAlignedMap = watermarkIsAlignedMap;
}
@Override
@@ -325,6 +331,16 @@ public void registerReleaseHookIfAbsent(
public int currentParallelism() {
return getRuntimeContext().getTaskInfo().getNumberOfParallelSubtasks();
}
+
+ @Override
+ public void emitWatermark(
+ org.apache.flink.api.common.watermark.Watermark watermark) {
+ checkState(watermarkIsAlignedMap.containsKey(watermark.getIdentifier()));
+ output.emitWatermark(
+ new WatermarkEvent(
+ watermark,
+ watermarkIsAlignedMap.get(watermark.getIdentifier())));
+ }
};
sourceReader = readerFactory.apply(context);
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/SourceOperatorFactory.java b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/SourceOperatorFactory.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/SourceOperatorFactory.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/SourceOperatorFactory.java
@@ -21,6 +21,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.common.watermark.WatermarkDeclaration;
import org.apache.flink.api.connector.source.Boundedness;
import org.apache.flink.api.connector.source.Source;
import org.apache.flink.api.connector.source.SourceReader;
@@ -35,10 +36,18 @@ Licensed to the Apache Software Foundation (ASF) under one
import org.apache.flink.streaming.runtime.tasks.ProcessingTimeService;
import org.apache.flink.streaming.runtime.tasks.ProcessingTimeServiceAware;
import org.apache.flink.streaming.runtime.tasks.StreamTask.CanEmitBatchOfRecordsChecker;
+import org.apache.flink.streaming.runtime.watermark.AbstractInternalWatermarkDeclaration;
+import org.apache.flink.streaming.util.watermark.WatermarkUtils;
import org.apache.flink.util.function.FunctionWithException;
import javax.annotation.Nullable;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
import static org.apache.flink.util.Preconditions.checkNotNull;
/** The Factory class for {@link SourceOperator}. */
@@ -118,7 +127,8 @@ public <T extends StreamOperator<OUT>> T createStreamOperator(
.getTaskManagerInfo()
.getTaskManagerExternalAddress(),
emitProgressiveWatermarks,
- parameters.getContainingTask().getCanEmitBatchOfRecords());
+ parameters.getContainingTask().getCanEmitBatchOfRecords(),
+ getSourceWatermarkDeclarations());
parameters.getOperatorEventDispatcher().registerEventHandler(operatorId, sourceOperator);
@@ -165,6 +175,10 @@ public void setOutputType(TypeInformation<OUT> type, ExecutionConfig executionCo
}
}
+ public Set<? extends WatermarkDeclaration> getSourceWatermarkDeclarations() {
+ return source.declareWatermarks();
+ }
+
/**
* This is a utility method to conjure up a "SplitT" generics variable binding so that we can
* construct the SourceOperator without resorting to "all raw types". That way, this methods
@@ -184,7 +198,8 @@ SourceOperator<T, SplitT> instantiateSourceOperator(
Configuration config,
String localHostName,
boolean emitProgressiveWatermarks,
- CanEmitBatchOfRecordsChecker canEmitBatchOfRecords) {
+ CanEmitBatchOfRecordsChecker canEmitBatchOfRecords,
+ Collection<? extends WatermarkDeclaration> watermarkDeclarations) {
// jumping through generics hoops: cast the generics away to then cast them back more
// strictly typed
@@ -197,6 +212,14 @@ SourceOperator<T, SplitT> instantiateSourceOperator(
final SimpleVersionedSerializer<SplitT> typedSplitSerializer =
(SimpleVersionedSerializer<SplitT>) splitSerializer;
+ Map<String, Boolean> watermarkIsAlignedMap =
+ WatermarkUtils.convertToInternalWatermarkDeclarations(
+ new HashSet<>(watermarkDeclarations))
+ .stream()
+ .collect(
+ Collectors.toMap(
+ AbstractInternalWatermarkDeclaration::getIdentifier,
+ AbstractInternalWatermarkDeclaration::isAligned));
return new SourceOperator<>(
parameters,
typedReaderFactory,
@@ -207,6 +230,7 @@ SourceOperator<T, SplitT> instantiateSourceOperator(
config,
localHostName,
emitProgressiveWatermarks,
- canEmitBatchOfRecords);
+ canEmitBatchOfRecords,
+ watermarkIsAlignedMap);
}
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/TimestampedCollector.java b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/TimestampedCollector.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/TimestampedCollector.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/TimestampedCollector.java
@@ -19,6 +19,7 @@
package org.apache.flink.streaming.api.operators;
import org.apache.flink.annotation.Internal;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.streaming.api.watermark.Watermark;
import org.apache.flink.streaming.runtime.streamrecord.LatencyMarker;
import org.apache.flink.streaming.runtime.streamrecord.RecordAttributes;
@@ -97,4 +98,9 @@ public void emitLatencyMarker(LatencyMarker latencyMarker) {
public void emitRecordAttributes(RecordAttributes recordAttributes) {
output.emitRecordAttributes(recordAttributes);
}
+
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) {
+ output.emitWatermark(watermark);
+ }
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/TwoInputStreamOperator.java b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/TwoInputStreamOperator.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/TwoInputStreamOperator.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/TwoInputStreamOperator.java
@@ -20,6 +20,7 @@
import org.apache.flink.annotation.Experimental;
import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.streaming.api.watermark.Watermark;
import org.apache.flink.streaming.runtime.streamrecord.LatencyMarker;
import org.apache.flink.streaming.runtime.streamrecord.RecordAttributes;
@@ -114,4 +115,18 @@ default void processRecordAttributes1(RecordAttributes recordAttributes) throws
*/
@Experimental
default void processRecordAttributes2(RecordAttributes recordAttributes) throws Exception {}
+
+ /**
+ * Processes a {@link org.apache.flink.api.common.watermark.Watermark} that arrived on the first
+ * input of this operator.
+ */
+ @Experimental
+ default void processWatermark1(WatermarkEvent watermark) throws Exception {}
+
+ /**
+ * Processes a {@link org.apache.flink.api.common.watermark.Watermark} that arrived on the
+ * second input of this operator.
+ */
+ @Experimental
+ default void processWatermark2(WatermarkEvent watermark) throws Exception {}
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/sort/MultiInputSortingDataInput.java b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/sort/MultiInputSortingDataInput.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/sort/MultiInputSortingDataInput.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/sort/MultiInputSortingDataInput.java
@@ -26,6 +26,7 @@
import org.apache.flink.configuration.Configuration;
import org.apache.flink.core.memory.DataOutputSerializer;
import org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.runtime.io.AvailabilityProvider;
import org.apache.flink.runtime.io.disk.iomanager.IOManager;
import org.apache.flink.runtime.jobgraph.tasks.TaskInvokable;
@@ -433,6 +434,9 @@ public void emitRecordAttributes(RecordAttributes recordAttributes) throws Excep
// RecordAttributes is not used in batch execution mode. We will ignore all the
// RecordAttributes.
}
+
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) throws Exception {}
}
/**
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/sort/SortingDataInput.java b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/sort/SortingDataInput.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/sort/SortingDataInput.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/sort/SortingDataInput.java
@@ -28,6 +28,7 @@
import org.apache.flink.core.memory.DataOutputSerializer;
import org.apache.flink.runtime.checkpoint.CheckpointException;
import org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.runtime.io.AvailabilityProvider;
import org.apache.flink.runtime.io.disk.iomanager.IOManager;
import org.apache.flink.runtime.jobgraph.tasks.TaskInvokable;
@@ -190,6 +191,9 @@ public void emitRecordAttributes(RecordAttributes recordAttributes) {
// The SortingDataInput is only used in batch execution mode. The RecordAttributes is
// not used in batch execution mode. We will ignore all the RecordAttributes.
}
+
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) throws Exception {}
}
@Override
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/AbstractStreamTaskNetworkInput.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/AbstractStreamTaskNetworkInput.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/AbstractStreamTaskNetworkInput.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/AbstractStreamTaskNetworkInput.java
@@ -18,8 +18,10 @@
package org.apache.flink.streaming.runtime.io;
import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.api.common.watermark.Watermark;
import org.apache.flink.runtime.checkpoint.channel.InputChannelInfo;
import org.apache.flink.runtime.event.AbstractEvent;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.runtime.io.network.api.EndOfData;
import org.apache.flink.runtime.io.network.api.EndOfPartitionEvent;
import org.apache.flink.runtime.io.network.api.serialization.RecordDeserializer;
@@ -31,13 +33,18 @@
import org.apache.flink.streaming.runtime.streamrecord.StreamElement;
import org.apache.flink.streaming.runtime.streamrecord.StreamElementSerializer;
import org.apache.flink.streaming.runtime.tasks.StreamTask.CanEmitBatchOfRecordsChecker;
+import org.apache.flink.streaming.runtime.watermark.AbstractInternalWatermarkDeclaration;
+import org.apache.flink.streaming.runtime.watermark.WatermarkCombiner;
import org.apache.flink.streaming.runtime.watermarkstatus.StatusWatermarkValve;
+import org.apache.flink.util.ExceptionUtils;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
import java.util.concurrent.CompletableFuture;
import static org.apache.flink.util.Preconditions.checkNotNull;
@@ -64,6 +71,7 @@ public abstract class AbstractStreamTaskNetworkInput<
private final RecordAttributesCombiner recordAttributesCombiner;
private InputChannelInfo lastChannel = null;
private R currentRecordDeserializer = null;
+ protected final Map<String, WatermarkCombiner> watermarkCombiners = new HashMap<>();
protected final CanEmitBatchOfRecordsChecker canEmitBatchOfRecords;
@@ -74,6 +82,24 @@ public AbstractStreamTaskNetworkInput(
int inputIndex,
Map<InputChannelInfo, R> recordDeserializers,
CanEmitBatchOfRecordsChecker canEmitBatchOfRecords) {
+ this(
+ checkpointedInputGate,
+ inputSerializer,
+ statusWatermarkValve,
+ inputIndex,
+ recordDeserializers,
+ canEmitBatchOfRecords,
+ Collections.emptySet());
+ }
+
+ public AbstractStreamTaskNetworkInput(
+ CheckpointedInputGate checkpointedInputGate,
+ TypeSerializer<T> inputSerializer,
+ StatusWatermarkValve statusWatermarkValve,
+ int inputIndex,
+ Map<InputChannelInfo, R> recordDeserializers,
+ CanEmitBatchOfRecordsChecker canEmitBatchOfRecords,
+ Set<AbstractInternalWatermarkDeclaration<?>> watermarkDeclarationSet) {
super();
this.checkpointedInputGate = checkpointedInputGate;
deserializationDelegate =
@@ -91,6 +117,21 @@ public AbstractStreamTaskNetworkInput(
this.canEmitBatchOfRecords = checkNotNull(canEmitBatchOfRecords);
this.recordAttributesCombiner =
new RecordAttributesCombiner(checkpointedInputGate.getNumberOfInputChannels());
+
+ for (AbstractInternalWatermarkDeclaration<?> watermarkDeclaration :
+ watermarkDeclarationSet) {
+ watermarkCombiners.put(
+ watermarkDeclaration.getIdentifier(),
+ watermarkDeclaration.createWatermarkCombiner(
+ flattenedChannelIndices.size(),
+ () -> {
+ try {
+ checkpointedInputGate.resumeGateConsumption();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }));
+ }
}
@Override
@@ -128,7 +169,7 @@ public DataInputStatus emitNext(DataOutput<T> output) throws Exception {
if (bufferOrEvent.get().isBuffer()) {
processBuffer(bufferOrEvent.get());
} else {
- DataInputStatus status = processEvent(bufferOrEvent.get());
+ DataInputStatus status = processEvent(bufferOrEvent.get(), output);
if (status == DataInputStatus.MORE_AVAILABLE && canEmitBatchOfRecords.check()) {
continue;
}
@@ -181,7 +222,28 @@ private boolean processElement(StreamElement streamElement, DataOutput<T> output
}
}
- protected DataInputStatus processEvent(BufferOrEvent bufferOrEvent) {
+ private void processWatermarkEvent(
+ InputChannelInfo inputChannelInfo,
+ WatermarkEvent generalizedWatermarkEvent,
+ DataOutput<T> output)
+ throws Exception {
+ Watermark watermark = generalizedWatermarkEvent.getWatermark();
+ WatermarkCombiner combiner = watermarkCombiners.get(watermark.getIdentifier());
+ combiner.combineWatermark(
+ watermark,
+ inputChannelInfo.getInputChannelIdx(),
+ outputWatermark -> {
+ try {
+ output.emitWatermark(
+ new WatermarkEvent(
+ outputWatermark, generalizedWatermarkEvent.isAligned()));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ });
+ }
+
+ protected DataInputStatus processEvent(BufferOrEvent bufferOrEvent, DataOutput<T> output) {
// Event received
final AbstractEvent event = bufferOrEvent.getEvent();
if (event.getClass() == EndOfData.class) {
@@ -205,6 +267,13 @@ protected DataInputStatus processEvent(BufferOrEvent bufferOrEvent) {
if (checkpointedInputGate.allChannelsRecovered()) {
return DataInputStatus.END_OF_RECOVERY;
}
+ } else if (event.getClass() == WatermarkEvent.class) {
+ try {
+ processWatermarkEvent(
+ bufferOrEvent.getChannelInfo(), (WatermarkEvent) event, output);
+ } catch (Exception e) {
+ ExceptionUtils.rethrow(e);
+ }
}
return DataInputStatus.MORE_AVAILABLE;
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/FinishedDataOutput.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/FinishedDataOutput.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/FinishedDataOutput.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/FinishedDataOutput.java
@@ -18,6 +18,7 @@
package org.apache.flink.streaming.runtime.io;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.streaming.api.watermark.Watermark;
import org.apache.flink.streaming.runtime.streamrecord.LatencyMarker;
import org.apache.flink.streaming.runtime.streamrecord.RecordAttributes;
@@ -59,4 +60,9 @@ public void emitLatencyMarker(LatencyMarker latencyMarker) throws Exception {
public void emitRecordAttributes(RecordAttributes recordAttributes) throws Exception {
LOG.debug("Unexpected recordAttributes after finish() received.");
}
+
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) throws Exception {
+ LOG.debug("Unexpected watermark {} after finish() received.", watermark);
+ }
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/PushingAsyncDataInput.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/PushingAsyncDataInput.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/PushingAsyncDataInput.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/PushingAsyncDataInput.java
@@ -18,6 +18,7 @@
package org.apache.flink.streaming.runtime.io;
import org.apache.flink.annotation.Internal;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.runtime.io.AvailabilityProvider;
import org.apache.flink.runtime.io.PullingAsyncDataInput;
import org.apache.flink.streaming.api.watermark.Watermark;
@@ -58,5 +59,7 @@ interface DataOutput<T> {
void emitLatencyMarker(LatencyMarker latencyMarker) throws Exception;
void emitRecordAttributes(RecordAttributes recordAttributes) throws Exception;
+
+ void emitWatermark(WatermarkEvent watermark) throws Exception;
}
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/RecordWriterOutput.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/RecordWriterOutput.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/RecordWriterOutput.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/RecordWriterOutput.java
@@ -24,6 +24,7 @@
import org.apache.flink.metrics.SimpleCounter;
import org.apache.flink.runtime.checkpoint.CheckpointException;
import org.apache.flink.runtime.event.AbstractEvent;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.runtime.io.network.api.CheckpointBarrier;
import org.apache.flink.runtime.io.network.api.writer.RecordWriter;
import org.apache.flink.runtime.plugable.SerializationDelegate;
@@ -248,4 +249,21 @@ public void emitRecordAttributes(RecordAttributes recordAttributes) {
throw new UncheckedIOException(e);
}
}
+
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) {
+ if (!recordWriter.isSubpartitionDerivable()) {
+ LOG.warn(
+ watermark
+ + " will be ignored, because its correctness cannot not be "
+ + "guaranteed when the subpartition information is not derivable.");
+ return;
+ }
+
+ try {
+ recordWriter.broadcastEvent(watermark, false);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/StreamMultipleInputProcessorFactory.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/StreamMultipleInputProcessorFactory.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/StreamMultipleInputProcessorFactory.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/StreamMultipleInputProcessorFactory.java
@@ -28,6 +28,7 @@
import org.apache.flink.metrics.Counter;
import org.apache.flink.metrics.SimpleCounter;
import org.apache.flink.runtime.checkpoint.InflightDataRescalingDescriptor;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.runtime.io.disk.iomanager.IOManager;
import org.apache.flink.runtime.jobgraph.tasks.TaskInvokable;
import org.apache.flink.runtime.memory.MemoryManager;
@@ -119,7 +120,8 @@ public static StreamMultipleInputProcessor create(
inflightDataRescalingDescriptor,
gatePartitioners,
taskInfo,
- canEmitBatchOfRecords);
+ canEmitBatchOfRecords,
+ streamConfig.getWatermarkDeclarations(userClassloader));
} else if (configuredInput instanceof StreamConfig.SourceInputConfig) {
StreamConfig.SourceInputConfig sourceInput =
(StreamConfig.SourceInputConfig) configuredInput;
@@ -295,6 +297,11 @@ public void emitLatencyMarker(LatencyMarker latencyMarker) throws Exception {
public void emitRecordAttributes(RecordAttributes recordAttributes) throws Exception {
input.processRecordAttributes(recordAttributes);
}
+
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) throws Exception {
+ input.processWatermark(watermark);
+ }
}
@SuppressWarnings({"unchecked", "rawtypes"})
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/StreamTaskNetworkInput.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/StreamTaskNetworkInput.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/StreamTaskNetworkInput.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/StreamTaskNetworkInput.java
@@ -31,11 +31,14 @@
import org.apache.flink.streaming.runtime.io.checkpointing.CheckpointedInputGate;
import org.apache.flink.streaming.runtime.streamrecord.StreamElement;
import org.apache.flink.streaming.runtime.tasks.StreamTask.CanEmitBatchOfRecordsChecker;
+import org.apache.flink.streaming.runtime.watermark.AbstractInternalWatermarkDeclaration;
import org.apache.flink.streaming.runtime.watermarkstatus.StatusWatermarkValve;
import org.apache.flink.streaming.runtime.watermarkstatus.WatermarkStatus;
import java.io.IOException;
+import java.util.Collections;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.CompletableFuture;
import static java.util.function.Function.identity;
@@ -68,13 +71,32 @@ public StreamTaskNetworkInput(
StatusWatermarkValve statusWatermarkValve,
int inputIndex,
CanEmitBatchOfRecordsChecker canEmitBatchOfRecords) {
+ this(
+ checkpointedInputGate,
+ inputSerializer,
+ ioManager,
+ statusWatermarkValve,
+ inputIndex,
+ canEmitBatchOfRecords,
+ Collections.emptySet());
+ }
+
+ public StreamTaskNetworkInput(
+ CheckpointedInputGate checkpointedInputGate,
+ TypeSerializer<T> inputSerializer,
+ IOManager ioManager,
+ StatusWatermarkValve statusWatermarkValve,
+ int inputIndex,
+ CanEmitBatchOfRecordsChecker canEmitBatchOfRecords,
+ Set<AbstractInternalWatermarkDeclaration<?>> watermarkDeclarationSet) {
super(
checkpointedInputGate,
inputSerializer,
statusWatermarkValve,
inputIndex,
getRecordDeserializers(checkpointedInputGate, ioManager),
- canEmitBatchOfRecords);
+ canEmitBatchOfRecords,
+ watermarkDeclarationSet);
}
// Initialize one deserializer per input channel
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/StreamTaskNetworkInputFactory.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/StreamTaskNetworkInputFactory.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/StreamTaskNetworkInputFactory.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/StreamTaskNetworkInputFactory.java
@@ -25,8 +25,10 @@
import org.apache.flink.streaming.runtime.io.recovery.RescalingStreamTaskNetworkInput;
import org.apache.flink.streaming.runtime.partitioner.StreamPartitioner;
import org.apache.flink.streaming.runtime.tasks.StreamTask.CanEmitBatchOfRecordsChecker;
+import org.apache.flink.streaming.runtime.watermark.AbstractInternalWatermarkDeclaration;
import org.apache.flink.streaming.runtime.watermarkstatus.StatusWatermarkValve;
+import java.util.Set;
import java.util.function.Function;
/** Factory for {@link StreamTaskNetworkInput} and {@link RescalingStreamTaskNetworkInput}. */
@@ -44,7 +46,8 @@ public static <T> StreamTaskInput<T> create(
InflightDataRescalingDescriptor rescalingDescriptorinflightDataRescalingDescriptor,
Function<Integer, StreamPartitioner<?>> gatePartitioners,
TaskInfo taskInfo,
- CanEmitBatchOfRecordsChecker canEmitBatchOfRecords) {
+ CanEmitBatchOfRecordsChecker canEmitBatchOfRecords,
+ Set<AbstractInternalWatermarkDeclaration<?>> watermarkDeclarationSet) {
return rescalingDescriptorinflightDataRescalingDescriptor.equals(
InflightDataRescalingDescriptor.NO_RESCALE)
? new StreamTaskNetworkInput<>(
@@ -53,7 +56,8 @@ public static <T> StreamTaskInput<T> create(
ioManager,
statusWatermarkValve,
inputIndex,
- canEmitBatchOfRecords)
+ canEmitBatchOfRecords,
+ watermarkDeclarationSet)
: new RescalingStreamTaskNetworkInput<>(
checkpointedInputGate,
inputSerializer,
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/StreamTwoInputProcessorFactory.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/StreamTwoInputProcessorFactory.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/StreamTwoInputProcessorFactory.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/StreamTwoInputProcessorFactory.java
@@ -26,6 +26,7 @@
import org.apache.flink.core.memory.ManagedMemoryUseCase;
import org.apache.flink.metrics.Counter;
import org.apache.flink.runtime.checkpoint.InflightDataRescalingDescriptor;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.runtime.io.disk.iomanager.IOManager;
import org.apache.flink.runtime.jobgraph.tasks.TaskInvokable;
import org.apache.flink.runtime.memory.MemoryManager;
@@ -94,7 +95,8 @@ public static <IN1, IN2> StreamMultipleInputProcessor create(
inflightDataRescalingDescriptor,
gatePartitioners,
taskInfo,
- canEmitBatchOfRecords);
+ canEmitBatchOfRecords,
+ streamConfig.getWatermarkDeclarations(userClassloader));
TypeSerializer<IN2> typeSerializer2 = streamConfig.getTypeSerializerIn(1, userClassloader);
StreamTaskInput<IN2> input2 =
StreamTaskNetworkInputFactory.create(
@@ -106,7 +108,8 @@ public static <IN1, IN2> StreamMultipleInputProcessor create(
inflightDataRescalingDescriptor,
gatePartitioners,
taskInfo,
- canEmitBatchOfRecords);
+ canEmitBatchOfRecords,
+ streamConfig.getWatermarkDeclarations(userClassloader));
InputSelectable inputSelectable =
streamOperator instanceof InputSelectable ? (InputSelectable) streamOperator : null;
@@ -298,6 +301,15 @@ public void emitRecordAttributes(RecordAttributes recordAttributes) throws Excep
operator.processRecordAttributes2(recordAttributes);
}
}
+
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) throws Exception {
+ if (inputIndex == 0) {
+ operator.processWatermark1(watermark);
+ } else {
+ operator.processWatermark2(watermark);
+ }
+ }
}
private static class FinishedOnRestoreWatermarkBypass {
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/checkpointing/CheckpointedInputGate.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/checkpointing/CheckpointedInputGate.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/checkpointing/CheckpointedInputGate.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/checkpointing/CheckpointedInputGate.java
@@ -227,6 +227,10 @@ public EndOfDataStatus hasReceivedEndOfData() {
return inputGate.hasReceivedEndOfData();
}
+ public void resumeGateConsumption() throws IOException {
+ inputGate.resumeGateConsumption();
+ }
+
/**
* Cleans up all internally held resources.
*
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/recovery/RescalingStreamTaskNetworkInput.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/recovery/RescalingStreamTaskNetworkInput.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/recovery/RescalingStreamTaskNetworkInput.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/io/recovery/RescalingStreamTaskNetworkInput.java
@@ -177,15 +177,15 @@ protected DemultiplexingRecordDeserializer<T> getActiveSerializer(
return deserialier;
}
- protected DataInputStatus processEvent(BufferOrEvent bufferOrEvent) {
+ protected DataInputStatus processEvent(BufferOrEvent bufferOrEvent, DataOutput<T> output) {
// Event received
final AbstractEvent event = bufferOrEvent.getEvent();
if (event instanceof SubtaskConnectionDescriptor) {
getActiveSerializer(bufferOrEvent.getChannelInfo())
.select((SubtaskConnectionDescriptor) event);
return DataInputStatus.MORE_AVAILABLE;
}
- return super.processEvent(bufferOrEvent);
+ return super.processEvent(bufferOrEvent, output);
}
@Override
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/BroadcastingOutputCollector.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/BroadcastingOutputCollector.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/BroadcastingOutputCollector.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/BroadcastingOutputCollector.java
@@ -19,6 +19,7 @@
import org.apache.flink.metrics.Counter;
import org.apache.flink.metrics.Gauge;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.streaming.api.operators.Output;
import org.apache.flink.streaming.api.watermark.Watermark;
import org.apache.flink.streaming.runtime.metrics.WatermarkGauge;
@@ -111,4 +112,11 @@ public void emitRecordAttributes(RecordAttributes recordAttributes) {
output.emitRecordAttributes(recordAttributes);
}
}
+
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) {
+ for (OutputWithChainingCheck<StreamRecord<T>> output : outputs) {
+ output.emitWatermark(watermark);
+ }
+ }
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/ChainingOutput.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/ChainingOutput.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/ChainingOutput.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/ChainingOutput.java
@@ -21,6 +21,7 @@
import org.apache.flink.metrics.Gauge;
import org.apache.flink.metrics.SimpleCounter;
import org.apache.flink.metrics.groups.OperatorMetricGroup;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.streaming.api.operators.Input;
import org.apache.flink.streaming.api.watermark.Watermark;
import org.apache.flink.streaming.runtime.io.RecordProcessorUtils;
@@ -164,4 +165,13 @@ public void emitRecordAttributes(RecordAttributes recordAttributes) {
throw new ExceptionInChainedOperatorException(e);
}
}
+
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) {
+ try {
+ input.processWatermark(watermark);
+ } catch (Exception e) {
+ throw new ExceptionInChainedOperatorException(e);
+ }
+ }
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/FinishedOnRestoreMainOperatorOutput.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/FinishedOnRestoreMainOperatorOutput.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/FinishedOnRestoreMainOperatorOutput.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/FinishedOnRestoreMainOperatorOutput.java
@@ -19,6 +19,7 @@
package org.apache.flink.streaming.runtime.tasks;
import org.apache.flink.metrics.Gauge;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.streaming.api.watermark.Watermark;
import org.apache.flink.streaming.runtime.io.RecordWriterOutput;
import org.apache.flink.streaming.runtime.metrics.WatermarkGauge;
@@ -77,6 +78,13 @@ public void emitRecordAttributes(RecordAttributes recordAttributes) {
}
}
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) {
+ for (RecordWriterOutput<?> streamOutput : streamOutputs) {
+ streamOutput.emitWatermark(watermark);
+ }
+ }
+
@Override
public void close() {}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/OneInputStreamTask.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/OneInputStreamTask.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/OneInputStreamTask.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/OneInputStreamTask.java
@@ -23,6 +23,7 @@
import org.apache.flink.api.common.typeutils.TypeSerializer;
import org.apache.flink.core.memory.ManagedMemoryUseCase;
import org.apache.flink.metrics.Counter;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.runtime.execution.Environment;
import org.apache.flink.runtime.io.network.partition.consumer.IndexedInputGate;
import org.apache.flink.runtime.metrics.MetricNames;
@@ -44,6 +45,7 @@
import org.apache.flink.streaming.runtime.streamrecord.LatencyMarker;
import org.apache.flink.streaming.runtime.streamrecord.RecordAttributes;
import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.streaming.runtime.watermark.AbstractInternalWatermarkDeclaration;
import org.apache.flink.streaming.runtime.watermarkstatus.StatusWatermarkValve;
import org.apache.flink.streaming.runtime.watermarkstatus.WatermarkStatus;
import org.apache.flink.util.function.ThrowingConsumer;
@@ -56,6 +58,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
+import java.util.Set;
import static org.apache.flink.streaming.api.graph.StreamConfig.requiresSorting;
import static org.apache.flink.util.Preconditions.checkNotNull;
@@ -195,6 +198,9 @@ private StreamTaskInput<IN> createTaskInput(CheckpointedInputGate inputGate) {
TypeSerializer<IN> inSerializer =
configuration.getTypeSerializerIn1(getUserCodeClassLoader());
+ Set<AbstractInternalWatermarkDeclaration<?>> watermarkDeclarationSet =
+ configuration.getWatermarkDeclarations(getUserCodeClassLoader());
+
return StreamTaskNetworkInputFactory.create(
inputGate,
inSerializer,
@@ -208,7 +214,8 @@ private StreamTaskInput<IN> createTaskInput(CheckpointedInputGate inputGate) {
.get(gateIndex)
.getPartitioner(),
getEnvironment().getTaskInfo(),
- getCanEmitBatchOfRecords());
+ getCanEmitBatchOfRecords(),
+ watermarkDeclarationSet);
}
/**
@@ -258,5 +265,10 @@ public void emitLatencyMarker(LatencyMarker latencyMarker) throws Exception {
public void emitRecordAttributes(RecordAttributes recordAttributes) throws Exception {
operator.processRecordAttributes(recordAttributes);
}
+
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) throws Exception {
+ operator.processWatermark(watermark);
+ }
}
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/SourceOperatorStreamTask.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/SourceOperatorStreamTask.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/SourceOperatorStreamTask.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/SourceOperatorStreamTask.java
@@ -25,6 +25,7 @@
import org.apache.flink.runtime.checkpoint.CheckpointOptions;
import org.apache.flink.runtime.checkpoint.SavepointType;
import org.apache.flink.runtime.checkpoint.SnapshotType;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.runtime.execution.Environment;
import org.apache.flink.runtime.io.network.api.StopMode;
import org.apache.flink.runtime.metrics.MetricNames;
@@ -324,6 +325,11 @@ public void emitRecordAttributes(RecordAttributes recordAttributes) {
output.emitRecordAttributes(recordAttributes);
}
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) throws Exception {
+ output.emitWatermark(watermark);
+ }
+
@Override
public void emitWatermark(Watermark watermark) {
long watermarkTimestamp = watermark.getTimestamp();
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/StreamIterationTail.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/StreamIterationTail.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/StreamIterationTail.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/StreamIterationTail.java
@@ -18,6 +18,7 @@
package org.apache.flink.streaming.runtime.tasks;
import org.apache.flink.annotation.Internal;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.runtime.execution.Environment;
import org.apache.flink.streaming.api.operators.AbstractStreamOperator;
import org.apache.flink.streaming.api.operators.OneInputStreamOperator;
@@ -142,6 +143,9 @@ public void emitLatencyMarker(LatencyMarker latencyMarker) {}
@Override
public void emitRecordAttributes(RecordAttributes recordAttributes) {}
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) {}
+
@Override
public void collect(StreamRecord<IN> record) {
try {
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/AbstractInternalWatermarkDeclaration.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/AbstractInternalWatermarkDeclaration.java
new file mode 100644
--- /dev/null
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/AbstractInternalWatermarkDeclaration.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.watermark;
+
+import org.apache.flink.api.common.watermark.BoolWatermarkDeclaration;
+import org.apache.flink.api.common.watermark.LongWatermarkDeclaration;
+import org.apache.flink.api.common.watermark.Watermark;
+import org.apache.flink.api.common.watermark.WatermarkCombinationPolicy;
+import org.apache.flink.api.common.watermark.WatermarkDeclaration;
+import org.apache.flink.api.common.watermark.WatermarkHandlingStrategy;
+
+/**
+ * The {@link AbstractInternalWatermarkDeclaration} class implements the {@code
+ * WatermarkDeclaration} interface and provides some internal-oriented methods, such as
+ * getting/setting the {@code align} flag and creating the {@link WatermarkCombiner}.
+ */
+public abstract class AbstractInternalWatermarkDeclaration<T> implements WatermarkDeclaration {
+
+ protected final String identifier;
+
+ protected final WatermarkCombinationPolicy combinationPolicy;
+
+ protected final WatermarkHandlingStrategy defaultHandlingStrategy;
+
+ protected final boolean isAligned;
+
+ public AbstractInternalWatermarkDeclaration(
+ String identifier,
+ WatermarkCombinationPolicy combinationPolicy,
+ WatermarkHandlingStrategy defaultHandlingStrategy,
+ boolean isAligned) {
+ this.identifier = identifier;
+ this.combinationPolicy = combinationPolicy;
+ this.defaultHandlingStrategy = defaultHandlingStrategy;
+ this.isAligned = isAligned;
+ }
+
+ @Override
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ /** Creates a new {@link Watermark} with the specified value. */
+ public abstract Watermark newWatermark(T val);
+
+ public WatermarkCombinationPolicy getCombinationPolicy() {
+ return combinationPolicy;
+ }
+
+ public WatermarkHandlingStrategy getDefaultHandlingStrategy() {
+ return defaultHandlingStrategy;
+ }
+
+ public boolean isAligned() {
+ return isAligned;
+ }
+
+ /** Creates a new {@link WatermarkCombiner} instance. */
+ public abstract WatermarkCombiner createWatermarkCombiner(
+ int numberOfInputChannels, Runnable gateResumer);
+
+ /**
+ * Converts a user-oriented {@link WatermarkDeclaration} to an internal-oriented {@link
+ * AbstractInternalWatermarkDeclaration}.
+ */
+ public static AbstractInternalWatermarkDeclaration<?> from(
+ WatermarkDeclaration watermarkDeclaration) {
+ if (watermarkDeclaration instanceof AbstractInternalWatermarkDeclaration) {
+ return (AbstractInternalWatermarkDeclaration<?>) watermarkDeclaration;
+ } else if (watermarkDeclaration instanceof BoolWatermarkDeclaration) {
+ return new InternalBoolWatermarkDeclaration(
+ (BoolWatermarkDeclaration) watermarkDeclaration);
+ } else if (watermarkDeclaration instanceof LongWatermarkDeclaration) {
+ return new InternalLongWatermarkDeclaration(
+ (LongWatermarkDeclaration) watermarkDeclaration);
+ } else {
+ throw new IllegalArgumentException(
+ "Unknown watermark declaration type: " + watermarkDeclaration.getClass());
+ }
+ }
+}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/Alignable.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/Alignable.java
new file mode 100644
--- /dev/null
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/Alignable.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.watermark;
+
+import org.apache.flink.api.common.watermark.Watermark;
+import org.apache.flink.api.common.watermark.WatermarkDeclaration;
+
+/**
+ * An interface used to represent the special {@link WatermarkDeclaration}s can create aligned
+ * {@link Watermark}s, which need to be aligned when the operator receives them from input channels.
+ * Note that this interface is currently only used for internal implementation.
+ */
+public interface Alignable {
+ /** Represents whether the created {@link Watermark} needs to be aligned. */
+ boolean isAligned();
+}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/AlignableBoolWatermarkDeclaration.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/AlignableBoolWatermarkDeclaration.java
new file mode 100644
--- /dev/null
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/AlignableBoolWatermarkDeclaration.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.watermark;
+
+import org.apache.flink.api.common.watermark.BoolWatermarkDeclaration;
+import org.apache.flink.api.common.watermark.WatermarkCombinationPolicy;
+import org.apache.flink.api.common.watermark.WatermarkHandlingStrategy;
+import org.apache.flink.util.Preconditions;
+
+/** An alignable {@link BoolWatermarkDeclaration}. */
+public class AlignableBoolWatermarkDeclaration extends BoolWatermarkDeclaration
+ implements Alignable {
+ private final boolean isAligned;
+
+ public AlignableBoolWatermarkDeclaration(
+ String identifier,
+ WatermarkCombinationPolicy combinationPolicyForChannel,
+ WatermarkHandlingStrategy defaultHandlingStrategyForFunction,
+ boolean isAligned) {
+ super(identifier, combinationPolicyForChannel, defaultHandlingStrategyForFunction);
+ Preconditions.checkArgument(
+ !isAligned || combinationPolicyForChannel.isCombineWaitForAllChannels(),
+ "The aligned watermark must wait for all channels during the combining process. Please set the WatermarkCombinationPolicy#combineWaitForAllChannels to true.");
+ this.isAligned = isAligned;
+ }
+
+ public boolean isAligned() {
+ return isAligned;
+ }
+}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/AlignableLongWatermarkDeclaration.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/AlignableLongWatermarkDeclaration.java
new file mode 100644
--- /dev/null
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/AlignableLongWatermarkDeclaration.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.watermark;
+
+import org.apache.flink.api.common.watermark.LongWatermarkDeclaration;
+import org.apache.flink.api.common.watermark.WatermarkCombinationPolicy;
+import org.apache.flink.api.common.watermark.WatermarkHandlingStrategy;
+import org.apache.flink.util.Preconditions;
+
+/** An alignable {@link LongWatermarkDeclaration}. */
+public class AlignableLongWatermarkDeclaration extends LongWatermarkDeclaration
+ implements Alignable {
+
+ private final boolean isAligned;
+
+ public AlignableLongWatermarkDeclaration(
+ String identifier,
+ WatermarkCombinationPolicy combinationPolicyForChannel,
+ WatermarkHandlingStrategy defaultHandlingStrategyForFunction,
+ boolean isAligned) {
+ super(identifier, combinationPolicyForChannel, defaultHandlingStrategyForFunction);
+ Preconditions.checkArgument(
+ !isAligned || combinationPolicyForChannel.isCombineWaitForAllChannels(),
+ "The aligned watermark must wait for all channels during the combining process. Please set the WatermarkCombinationPolicy#combineWaitForAllChannels to true.");
+ this.isAligned = isAligned;
+ }
+
+ @Override
+ public boolean isAligned() {
+ return isAligned;
+ }
+}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/AlignedWatermarkCombiner.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/AlignedWatermarkCombiner.java
new file mode 100644
--- /dev/null
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/AlignedWatermarkCombiner.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.watermark;
+
+import org.apache.flink.api.common.watermark.Watermark;
+
+import java.util.BitSet;
+import java.util.function.Consumer;
+
+/**
+ * A {@link WatermarkCombiner} is design to align {@link Watermark}s. It will combine watermarks
+ * after receiving watermarks from all upstream input channels.
+ *
+ * <p>The combine process will perform the following three steps: (1) send the combined watermark
+ * (actually the last received watermark) to downstream, (2) clear the received watermarks, (3)
+ * resume input gate.
+ *
+ * <p>Note that the aligned Watermarks should have the same value within a batch.
+ */
+public class AlignedWatermarkCombiner implements WatermarkCombiner {
+ /** The number of upstream input channels. */
+ private int numberOfInputChannels;
+
+ /** A bitset to record whether the watermark has been received from each channel. */
+ private final BitSet hasReceiveWatermarks;
+
+ /** The input gate resume callback. */
+ private Runnable gateResumer;
+
+ public AlignedWatermarkCombiner(int numberOfInputChannels, Runnable gateResumer) {
+ this.numberOfInputChannels = numberOfInputChannels;
+ this.hasReceiveWatermarks = new BitSet(numberOfInputChannels);
+ this.gateResumer = gateResumer;
+ }
+
+ @Override
+ public void combineWatermark(
+ Watermark watermark, int channelIndex, Consumer<Watermark> watermarkEmitter)
+ throws Exception {
+
+ // mark the channel has received the watermark
+ hasReceiveWatermarks.set(channelIndex);
+
+ // once receive all watermarks, perform combine process
+ if (hasReceiveWatermarks.cardinality() == numberOfInputChannels) {
+ // send the combined watermark to downstream
+ watermarkEmitter.accept(watermark);
+ // clear the received watermarks
+ hasReceiveWatermarks.clear();
+ // resume input gate
+ gateResumer.run();
+ }
+ }
+}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/BoolWatermarkCombiner.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/BoolWatermarkCombiner.java
new file mode 100644
--- /dev/null
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/BoolWatermarkCombiner.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.watermark;
+
+import org.apache.flink.api.common.watermark.BoolWatermark;
+import org.apache.flink.api.common.watermark.Watermark;
+import org.apache.flink.api.common.watermark.WatermarkCombinationFunction;
+import org.apache.flink.api.common.watermark.WatermarkCombinationPolicy;
+
+import java.util.BitSet;
+import java.util.function.Consumer;
+
+import static org.apache.flink.util.Preconditions.checkState;
+
+/**
+ * A {@link WatermarkCombiner} for unaligned {@link BoolWatermark}s.
+ *
+ * <p>The combination process will perform the following steps: (1) determine if it satisfies the
+ * condition of {@link WatermarkCombinationPolicy#isCombineWaitForAllChannels()}, (2) calculate the
+ * combined watermark value, (3) send the combined watermark to downstream only when the value
+ * differs from the previous sent one or if it's the first time sending.
+ */
+public class BoolWatermarkCombiner implements WatermarkCombiner {
+
+ private final WatermarkCombinationPolicy combinationPolicy;
+
+ /** The number of upstream input channels. */
+ private final int numberOfInputChannels;
+
+ /** A bitset to record whether the watermark has been received from each channel. */
+ private final BitSet hasReceiveWatermarks;
+
+ /** The received watermark value for each channel. */
+ private final BitSet watermarkValues;
+
+ /**
+ * Send only the watermark that differs from the previous sent one, we need to record the
+ * previous sent watermark value and whether is the first time sending.
+ */
+ private boolean previousEmitWatermarkValue = false;
+
+ private boolean isFirstTimeEmit = true;
+
+ public BoolWatermarkCombiner(
+ WatermarkCombinationPolicy combinationPolicy, int numberOfInputChannels) {
+ checkState(
+ combinationPolicy.getWatermarkCombinationFunction()
+ instanceof WatermarkCombinationFunction.BoolWatermarkCombinationFunction);
+ this.combinationPolicy = combinationPolicy;
+ this.numberOfInputChannels = numberOfInputChannels;
+ this.hasReceiveWatermarks = new BitSet(numberOfInputChannels);
+ this.watermarkValues = new BitSet(numberOfInputChannels);
+
+ if (combinationPolicy.getWatermarkCombinationFunction()
+ == WatermarkCombinationFunction.BoolWatermarkCombinationFunction.OR) {
+ // Initialize the watermarkValues to all false when using OR strategy
+ watermarkValues.clear(0, numberOfInputChannels);
+ } else if (combinationPolicy.getWatermarkCombinationFunction()
+ == WatermarkCombinationFunction.BoolWatermarkCombinationFunction.AND) {
+ // Initialize the watermarkValues to all true when using AND strategy
+ watermarkValues.set(0, numberOfInputChannels);
+ } else {
+ throw new IllegalArgumentException(
+ "Illegal WatermarkCombinationFunction for BoolWatermarkCombiner: "
+ + combinationPolicy.getWatermarkCombinationFunction());
+ }
+ }
+
+ @Override
+ public void combineWatermark(
+ Watermark watermark, int channelIndex, Consumer<Watermark> watermarkEmitter)
+ throws Exception {
+ checkState(watermark instanceof BoolWatermark);
+
+ hasReceiveWatermarks.set(channelIndex);
+ // Update the watermark for the current channel
+ watermarkValues.set(channelIndex, ((BoolWatermark) watermark).getValue());
+
+ if (combinationPolicy.isCombineWaitForAllChannels()
+ && hasReceiveWatermarks.cardinality() < numberOfInputChannels) {
+ // Not all watermarks have been received yet
+ return;
+ }
+
+ // calculate the combined watermark value
+ boolean combinedWatermarkValue;
+ if (combinationPolicy.getWatermarkCombinationFunction()
+ == WatermarkCombinationFunction.BoolWatermarkCombinationFunction.OR) {
+ combinedWatermarkValue = watermarkValues.cardinality() > 0;
+ } else {
+ combinedWatermarkValue = watermarkValues.cardinality() == numberOfInputChannels;
+ }
+
+ if (shouldEmitWatermark(combinedWatermarkValue)) {
+ // send the combined watermark to downstream
+ watermarkEmitter.accept(
+ new BoolWatermark(combinedWatermarkValue, watermark.getIdentifier()));
+ previousEmitWatermarkValue = combinedWatermarkValue;
+ }
+ }
+
+ private boolean shouldEmitWatermark(boolean combinedWatermarkValue) {
+ if (isFirstTimeEmit) {
+ isFirstTimeEmit = false;
+ return true;
+ }
+ return combinedWatermarkValue != previousEmitWatermarkValue;
+ }
+}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/InternalBoolWatermarkDeclaration.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/InternalBoolWatermarkDeclaration.java
new file mode 100644
--- /dev/null
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/InternalBoolWatermarkDeclaration.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.watermark;
+
+import org.apache.flink.api.common.watermark.BoolWatermark;
+import org.apache.flink.api.common.watermark.BoolWatermarkDeclaration;
+import org.apache.flink.api.common.watermark.WatermarkCombinationPolicy;
+import org.apache.flink.api.common.watermark.WatermarkHandlingStrategy;
+
+/**
+ * The {@link InternalBoolWatermarkDeclaration} class implements the {@link
+ * AbstractInternalWatermarkDeclaration} interface and provides additional functionality specific to
+ * boolean-type watermarks.
+ */
+public class InternalBoolWatermarkDeclaration
+ extends AbstractInternalWatermarkDeclaration<Boolean> {
+
+ public InternalBoolWatermarkDeclaration(BoolWatermarkDeclaration declaration) {
+ this(
+ declaration.getIdentifier(),
+ declaration.getCombinationPolicy(),
+ declaration.getDefaultHandlingStrategy(),
+ (declaration instanceof Alignable) && ((Alignable) declaration).isAligned());
+ }
+
+ public InternalBoolWatermarkDeclaration(
+ String identifier,
+ WatermarkCombinationPolicy combinationPolicyForChannel,
+ WatermarkHandlingStrategy defaultHandlingStrategyForFunction,
+ boolean isAligned) {
+ super(
+ identifier,
+ combinationPolicyForChannel,
+ defaultHandlingStrategyForFunction,
+ isAligned);
+ }
+
+ /** Creates a new {@code BoolWatermark} with the specified value. */
+ @Override
+ public BoolWatermark newWatermark(Boolean val) {
+ return new BoolWatermark(val, getIdentifier());
+ }
+
+ @Override
+ public WatermarkCombiner createWatermarkCombiner(
+ int numberOfInputChannels, Runnable gateResumer) {
+ if (isAligned) {
+ return new AlignedWatermarkCombiner(numberOfInputChannels, gateResumer);
+ } else {
+ return new BoolWatermarkCombiner(getCombinationPolicy(), numberOfInputChannels);
+ }
+ }
+}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/InternalLongWatermarkDeclaration.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/InternalLongWatermarkDeclaration.java
new file mode 100644
--- /dev/null
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/InternalLongWatermarkDeclaration.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.watermark;
+
+import org.apache.flink.api.common.watermark.LongWatermark;
+import org.apache.flink.api.common.watermark.LongWatermarkDeclaration;
+import org.apache.flink.api.common.watermark.WatermarkCombinationPolicy;
+import org.apache.flink.api.common.watermark.WatermarkHandlingStrategy;
+
+/**
+ * The {@link InternalLongWatermarkDeclaration} class implements the {@link
+ * AbstractInternalWatermarkDeclaration} interface and provides additional functionality specific to
+ * long-type watermarks.
+ */
+public class InternalLongWatermarkDeclaration extends AbstractInternalWatermarkDeclaration<Long> {
+
+ public InternalLongWatermarkDeclaration(LongWatermarkDeclaration declaration) {
+ this(
+ declaration.getIdentifier(),
+ declaration.getCombinationPolicy(),
+ declaration.getDefaultHandlingStrategy(),
+ (declaration instanceof Alignable) && ((Alignable) declaration).isAligned());
+ }
+
+ public InternalLongWatermarkDeclaration(
+ String identifier,
+ WatermarkCombinationPolicy combinationPolicyForChannel,
+ WatermarkHandlingStrategy defaultHandlingStrategyForFunction,
+ boolean isAligned) {
+ super(
+ identifier,
+ combinationPolicyForChannel,
+ defaultHandlingStrategyForFunction,
+ isAligned);
+ }
+
+ /** Creates a new {@code LongWatermark} with the specified value. */
+ @Override
+ public LongWatermark newWatermark(Long val) {
+ return new LongWatermark(val, this.getIdentifier());
+ }
+
+ @Override
+ public WatermarkCombiner createWatermarkCombiner(
+ int numberOfInputChannels, Runnable gateResumer) {
+ if (isAligned) {
+ return new AlignedWatermarkCombiner(numberOfInputChannels, gateResumer);
+ } else {
+ return new LongWatermarkCombiner(getCombinationPolicy(), numberOfInputChannels);
+ }
+ }
+}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/LongWatermarkCombiner.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/LongWatermarkCombiner.java
new file mode 100644
--- /dev/null
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/LongWatermarkCombiner.java
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.watermark;
+
+import org.apache.flink.api.common.watermark.LongWatermark;
+import org.apache.flink.api.common.watermark.Watermark;
+import org.apache.flink.api.common.watermark.WatermarkCombinationFunction;
+import org.apache.flink.api.common.watermark.WatermarkCombinationPolicy;
+import org.apache.flink.streaming.runtime.watermarkstatus.HeapPriorityQueue;
+import org.apache.flink.streaming.runtime.watermarkstatus.HeapPriorityQueue.HeapPriorityQueueElement;
+
+import java.util.BitSet;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Consumer;
+
+import static org.apache.flink.util.Preconditions.checkState;
+
+/**
+ * A {@link WatermarkCombiner} for unaligned {@link LongWatermark}s.
+ *
+ * <p>The combination process will perform the following steps: (1) determine if it satisfies the
+ * condition of {@link WatermarkCombinationPolicy#isCombineWaitForAllChannels()}, (2) calculate the
+ * combined watermark value, (3) send the combined watermark to downstream only when the value
+ * differs from the previous sent one or if it's the first time sending.
+ */
+public class LongWatermarkCombiner implements WatermarkCombiner {
+
+ private final WatermarkCombinationPolicy combinationPolicy;
+
+ /** The number of upstream input channels. */
+ private final int numberOfInputChannels;
+
+ /** A bitset to record whether the watermark has been received from each channel. */
+ private final BitSet hasReceiveWatermarks;
+
+ /** Channel index to {@link LongWatermarkElement}. */
+ private final Map<Integer, LongWatermarkElement> channelWatermarks;
+
+ /** A heap-based priority queue to help find the minimum/maximum watermark. */
+ private final HeapPriorityQueue<LongWatermarkElement> orderedChannelWatermarks;
+
+ /** The comparator to compare the watermark value of two {@link LongWatermarkElement}s. */
+ private final HeapPriorityQueue.PriorityComparator<LongWatermarkElement> watermarkComparator;
+
+ /**
+ * Send only the watermark that differs from the previous sent one, we need to record the
+ * previous sent watermark value and whether is the first time sending.
+ */
+ private final LongWatermarkElement previousEmitWatermarkElement = new LongWatermarkElement(-1);
+
+ private boolean isFirstTimeEmit = true;
+
+ public LongWatermarkCombiner(
+ WatermarkCombinationPolicy combinationPolicy, int numberOfInputChannels) {
+ checkState(
+ combinationPolicy.getWatermarkCombinationFunction()
+ instanceof
+ WatermarkCombinationFunction.NumericWatermarkCombinationFunction);
+ this.combinationPolicy = combinationPolicy;
+ this.numberOfInputChannels = numberOfInputChannels;
+ this.hasReceiveWatermarks = new BitSet(numberOfInputChannels);
+ this.channelWatermarks = new HashMap<>(numberOfInputChannels);
+
+ // according to the combination strategy create the comparator and the {@link
+ // LongWatermarkElement} initial value
+ long initValue;
+ if (combinationPolicy.getWatermarkCombinationFunction()
+ == WatermarkCombinationFunction.NumericWatermarkCombinationFunction.MIN) {
+ this.watermarkComparator =
+ (left, right) ->
+ Long.compare(left.getWatermarkValue(), right.getWatermarkValue());
+ initValue = Long.MAX_VALUE;
+ } else {
+ this.watermarkComparator =
+ (left, right) ->
+ Long.compare(right.getWatermarkValue(), left.getWatermarkValue());
+ initValue = Long.MIN_VALUE;
+ }
+
+ // init the watermark elements of {@code #channelWatermarks} and {@code
+ // #orderedChannelWatermarks}
+ this.orderedChannelWatermarks =
+ new HeapPriorityQueue<>(watermarkComparator, numberOfInputChannels);
+ for (int i = 0; i < numberOfInputChannels; i++) {
+ LongWatermarkElement watermarkElement = new LongWatermarkElement(initValue);
+ channelWatermarks.put(i, watermarkElement);
+ orderedChannelWatermarks.add(watermarkElement);
+ }
+ }
+
+ @Override
+ public void combineWatermark(
+ Watermark watermark, int channelIndex, Consumer<Watermark> watermarkEmitter) {
+ checkState(watermark instanceof LongWatermark);
+
+ hasReceiveWatermarks.set(channelIndex);
+ // Update the watermark for the current channel
+ channelWatermarks
+ .get(channelIndex)
+ .setWatermarkValue(((LongWatermark) watermark).getValue());
+ orderedChannelWatermarks.adjustModifiedElement(channelWatermarks.get(channelIndex));
+
+ if (combinationPolicy.isCombineWaitForAllChannels()
+ && hasReceiveWatermarks.cardinality() < numberOfInputChannels) {
+ // Not all watermarks have been received yet
+ return;
+ }
+
+ // the combined watermark should be the first node of {@code orderedChannelWatermarks}
+
+ if (shouldEmitWatermark(orderedChannelWatermarks.peek())) {
+ // send the combined watermark to downstream
+ watermarkEmitter.accept(
+ new LongWatermark(
+ orderedChannelWatermarks.peek().getWatermarkValue(),
+ watermark.getIdentifier()));
+ previousEmitWatermarkElement.setWatermarkValue(
+ orderedChannelWatermarks.peek().getWatermarkValue());
+ }
+ }
+
+ private boolean shouldEmitWatermark(LongWatermarkElement combinedWatermarkElement) {
+ if (isFirstTimeEmit) {
+ isFirstTimeEmit = false;
+ return true;
+ }
+ return watermarkComparator.comparePriority(
+ combinedWatermarkElement, previousEmitWatermarkElement)
+ != 0;
+ }
+
+ /**
+ * This class implements {@link HeapPriorityQueueElement} to help find the maximum/minimum
+ * {@link LongWatermark}.
+ */
+ protected static class LongWatermarkElement implements HeapPriorityQueueElement {
+ private long watermarkValue;
+
+ /**
+ * This field holds the current physical index of this watermark when it is managed by a
+ * {@link HeapPriorityQueue}.
+ */
+ private int heapIndex = HeapPriorityQueueElement.NOT_CONTAINED;
+
+ public LongWatermarkElement(long watermarkValue) {
+ this.watermarkValue = watermarkValue;
+ }
+
+ @Override
+ public int getInternalIndex() {
+ return heapIndex;
+ }
+
+ @Override
+ public void setInternalIndex(int newIndex) {
+ this.heapIndex = newIndex;
+ }
+
+ public void setWatermarkValue(long watermarkValue) {
+ this.watermarkValue = watermarkValue;
+ }
+
+ public long getWatermarkValue() {
+ return watermarkValue;
+ }
+ }
+}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/WatermarkCombiner.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/WatermarkCombiner.java
new file mode 100644
--- /dev/null
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermark/WatermarkCombiner.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.watermark;
+
+import org.apache.flink.api.common.watermark.Watermark;
+import org.apache.flink.api.common.watermark.WatermarkCombinationPolicy;
+import org.apache.flink.api.common.watermark.WatermarkDeclaration;
+
+import java.util.function.Consumer;
+
+/**
+ * A class used to combine {@link Watermark}s. The combiner will be created by {@link
+ * WatermarkDeclaration} according to the {@link WatermarkCombinationPolicy}.
+ */
+public interface WatermarkCombiner {
+ void combineWatermark(
+ Watermark watermark, int channelIndex, Consumer<Watermark> watermarkEmitter)
+ throws Exception;
+}
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermarkstatus/HeapPriorityQueue.java b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermarkstatus/HeapPriorityQueue.java
--- a/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermarkstatus/HeapPriorityQueue.java
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/watermarkstatus/HeapPriorityQueue.java
@@ -249,7 +249,7 @@ private int increaseSizeByOne() {
*
* @param <T> type of the compared objects.
*/
- interface PriorityComparator<T> {
+ public interface PriorityComparator<T> {
/**
* Compares two objects for priority. Returns a negative integer, zero, or a positive
@@ -267,7 +267,7 @@ interface PriorityComparator<T> {
* Interface for objects that can be managed by a {@link HeapPriorityQueue}. Such an object can
* only be contained in at most one {@link HeapPriorityQueue} at a time.
*/
- interface HeapPriorityQueueElement {
+ public interface HeapPriorityQueueElement {
/**
* The index that indicates that a {@link HeapPriorityQueueElement} object is not contained
diff --git a/flink-runtime/src/main/java/org/apache/flink/streaming/util/watermark/WatermarkUtils.java b/flink-runtime/src/main/java/org/apache/flink/streaming/util/watermark/WatermarkUtils.java
new file mode 100644
--- /dev/null
+++ b/flink-runtime/src/main/java/org/apache/flink/streaming/util/watermark/WatermarkUtils.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.util.watermark;
+
+import org.apache.flink.api.common.functions.Function;
+import org.apache.flink.api.common.watermark.Watermark;
+import org.apache.flink.api.common.watermark.WatermarkDeclaration;
+import org.apache.flink.datastream.api.function.ProcessFunction;
+import org.apache.flink.runtime.asyncprocessing.operators.AbstractAsyncStateUdfStreamOperator;
+import org.apache.flink.streaming.api.graph.StreamGraph;
+import org.apache.flink.streaming.api.graph.StreamNode;
+import org.apache.flink.streaming.api.operators.SimpleOperatorFactory;
+import org.apache.flink.streaming.api.operators.SourceOperatorFactory;
+import org.apache.flink.streaming.api.operators.StreamOperator;
+import org.apache.flink.streaming.runtime.watermark.AbstractInternalWatermarkDeclaration;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/** Utils class for {@link Watermark}. */
+public final class WatermarkUtils {
+
+ /**
+ * Retrieve the declared watermarks from StreamGraph and convert them into {@code
+ * InternalWatermarkDeclaration}.
+ */
+ public static Set<AbstractInternalWatermarkDeclaration<?>>
+ getInternalWatermarkDeclarationsFromStreamGraph(StreamGraph streamGraph) {
+ Collection<StreamNode> streamNodes = streamGraph.getStreamNodes();
+ Set<WatermarkDeclaration> declarations =
+ streamNodes.stream()
+ .map(StreamNode::getOperatorFactory)
+ .filter(
+ factory ->
+ factory instanceof SimpleOperatorFactory
+ || factory instanceof SourceOperatorFactory)
+ .map(
+ factory -> {
+ if (factory instanceof SimpleOperatorFactory) {
+ return getWatermarkDeclarations(
+ ((SimpleOperatorFactory<?>) factory).getOperator());
+ } else {
+ return ((SourceOperatorFactory<?>) factory)
+ .getSourceWatermarkDeclarations();
+ }
+ })
+ .flatMap(Collection::stream)
+ .collect(Collectors.toSet());
+ return convertToInternalWatermarkDeclarations(declarations);
+ }
+
+ /**
+ * Retrieve the user-defined {@link WatermarkDeclaration}s of {@link ProcessFunction}. The
+ * {@link WatermarkDeclaration} defined by the source operator can be retrieved from {@link
+ * SourceOperatorFactory#getSourceWatermarkDeclarations()}.
+ */
+ private static Collection<? extends WatermarkDeclaration> getWatermarkDeclarations(
+ StreamOperator<?> streamOperator) {
+ if (streamOperator instanceof AbstractAsyncStateUdfStreamOperator) {
+ Function f =
+ ((AbstractAsyncStateUdfStreamOperator<?, ?>) streamOperator).getUserFunction();
+ if (f instanceof ProcessFunction) {
+ return ((ProcessFunction) f).declareWatermarks();
+ }
+ }
+ return Collections.emptySet();
+ }
+
+ /**
+ * Convert user-oriented {@link WatermarkDeclaration} instance to internal-oriented {@link
+ * AbstractInternalWatermarkDeclaration} instance.
+ */
+ public static Set<AbstractInternalWatermarkDeclaration<?>>
+ convertToInternalWatermarkDeclarations(
+ Set<WatermarkDeclaration> watermarkDeclarations) {
+ return watermarkDeclarations.stream()
+ .map(AbstractInternalWatermarkDeclaration::from)
+ .collect(Collectors.toSet());
+ }
+}
diff --git a/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/output/BroadcastingOutput.java b/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/output/BroadcastingOutput.java
--- a/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/output/BroadcastingOutput.java
+++ b/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/output/BroadcastingOutput.java
@@ -18,6 +18,7 @@
package org.apache.flink.table.runtime.operators.multipleinput.output;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.streaming.api.operators.Output;
import org.apache.flink.streaming.api.watermark.Watermark;
import org.apache.flink.streaming.runtime.streamrecord.LatencyMarker;
@@ -98,4 +99,11 @@ public void emitRecordAttributes(RecordAttributes recordAttributes) {
output.emitRecordAttributes(recordAttributes);
}
}
+
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) {
+ for (Output<StreamRecord<RowData>> output : outputs) {
+ output.emitWatermark(watermark);
+ }
+ }
}
diff --git a/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/output/CopyingSecondInputOfTwoInputStreamOperatorOutput.java b/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/output/CopyingSecondInputOfTwoInputStreamOperatorOutput.java
--- a/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/output/CopyingSecondInputOfTwoInputStreamOperatorOutput.java
+++ b/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/output/CopyingSecondInputOfTwoInputStreamOperatorOutput.java
@@ -19,6 +19,7 @@
package org.apache.flink.table.runtime.operators.multipleinput.output;
import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.streaming.api.operators.Output;
import org.apache.flink.streaming.api.operators.TwoInputStreamOperator;
import org.apache.flink.streaming.api.watermark.Watermark;
@@ -82,6 +83,15 @@ public void emitRecordAttributes(RecordAttributes recordAttributes) {
}
}
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) {
+ try {
+ operator.processWatermark2(watermark);
+ } catch (Exception e) {
+ throw new ExceptionInMultipleInputOperatorException(e);
+ }
+ }
+
@Override
public void collect(StreamRecord<RowData> record) {
pushToOperator(record);
diff --git a/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/output/FirstInputOfTwoInputStreamOperatorOutput.java b/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/output/FirstInputOfTwoInputStreamOperatorOutput.java
--- a/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/output/FirstInputOfTwoInputStreamOperatorOutput.java
+++ b/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/output/FirstInputOfTwoInputStreamOperatorOutput.java
@@ -18,6 +18,7 @@
package org.apache.flink.table.runtime.operators.multipleinput.output;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.streaming.api.operators.Output;
import org.apache.flink.streaming.api.operators.TwoInputStreamOperator;
import org.apache.flink.streaming.api.watermark.Watermark;
@@ -78,6 +79,15 @@ public void emitRecordAttributes(RecordAttributes recordAttributes) {
}
}
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) {
+ try {
+ operator.processWatermark1(watermark);
+ } catch (Exception e) {
+ throw new ExceptionInMultipleInputOperatorException(e);
+ }
+ }
+
@Override
public void collect(StreamRecord<RowData> record) {
pushToOperator(record);
diff --git a/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/output/OneInputStreamOperatorOutput.java b/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/output/OneInputStreamOperatorOutput.java
--- a/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/output/OneInputStreamOperatorOutput.java
+++ b/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/output/OneInputStreamOperatorOutput.java
@@ -18,6 +18,7 @@
package org.apache.flink.table.runtime.operators.multipleinput.output;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.streaming.api.operators.OneInputStreamOperator;
import org.apache.flink.streaming.api.operators.Output;
import org.apache.flink.streaming.api.watermark.Watermark;
@@ -77,6 +78,15 @@ public void emitRecordAttributes(RecordAttributes recordAttributes) {
}
}
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) {
+ try {
+ operator.processWatermark(watermark);
+ } catch (Exception e) {
+ throw new ExceptionInMultipleInputOperatorException(e);
+ }
+ }
+
@Override
public void collect(StreamRecord<RowData> record) {
pushToOperator(record);
diff --git a/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/output/SecondInputOfTwoInputStreamOperatorOutput.java b/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/output/SecondInputOfTwoInputStreamOperatorOutput.java
--- a/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/output/SecondInputOfTwoInputStreamOperatorOutput.java
+++ b/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/output/SecondInputOfTwoInputStreamOperatorOutput.java
@@ -18,6 +18,7 @@
package org.apache.flink.table.runtime.operators.multipleinput.output;
+import org.apache.flink.runtime.event.WatermarkEvent;
import org.apache.flink.streaming.api.operators.Output;
import org.apache.flink.streaming.api.operators.TwoInputStreamOperator;
import org.apache.flink.streaming.api.watermark.Watermark;
@@ -78,6 +79,15 @@ public void emitRecordAttributes(RecordAttributes recordAttributes) {
}
}
+ @Override
+ public void emitWatermark(WatermarkEvent watermark) {
+ try {
+ operator.processWatermark2(watermark);
+ } catch (Exception e) {
+ throw new ExceptionInMultipleInputOperatorException(e);
+ }
+ }
+
@Override
public void collect(StreamRecord<RowData> record) {
pushToOperator(record);
diff --git a/pom.xml b/pom.xml
--- a/pom.xml
+++ b/pom.xml
@@ -2398,6 +2398,9 @@ under the License.
<exclude>org.apache.flink.api.connector.sink2.Sink</exclude>
<!-- FLINK-36245 move SourceFunction to legacy package in flink-2.0. -->
<exclude>org.apache.flink.walkthrough.common.source.TransactionSource</exclude>
+ <!-- FLIP-467 Introduce Generalized Watermarks in flink-2.0. -->
+ <exclude>org.apache.flink.api.connector.source.Source</exclude>
+ <exclude>org.apache.flink.api.connector.source.SourceReaderContext</exclude>
<!-- MARKER: end exclusions -->
</excludes>
<accessModifier>public</accessModifier>
|