|
10 | 10 | import static org.mockito.Mockito.mock; |
11 | 11 | import static org.mockito.Mockito.when; |
12 | 12 |
|
| 13 | +import java.util.function.Consumer; |
13 | 14 | import org.apache.calcite.rel.RelNode; |
14 | 15 | import org.junit.Before; |
15 | 16 | import org.junit.Test; |
@@ -52,47 +53,95 @@ public void setUp() { |
52 | 53 | } |
53 | 54 |
|
54 | 55 | @Test |
55 | | - public void pluggableDataformatIndexRoutesToAnalytics() { |
56 | | - registerIndex( |
| 56 | + public void pplQueryRoutesToAnalyticsForParquetIndex() { |
| 57 | + withParquetIndex( |
57 | 58 | "parquet_logs", |
58 | | - Settings.builder() |
59 | | - .put(IndexSettings.PLUGGABLE_DATAFORMAT_ENABLED_SETTING.getKey(), true) |
60 | | - .put(IndexSettings.PLUGGABLE_DATAFORMAT_VALUE_SETTING.getKey(), "composite") |
61 | | - .build()); |
| 59 | + index -> { |
| 60 | + assertTrue(action.isAnalyticsIndex("source = parquet_logs | fields ts", QueryType.PPL)); |
| 61 | + assertTrue( |
| 62 | + action.isAnalyticsIndex( |
| 63 | + "source = opensearch.parquet_logs | fields ts", QueryType.PPL)); |
| 64 | + }); |
| 65 | + } |
62 | 66 |
|
63 | | - assertTrue(action.isAnalyticsIndex("source = parquet_logs | fields ts", QueryType.PPL)); |
64 | | - assertTrue( |
65 | | - action.isAnalyticsIndex("source = opensearch.parquet_logs | fields ts", QueryType.PPL)); |
| 67 | + @Test |
| 68 | + public void sqlQueryRoutesToAnalyticsForParquetIndex() { |
| 69 | + withParquetIndex( |
| 70 | + "parquet_logs", |
| 71 | + index -> { |
| 72 | + assertTrue(action.isAnalyticsIndex("SELECT * FROM parquet_logs", QueryType.SQL)); |
| 73 | + assertTrue( |
| 74 | + action.isAnalyticsIndex( |
| 75 | + "SELECT ts, level FROM parquet_logs WHERE level = 'ERROR'", QueryType.SQL)); |
| 76 | + assertTrue( |
| 77 | + action.isAnalyticsIndex("SELECT * FROM opensearch.parquet_logs", QueryType.SQL)); |
| 78 | + }); |
66 | 79 | } |
67 | 80 |
|
68 | 81 | @Test |
69 | | - public void pluggableEnabledButLuceneFormatRoutesToLucene() { |
70 | | - registerIndex( |
| 82 | + public void pplQueryRoutesToLuceneForLuceneIndex() { |
| 83 | + withLuceneIndex( |
71 | 84 | "lucene_logs", |
72 | | - Settings.builder() |
73 | | - .put(IndexSettings.PLUGGABLE_DATAFORMAT_ENABLED_SETTING.getKey(), true) |
74 | | - .put(IndexSettings.PLUGGABLE_DATAFORMAT_VALUE_SETTING.getKey(), "lucene") |
75 | | - .build()); |
76 | | - |
77 | | - assertFalse(action.isAnalyticsIndex("source = lucene_logs | fields ts", QueryType.PPL)); |
| 85 | + index -> { |
| 86 | + assertFalse(action.isAnalyticsIndex("source = lucene_logs | fields ts", QueryType.PPL)); |
| 87 | + }); |
78 | 88 | } |
79 | 89 |
|
80 | 90 | @Test |
81 | | - public void indexWithoutSettingRoutesToLucene() { |
82 | | - registerIndex("plain_logs", Settings.EMPTY); |
83 | | - |
84 | | - assertFalse(action.isAnalyticsIndex("source = plain_logs | fields ts", QueryType.PPL)); |
| 91 | + public void sqlQueryRoutesToLuceneForLuceneIndex() { |
| 92 | + withLuceneIndex( |
| 93 | + "plain_logs", |
| 94 | + index -> { |
| 95 | + assertFalse(action.isAnalyticsIndex("SELECT * FROM plain_logs", QueryType.SQL)); |
| 96 | + }); |
85 | 97 | } |
86 | 98 |
|
87 | 99 | @Test |
88 | 100 | public void missingIndexRoutesToLucene() { |
89 | 101 | assertFalse(action.isAnalyticsIndex("source = does_not_exist | fields ts", QueryType.PPL)); |
| 102 | + assertFalse(action.isAnalyticsIndex("SELECT * FROM does_not_exist", QueryType.SQL)); |
90 | 103 | } |
91 | 104 |
|
92 | 105 | @Test |
93 | 106 | public void nullAndEmptyQueriesRouteToLucene() { |
94 | 107 | assertFalse(action.isAnalyticsIndex(null, QueryType.PPL)); |
95 | 108 | assertFalse(action.isAnalyticsIndex("", QueryType.PPL)); |
| 109 | + assertFalse(action.isAnalyticsIndex(null, QueryType.SQL)); |
| 110 | + assertFalse(action.isAnalyticsIndex("", QueryType.SQL)); |
| 111 | + } |
| 112 | + |
| 113 | + @Test |
| 114 | + public void showStatementRoutesToLucene() { |
| 115 | + withParquetIndex( |
| 116 | + "parquet_logs", |
| 117 | + index -> { |
| 118 | + assertFalse(action.isAnalyticsIndex("SHOW TABLES LIKE 'parquet_logs'", QueryType.SQL)); |
| 119 | + }); |
| 120 | + } |
| 121 | + |
| 122 | + @Test |
| 123 | + public void describeStatementRoutesToLucene() { |
| 124 | + withParquetIndex( |
| 125 | + "parquet_logs", |
| 126 | + index -> { |
| 127 | + assertFalse( |
| 128 | + action.isAnalyticsIndex("DESCRIBE TABLES LIKE 'parquet_logs'", QueryType.SQL)); |
| 129 | + }); |
| 130 | + } |
| 131 | + |
| 132 | + private void withParquetIndex(String name, Consumer<String> assertions) { |
| 133 | + registerIndex( |
| 134 | + name, |
| 135 | + Settings.builder() |
| 136 | + .put(IndexSettings.PLUGGABLE_DATAFORMAT_ENABLED_SETTING.getKey(), true) |
| 137 | + .put(IndexSettings.PLUGGABLE_DATAFORMAT_VALUE_SETTING.getKey(), "composite") |
| 138 | + .build()); |
| 139 | + assertions.accept(name); |
| 140 | + } |
| 141 | + |
| 142 | + private void withLuceneIndex(String name, Consumer<String> assertions) { |
| 143 | + registerIndex(name, Settings.EMPTY); |
| 144 | + assertions.accept(name); |
96 | 145 | } |
97 | 146 |
|
98 | 147 | private void registerIndex(String name, Settings settings) { |
|
0 commit comments