@Test public void testLongQualifier() { try { TimestampSamplerFactory.getInstance("1sa", 130); Assert.fail(); } catch (SqlException e) { Assert.assertEquals(131, e.getPosition()); TestUtils.assertContains(e.getMessage(), "expected single letter qualifier"); } }
public static TimestampSampler getInstance(CharSequence cs, int position) throws SqlException { int k = -1; if (cs == null) { throw SqlException.$(position, "missing interval"); } final int len = cs.length(); for (int i = 0; i < len; i++) { char c = cs.charAt(i); if (c < '0' || c > '9') { k = i; break; } } if (k == -1) { throw SqlException.$(position + len, "expected interval qualifier"); } if (k + 1 < len) { throw SqlException.$(position + k, "expected single letter qualifier"); } try { final int n; if (k == 0) { n = 1; } else { n = Numbers.parseInt(cs, 0, k); if (n == 0) { throw SqlException.$(position, "zero is not a valid sample value"); } } switch (cs.charAt(k)) { case 'T': return new MicroTimestampSampler(Timestamps.MILLI_MICROS * n); case 's': return new MicroTimestampSampler(Timestamps.SECOND_MICROS * n); case 'm': return new MicroTimestampSampler(Timestamps.MINUTE_MICROS * n); case 'h': return new MicroTimestampSampler(Timestamps.HOUR_MICROS * n); case 'd': return new MicroTimestampSampler(Timestamps.DAY_MICROS * n); case 'M': return new MonthTimestampSampler(n); case 'y': return new YearTimestampSampler(n); default: break; } } catch (NumericException ignore) { assert false; } throw SqlException.$(position + k, "unsupported interval qualifier"); }
TimestampSamplerFactory { public static TimestampSampler getInstance(CharSequence cs, int position) throws SqlException { int k = -1; if (cs == null) { throw SqlException.$(position, "missing interval"); } final int len = cs.length(); for (int i = 0; i < len; i++) { char c = cs.charAt(i); if (c < '0' || c > '9') { k = i; break; } } if (k == -1) { throw SqlException.$(position + len, "expected interval qualifier"); } if (k + 1 < len) { throw SqlException.$(position + k, "expected single letter qualifier"); } try { final int n; if (k == 0) { n = 1; } else { n = Numbers.parseInt(cs, 0, k); if (n == 0) { throw SqlException.$(position, "zero is not a valid sample value"); } } switch (cs.charAt(k)) { case 'T': return new MicroTimestampSampler(Timestamps.MILLI_MICROS * n); case 's': return new MicroTimestampSampler(Timestamps.SECOND_MICROS * n); case 'm': return new MicroTimestampSampler(Timestamps.MINUTE_MICROS * n); case 'h': return new MicroTimestampSampler(Timestamps.HOUR_MICROS * n); case 'd': return new MicroTimestampSampler(Timestamps.DAY_MICROS * n); case 'M': return new MonthTimestampSampler(n); case 'y': return new YearTimestampSampler(n); default: break; } } catch (NumericException ignore) { assert false; } throw SqlException.$(position + k, "unsupported interval qualifier"); } }
TimestampSamplerFactory { public static TimestampSampler getInstance(CharSequence cs, int position) throws SqlException { int k = -1; if (cs == null) { throw SqlException.$(position, "missing interval"); } final int len = cs.length(); for (int i = 0; i < len; i++) { char c = cs.charAt(i); if (c < '0' || c > '9') { k = i; break; } } if (k == -1) { throw SqlException.$(position + len, "expected interval qualifier"); } if (k + 1 < len) { throw SqlException.$(position + k, "expected single letter qualifier"); } try { final int n; if (k == 0) { n = 1; } else { n = Numbers.parseInt(cs, 0, k); if (n == 0) { throw SqlException.$(position, "zero is not a valid sample value"); } } switch (cs.charAt(k)) { case 'T': return new MicroTimestampSampler(Timestamps.MILLI_MICROS * n); case 's': return new MicroTimestampSampler(Timestamps.SECOND_MICROS * n); case 'm': return new MicroTimestampSampler(Timestamps.MINUTE_MICROS * n); case 'h': return new MicroTimestampSampler(Timestamps.HOUR_MICROS * n); case 'd': return new MicroTimestampSampler(Timestamps.DAY_MICROS * n); case 'M': return new MonthTimestampSampler(n); case 'y': return new YearTimestampSampler(n); default: break; } } catch (NumericException ignore) { assert false; } throw SqlException.$(position + k, "unsupported interval qualifier"); }  }
TimestampSamplerFactory { public static TimestampSampler getInstance(CharSequence cs, int position) throws SqlException { int k = -1; if (cs == null) { throw SqlException.$(position, "missing interval"); } final int len = cs.length(); for (int i = 0; i < len; i++) { char c = cs.charAt(i); if (c < '0' || c > '9') { k = i; break; } } if (k == -1) { throw SqlException.$(position + len, "expected interval qualifier"); } if (k + 1 < len) { throw SqlException.$(position + k, "expected single letter qualifier"); } try { final int n; if (k == 0) { n = 1; } else { n = Numbers.parseInt(cs, 0, k); if (n == 0) { throw SqlException.$(position, "zero is not a valid sample value"); } } switch (cs.charAt(k)) { case 'T': return new MicroTimestampSampler(Timestamps.MILLI_MICROS * n); case 's': return new MicroTimestampSampler(Timestamps.SECOND_MICROS * n); case 'm': return new MicroTimestampSampler(Timestamps.MINUTE_MICROS * n); case 'h': return new MicroTimestampSampler(Timestamps.HOUR_MICROS * n); case 'd': return new MicroTimestampSampler(Timestamps.DAY_MICROS * n); case 'M': return new MonthTimestampSampler(n); case 'y': return new YearTimestampSampler(n); default: break; } } catch (NumericException ignore) { assert false; } throw SqlException.$(position + k, "unsupported interval qualifier"); }  static TimestampSampler getInstance(CharSequence cs, int position); }
TimestampSamplerFactory { public static TimestampSampler getInstance(CharSequence cs, int position) throws SqlException { int k = -1; if (cs == null) { throw SqlException.$(position, "missing interval"); } final int len = cs.length(); for (int i = 0; i < len; i++) { char c = cs.charAt(i); if (c < '0' || c > '9') { k = i; break; } } if (k == -1) { throw SqlException.$(position + len, "expected interval qualifier"); } if (k + 1 < len) { throw SqlException.$(position + k, "expected single letter qualifier"); } try { final int n; if (k == 0) { n = 1; } else { n = Numbers.parseInt(cs, 0, k); if (n == 0) { throw SqlException.$(position, "zero is not a valid sample value"); } } switch (cs.charAt(k)) { case 'T': return new MicroTimestampSampler(Timestamps.MILLI_MICROS * n); case 's': return new MicroTimestampSampler(Timestamps.SECOND_MICROS * n); case 'm': return new MicroTimestampSampler(Timestamps.MINUTE_MICROS * n); case 'h': return new MicroTimestampSampler(Timestamps.HOUR_MICROS * n); case 'd': return new MicroTimestampSampler(Timestamps.DAY_MICROS * n); case 'M': return new MonthTimestampSampler(n); case 'y': return new YearTimestampSampler(n); default: break; } } catch (NumericException ignore) { assert false; } throw SqlException.$(position + k, "unsupported interval qualifier"); }  static TimestampSampler getInstance(CharSequence cs, int position);  }