use of com.questdb.common.NumericException in project questdb by bluestreak01.
the class QueryFilterAnalyser method analyzeInInterval.
private boolean analyzeInInterval(IntrinsicModel model, ExprNode col, ExprNode in) throws ParserException {
if (!isTimestamp(col)) {
return false;
}
if (in.paramCount > 3) {
throw ParserException.$(in.args.getQuick(0).position, "Too many args");
}
if (in.paramCount < 3) {
throw ParserException.$(in.position, "Too few args");
}
ExprNode lo = in.args.getQuick(1);
ExprNode hi = in.args.getQuick(0);
if (lo.type == ExprNode.CONSTANT && hi.type == ExprNode.CONSTANT) {
long loMillis;
long hiMillis;
try {
loMillis = DateFormatUtils.tryParse(lo.token, 1, lo.token.length() - 1);
} catch (NumericException ignore) {
throw ParserException.invalidDate(lo.position);
}
try {
hiMillis = DateFormatUtils.tryParse(hi.token, 1, hi.token.length() - 1);
} catch (NumericException ignore) {
throw ParserException.invalidDate(hi.position);
}
model.intersectIntervals(loMillis, hiMillis);
in.intrinsicValue = IntrinsicValue.TRUE;
return true;
}
return false;
}
use of com.questdb.common.NumericException in project questdb by bluestreak01.
the class Misc method urlDecode.
public static int urlDecode(long lo, long hi, CharSequenceObjHashMap<CharSequence> map, ObjectPool<DirectByteCharSequence> pool) {
long _lo = lo;
long rp = lo;
long wp = lo;
final DirectByteCharSequence temp = pool.next();
int offset = 0;
CharSequence name = null;
while (rp < hi) {
char b = (char) Unsafe.getUnsafe().getByte(rp++);
switch(b) {
case '=':
if (_lo < wp) {
name = pool.next().of(_lo, wp);
}
_lo = rp - offset;
break;
case '&':
if (name != null) {
map.put(name, pool.next().of(_lo, wp));
name = null;
} else if (_lo < wp) {
map.put(pool.next().of(_lo, wp), "");
}
_lo = rp - offset;
break;
case '+':
Unsafe.getUnsafe().putByte(wp++, (byte) ' ');
continue;
case '%':
try {
if (rp + 1 < hi) {
Unsafe.getUnsafe().putByte(wp++, (byte) Numbers.parseHexInt(temp.of(rp, rp += 2)));
offset += 2;
continue;
}
} catch (NumericException ignore) {
}
name = null;
break;
default:
break;
}
Unsafe.getUnsafe().putByte(wp++, (byte) b);
}
if (_lo < wp) {
if (name != null) {
map.put(name, pool.next().of(_lo, wp));
} else {
map.put(pool.next().of(_lo, wp), "");
}
}
return offset;
}
use of com.questdb.common.NumericException in project questdb by bluestreak01.
the class CairoLineProtoParserTest method testCannotCreateTable.
@Test
public void testCannotCreateTable() throws Exception {
TestFilesFacade ff = new TestFilesFacade() {
boolean called = false;
@Override
public int mkdirs(LPSZ path, int mode) {
if (Chars.endsWith(path, "x" + Files.SEPARATOR)) {
called = true;
return -1;
}
return super.mkdirs(path, mode);
}
@Override
public boolean wasCalled() {
return called;
}
};
final String expected = "sym\tdouble\tint\tbool\tstr\ttimestamp\n" + "zzz\t1.300000000000\t11\tfalse\tnice\t2017-10-03T10:00:00.000Z\n";
String lines = "x,sym2=xyz double=1.6,int=15i,bool=true,str=\"string1\"\n" + "x,sym1=abc double=1.3,int=11i,bool=false,str=\"string2\"\n" + "y,sym=zzz double=1.3,int=11i,bool=false,str=\"nice\"\n";
CairoConfiguration configuration = new DefaultCairoConfiguration(root) {
@Override
public FilesFacade getFilesFacade() {
return ff;
}
@Override
public MicrosecondClock getClock() {
try {
return new TestMicroClock(DateFormatUtils.parseDateTime("2017-10-03T10:00:00.000Z"), 10);
} catch (NumericException e) {
throw new RuntimeException(e);
}
}
};
assertThat(expected, lines, "y", configuration);
Assert.assertTrue(ff.wasCalled());
try (Path path = new Path()) {
Assert.assertEquals(TableUtils.TABLE_DOES_NOT_EXIST, TableUtils.exists(ff, path, root, "all"));
}
}
use of com.questdb.common.NumericException in project questdb by bluestreak01.
the class QueryParser method parseCreateJournal.
private ParsedModel parseCreateJournal() throws ParserException {
ExprNode name = exprNodePool.next();
name.token = Chars.stripQuotes(tok().toString());
name.position = lexer.position();
name.type = ExprNode.LITERAL;
CharSequence tok = tok();
final JournalStructure struct;
final QueryModel queryModel;
if (Chars.equals(tok, '(')) {
queryModel = null;
struct = new JournalStructure(name.token);
lexer.unparse();
parseJournalFields(struct);
} else if (Chars.equals(tok, "as")) {
expectTok('(');
queryModel = parseQuery(true);
struct = null;
expectTok(')');
} else {
throw QueryError.position(lexer.position()).$("Unexpected token").$();
}
CreateJournalModel model = createJournalModelPool.next();
model.setStruct(struct);
model.setQueryModel(queryModel);
model.setName(name);
tok = lexer.optionTok();
while (tok != null && Chars.equals(tok, ',')) {
int pos = lexer.position();
tok = tok();
if (Chars.equals(tok, "index")) {
expectTok('(');
ColumnIndexModel columnIndexModel = columnIndexModelPool.next();
columnIndexModel.setName(expectLiteral());
pos = lexer.position();
tok = tok();
if (Chars.equals(tok, "buckets")) {
try {
columnIndexModel.setBuckets(Numbers.ceilPow2(Numbers.parseInt(tok())) - 1);
} catch (NumericException e) {
throw QueryError.$(pos, "Int constant expected");
}
pos = lexer.position();
tok = tok();
}
expectTok(tok, pos, ')');
model.addColumnIndexModel(columnIndexModel);
tok = lexer.optionTok();
} else if (Chars.equals(tok, "cast")) {
expectTok('(');
ColumnCastModel columnCastModel = columnCastModelPool.next();
columnCastModel.setName(expectLiteral());
expectTok(tok(), "as");
ExprNode node = expectLiteral();
int type = ColumnType.columnTypeOf(node.token);
if (type == -1) {
throw QueryError.$(node.position, "invalid type");
}
columnCastModel.setType(type, node.position);
if (type == ColumnType.SYMBOL) {
tok = lexer.optionTok();
pos = lexer.position();
if (Chars.equals(tok, "count")) {
try {
columnCastModel.setCount(Numbers.parseInt(tok()));
tok = tok();
} catch (NumericException e) {
throw QueryError.$(pos, "int value expected");
}
}
} else {
pos = lexer.position();
tok = tok();
}
expectTok(tok, pos, ')');
if (!model.addColumnCastModel(columnCastModel)) {
throw QueryError.$(columnCastModel.getName().position, "duplicate cast");
}
tok = lexer.optionTok();
} else {
throw QueryError.$(pos, "Unexpected token");
}
}
ExprNode timestamp = parseTimestamp(tok);
if (timestamp != null) {
model.setTimestamp(timestamp);
tok = lexer.optionTok();
}
ExprNode partitionBy = parsePartitionBy(tok);
if (partitionBy != null) {
model.setPartitionBy(partitionBy);
tok = lexer.optionTok();
}
ExprNode hint = parseRecordHint(tok);
if (hint != null) {
model.setRecordHint(hint);
tok = lexer.optionTok();
}
if (tok != null) {
throw QueryError.$(lexer.position(), "Unexpected token");
}
return model;
}
use of com.questdb.common.NumericException in project questdb by bluestreak01.
the class CairoLineProtoParserTest method testReservedName.
@Test
public void testReservedName() throws Exception {
final String expected = "sym\tdouble\tint\tbool\tstr\ttimestamp\n" + "ok\t2.100000000000\t11\tfalse\tdone\t2017-10-03T10:00:00.000Z\n";
String lines = "x,sym2=xyz double=1.6,int=15i,bool=true,str=\"string1\"\n" + "x,sym1=abc double=1.3,int=11i,bool=false,str=\"string2\"\n" + "y,sym=ok double=2.1,int=11i,bool=false,str=\"done\"\n";
CairoConfiguration configuration = new DefaultCairoConfiguration(root) {
@Override
public MicrosecondClock getClock() {
try {
return new TestMicroClock(DateFormatUtils.parseDateTime("2017-10-03T10:00:00.000Z"), 10);
} catch (NumericException e) {
throw new RuntimeException(e);
}
}
};
try (Path path = new Path()) {
Files.mkdirs(path.of(root).concat("x").put(Files.SEPARATOR).$(), configuration.getMkDirMode());
assertThat(expected, lines, "y", configuration);
Assert.assertEquals(TableUtils.TABLE_RESERVED, TableUtils.exists(configuration.getFilesFacade(), path, root, "x"));
}
}
Aggregations