MCPcopy Create free account
hub / github.com/questdb/questdb / expectMicros

Method expectMicros

core/src/main/java/io/questdb/griffin/SqlUtil.java:342–402  ·  view source on GitHub ↗
(CharSequence tok, int position)

Source from the content-addressed store, hash-verified

340 }
341
342 public static long expectMicros(CharSequence tok, int position) throws SqlException {
343 final int len = tok.length();
344 final int k = findEndOfDigitsPos(tok, len, position);
345
346 try {
347 long interval = Numbers.parseLong(tok, 0, k);
348 int nChars = len - k;
349 if (nChars > 2) {
350 throw SqlException.$(position + k, "expected 1/2 letter interval qualifier in ").put(tok);
351 }
352 TimestampDriver driver = MicrosTimestampDriver.INSTANCE;
353
354 switch (tok.charAt(k)) {
355 case 's':
356 if (nChars == 1) {
357 // seconds
358 return driver.fromSeconds(interval);
359 }
360 break;
361 case 'm':
362 if (nChars == 1) {
363 // minutes
364 return driver.fromMinutes((int) interval);
365 } else {
366 if (tok.charAt(k + 1) == 's') {
367 // millis
368 return driver.fromMillis((int) interval);
369 }
370 }
371 break;
372 case 'h':
373 if (nChars == 1) {
374 // hours
375 return driver.fromHours((int) interval);
376 }
377 break;
378 case 'd':
379 if (nChars == 1) {
380 // days
381 return driver.fromDays((int) interval);
382 }
383 break;
384 case 'u':
385 if (nChars == 2 && tok.charAt(k + 1) == 's') {
386 return driver.fromMicros(interval);
387 }
388 break;
389 case 'n':
390 if (nChars == 2 && tok.charAt(k + 1) == 's') {
391 return driver.fromNanos(interval);
392 }
393 break;
394 default:
395 break;
396 }
397 } catch (NumericException ex) {
398 // Ignored
399 }

Callers 6

testParseMicrosMethod · 0.95
alterTableSetParamMethod · 0.95
parseCreateTableMethod · 0.95
parseInsertMethod · 0.95

Calls 13

findEndOfDigitsPosMethod · 0.95
parseLongMethod · 0.95
$Method · 0.95
fromSecondsMethod · 0.95
fromMinutesMethod · 0.95
fromMillisMethod · 0.95
fromHoursMethod · 0.95
fromDaysMethod · 0.95
fromMicrosMethod · 0.95
fromNanosMethod · 0.95
lengthMethod · 0.65
putMethod · 0.65

Tested by 3

testParseMicrosMethod · 0.76