use of org.h2.table.IndexColumn in project ignite by apache.
the class GridSqlSortColumn method toIndexColumns.
/**
* @param tbl Table.
* @param sortCols Sort columns.
* @return Index columns.
*/
public static IndexColumn[] toIndexColumns(Table tbl, List<GridSqlSortColumn> sortCols) {
assert !F.isEmpty(sortCols);
IndexColumn[] res = new IndexColumn[sortCols.size()];
for (int i = 0; i < res.length; i++) {
GridSqlSortColumn sc = sortCols.get(i);
Column col = tbl.getColumn(sc.column());
IndexColumn c = new IndexColumn();
c.column = col;
c.columnName = col.getName();
c.sortType = sc.asc ? SortOrder.ASCENDING : SortOrder.DESCENDING;
if (sc.nullsFirst)
c.sortType |= SortOrder.NULLS_FIRST;
if (sc.nullsLast)
c.sortType |= SortOrder.NULLS_LAST;
res[i] = c;
}
return res;
}
use of org.h2.table.IndexColumn in project ignite by apache.
the class H2TableDescriptor method createSystemIndexes.
/** {@inheritDoc} */
@Override
public ArrayList<Index> createSystemIndexes(GridH2Table tbl) {
ArrayList<Index> idxs = new ArrayList<>();
IndexColumn keyCol = tbl.indexColumn(KEY_COL, SortOrder.ASCENDING);
IndexColumn affCol = tbl.getAffinityKeyColumn();
if (affCol != null && H2Utils.equals(affCol, keyCol))
affCol = null;
GridH2RowDescriptor desc = tbl.rowDescriptor();
Index hashIdx = createHashIndex(tbl, "_key_PK_hash", H2Utils.treeIndexColumns(desc, new ArrayList<IndexColumn>(2), keyCol, affCol));
if (hashIdx != null)
idxs.add(hashIdx);
// Add primary key index.
Index pkIdx = idx.createSortedIndex(schema, "_key_PK", tbl, true, H2Utils.treeIndexColumns(desc, new ArrayList<IndexColumn>(2), keyCol, affCol), -1);
idxs.add(pkIdx);
if (type().valueClass() == String.class) {
try {
luceneIdx = new GridLuceneIndex(idx.kernalContext(), schema.offheap(), tbl.cacheName(), type);
} catch (IgniteCheckedException e1) {
throw new IgniteException(e1);
}
}
boolean affIdxFound = false;
GridQueryIndexDescriptor textIdx = type.textIndex();
if (textIdx != null) {
try {
luceneIdx = new GridLuceneIndex(idx.kernalContext(), schema.offheap(), tbl.cacheName(), type);
} catch (IgniteCheckedException e1) {
throw new IgniteException(e1);
}
}
// Locate index where affinity column is first (if any).
if (affCol != null) {
for (GridQueryIndexDescriptor idxDesc : type.indexes().values()) {
if (idxDesc.type() != QueryIndexType.SORTED)
continue;
String firstField = idxDesc.fields().iterator().next();
Column col = tbl.getColumn(firstField);
IndexColumn idxCol = tbl.indexColumn(col.getColumnId(), idxDesc.descending(firstField) ? SortOrder.DESCENDING : SortOrder.ASCENDING);
affIdxFound |= H2Utils.equals(idxCol, affCol);
}
}
// Add explicit affinity key index if nothing alike was found.
if (affCol != null && !affIdxFound) {
idxs.add(idx.createSortedIndex(schema, "AFFINITY_KEY", tbl, false, H2Utils.treeIndexColumns(desc, new ArrayList<IndexColumn>(2), affCol, keyCol), -1));
}
return idxs;
}
use of org.h2.table.IndexColumn in project ignite by apache.
the class H2Utils method indexCreateSql.
/**
* Generate {@code CREATE INDEX} SQL statement for given params.
* @param fullTblName Fully qualified table name.
* @param h2Idx H2 index.
* @param ifNotExists Quietly skip index creation if it exists.
* @return Statement string.
*/
public static String indexCreateSql(String fullTblName, GridH2IndexBase h2Idx, boolean ifNotExists) {
boolean spatial = F.eq(SPATIAL_IDX_CLS, h2Idx.getClass().getName());
GridStringBuilder sb = new SB("CREATE ").a(spatial ? "SPATIAL " : "").a("INDEX ").a(ifNotExists ? "IF NOT EXISTS " : "").a(withQuotes(h2Idx.getName())).a(" ON ").a(fullTblName).a(" (");
boolean first = true;
for (IndexColumn col : h2Idx.getIndexColumns()) {
if (first)
first = false;
else
sb.a(", ");
sb.a(withQuotes(col.columnName)).a(" ").a(col.sortType == SortOrder.ASCENDING ? "ASC" : "DESC");
}
sb.a(')');
return sb.toString();
}
use of org.h2.table.IndexColumn in project ignite by apache.
the class H2Tree method compare.
/** {@inheritDoc} */
@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;
}
}
use of org.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);
res.add(idx);
}
return res;
}
Aggregations