Search in sources :

Example 1 with RowIterator

use of org.hsqldb_voltpatches.navigator.RowIterator in project voltdb by VoltDB.

the class ExpressionLogical method getAllAnyValue.

/** @todo - null value in rows */
private Boolean getAllAnyValue(Session session, Object[] data, SubQuery subquery) {
    Table table = subquery.getTable();
    boolean empty = table.isEmpty(session);
    Index index = table.getFullIndex();
    RowIterator it;
    Row firstrow;
    PersistentStore store = session.sessionData.getRowStore(table);
    Row lastrow = index.lastRow(session, store);
    Object[] lastdata;
    Object[] firstdata;
    switch(exprSubType) {
        case OpTypes.ANY_QUANTIFIED:
            {
                if (empty) {
                    return Boolean.FALSE;
                }
                if (countNulls(data) == data.length) {
                    return null;
                }
                lastdata = lastrow.getData();
                if (countNulls(lastdata) == data.length) {
                    return null;
                }
                convertToType(session, data, nodes[LEFT].nodeDataTypes, nodes[RIGHT].nodeDataTypes);
                if (opType == OpTypes.EQUAL) {
                    it = index.findFirstRow(session, store, data);
                    return it.hasNext() ? Boolean.TRUE : Boolean.FALSE;
                }
                it = index.findFirstRowNotNull(session, store);
                firstrow = it.getNextRow();
                firstdata = firstrow.getData();
                Boolean comparefirst = compareValues(session, data, firstdata);
                Boolean comparelast = compareValues(session, data, lastdata);
                switch(opType) {
                    case OpTypes.NOT_EQUAL:
                        return Boolean.TRUE.equals(comparefirst) || Boolean.TRUE.equals(comparelast) ? Boolean.TRUE : Boolean.FALSE;
                    case OpTypes.GREATER:
                        return comparefirst;
                    case OpTypes.GREATER_EQUAL:
                        return comparefirst;
                    case OpTypes.SMALLER:
                        return comparelast;
                    case OpTypes.SMALLER_EQUAL:
                        return comparelast;
                }
                break;
            }
        case OpTypes.ALL_QUANTIFIED:
            {
                if (empty) {
                    return Boolean.TRUE;
                }
                if (countNulls(data) == data.length) {
                    return null;
                }
                it = index.firstRow(session, store);
                firstrow = it.getNextRow();
                firstdata = firstrow.getData();
                if (countNulls(firstdata) == data.length) {
                    return null;
                }
                convertToType(session, data, nodes[LEFT].nodeDataTypes, nodes[RIGHT].nodeDataTypes);
                it = index.findFirstRow(session, store, data);
                if (opType == OpTypes.EQUAL) {
                    if (it.hasNext()) {
                        return subquery.getTable().getRowCount(store) == 1 ? Boolean.TRUE : Boolean.FALSE;
                    } else {
                        return Boolean.FALSE;
                    }
                }
                if (opType == OpTypes.NOT_EQUAL) {
                    return it.hasNext() ? Boolean.FALSE : Boolean.TRUE;
                }
                lastdata = lastrow.getData();
                Boolean comparefirst = compareValues(session, data, firstdata);
                Boolean comparelast = compareValues(session, data, lastdata);
                switch(opType) {
                    case OpTypes.GREATER:
                        return comparelast;
                    case OpTypes.GREATER_EQUAL:
                        return comparelast;
                    case OpTypes.SMALLER:
                        return comparefirst;
                    case OpTypes.SMALLER_EQUAL:
                        return comparefirst;
                }
                break;
            }
    }
    return null;
}
Also used : RowIterator(org.hsqldb_voltpatches.navigator.RowIterator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) Index(org.hsqldb_voltpatches.index.Index)

Example 2 with RowIterator

use of org.hsqldb_voltpatches.navigator.RowIterator in project voltdb by VoltDB.

the class DataFileDefrag method writeTableToDataFile.

int[] writeTableToDataFile(Table table) throws IOException {
    Session session = database.getSessionManager().getSysSession();
    PersistentStore store = session.sessionData.getRowStore(table);
    RowOutputInterface rowOut = new RowOutputBinary();
    DoubleIntIndex pointerLookup = new DoubleIntIndex(table.getPrimaryIndex().sizeEstimate(store), false);
    int[] rootsArray = table.getIndexRootsArray();
    long pos = fileOffset;
    int count = 0;
    pointerLookup.setKeysSearchTarget();
    Error.printSystemOut("lookup begins: " + stopw.elapsedTime());
    RowIterator it = table.rowIterator(session);
    for (; it.hasNext(); count++) {
        CachedObject row = it.getNextRow();
        pointerLookup.addUnsorted(row.getPos(), (int) (pos / scale));
        if (count % 50000 == 0) {
            Error.printSystemOut("pointer pair for row " + count + " " + row.getPos() + " " + pos);
        }
        pos += row.getStorageSize();
    }
    Error.printSystemOut(table.getName().name + " list done ", stopw.elapsedTime());
    count = 0;
    it = table.rowIterator(session);
    for (; it.hasNext(); count++) {
        CachedObject row = it.getNextRow();
        rowOut.reset();
        row.write(rowOut, pointerLookup);
        fileStreamOut.write(rowOut.getOutputStream().getBuffer(), 0, rowOut.size());
        fileOffset += row.getStorageSize();
        if ((count) % 50000 == 0) {
            Error.printSystemOut(count + " rows " + stopw.elapsedTime());
        }
    }
    for (int i = 0; i < rootsArray.length; i++) {
        if (rootsArray[i] == -1) {
            continue;
        }
        int lookupIndex = pointerLookup.findFirstEqualKeyIndex(rootsArray[i]);
        if (lookupIndex == -1) {
            throw Error.error(ErrorCode.DATA_FILE_ERROR);
        }
        rootsArray[i] = pointerLookup.getValue(lookupIndex);
    }
    setTransactionRowLookups(pointerLookup);
    Error.printSystemOut(table.getName().name + " : table converted");
    return rootsArray;
}
Also used : RowOutputInterface(org.hsqldb_voltpatches.rowio.RowOutputInterface) RowIterator(org.hsqldb_voltpatches.navigator.RowIterator) DoubleIntIndex(org.hsqldb_voltpatches.lib.DoubleIntIndex) RowOutputBinary(org.hsqldb_voltpatches.rowio.RowOutputBinary) Session(org.hsqldb_voltpatches.Session)

Example 3 with RowIterator

use of org.hsqldb_voltpatches.navigator.RowIterator in project voltdb by VoltDB.

the class TableWorks method checkConvertColDataType.

/**
     *
     * @param oldCol Column
     * @param newCol Column
     */
void checkConvertColDataType(ColumnSchema oldCol, ColumnSchema newCol) {
    int colIndex = table.getColumnIndex(oldCol.getName().name);
    RowIterator it = table.rowIterator(session);
    while (it.hasNext()) {
        Row row = it.getNextRow();
        Object o = row.getData()[colIndex];
        newCol.getDataType().convertToType(session, o, oldCol.getDataType());
    }
}
Also used : RowIterator(org.hsqldb_voltpatches.navigator.RowIterator)

Example 4 with RowIterator

use of org.hsqldb_voltpatches.navigator.RowIterator in project voltdb by VoltDB.

the class Table method deleteNoCheckFromLog.

/**
     * For log statements. Delete a single row.
     */
public void deleteNoCheckFromLog(Session session, Object[] data) {
    Row row = null;
    PersistentStore store = session.sessionData.getRowStore(this);
    if (hasPrimaryKey()) {
        RowIterator it = getPrimaryIndex().findFirstRow(session, store, data, primaryKeyColsSequence);
        row = it.getNextRow();
    } else if (bestIndex == null) {
        RowIterator it = rowIterator(session);
        while (true) {
            row = it.getNextRow();
            if (row == null) {
                break;
            }
            if (IndexAVL.compareRows(row.getData(), data, defaultColumnMap, colTypes) == 0) {
                break;
            }
        }
    } else {
        RowIterator it = bestIndex.findFirstRow(session, store, data);
        while (true) {
            row = it.getNextRow();
            if (row == null) {
                break;
            }
            Object[] rowdata = row.getData();
            // reached end of range
            if (bestIndex.compareRowNonUnique(data, bestIndex.getColumns(), rowdata) != 0) {
                row = null;
                break;
            }
            if (IndexAVL.compareRows(rowdata, data, defaultColumnMap, colTypes) == 0) {
                break;
            }
        }
    }
    if (row == null) {
        return;
    }
    deleteNoCheck(session, row);
}
Also used : RowIterator(org.hsqldb_voltpatches.navigator.RowIterator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore)

Example 5 with RowIterator

use of org.hsqldb_voltpatches.navigator.RowIterator in project voltdb by VoltDB.

the class ScriptWriterBase method writeExistingData.

protected void writeExistingData() throws IOException {
    // start with blank schema - SET SCHEMA to log
    currentSession.loggedSchema = null;
    Iterator schemas = database.schemaManager.allSchemaNameIterator();
    while (schemas.hasNext()) {
        String schema = (String) schemas.next();
        Iterator tables = database.schemaManager.databaseObjectIterator(schema, SchemaObject.TABLE);
        while (tables.hasNext()) {
            Table t = (Table) tables.next();
            // write all memory table data
            // write cached table data unless index roots have been written
            // write all text table data apart from readonly text tables
            // unless index roots have been written
            boolean script = false;
            switch(t.getTableType()) {
                case TableBase.MEMORY_TABLE:
                    script = true;
                    break;
                case TableBase.CACHED_TABLE:
                    script = includeCachedData;
                    break;
                case TableBase.TEXT_TABLE:
                    script = includeCachedData && !t.isReadOnly();
                    break;
            }
            try {
                if (script) {
                    schemaToLog = t.getName().schema;
                    writeTableInit(t);
                    RowIterator it = t.rowIterator(currentSession);
                    while (it.hasNext()) {
                        writeRow(currentSession, t, it.getNextRow().getData());
                    }
                    writeTableTerm(t);
                }
            } catch (Exception e) {
                throw Error.error(ErrorCode.FILE_IO_ERROR, e.toString());
            }
        }
    }
    writeDataTerm();
}
Also used : Table(org.hsqldb_voltpatches.Table) RowIterator(org.hsqldb_voltpatches.navigator.RowIterator) RowIterator(org.hsqldb_voltpatches.navigator.RowIterator) Iterator(org.hsqldb_voltpatches.lib.Iterator) IOException(java.io.IOException)

Aggregations

RowIterator (org.hsqldb_voltpatches.navigator.RowIterator)14 Row (org.hsqldb_voltpatches.Row)4 Index (org.hsqldb_voltpatches.index.Index)4 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)4 RowAVL (org.hsqldb_voltpatches.RowAVL)2 NodeAVL (org.hsqldb_voltpatches.index.NodeAVL)2 HashMappedList (org.hsqldb_voltpatches.lib.HashMappedList)2 IOException (java.io.IOException)1 HsqlException (org.hsqldb_voltpatches.HsqlException)1 Session (org.hsqldb_voltpatches.Session)1 Table (org.hsqldb_voltpatches.Table)1 DoubleIntIndex (org.hsqldb_voltpatches.lib.DoubleIntIndex)1 Iterator (org.hsqldb_voltpatches.lib.Iterator)1 CachedObject (org.hsqldb_voltpatches.persist.CachedObject)1 RowOutputBinary (org.hsqldb_voltpatches.rowio.RowOutputBinary)1 RowOutputInterface (org.hsqldb_voltpatches.rowio.RowOutputInterface)1