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));
}
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;
}
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;
}
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();
}
Aggregations