Search in sources :

Example 66 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class IgniteCacheRandomOperationBenchmark method configureCacheSqlDescriptor.

/**
     * @param cacheName Ignite cache name.
     * @param qryEntity Query entry.
     * @param valCls Class of value.
     * @throws ClassNotFoundException If fail.
     */
private void configureCacheSqlDescriptor(String cacheName, QueryEntity qryEntity, Class valCls) throws ClassNotFoundException {
    List<SqlCacheDescriptor> descs = cacheSqlDescriptors.get(cacheName);
    if (descs == null) {
        descs = new ArrayList<>();
        cacheSqlDescriptors.put(cacheName, descs);
    }
    Map<String, Class> indexedFields = new HashMap<>();
    for (QueryIndex index : qryEntity.getIndexes()) {
        for (String iField : index.getFieldNames()) {
            indexedFields.put(iField, Class.forName(qryEntity.getFields().get(iField)));
        }
    }
    descs.add(new SqlCacheDescriptor(valCls, qryEntity.getFields().keySet(), indexedFields));
}
Also used : HashMap(java.util.HashMap) QueryIndex(org.apache.ignite.cache.QueryIndex)

Example 67 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class DatabaseMetadataDialect method index.

/**
     * Create index descriptor.
     *
     * @param idxName Index name.
     * @return New initialized {@code QueryIndex} instance.
     */
protected QueryIndex index(String idxName) {
    QueryIndex idx = new QueryIndex();
    idx.setName(idxName);
    idx.setIndexType(QueryIndexType.SORTED);
    idx.setFields(new LinkedHashMap<String, Boolean>());
    return idx;
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex)

Example 68 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class JdbcMetadataDialect method tables.

/** {@inheritDoc} */
@Override
public Collection<DbTable> tables(Connection conn, List<String> schemas, boolean tblsOnly) throws SQLException {
    DatabaseMetaData dbMeta = conn.getMetaData();
    Set<String> sys = systemSchemas();
    Collection<String> unsignedTypes = unsignedTypes(dbMeta);
    if (schemas.isEmpty())
        schemas.add(null);
    Collection<DbTable> tbls = new ArrayList<>();
    for (String toSchema : schemas) {
        try (ResultSet tblsRs = dbMeta.getTables(useCatalog() ? toSchema : null, useSchema() ? toSchema : null, "%", tblsOnly ? TABLES_ONLY : TABLES_AND_VIEWS)) {
            while (tblsRs.next()) {
                String tblCatalog = tblsRs.getString(TBL_CATALOG_IDX);
                String tblSchema = tblsRs.getString(TBL_SCHEMA_IDX);
                String tblName = tblsRs.getString(TBL_NAME_IDX);
                // In case of MySql we should use catalog.
                String schema = tblSchema != null ? tblSchema : tblCatalog;
                // Skip system schemas.
                if (sys.contains(schema))
                    continue;
                Collection<String> pkCols = new HashSet<>();
                try (ResultSet pkRs = dbMeta.getPrimaryKeys(tblCatalog, tblSchema, tblName)) {
                    while (pkRs.next()) pkCols.add(pkRs.getString(PK_COL_NAME_IDX));
                }
                Collection<DbColumn> cols = new ArrayList<>();
                try (ResultSet colsRs = dbMeta.getColumns(tblCatalog, tblSchema, tblName, null)) {
                    while (colsRs.next()) {
                        String colName = colsRs.getString(COL_NAME_IDX);
                        cols.add(new DbColumn(colName, colsRs.getInt(COL_DATA_TYPE_IDX), pkCols.contains(colName), colsRs.getInt(COL_NULLABLE_IDX) == DatabaseMetaData.columnNullable, unsignedTypes.contains(colsRs.getString(COL_TYPE_NAME_IDX))));
                    }
                }
                Map<String, QueryIndex> idxs = new LinkedHashMap<>();
                try (ResultSet idxRs = dbMeta.getIndexInfo(tblCatalog, tblSchema, tblName, false, true)) {
                    while (idxRs.next()) {
                        String idxName = idxRs.getString(IDX_NAME_IDX);
                        String colName = idxRs.getString(IDX_COL_NAME_IDX);
                        if (idxName == null || colName == null)
                            continue;
                        QueryIndex idx = idxs.get(idxName);
                        if (idx == null) {
                            idx = index(idxName);
                            idxs.put(idxName, idx);
                        }
                        String askOrDesc = idxRs.getString(IDX_ASC_OR_DESC_IDX);
                        Boolean asc = askOrDesc == null || "A".equals(askOrDesc);
                        idx.getFields().put(colName, asc);
                    }
                }
                tbls.add(table(schema, tblName, cols, idxs.values()));
            }
        }
    }
    return tbls;
}
Also used : DbColumn(org.apache.ignite.console.agent.db.DbColumn) ArrayList(java.util.ArrayList) DatabaseMetaData(java.sql.DatabaseMetaData) LinkedHashMap(java.util.LinkedHashMap) ResultSet(java.sql.ResultSet) QueryIndex(org.apache.ignite.cache.QueryIndex) DbTable(org.apache.ignite.console.agent.db.DbTable) HashSet(java.util.HashSet)

Example 69 with QueryIndex

use of org.apache.ignite.cache.QueryIndex in project ignite by apache.

the class OracleMetadataDialect method indexes.

/**
     * Retrieve index columns.
     *
     * @param stmt Prepared SQL statement to execute.
     * @param owner DB owner.
     * @param tbl Table name.
     * @return Indexes.
     * @throws SQLException If failed to retrieve indexes columns.
     */
private Collection<QueryIndex> indexes(PreparedStatement stmt, String owner, String tbl) throws SQLException {
    Map<String, QueryIndex> idxs = new LinkedHashMap<>();
    stmt.setString(1, owner);
    stmt.setString(2, tbl);
    try (ResultSet idxsRs = stmt.executeQuery()) {
        while (idxsRs.next()) {
            String idxName = idxsRs.getString(IDX_NAME_IDX);
            QueryIndex idx = idxs.get(idxName);
            if (idx == null) {
                idx = index(idxName);
                idxs.put(idxName, idx);
            }
            String expr = idxsRs.getString(IDX_EXPR_IDX);
            String col = expr == null ? idxsRs.getString(IDX_COL_NAME_IDX) : expr.replaceAll("\"", "");
            idx.getFields().put(col, !"DESC".equals(idxsRs.getString(IDX_COL_DESCEND_IDX)));
        }
    }
    return idxs.values();
}
Also used : ResultSet(java.sql.ResultSet) QueryIndex(org.apache.ignite.cache.QueryIndex) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

QueryIndex (org.apache.ignite.cache.QueryIndex)69 QueryEntity (org.apache.ignite.cache.QueryEntity)35 LinkedHashMap (java.util.LinkedHashMap)25 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)21 ArrayList (java.util.ArrayList)18 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)16 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 Ignite (org.apache.ignite.Ignite)13 IgniteException (org.apache.ignite.IgniteException)8 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)8 HashMap (java.util.HashMap)7 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)7 CacheException (javax.cache.CacheException)6 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)6 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 HashSet (java.util.HashSet)4 Map (java.util.Map)4 BinaryObject (org.apache.ignite.binary.BinaryObject)4