sql_part.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import { SqlPartDef, SqlPart } from 'app/angular/components/sql_part/sql_part';
  2. const index: any[] = [];
  3. function createPart(part: any): any {
  4. const def = index[part.type];
  5. if (!def) {
  6. return null;
  7. }
  8. return new SqlPart(part, def);
  9. }
  10. function register(options: any) {
  11. index[options.type] = new SqlPartDef(options);
  12. }
  13. register({
  14. type: 'column',
  15. style: 'label',
  16. params: [{ type: 'column', dynamicLookup: true }],
  17. defaultParams: ['value'],
  18. });
  19. register({
  20. type: 'expression',
  21. style: 'expression',
  22. label: 'Expr:',
  23. params: [
  24. { name: 'left', type: 'string', dynamicLookup: true },
  25. { name: 'op', type: 'string', dynamicLookup: true },
  26. { name: 'right', type: 'string', dynamicLookup: true },
  27. ],
  28. defaultParams: ['value', '=', 'value'],
  29. });
  30. register({
  31. type: 'macro',
  32. style: 'label',
  33. label: 'Macro:',
  34. params: [],
  35. defaultParams: [],
  36. });
  37. register({
  38. type: 'aggregate',
  39. style: 'label',
  40. params: [
  41. {
  42. name: 'name',
  43. type: 'string',
  44. options: [],
  45. baseOptions: ['avg', 'count', 'min', 'max', 'sum', 'stddev', 'variance'],
  46. timescaleOptions: ['first', 'last'],
  47. },
  48. ],
  49. defaultParams: ['avg'],
  50. });
  51. register({
  52. type: 'percentile',
  53. label: 'Aggregate:',
  54. style: 'label',
  55. params: [
  56. {
  57. name: 'name',
  58. type: 'string',
  59. options: ['percentile_cont', 'percentile_disc'],
  60. },
  61. {
  62. name: 'fraction',
  63. type: 'number',
  64. options: ['0.5', '0.75', '0.9', '0.95', '0.99'],
  65. },
  66. ],
  67. defaultParams: ['percentile_cont', '0.95'],
  68. });
  69. register({
  70. type: 'alias',
  71. style: 'label',
  72. params: [{ name: 'name', type: 'string', quote: 'double' }],
  73. defaultParams: ['alias'],
  74. });
  75. register({
  76. type: 'time',
  77. style: 'function',
  78. label: 'time',
  79. params: [
  80. {
  81. name: 'interval',
  82. type: 'interval',
  83. options: ['$__interval', '1s', '10s', '1m', '5m', '10m', '15m', '1h'],
  84. },
  85. {
  86. name: 'fill',
  87. type: 'string',
  88. options: ['none', 'NULL', 'previous', '0'],
  89. },
  90. ],
  91. defaultParams: ['$__interval', 'none'],
  92. });
  93. register({
  94. type: 'window',
  95. style: 'label',
  96. params: [
  97. {
  98. name: 'function',
  99. type: 'string',
  100. options: ['delta', 'increase', 'rate', 'sum'],
  101. },
  102. ],
  103. defaultParams: ['increase'],
  104. });
  105. register({
  106. type: 'moving_window',
  107. style: 'label',
  108. label: 'Moving Window:',
  109. params: [
  110. {
  111. name: 'function',
  112. type: 'string',
  113. options: ['avg'],
  114. },
  115. {
  116. name: 'window_size',
  117. type: 'number',
  118. options: ['3', '5', '7', '10', '20'],
  119. },
  120. ],
  121. defaultParams: ['avg', '5'],
  122. });
  123. export default {
  124. create: createPart,
  125. };