use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class TableWriterTest method verifyTimestampPartitions.
void verifyTimestampPartitions(VirtualMemory vmem, int n) {
int i;
DateFormatCompiler compiler = new DateFormatCompiler();
DateFormat fmt = compiler.compile("yyyy-MM-dd");
DateLocale enGb = DateLocaleFactory.INSTANCE.getDateLocale("en-gb");
try (Path vp = new Path()) {
for (i = 0; i < n; i++) {
vp.of(root).concat(PRODUCT).put(Files.SEPARATOR);
fmt.format(vmem.getLong(i * 8), enGb, "UTC", vp);
if (!FF.exists(vp.$())) {
Assert.fail();
}
}
}
}
use of com.questdb.std.str.Path 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"));
}
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class Chars method splitLpsz.
/**
* Split character sequence into a list of lpsz strings. This function
* uses space as a delimiter and it honours spaces in double quotes. Main
* use for this code is to produce list of C-compatible argument values from
* command line.
*
* @param args command line
* @return list of 0-terminated strings
*/
public static ObjList<Path> splitLpsz(CharSequence args) {
final ObjList<Path> paths = new ObjList<>();
int n = args.length();
int lastLen = 0;
int lastIndex = 0;
boolean inQuote = false;
for (int i = 0; i < n; i++) {
char b = args.charAt(i);
switch(b) {
case ' ':
// ab c
if (lastLen > 0) {
if (inQuote) {
lastLen++;
} else {
paths.add(new Path().of(args, lastIndex, lastLen + lastIndex).$());
lastLen = 0;
}
}
break;
case '"':
inQuote = !inQuote;
break;
default:
if (lastLen == 0) {
lastIndex = i;
}
lastLen++;
break;
}
}
if (lastLen > 0) {
paths.add(new Path().of(args, lastIndex, lastLen + lastIndex).$());
}
return paths;
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class LogFileWriter method bindProperties.
@Override
public void bindProperties() {
if (this.bufferSize != null) {
try {
bufSize = Numbers.parseIntSize(this.bufferSize);
} catch (NumericException e) {
throw new LogError("Invalid value for bufferSize");
}
} else {
bufSize = DEFAULT_BUFFER_SIZE;
}
this.buf = _wptr = Unsafe.malloc(bufSize);
this.lim = buf + bufSize;
try (Path path = new Path().of(location).$()) {
if (truncate != null && Chars.equalsIgnoreCase(truncate, "true")) {
this.fd = Files.openRW(path);
Files.truncate(fd, 0);
} else {
this.fd = Files.openAppend(path);
}
}
if (this.fd == -1) {
throw new LogError("Cannot open file for append: " + location);
}
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class TypeProbeCollection method parseFile.
private void parseFile(CharSequence fileName, DateFormatFactory dateFormatFactory, DateLocaleFactory dateLocaleFactory) throws IOException {
final DirectByteCharSequence dbcs = new DirectByteCharSequence();
try (Path path = new Path().of(fileName).$()) {
long fd = Files.openRO(path);
if (fd < 0) {
throw new IOException("Cannot open " + fileName + " [errno=" + Os.errno() + ']');
}
long sz = Files.length(fd);
long buf = Unsafe.malloc(sz);
try {
Files.read(fd, buf, sz, 0);
long p = buf;
long hi = p + sz;
long _lo = p;
boolean newline = true;
boolean comment = false;
boolean quote = false;
boolean space = true;
String pattern = null;
while (p < hi) {
char b = (char) Unsafe.getUnsafe().getByte(p++);
switch(b) {
case '#':
comment = newline;
break;
case '\'':
// inside comment, ignore
if (comment) {
continue;
}
if (quote) {
// we were inside quote, close out and check which part to assign result to
if (pattern == null) {
pattern = dbcs.of(_lo, p - 1).toString();
_lo = p;
space = true;
quote = false;
} else {
// pattern has been assigned, should never end up here
LOG.error().$("Internal error").$();
}
} else if (newline) {
// only start quote if it is at beginning of line
_lo = p;
quote = true;
}
break;
case ' ':
case '\t':
if (comment || quote) {
continue;
}
if (space) {
_lo = p;
continue;
}
space = true;
newline = false;
String s = dbcs.of(_lo, p - 1).toString();
if (pattern == null) {
pattern = s;
_lo = p;
space = true;
} else {
DateLocale locale = dateLocaleFactory.getDateLocale(s);
if (locale == null) {
LOG.error().$("Unknown date locale: ").$(s).$();
// skip rest of line
comment = true;
continue;
}
probes.add(new DateProbe(dateFormatFactory, locale, pattern));
}
break;
case '\n':
case '\r':
if (!comment) {
if (_lo < p - 1) {
s = dbcs.of(_lo, p - 1).toString();
if (pattern == null) {
// no date locale, use default
probes.add(new DateProbe(dateFormatFactory, dateLocaleFactory.getDefaultDateLocale(), s));
} else {
DateLocale locale = dateLocaleFactory.getDateLocale(s);
if (locale == null) {
LOG.error().$("Unknown date locale: ").$(s).$();
} else {
probes.add(new DateProbe(dateFormatFactory, locale, pattern));
}
}
} else if (pattern != null) {
probes.add(new DateProbe(dateFormatFactory, dateLocaleFactory.getDefaultDateLocale(), pattern));
}
}
newline = true;
comment = false;
quote = false;
pattern = null;
space = false;
_lo = p;
break;
default:
if (newline) {
newline = false;
}
if (space) {
space = false;
}
break;
}
}
} finally {
Unsafe.free(buf, sz);
}
}
}
Aggregations