use of org.h2.table.IndexColumn in project ignite by apache.
the class IgniteH2Indexing method tablesInformation.
/**
* {@inheritDoc}
*/
@Override
public Collection<TableInformation> tablesInformation(String schemaNamePtrn, String tblNamePtrn, String... tblTypes) {
Set<String> types = F.isEmpty(tblTypes) ? Collections.emptySet() : new HashSet<>(Arrays.asList(tblTypes));
Collection<TableInformation> infos = new ArrayList<>();
boolean allTypes = F.isEmpty(tblTypes);
if (allTypes || types.contains(TableType.TABLE.name())) {
schemaMgr.dataTables().stream().filter(t -> matches(t.getSchema().getName(), schemaNamePtrn)).filter(t -> matches(t.getName(), tblNamePtrn)).map(t -> {
int cacheGrpId = t.cacheInfo().groupId();
CacheGroupDescriptor cacheGrpDesc = ctx.cache().cacheGroupDescriptors().get(cacheGrpId);
// We should skip table in case regarding cache group has been removed.
if (cacheGrpDesc == null)
return null;
GridQueryTypeDescriptor type = t.rowDescriptor().type();
IndexColumn affCol = t.getExplicitAffinityKeyColumn();
String affinityKeyCol = affCol != null ? affCol.columnName : null;
return new TableInformation(t.getSchema().getName(), t.getName(), TableType.TABLE.name(), cacheGrpId, cacheGrpDesc.cacheOrGroupName(), t.cacheId(), t.cacheName(), affinityKeyCol, type.keyFieldAlias(), type.valueFieldAlias(), type.keyTypeName(), type.valueTypeName());
}).filter(Objects::nonNull).forEach(infos::add);
}
if ((allTypes || types.contains(TableType.VIEW.name())) && matches(QueryUtils.SCHEMA_SYS, schemaNamePtrn)) {
schemaMgr.systemViews().stream().filter(t -> matches(t.getTableName(), tblNamePtrn)).map(v -> new TableInformation(QueryUtils.SCHEMA_SYS, v.getTableName(), TableType.VIEW.name())).forEach(infos::add);
}
return infos;
}
use of org.h2.table.IndexColumn in project ignite by apache.
the class IgniteH2Indexing method columnsInformation.
/**
* {@inheritDoc}
*/
@Override
public Collection<ColumnInformation> columnsInformation(String schemaNamePtrn, String tblNamePtrn, String colNamePtrn) {
Collection<ColumnInformation> infos = new ArrayList<>();
// Gather information about tables.
schemaMgr.dataTables().stream().filter(t -> matches(t.getSchema().getName(), schemaNamePtrn)).filter(t -> matches(t.getName(), tblNamePtrn)).flatMap(tbl -> {
IndexColumn affCol = tbl.getAffinityKeyColumn();
return Stream.of(tbl.getColumns()).filter(Column::getVisible).filter(c -> matches(c.getName(), colNamePtrn)).map(c -> {
GridQueryProperty prop = tbl.rowDescriptor().type().property(c.getName());
boolean isAff = affCol != null && c.getColumnId() == affCol.column.getColumnId();
return new ColumnInformation(c.getColumnId() - QueryUtils.DEFAULT_COLUMNS_COUNT + 1, tbl.getSchema().getName(), tbl.getName(), c.getName(), prop.type(), c.isNullable(), prop.defaultValue(), prop.precision(), prop.scale(), isAff);
});
}).forEach(infos::add);
// Gather information about system views.
if (matches(QueryUtils.SCHEMA_SYS, schemaNamePtrn)) {
schemaMgr.systemViews().stream().filter(v -> matches(v.getTableName(), tblNamePtrn)).flatMap(view -> Stream.of(view.getColumns()).filter(c -> matches(c.getName(), colNamePtrn)).map(c -> new ColumnInformation(c.getColumnId() + 1, QueryUtils.SCHEMA_SYS, view.getTableName(), c.getName(), IgniteUtils.classForName(DataType.getTypeClassName(c.getType()), Object.class), c.isNullable(), null, (int) c.getPrecision(), c.getScale(), false))).forEach(infos::add);
}
return infos;
}
use of org.h2.table.IndexColumn in project ignite by apache.
the class H2TreeIndex method toSearchRowMessage.
/**
* @param row Search row.
* @return Row message.
*/
public 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;
}
use of org.h2.table.IndexColumn in project ignite by apache.
the class H2TreeIndex method createLookupBatch.
/**
* {@inheritDoc}
*/
@Override
public IndexLookupBatch createLookupBatch(TableFilter[] filters, int filter) {
QueryContext qctx = H2Utils.context(filters[filter].getSession());
if (qctx == null || qctx.distributedJoinContext() == null || !getTable().isPartitioned())
return null;
IndexColumn affCol = getTable().getAffinityKeyColumn();
GridH2RowDescriptor desc = getTable().rowDescriptor();
int affColId = -1;
boolean ucast = false;
if (affCol != null) {
affColId = affCol.column.getColumnId();
int[] masks = filters[filter].getMasks();
if (masks != null) {
ucast = (masks[affColId] & IndexCondition.EQUALITY) != 0 || desc.checkKeyIndexCondition(masks, IndexCondition.EQUALITY);
}
}
return new DistributedLookupBatch(this, cctx, ucast, affColId);
}
use of org.h2.table.IndexColumn in project ignite by apache.
the class GridSqlQueryParser method parseCreateIndex.
/**
* Parse {@code CREATE INDEX} statement.
*
* @param createIdx {@code CREATE INDEX} statement.
* @see <a href="http://h2database.com/html/grammar.html#create_index">H2 {@code CREATE INDEX} spec.</a>
*/
private GridSqlCreateIndex parseCreateIndex(CreateIndex createIdx) {
if (CREATE_INDEX_HASH.get(createIdx) || CREATE_INDEX_PRIMARY_KEY.get(createIdx) || CREATE_INDEX_UNIQUE.get(createIdx)) {
throw new IgniteSQLException("Only SPATIAL modifier is supported for CREATE INDEX", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
}
GridSqlCreateIndex res = new GridSqlCreateIndex();
Schema schema = SCHEMA_COMMAND_SCHEMA.get(createIdx);
String tblName = CREATE_INDEX_TABLE_NAME.get(createIdx);
res.schemaName(schema.getName());
res.tableName(tblName);
res.ifNotExists(CREATE_INDEX_IF_NOT_EXISTS.get(createIdx));
QueryIndex idx = new QueryIndex();
idx.setName(CREATE_INDEX_NAME.get(createIdx));
idx.setIndexType(CREATE_INDEX_SPATIAL.get(createIdx) ? QueryIndexType.GEOSPATIAL : QueryIndexType.SORTED);
IndexColumn[] cols = CREATE_INDEX_COLUMNS.get(createIdx);
LinkedHashMap<String, Boolean> flds = new LinkedHashMap<>(cols.length);
for (IndexColumn col : CREATE_INDEX_COLUMNS.get(createIdx)) {
int sortType = INDEX_COLUMN_SORT_TYPE.get(col);
if ((sortType & SortOrder.NULLS_FIRST) != 0 || (sortType & SortOrder.NULLS_LAST) != 0) {
throw new IgniteSQLException("NULLS FIRST and NULLS LAST modifiers are not supported for index columns", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
}
Boolean prev = flds.put(INDEX_COLUMN_NAME.get(col), (sortType & SortOrder.DESCENDING) == 0);
if (prev != null) {
String prevCol = INDEX_COLUMN_NAME.get(col) + " " + (prev ? "ASC" : "DESC");
throw new IgniteSQLException("Already defined column in index: " + prevCol, IgniteQueryErrorCode.COLUMN_ALREADY_EXISTS);
}
}
idx.setFields(flds);
res.index(idx);
return res;
}
Aggregations