sql_part.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { SqlPartDef, SqlPart } from 'app/core/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: ['avg', 'count', 'min', 'max', 'sum', 'stddev', 'variance'],
  45. },
  46. ],
  47. defaultParams: ['avg'],
  48. });
  49. register({
  50. type: 'percentile',
  51. label: 'Aggregate:',
  52. style: 'label',
  53. params: [
  54. {
  55. name: 'name',
  56. type: 'string',
  57. options: ['percentile_cont', 'percentile_disc'],
  58. },
  59. {
  60. name: 'fraction',
  61. type: 'number',
  62. options: ['0.5', '0.75', '0.9', '0.95', '0.99'],
  63. },
  64. ],
  65. defaultParams: ['percentile_cont', '0.95'],
  66. });
  67. register({
  68. type: 'alias',
  69. style: 'label',
  70. params: [{ name: 'name', type: 'string', quote: 'double' }],
  71. defaultParams: ['alias'],
  72. });
  73. register({
  74. type: 'time',
  75. style: 'function',
  76. label: 'time',
  77. params: [
  78. {
  79. name: 'interval',
  80. type: 'interval',
  81. options: ['$__interval', '1s', '10s', '1m', '5m', '10m', '15m', '1h'],
  82. },
  83. {
  84. name: 'fill',
  85. type: 'string',
  86. options: ['none', 'NULL', 'previous', '0'],
  87. },
  88. ],
  89. defaultParams: ['$__interval', 'none'],
  90. });
  91. register({
  92. type: 'window',
  93. style: 'label',
  94. params: [
  95. {
  96. name: 'function',
  97. type: 'string',
  98. options: ['delta', 'increase', 'rate', 'sum'],
  99. },
  100. ],
  101. defaultParams: ['increase'],
  102. });
  103. register({
  104. type: 'moving_window',
  105. style: 'label',
  106. label: 'Moving Window:',
  107. params: [
  108. {
  109. name: 'function',
  110. type: 'string',
  111. options: ['avg'],
  112. },
  113. {
  114. name: 'window_size',
  115. type: 'number',
  116. options: ['3', '5', '7', '10', '20'],
  117. },
  118. ],
  119. defaultParams: ['avg', '5'],
  120. });
  121. export default {
  122. create: createPart,
  123. };