use of org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor in project ignite by apache.
the class H2DynamicIndexingComplexTest method assertPerson.
/**
* Check contents of SQL data row and corresponding cache entry.
* @param id Expected id.
* @param name Expected name.
* @param age Expected age.
* @param company Expected company.
* @param city Expected city.
* @param person Data row.
*/
private void assertPerson(int id, String name, int age, String company, String city, List<?> person) {
assertEquals(name, name(person));
assertEquals(age, age(person));
assertEquals(company, company(person));
assertEquals(city, city(person));
String cacheName = "SQL_PUBLIC_PERSON";
Collection<GridQueryTypeDescriptor> descs = node().context().query().types(cacheName);
assertEquals(1, descs.size());
GridQueryTypeDescriptor desc = descs.iterator().next();
String keyType = desc.keyTypeName();
String valType = desc.valueTypeName();
BinaryObject k = node().binary().builder(keyType).setField("id", id).setField("name", name).setField("city", city).build();
Object v = node().cache(cacheName).withKeepBinary().get(k);
assertNotNull(v);
BinaryObject expVal = node().binary().builder(valType).setField("age", age).setField("company", company).build();
assertEquals(expVal, v);
}
use of org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor in project ignite by apache.
the class OdbcRequestHandler method getTablesMeta.
/**
* {@link OdbcQueryGetTablesMetaRequest} command handler.
*
* @param req Get tables metadata request.
* @return Response.
*/
private ClientListenerResponse getTablesMeta(OdbcQueryGetTablesMetaRequest req) {
try {
List<OdbcTableMeta> meta = new ArrayList<>();
String schemaPattern = OdbcUtils.removeQuotationMarksIfNeeded(req.schema());
for (String cacheName : ctx.cache().publicCacheNames()) {
for (GridQueryTypeDescriptor table : ctx.query().types(cacheName)) {
if (!matches(table.schemaName(), schemaPattern) || !matches(table.tableName(), req.table()) || !matchesTableType("TABLE", req.tableType()))
continue;
OdbcTableMeta tableMeta = new OdbcTableMeta(null, table.schemaName(), table.tableName(), "TABLE");
if (!meta.contains(tableMeta))
meta.add(tableMeta);
}
}
OdbcQueryGetTablesMetaResult res = new OdbcQueryGetTablesMetaResult(meta);
return new OdbcResponse(res);
} catch (Exception e) {
U.error(log, "Failed to get tables metadata [reqId=" + req.requestId() + ", req=" + req + ']', e);
return exceptionToResult(e);
}
}
use of org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor in project ignite by apache.
the class JdbcMetadataInfo method getPrimaryKeys.
/**
* See {@link DatabaseMetaData#getPrimaryKeys(String, String, String)} for details.
*
* Ignite has only one possible CATALOG_NAME, it is handled on the client (driver) side.
*
* @return Collection of primary keys information for tables that matches specified schema and table name patterns.
*/
public Collection<JdbcPrimaryKeyMeta> getPrimaryKeys(String schemaNamePtrn, String tblNamePtrn) {
Collection<JdbcPrimaryKeyMeta> meta = new HashSet<>();
for (String cacheName : ctx.cache().publicCacheNames()) {
for (GridQueryTypeDescriptor table : ctx.query().types(cacheName)) {
if (!matches(table.schemaName(), schemaNamePtrn))
continue;
if (!matches(table.tableName(), tblNamePtrn))
continue;
List<String> fields = new ArrayList<>();
for (String field : table.fields().keySet()) {
if (table.property(field).key())
fields.add(field);
}
final String keyName = table.keyFieldName() == null ? "PK_" + table.schemaName() + "_" + table.tableName() : table.keyFieldName();
if (fields.isEmpty()) {
String keyColName = table.keyFieldName() == null ? QueryUtils.KEY_FIELD_NAME : table.keyFieldName();
meta.add(new JdbcPrimaryKeyMeta(table.schemaName(), table.tableName(), keyName, Collections.singletonList(keyColName)));
} else
meta.add(new JdbcPrimaryKeyMeta(table.schemaName(), table.tableName(), keyName, fields));
}
}
return meta;
}
use of org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor in project ignite by apache.
the class JdbcMetadataInfo method getIndexesMeta.
/**
* See {@link DatabaseMetaData#getIndexInfo(String, String, String, boolean, boolean)} for details.
*
* Ignite has only one possible CATALOG_NAME, it is handled on the client (driver) side. Parameters {@code unique}
* {@code approximate} are ignored.
*
* @return Sorted by index name collection of index info, filtered according to specified criterias.
*/
public SortedSet<JdbcIndexMeta> getIndexesMeta(String schemaNamePtrn, String tblNamePtrn) {
final Comparator<JdbcIndexMeta> byIndexName = new Comparator<JdbcIndexMeta>() {
@Override
public int compare(JdbcIndexMeta o1, JdbcIndexMeta o2) {
return o1.indexName().compareTo(o2.indexName());
}
};
TreeSet<JdbcIndexMeta> meta = new TreeSet<>(byIndexName);
for (String cacheName : ctx.cache().publicCacheNames()) {
for (GridQueryTypeDescriptor table : ctx.query().types(cacheName)) {
if (!matches(table.schemaName(), schemaNamePtrn))
continue;
if (!matches(table.tableName(), tblNamePtrn))
continue;
for (GridQueryIndexDescriptor idxDesc : table.indexes().values()) meta.add(new JdbcIndexMeta(table.schemaName(), table.tableName(), idxDesc));
}
}
return meta;
}
use of org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor in project ignite by apache.
the class GridCommandHandlerBrokenIndexTest method addBadIndex.
/**
* Adds index that fails on {@code find()}.
*/
private void addBadIndex() {
IgniteEx ignite = grid(0);
int grpId = CU.cacheGroupId(CACHE_NAME, GROUP_NAME);
CacheGroupContext grpCtx = ignite.context().cache().cacheGroup(grpId);
assertNotNull(grpCtx);
GridQueryProcessor qry = ignite.context().query();
IgniteH2Indexing indexing = (IgniteH2Indexing) qry.getIndexing();
outer: for (GridCacheContext ctx : grpCtx.caches()) {
Collection<GridQueryTypeDescriptor> types = qry.types(ctx.name());
if (!F.isEmpty(types)) {
for (GridQueryTypeDescriptor type : types) {
GridH2Table gridH2Tbl = indexing.schemaManager().dataTable(ctx.name(), type.tableName());
if (gridH2Tbl == null)
continue;
ArrayList<Index> indexes = gridH2Tbl.getIndexes();
BadIndex bi = null;
for (Index idx : indexes) {
if (idx instanceof H2TreeIndexBase) {
bi = new BadIndex(gridH2Tbl, IDX_NAME, idx.getIndexColumns(), idx.getIndexType());
break;
}
}
if (bi != null) {
indexes.add(bi);
break outer;
}
}
}
}
}
Aggregations