Search in sources :

Example 6 with RecordColumnMetadata

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

the class TableReaderMetadataTimestampTest method assertThat.

private void assertThat(String expected, int expectedInitialTimestampIndex) throws Exception {
    int columnCount = 11;
    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).$())) {
                Assert.assertEquals(12, metadata.getColumnCount());
                Assert.assertEquals(expectedInitialTimestampIndex, metadata.getTimestampIndex());
                try (TableWriter writer = new TableWriter(configuration, "all")) {
                    writer.removeColumn("timestamp");
                }
                long pTransitionIndex = metadata.createTransitionIndex();
                StringSink sink = new StringSink();
                try {
                    metadata.applyTransitionIndex(pTransitionIndex);
                    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);
                    Assert.assertEquals(-1, metadata.getTimestampIndex());
                } finally {
                    TableReaderMetadata.freeTransitionIndex(pTransitionIndex);
                }
            }
        }
    });
}
Also used : Path(com.questdb.std.str.Path) RecordColumnMetadata(com.questdb.common.RecordColumnMetadata) StringSink(com.questdb.std.str.StringSink)

Example 7 with RecordColumnMetadata

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

the class TableReaderMetadataTimestampTest method assertThatTimestampRemains.

private void assertThatTimestampRemains(TableReaderMetadataTest.ColumnManipulator manipulator, String expected, int expectedInitialTimestampIndex, int expectedFinalTimestampIndex, int expectedColumnCount) 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).$())) {
                Assert.assertEquals(12, metadata.getColumnCount());
                Assert.assertEquals(expectedInitialTimestampIndex, metadata.getTimestampIndex());
                try (TableWriter writer = new TableWriter(configuration, "all")) {
                    manipulator.restructure(writer);
                }
                long address = metadata.createTransitionIndex();
                StringSink sink = new StringSink();
                try {
                    metadata.applyTransitionIndex(address);
                    Assert.assertEquals(expectedColumnCount, metadata.getColumnCount());
                    for (int i = 0; i < expectedColumnCount; i++) {
                        RecordColumnMetadata m = metadata.getColumnQuick(i);
                        sink.put(m.getName()).put(':').put(ColumnType.nameOf(m.getType())).put('\n');
                    }
                    TestUtils.assertEquals(expected, sink);
                    Assert.assertEquals(expectedFinalTimestampIndex, metadata.getTimestampIndex());
                } finally {
                    TableReaderMetadata.freeTransitionIndex(address);
                }
            }
        }
    });
}
Also used : Path(com.questdb.std.str.Path) RecordColumnMetadata(com.questdb.common.RecordColumnMetadata) StringSink(com.questdb.std.str.StringSink)

Example 8 with RecordColumnMetadata

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

the class AvgAggregator method prepare.

@Override
public void prepare(ObjList<RecordColumnMetadata> columns, int offset) {
    columns.add(INTERNAL_COL_TOTAL);
    columns.add(INTERNAL_COL_LOCAL_TOTAL);
    columns.add(INTERNAL_COL_SUM);
    columns.add(INTERNAL_COL_LIST_HEAD);
    columns.add(INTERNAL_COL_LIST_TAIL);
    columns.add(new ColumnMetadata().setName(getName()).setType(ColumnType.DOUBLE));
    oTotal = offset;
    oLocalTotal = offset + 1;
    oSum = offset + 2;
    oListHead = offset + 3;
    oListTail = offset + 4;
    oAvg = offset + 5;
}
Also used : RecordColumnMetadata(com.questdb.common.RecordColumnMetadata) ColumnMetadata(com.questdb.store.factory.configuration.ColumnMetadata)

Example 9 with RecordColumnMetadata

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

the class VarAggregator method prepare.

@Override
public void prepare(ObjList<RecordColumnMetadata> columns, int offset) {
    columns.add(INTERNAL_COL_TOTAL);
    columns.add(INTERNAL_COL_LOCAL_TOTAL);
    columns.add(INTERNAL_COL_SUM);
    columns.add(INTERNAL_COL_MEAN_HEAD);
    columns.add(INTERNAL_COL_MEAN_TAIL);
    columns.add(INTERNAL_COL_VALUES_HEAD);
    columns.add(INTERNAL_COL_VALUES_TAIL);
    columns.add(new ColumnMetadata().setName(getName()).setType(ColumnType.DOUBLE));
    oTotal = offset;
    oPartialTotal = offset + 1;
    oPartialSum = offset + 2;
    oPartialHead = offset + 3;
    oPartialTail = offset + 4;
    oValuesHead = offset + 5;
    oValuesTail = offset + 6;
    oVariance = offset + 7;
}
Also used : RecordColumnMetadata(com.questdb.common.RecordColumnMetadata) ColumnMetadata(com.questdb.store.factory.configuration.ColumnMetadata)

Example 10 with RecordColumnMetadata

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

the class CsvHandler method resume.

@SuppressWarnings("ConstantConditions")
@Override
public void resume(IOContext context) throws IOException {
    ExportHandlerContext ctx = localContext.get(context);
    if (ctx == null || ctx.cursor == null) {
        return;
    }
    final ChunkedResponse r = context.chunkedResponse();
    final int columnCount = ctx.metadata.getColumnCount();
    OUT: while (true) {
        try {
            SWITCH: switch(ctx.queryState) {
                case QUERY_METADATA:
                    for (; ctx.columnIndex < columnCount; ctx.columnIndex++) {
                        RecordColumnMetadata column = ctx.metadata.getColumnQuick(ctx.columnIndex);
                        r.bookmark();
                        if (ctx.columnIndex > 0) {
                            r.put(',');
                        }
                        r.putQuoted(column.getName());
                    }
                    r.put(Misc.EOL);
                    ctx.queryState = QUERY_RECORD_START;
                // fall through
                case QUERY_RECORD_START:
                    if (ctx.record == null) {
                        // check if cursor has any records
                        while (true) {
                            if (ctx.cursor.hasNext()) {
                                ctx.record = ctx.cursor.next();
                                ctx.count++;
                                if (ctx.count > ctx.skip) {
                                    break;
                                }
                            } else {
                                ctx.cursor.releaseCursor();
                                ctx.cursor = null;
                                ctx.queryState = QUERY_DATA_SUFFIX;
                                break SWITCH;
                            }
                        }
                    }
                    if (ctx.count > ctx.stop) {
                        ctx.queryState = QUERY_DATA_SUFFIX;
                        break;
                    }
                    ctx.queryState = QUERY_RECORD_COLUMNS;
                    ctx.columnIndex = 0;
                // fall through
                case QUERY_RECORD_COLUMNS:
                    for (; ctx.columnIndex < columnCount; ctx.columnIndex++) {
                        RecordColumnMetadata m = ctx.metadata.getColumnQuick(ctx.columnIndex);
                        r.bookmark();
                        if (ctx.columnIndex > 0) {
                            r.put(',');
                        }
                        putValue(r, m.getType(), ctx.record, ctx.columnIndex);
                    }
                    r.bookmark();
                    r.put(Misc.EOL);
                    ctx.record = null;
                    ctx.queryState = QUERY_RECORD_START;
                    break;
                case QUERY_DATA_SUFFIX:
                    sendDone(r, ctx);
                    break OUT;
                default:
                    break OUT;
            }
        } catch (ResponseContentBufferTooSmallException ignored) {
            if (r.resetToBookmark()) {
                r.sendChunk();
            } else {
                // what we have here is out unit of data, column value or query
                // is larger that response content buffer
                // all we can do in this scenario is to log appropriately
                // and disconnect socket
                ctx.info().$("Response buffer is too small, state=").$(ctx.queryState).$();
                throw DisconnectedChannelException.INSTANCE;
            }
        }
    }
}
Also used : ResponseContentBufferTooSmallException(com.questdb.ex.ResponseContentBufferTooSmallException) RecordColumnMetadata(com.questdb.common.RecordColumnMetadata) ChunkedResponse(com.questdb.net.http.ChunkedResponse)

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