Search in sources :

Example 16 with GridQueryTypeDescriptor

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);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObject(org.apache.ignite.binary.BinaryObject) GridQueryTypeDescriptor(org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor)

Example 17 with GridQueryTypeDescriptor

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);
    }
}
Also used : ArrayList(java.util.ArrayList) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) BatchUpdateException(java.sql.BatchUpdateException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) GridQueryTypeDescriptor(org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor)

Example 18 with GridQueryTypeDescriptor

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;
}
Also used : ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) GridQueryTypeDescriptor(org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor)

Example 19 with GridQueryTypeDescriptor

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;
}
Also used : TreeSet(java.util.TreeSet) GridQueryIndexDescriptor(org.apache.ignite.internal.processors.query.GridQueryIndexDescriptor) Comparator(java.util.Comparator) GridQueryTypeDescriptor(org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor)

Example 20 with GridQueryTypeDescriptor

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;
                }
            }
        }
    }
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) H2TreeIndexBase(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndexBase) ArrayList(java.util.ArrayList) Index(org.h2.index.Index) GridQueryTypeDescriptor(org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor) IgniteEx(org.apache.ignite.internal.IgniteEx) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) GridQueryProcessor(org.apache.ignite.internal.processors.query.GridQueryProcessor) Collection(java.util.Collection) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) IgniteH2Indexing(org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing)

Aggregations

GridQueryTypeDescriptor (org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor)29 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)16 GridQueryProperty (org.apache.ignite.internal.processors.query.GridQueryProperty)13 ArrayList (java.util.ArrayList)12 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)11 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 HashMap (java.util.HashMap)9 Map (java.util.Map)9 LinkedHashMap (java.util.LinkedHashMap)8 BatchUpdateException (java.sql.BatchUpdateException)7 HashSet (java.util.HashSet)7 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)7 GridH2RowDescriptor (org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor)7 Column (org.h2.table.Column)7 List (java.util.List)6 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)6 IgniteException (org.apache.ignite.IgniteException)5 BinaryObject (org.apache.ignite.binary.BinaryObject)5 QueryIndex (org.apache.ignite.cache.QueryIndex)5 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)5