simple_paritioning.sql 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. pragma FeatureR010="prototype";
  2. pragma config.flags("MatchRecognizeStream", "disable");
  3. $data = [
  4. <|dt:15, host:"fqdn1", key:0|>,
  5. <|dt:16, host:"fqdn1", key:1|>,
  6. <|dt:17, host:"fqdn1", key:2|>,
  7. <|dt:18, host:"fqdn1", key:3|>,
  8. <|dt:19, host:"fqdn1", key:4|>,
  9. <|dt:20, host:"fqdn1", key:5|>,
  10. <|dt:21, host:"fqdn1", key:6|>,
  11. <|dt:22, host:"fqdn1", key:7|>,
  12. <|dt:23, host:"fqdn_2", key:0|>,
  13. <|dt:24, host:"fqdn1", key:8|>,
  14. <|dt:25, host:"fqdn1", key:9|>,
  15. <|dt:26, host:"fqdn1", key:10|>,
  16. <|dt:27, host:"fqdn__3", key:30|>,
  17. <|dt:28, host:"fqdn__3", key:1|>,
  18. <|dt:29, host:"fqdn__3", key:2|>,
  19. <|dt:30, host:"fqdn__3", key:3|>,
  20. <|dt:31, host:"fqdn__3", key:4|>,
  21. <|dt:32, host:"fqdn1", key:11|>,
  22. <|dt:33, host:"fqdn1", key:12|>,
  23. <|dt:34, host:"fqdn1", key:13|>,
  24. <|dt:35, host:"fqdn1", key:14|>,
  25. <|dt:36, host:"fqdn__3", key:15|>
  26. ];
  27. select * from AS_TABLE($data) MATCH_RECOGNIZE(
  28. PARTITION BY host
  29. ORDER BY dt
  30. MEASURES
  31. Last(Q.dt) as T,
  32. First(Y.key) as Key
  33. ONE ROW PER MATCH
  34. AFTER MATCH SKIP TO NEXT ROW
  35. PATTERN (
  36. (Y Q)
  37. )
  38. DEFINE
  39. Y as (Y.key) % 3 = 0,
  40. Q as (Q.key) % 3 <> 0
  41. ) as MR
  42. ORDER BY MR.T;