Skip to content

Commit f6d596e

Browse files
authored
fix(sql): exception when JIT compiling a filter like WHERE symbol = '''' (#5958)
1 parent 129c7b0 commit f6d596e

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

core/src/main/java/io/questdb/griffin/engine/functions/constants/SymbolConstant.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public SymbolConstant(CharSequence value, int index) {
4848
this.utf8Value = null;
4949
this.index = SymbolTable.VALUE_IS_NULL;
5050
} else {
51-
if (Chars.startsWith(value, '\'')) {
51+
if (Chars.startsWith(value, '\'')
52+
&& Chars.endsWith(value, '\'')
53+
&& value.length() > 1) {
5254
this.value = Chars.toString(value, 1, value.length() - 1);
5355
} else {
5456
this.value = Chars.toString(value);

core/src/test/java/io/questdb/test/griffin/CompiledFilterTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,46 @@ public void testDeferredSymbolConstants() throws Exception {
179179
});
180180
}
181181

182+
@Test
183+
public void testFilteringOnSingleQuote() throws Exception {
184+
assertQueryAndPlan("Time\tSpread\tBid_Volume\task_volume\n",
185+
"SELECT timestamp as Time,\n" +
186+
"avg(asks[1,1]-bids[1,1]) as Spread,\n" +
187+
"sum(bids[1,1]*bids[2,1]) as Bid_Volume,\n" +
188+
"sum(asks[1,1]*asks[2,1]) as ask_volume\n" +
189+
"FROM market_data\n" +
190+
"WHERE symbol = ''''\n" +
191+
"SAMPLE BY 1s\n" +
192+
"ORDER BY timestamp DESC\n" +
193+
"LIMIT 6;",
194+
"\n" +
195+
"CREATE TABLE 'market_data' ( \n" +
196+
"\ttimestamp TIMESTAMP,\n" +
197+
"\tsymbol SYMBOL CAPACITY 16384 CACHE,\n" +
198+
"\tbids DOUBLE[][],\n" +
199+
"\tasks DOUBLE[][]\n" +
200+
") timestamp(timestamp);",
201+
"Time###DESC",
202+
"INSERT INTO market_data (timestamp, symbol, bids, asks) " +
203+
"VALUES " +
204+
"(0, 'abc', array[[1d,2d],[3d,4d]], array[[2d,3d],[4d,5d]]), " +
205+
"(10_000_000, '''', array[[10d,20d],[30d,40d]], array[[20d,30d],[40d,50d]]);",
206+
"Time\tSpread\tBid_Volume\task_volume\n" +
207+
"1970-01-01T00:00:10.000000Z\t10.0\t300.0\t800.0\n",
208+
true,
209+
true,
210+
false,
211+
"Sort light lo: 6\n" +
212+
" keys: [Time desc]\n" +
213+
" Async JIT Group By workers: 1\n" +
214+
" keys: [Time]\n" +
215+
" values: [avg(asks[1,1]-bids[1,1]),sum(bids[1,1]*bids[2,1]),sum(asks[1,1]*asks[2,1])]\n" +
216+
" filter: symbol='''\n" +
217+
" PageFrame\n" +
218+
" Row forward scan\n" +
219+
" Frame forward scan on: market_data\n");
220+
}
221+
182222
@Test
183223
public void testIndexBindVariableReplacedContext() throws Exception {
184224
assertMemoryLeak(() -> {

0 commit comments

Comments
 (0)