Search in sources :

Example 1 with RecordColumnMetadata

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

the class ImportHandler method resumeJson.

private static void resumeJson(ImportHandlerContext ctx, ChunkedResponse r) throws DisconnectedChannelException, SlowWritableChannelException {
    final JournalMetadata m = ctx.importer.getJournalMetadata();
    final ObjList<ImportedColumnMetadata> importedMetadata = ctx.importer.getImportedMetadata();
    final int columnCount = m.getColumnCount();
    final LongList errors = ctx.importer.getErrors();
    switch(ctx.responseState) {
        case RESPONSE_PREFIX:
            long totalRows = ctx.textParser.getLineCount();
            long importedRows = ctx.importer.getImportedRowCount();
            r.put('{').putQuoted("status").put(':').putQuoted("OK").put(',').putQuoted("location").put(':').encodeUtf8AndQuote(FileNameExtractorCharSequence.get(m.getName())).put(',').putQuoted("rowsRejected").put(':').put(totalRows - importedRows).put(',').putQuoted("rowsImported").put(':').put(importedRows).put(',').putQuoted("header").put(':').put(ctx.importer.isHeader()).put(',').putQuoted("columns").put(':').put('[');
            ctx.responseState = RESPONSE_COLUMN;
        // fall through
        case RESPONSE_COLUMN:
            for (; ctx.columnIndex < columnCount; ctx.columnIndex++) {
                RecordColumnMetadata cm = m.getColumnQuick(ctx.columnIndex);
                ImportedColumnMetadata im = importedMetadata.getQuick(ctx.columnIndex);
                r.bookmark();
                if (ctx.columnIndex > 0) {
                    r.put(',');
                }
                r.put('{').putQuoted("name").put(':').putQuoted(cm.getName()).put(',').putQuoted("type").put(':').putQuoted(ColumnType.nameOf(cm.getType())).put(',').putQuoted("size").put(':').put(ColumnType.sizeOf(cm.getType())).put(',').putQuoted("errors").put(':').put(errors.getQuick(ctx.columnIndex));
                if (im.pattern != null) {
                    r.put(',').putQuoted("pattern").put(':').putQuoted(im.pattern);
                }
                if (im.dateLocale != null) {
                    r.put(',').putQuoted("locale").put(':').putQuoted(im.dateLocale.getId());
                }
                r.put('}');
            }
            ctx.responseState = RESPONSE_SUFFIX;
        // fall through
        case RESPONSE_SUFFIX:
            r.bookmark();
            r.put(']').put('}');
            r.sendChunk();
            r.done();
            break;
        default:
            break;
    }
}
Also used : JournalMetadata(com.questdb.store.factory.configuration.JournalMetadata) ImportedColumnMetadata(com.questdb.parser.ImportedColumnMetadata) RecordColumnMetadata(com.questdb.common.RecordColumnMetadata)

Example 2 with RecordColumnMetadata

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

the class QueryFilterAnalyser method analyzeListOfValues.

private boolean analyzeListOfValues(IntrinsicModel model, String col, RecordMetadata meta, ExprNode node) {
    RecordColumnMetadata colMeta = meta.getColumn(col);
    if (colMeta.isIndexed()) {
        boolean newColumn = true;
        if (preferredKeyColumn != null && !col.equals(preferredKeyColumn)) {
            return false;
        }
        // check if we already have indexed column and it is of worse selectivity
        if (model.keyColumn != null && (newColumn = !model.keyColumn.equals(col)) && colMeta.getBucketCount() <= meta.getColumn(model.keyColumn).getBucketCount()) {
            return false;
        }
        int i = node.paramCount - 1;
        tempKeys.clear();
        tempPos.clear();
        // if any of values is not an indexed constant - bail out
        if (i == 1) {
            if (node.rhs == null || node.rhs.type != ExprNode.CONSTANT) {
                return false;
            }
            if (tempKeys.add(Chars.stripQuotes(node.rhs.token))) {
                tempPos.add(node.position);
            }
        } else {
            for (i--; i > -1; i--) {
                ExprNode c = node.args.getQuick(i);
                if (c.type != ExprNode.CONSTANT) {
                    return false;
                }
                if (tempKeys.add(Chars.stripQuotes(c.token))) {
                    tempPos.add(c.position);
                }
            }
        }
        // and reset intrinsic values on nodes associated with old column
        if (newColumn) {
            model.keyValues.clear();
            model.keyValuePositions.clear();
            model.keyValues.addAll(tempKeys);
            model.keyValuePositions.addAll(tempPos);
            for (int n = 0, k = keyNodes.size(); n < k; n++) {
                keyNodes.getQuick(n).intrinsicValue = IntrinsicValue.UNDEFINED;
            }
            keyNodes.clear();
            model.keyColumn = col;
            keyNodes.add(node);
            node.intrinsicValue = IntrinsicValue.TRUE;
            return true;
        } else if (!model.keyValuesIsLambda) {
            // calculate overlap of values
            replaceAllWithOverlap(model);
            keyNodes.add(node);
            node.intrinsicValue = IntrinsicValue.TRUE;
            return true;
        }
    }
    return false;
}
Also used : ExprNode(com.questdb.parser.sql.model.ExprNode) RecordColumnMetadata(com.questdb.common.RecordColumnMetadata)

Example 3 with RecordColumnMetadata

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

the class VwapAggregator method prepare.

@Override
public void prepare(ObjList<RecordColumnMetadata> columns, int offset) {
    columns.add(INTERNAL_COL_AMOUNT);
    columns.add(INTERNAL_COL_QUANTITY);
    columns.add(new ColumnMetadata().setName(getName()).setType(ColumnType.DOUBLE));
    sumAmtIdx = offset;
    sumQtyIdx = offset + 1;
    vwap = offset + 2;
}
Also used : RecordColumnMetadata(com.questdb.common.RecordColumnMetadata) ColumnMetadata(com.questdb.store.factory.configuration.ColumnMetadata)

Example 4 with RecordColumnMetadata

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

the class QueryFilterAnalyser method analyzeInLambda.

private boolean analyzeInLambda(IntrinsicModel model, String col, RecordMetadata meta, ExprNode node) throws ParserException {
    RecordColumnMetadata colMeta = meta.getColumn(col);
    if (colMeta.isIndexed()) {
        if (preferredKeyColumn != null && !col.equals(preferredKeyColumn)) {
            return false;
        }
        if (node.rhs == null || node.rhs.type != ExprNode.LAMBDA) {
            return false;
        }
        // check if we already have indexed column and it is of worse selectivity
        if (model.keyColumn != null && (!model.keyColumn.equals(col)) && colMeta.getBucketCount() <= meta.getColumn(model.keyColumn).getBucketCount()) {
            // todo: no test hit
            return false;
        }
        // todo: this is going to fail if "in" args are functions
        if ((col.equals(model.keyColumn) && model.keyValuesIsLambda) || node.paramCount > 2) {
            throw QueryError.$(node.position, "Multiple lambda expressions not supported");
        }
        model.keyValues.clear();
        model.keyValuePositions.clear();
        model.keyValues.add(Chars.stripQuotes(node.rhs.token));
        model.keyValuePositions.add(node.position);
        model.keyValuesIsLambda = true;
        // revert previously processed nodes
        for (int n = 0, k = keyNodes.size(); n < k; n++) {
            keyNodes.getQuick(n).intrinsicValue = IntrinsicValue.UNDEFINED;
        }
        keyNodes.clear();
        model.keyColumn = col;
        keyNodes.add(node);
        node.intrinsicValue = IntrinsicValue.TRUE;
        return true;
    }
    return false;
}
Also used : RecordColumnMetadata(com.questdb.common.RecordColumnMetadata)

Example 5 with RecordColumnMetadata

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

the class TableReaderMetadataTest method assertThat.

private void assertThat(String expected, ColumnManipulator manipulator, int columnCount) throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (Path path = new Path().of(root).concat("all")) {
            try (TableReaderMetadata metadata = new TableReaderMetadata(FilesFacadeImpl.INSTANCE, "all", path.concat(TableUtils.META_FILE_NAME).$())) {
                try (TableWriter writer = new TableWriter(configuration, "all")) {
                    manipulator.restructure(writer);
                }
                long pTranstionIndex = metadata.createTransitionIndex();
                StringSink sink = new StringSink();
                try {
                    metadata.applyTransitionIndex(pTranstionIndex);
                    Assert.assertEquals(columnCount, metadata.getColumnCount());
                    for (int i = 0; i < columnCount; i++) {
                        RecordColumnMetadata m = metadata.getColumnQuick(i);
                        sink.put(m.getName()).put(':').put(ColumnType.nameOf(m.getType())).put('\n');
                    }
                    TestUtils.assertEquals(expected, sink);
                    if (expected.length() > 0) {
                        String[] lines = expected.split("\n");
                        Assert.assertEquals(columnCount, lines.length);
                        for (int i = 0; i < columnCount; i++) {
                            int p = lines[i].indexOf(':');
                            Assert.assertEquals(i, metadata.getColumnIndexQuiet(lines[i].substring(0, p)));
                        }
                    }
                } finally {
                    TableReaderMetadata.freeTransitionIndex(pTranstionIndex);
                }
            }
        }
    });
}
Also used : Path(com.questdb.std.str.Path) RecordColumnMetadata(com.questdb.common.RecordColumnMetadata) StringSink(com.questdb.std.str.StringSink)

Aggregations

RecordColumnMetadata (com.questdb.common.RecordColumnMetadata)17 FlyweightCharSequence (com.questdb.std.str.FlyweightCharSequence)4 Path (com.questdb.std.str.Path)3 StringSink (com.questdb.std.str.StringSink)3 ColumnMetadata (com.questdb.store.factory.configuration.ColumnMetadata)3 ResponseContentBufferTooSmallException (com.questdb.ex.ResponseContentBufferTooSmallException)2 ChunkedResponse (com.questdb.net.http.ChunkedResponse)2 ExprNode (com.questdb.griffin.common.ExprNode)1 ImportedColumnMetadata (com.questdb.parser.ImportedColumnMetadata)1 ExprNode (com.questdb.parser.sql.model.ExprNode)1 JournalMetadata (com.questdb.store.factory.configuration.JournalMetadata)1