Search in sources :

Example 6 with NumericException

use of com.questdb.common.NumericException in project questdb by bluestreak01.

the class Journal method configurePartitions.

private void configurePartitions() {
    File[] files = getLocation().listFiles(f -> f.isDirectory() && !f.getName().startsWith(Constants.TEMP_DIRECTORY_PREFIX));
    int partitionIndex = 0;
    if (files != null && tx.journalMaxRowID > 0) {
        Arrays.sort(files);
        for (int i = 0; i < files.length; i++) {
            File f = files[i];
            if (partitionIndex > Rows.toPartitionIndex(tx.journalMaxRowID)) {
                break;
            }
            long txLimit = Journal.TX_LIMIT_EVAL;
            long[] indexTxAddresses = null;
            if (partitionIndex == Rows.toPartitionIndex(tx.journalMaxRowID)) {
                txLimit = Rows.toLocalRowID(tx.journalMaxRowID);
                indexTxAddresses = tx.indexPointers;
            }
            try {
                Interval interval = new Interval(f.getName(), getMetadata().getPartitionBy());
                if (partitionIndex < partitions.size()) {
                    Partition<T> partition = partitions.getQuick(partitionIndex);
                    Interval that = partition.getInterval();
                    if (that == null || that.equals(interval)) {
                        partition.applyTx(txLimit, indexTxAddresses);
                        partitionIndex++;
                    } else {
                        partition.close();
                        partitions.remove(partitionIndex);
                    }
                } else {
                    partitions.add(new Partition<>(this, interval, partitionIndex++, txLimit, indexTxAddresses, sequentialAccess));
                }
            } catch (NumericException e) {
                LOG.info().$("Foreign directory: ").$(f.getName()).$();
            }
        }
    }
    configureIrregularPartition();
}
Also used : NumericException(com.questdb.common.NumericException) File(java.io.File) Interval(com.questdb.std.time.Interval)

Example 7 with NumericException

use of com.questdb.common.NumericException in project questdb by bluestreak01.

the class Net method parseIPv4.

private static int parseIPv4(CharSequence address) {
    int ip = 0;
    int count = 0;
    int lo = 0;
    int hi;
    try {
        while ((hi = Chars.indexOf(address, lo, '.')) > -1) {
            int n = Numbers.parseInt(address, lo, hi);
            ip = (ip << 8) | n;
            count++;
            lo = hi + 1;
        }
        if (count != 3) {
            throw new NetworkError("Invalid ip address: " + address);
        }
        return (ip << 8) | Numbers.parseInt(address, lo, address.length());
    } catch (NumericException e) {
        throw new NetworkError("Invalid ip address: " + address);
    }
}
Also used : NetworkError(com.questdb.std.ex.NetworkError) NumericException(com.questdb.common.NumericException)

Example 8 with NumericException

use of com.questdb.common.NumericException 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 9 with NumericException

use of com.questdb.common.NumericException in project questdb by bluestreak01.

the class StaticContentHandler method send.

private void send(IOContext context, LPSZ path, boolean asAttachment) throws IOException {
    int n = Chars.lastIndexOf(path, '.');
    if (n == -1) {
        LOG.info().$("Missing extension: ").$(path).$();
        context.simpleResponse().send(404);
        return;
    }
    CharSequence contentType = mimeTypes.valueAt(mimeTypes.keyIndex(path, n + 1, path.length()));
    CharSequence val;
    if ((val = context.request.getHeader("Range")) != null) {
        sendRange(context, val, path, contentType, asAttachment);
        return;
    }
    int l;
    if ((val = context.request.getHeader("If-None-Match")) != null && (l = val.length()) > 2 && val.charAt(0) == '"' && val.charAt(l - 1) == '"') {
        try {
            long that = Numbers.parseLong(val, 1, l - 1);
            if (that == Files.getLastModified(path)) {
                context.simpleResponse().sendEmptyBody(304);
                return;
            }
        } catch (NumericException e) {
            LOG.info().$("Received wrong tag [").$(val).$("] for ").$(path).$();
            context.simpleResponse().send(400);
            return;
        }
    }
    sendVanilla(context, path, contentType, asAttachment);
}
Also used : FileNameExtractorCharSequence(com.questdb.std.str.FileNameExtractorCharSequence) NumericException(com.questdb.common.NumericException)

Example 10 with NumericException

use of com.questdb.common.NumericException in project questdb by bluestreak01.

the class QueryFilterAnalyser method analyzeNotInInterval.

private boolean analyzeNotInInterval(IntrinsicModel model, ExprNode col, ExprNode in) throws ParserException {
    if (!isTimestamp(col)) {
        return false;
    }
    if (in.paramCount > 3) {
        throw QueryError.$(in.args.getQuick(0).position, "Too many args");
    }
    if (in.paramCount < 3) {
        throw QueryError.$(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(quoteEraser.ofQuoted(lo.token));
        } catch (NumericException ignore) {
            throw QueryError.$(lo.position, "Unknown date format");
        }
        try {
            hiMillis = DateFormatUtils.tryParse(quoteEraser.ofQuoted(hi.token));
        } catch (NumericException ignore) {
            throw QueryError.$(hi.position, "Unknown date format");
        }
        model.subtractIntervals(loMillis, hiMillis);
        in.intrinsicValue = IntrinsicValue.TRUE;
        return true;
    }
    return false;
}
Also used : ExprNode(com.questdb.parser.sql.model.ExprNode) NumericException(com.questdb.common.NumericException)

Aggregations

NumericException (com.questdb.common.NumericException)12 Path (com.questdb.std.str.Path)3 ExprNode (com.questdb.griffin.common.ExprNode)2 ExprNode (com.questdb.parser.sql.model.ExprNode)2 TestMicroClock (com.questdb.test.tools.TestMicroClock)2 Test (org.junit.Test)2 NetworkError (com.questdb.std.ex.NetworkError)1 DirectByteCharSequence (com.questdb.std.str.DirectByteCharSequence)1 FileNameExtractorCharSequence (com.questdb.std.str.FileNameExtractorCharSequence)1 LPSZ (com.questdb.std.str.LPSZ)1 Interval (com.questdb.std.time.Interval)1 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)1 File (java.io.File)1