Search in sources :

Example 66 with Path

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();
            }
        }
    }
}
Also used : Path(com.questdb.std.str.Path)

Example 67 with Path

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"));
    }
}
Also used : Path(com.questdb.std.str.Path) NumericException(com.questdb.common.NumericException) TestMicroClock(com.questdb.test.tools.TestMicroClock) Test(org.junit.Test)

Example 68 with Path

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;
}
Also used : Path(com.questdb.std.str.Path)

Example 69 with Path

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);
    }
}
Also used : Path(com.questdb.std.str.Path) NumericException(com.questdb.common.NumericException)

Example 70 with Path

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);
        }
    }
}
Also used : Path(com.questdb.std.str.Path) DateLocale(com.questdb.std.time.DateLocale) DirectByteCharSequence(com.questdb.std.str.DirectByteCharSequence) IOException(java.io.IOException)

Aggregations

Path (com.questdb.std.str.Path)74 Test (org.junit.Test)46 File (java.io.File)8 Rnd (com.questdb.std.Rnd)7 LPSZ (com.questdb.std.str.LPSZ)6 NativeLPSZ (com.questdb.std.str.NativeLPSZ)5 NumericException (com.questdb.common.NumericException)3 RecordColumnMetadata (com.questdb.common.RecordColumnMetadata)3 DirectCharSequence (com.questdb.std.str.DirectCharSequence)3 StringSink (com.questdb.std.str.StringSink)3 RowCursor (com.questdb.common.RowCursor)2 CreateTableModel (com.questdb.griffin.lexer.model.CreateTableModel)2 ObjList (com.questdb.std.ObjList)2 JournalMetadata (com.questdb.store.factory.configuration.JournalMetadata)2 TestMicroClock (com.questdb.test.tools.TestMicroClock)2 ByteBuffer (java.nio.ByteBuffer)2 Record (com.questdb.common.Record)1 RecordCursor (com.questdb.common.RecordCursor)1 Chars (com.questdb.std.Chars)1 FilesFacade (com.questdb.std.FilesFacade)1