Search in sources :

Example 1 with IndexColumn

use of org.gridgain.internal.h2.table.IndexColumn in project ignite by apache.

the class GridH2TreeIndex method toString.

/** {@inheritDoc} */
@Override
public String toString() {
    SB sb = new SB((indexType.isUnique() ? "Unique index '" : "Index '") + getName() + "' [");
    boolean first = true;
    for (IndexColumn col : getIndexColumns()) {
        if (first)
            first = false;
        else
            sb.a(", ");
        sb.a(col.getSQL());
    }
    sb.a(" ]");
    return sb.toString();
}
Also used : SB(org.apache.ignite.internal.util.typedef.internal.SB) IndexColumn(org.h2.table.IndexColumn)

Example 2 with IndexColumn

use of org.gridgain.internal.h2.table.IndexColumn in project ignite by apache.

the class GridSqlQuerySplitter method extractPartitionFromEquality.

/**
 * Analyses the equality operation and extracts the partition if possible
 *
 * @param op AST equality operation.
 * @param ctx Kernal Context.
 * @return partition info, or {@code null} if none identified
 */
private static CacheQueryPartitionInfo extractPartitionFromEquality(GridSqlOperation op, GridKernalContext ctx) throws IgniteCheckedException {
    assert op.operationType() == GridSqlOperationType.EQUAL;
    GridSqlElement left = op.child(0);
    GridSqlElement right = op.child(1);
    if (!(left instanceof GridSqlColumn))
        return null;
    if (!(right instanceof GridSqlConst) && !(right instanceof GridSqlParameter))
        return null;
    GridSqlColumn column = (GridSqlColumn) left;
    assert column.column().getTable() instanceof GridH2Table;
    GridH2Table tbl = (GridH2Table) column.column().getTable();
    GridH2RowDescriptor desc = tbl.rowDescriptor();
    IndexColumn affKeyCol = tbl.getAffinityKeyColumn();
    int colId = column.column().getColumnId();
    if ((affKeyCol == null || colId != affKeyCol.column.getColumnId()) && !desc.isKeyColumn(colId))
        return null;
    if (right instanceof GridSqlConst) {
        GridSqlConst constant = (GridSqlConst) right;
        return new CacheQueryPartitionInfo(ctx.affinity().partition(tbl.cacheName(), constant.value().getObject()), null, null, -1, -1);
    }
    GridSqlParameter param = (GridSqlParameter) right;
    return new CacheQueryPartitionInfo(-1, tbl.cacheName(), tbl.getName(), column.column().getType(), param.index());
}
Also used : GridH2RowDescriptor(org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) CacheQueryPartitionInfo(org.apache.ignite.internal.processors.cache.query.CacheQueryPartitionInfo) IndexColumn(org.h2.table.IndexColumn)

Example 3 with IndexColumn

use of org.gridgain.internal.h2.table.IndexColumn in project ignite by apache.

the class H2Tree method compare.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("ForLoopReplaceableByForEach")
@Override
protected int compare(BPlusIO<SearchRow> io, long pageAddr, int idx, SearchRow row) throws IgniteCheckedException {
    if (inlineSize() == 0)
        return compareRows(getRow(io, pageAddr, idx), row);
    else {
        int off = io.offset(idx);
        int fieldOff = 0;
        int lastIdxUsed = 0;
        for (int i = 0; i < inlineIdxs.size(); i++) {
            InlineIndexHelper inlineIdx = inlineIdxs.get(i);
            Value v2 = row.getValue(inlineIdx.columnIndex());
            if (v2 == null)
                return 0;
            int c = inlineIdx.compare(pageAddr, off + fieldOff, inlineSize() - fieldOff, v2, comp);
            if (c == -2)
                break;
            lastIdxUsed++;
            if (c != 0)
                return c;
            fieldOff += inlineIdx.fullSize(pageAddr, off + fieldOff);
            if (fieldOff > inlineSize())
                break;
        }
        if (lastIdxUsed == cols.length)
            return 0;
        SearchRow rowData = getRow(io, pageAddr, idx);
        for (int i = lastIdxUsed, len = cols.length; i < len; i++) {
            IndexColumn col = cols[i];
            int idx0 = col.column.getColumnId();
            Value v2 = row.getValue(idx0);
            if (v2 == null) {
                // Can't compare further.
                return 0;
            }
            Value v1 = rowData.getValue(idx0);
            int c = compareValues(v1, v2);
            if (c != 0)
                return InlineIndexHelper.fixSort(c, col.sortType);
        }
        return 0;
    }
}
Also used : Value(org.h2.value.Value) SearchRow(org.h2.result.SearchRow) IndexColumn(org.h2.table.IndexColumn)

Example 4 with IndexColumn

use of org.gridgain.internal.h2.table.IndexColumn in project ignite by apache.

the class GridH2IndexBase method toSearchRowMessage.

/**
 * @param row Search row.
 * @return Row message.
 */
private GridH2RowMessage toSearchRowMessage(SearchRow row) {
    if (row == null)
        return null;
    List<GridH2ValueMessage> vals = new ArrayList<>(indexColumns.length);
    for (IndexColumn idxCol : indexColumns) {
        Value val = row.getValue(idxCol.column.getColumnId());
        if (val == null)
            break;
        try {
            vals.add(GridH2ValueMessageFactory.toMessage(val));
        } catch (IgniteCheckedException e) {
            throw new CacheException(e);
        }
    }
    GridH2RowMessage res = new GridH2RowMessage();
    res.values(vals);
    return res;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheException(javax.cache.CacheException) GridH2ValueMessage(org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2ValueMessage) ArrayList(java.util.ArrayList) Value(org.h2.value.Value) GridH2RowMessage(org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2RowMessage) IndexColumn(org.h2.table.IndexColumn)

Example 5 with IndexColumn

use of org.gridgain.internal.h2.table.IndexColumn in project ignite by apache.

the class H2TreeIndex method getAvailableInlineColumns.

/**
 * @param cols Columns array.
 * @return List of {@link InlineIndexHelper} objects.
 */
private List<InlineIndexHelper> getAvailableInlineColumns(IndexColumn[] cols) {
    List<InlineIndexHelper> res = new ArrayList<>();
    for (IndexColumn col : cols) {
        if (!InlineIndexHelper.AVAILABLE_TYPES.contains(col.column.getType()))
            break;
        InlineIndexHelper idx = new InlineIndexHelper(col.column.getType(), col.column.getColumnId(), col.sortType, table.getCompareMode());
        res.add(idx);
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) IndexColumn(org.h2.table.IndexColumn)

Aggregations

IndexColumn (org.h2.table.IndexColumn)85 IndexColumn (org.gridgain.internal.h2.table.IndexColumn)45 Column (org.h2.table.Column)42 ArrayList (java.util.ArrayList)29 Column (org.gridgain.internal.h2.table.Column)24 Index (org.h2.index.Index)16 Value (org.h2.value.Value)15 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)14 ExpressionColumn (org.h2.expression.ExpressionColumn)14 Value (org.gridgain.internal.h2.value.Value)13 Index (org.gridgain.internal.h2.index.Index)12 Constraint (org.h2.constraint.Constraint)12 CacheException (javax.cache.CacheException)11 AlterTableAddConstraint (org.h2.command.ddl.AlterTableAddConstraint)11 Expression (org.h2.expression.Expression)11 Table (org.h2.table.Table)11 TableFilter (org.h2.table.TableFilter)10 ValueBigint (org.h2.value.ValueBigint)10 LinkedHashMap (java.util.LinkedHashMap)9 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)9