Search in sources :

Example 36 with QueryIndex

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

the class AbstractJdbcPojoQuerySelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    GridTestProperties.setProperty(GridTestProperties.MARSH_CLASS_NAME, BinaryMarshaller.class.getName());
    IgniteConfiguration cfg = super.getConfiguration(gridName);
    CacheConfiguration<?, ?> cache = defaultCacheConfiguration();
    cache.setWriteSynchronizationMode(FULL_SYNC);
    cache.setAtomicityMode(TRANSACTIONAL);
    TcpDiscoverySpi disco = new TcpDiscoverySpi();
    disco.setIpFinder(IP_FINDER);
    cfg.setDiscoverySpi(disco);
    cfg.setConnectorConfiguration(new ConnectorConfiguration());
    QueryEntity queryEntity = new QueryEntity();
    queryEntity.setKeyType("java.lang.String");
    queryEntity.setValueType("org.apache.ignite.internal.JdbcTestObject");
    queryEntity.addQueryField("id", "java.lang.Integer", null);
    queryEntity.addQueryField("testObject", "org.apache.ignite.internal.JdbcTestObject2", null);
    queryEntity.setIndexes(Collections.singletonList(new QueryIndex("id")));
    cache.setQueryEntities(Collections.singletonList(queryEntity));
    cfg.setCacheConfiguration(cache);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) QueryIndex(org.apache.ignite.cache.QueryIndex) ConnectorConfiguration(org.apache.ignite.configuration.ConnectorConfiguration) QueryEntity(org.apache.ignite.cache.QueryEntity) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 37 with QueryIndex

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

the class JdbcThinMetadataSelfTest method beforeTestsStarted.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTestsStarted() throws Exception {
    super.beforeTestsStarted();
    startGridsMultiThreaded(3);
    IgniteCache<String, Organization> orgCache = jcache(grid(0), cacheConfiguration(new QueryEntity(String.class.getName(), Organization.class.getName()).addQueryField("id", Integer.class.getName(), null).addQueryField("name", String.class.getName(), null).setIndexes(Arrays.asList(new QueryIndex("id"), new QueryIndex("name", false, "org_name_index")))), "org");
    assert orgCache != null;
    orgCache.put("o1", new Organization(1, "A"));
    orgCache.put("o2", new Organization(2, "B"));
    LinkedHashMap<String, Boolean> persFields = new LinkedHashMap<>();
    persFields.put("name", true);
    persFields.put("age", false);
    IgniteCache<AffinityKey, Person> personCache = jcache(grid(0), cacheConfiguration(new QueryEntityEx(new QueryEntity(AffinityKey.class.getName(), Person.class.getName()).addQueryField("name", String.class.getName(), null).addQueryField("age", Integer.class.getName(), null).addQueryField("orgId", Integer.class.getName(), null).setIndexes(Arrays.asList(new QueryIndex("orgId"), new QueryIndex().setFields(persFields)))).setNotNullFields(new HashSet<>(Arrays.asList("age", "name")))), "pers");
    assert personCache != null;
    personCache.put(new AffinityKey<>("p1", "o1"), new Person("John White", 25, 1));
    personCache.put(new AffinityKey<>("p2", "o1"), new Person("Joe Black", 35, 1));
    personCache.put(new AffinityKey<>("p3", "o2"), new Person("Mike Green", 40, 2));
    try (Connection conn = DriverManager.getConnection(URL)) {
        Statement stmt = conn.createStatement();
        stmt.execute("CREATE TABLE TEST (ID INT, NAME VARCHAR(50) default 'default name', " + "age int default 21, VAL VARCHAR(50), PRIMARY KEY (ID, NAME))");
        stmt.execute("CREATE TABLE \"Quoted\" (\"Id\" INT primary key, \"Name\" VARCHAR(50)) WITH WRAP_KEY");
        stmt.execute("CREATE INDEX \"MyTestIndex quoted\" on \"Quoted\" (\"Id\" DESC)");
        stmt.execute("CREATE INDEX IDX ON TEST (ID ASC)");
    }
}
Also used : QueryEntityEx(org.apache.ignite.internal.processors.query.QueryEntityEx) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) QueryEntity(org.apache.ignite.cache.QueryEntity) LinkedHashMap(java.util.LinkedHashMap) QueryIndex(org.apache.ignite.cache.QueryIndex) AffinityKey(org.apache.ignite.cache.affinity.AffinityKey)

Example 38 with QueryIndex

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

the class CacheQueryBuildValueTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setMarshaller(null);
    ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
    CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
    QueryEntity entity = new QueryEntity();
    entity.setKeyType(Integer.class.getName());
    entity.setValueType(TestBuilderValue.class.getName());
    ArrayList<QueryIndex> idxs = new ArrayList<>();
    QueryIndex idx = new QueryIndex("iVal");
    idxs.add(idx);
    LinkedHashMap<String, String> fields = new LinkedHashMap<>();
    fields.put("iVal", Integer.class.getName());
    entity.setFields(fields);
    entity.setIndexes(idxs);
    ccfg.setQueryEntities(Collections.singleton(entity));
    cfg.setCacheConfiguration(ccfg);
    BinaryConfiguration binaryCfg = new BinaryConfiguration();
    BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
    typeCfg.setTypeName(TestBuilderValue.class.getName());
    binaryCfg.setTypeConfigurations(Collections.singletonList(typeCfg));
    cfg.setBinaryConfiguration(binaryCfg);
    return cfg;
}
Also used : ArrayList(java.util.ArrayList) QueryEntity(org.apache.ignite.cache.QueryEntity) LinkedHashMap(java.util.LinkedHashMap) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) QueryIndex(org.apache.ignite.cache.QueryIndex) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 39 with QueryIndex

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

the class IgnitePdsCacheRebalancingAbstractTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);
    cfg.setConsistentId(gridName);
    CacheConfiguration ccfg1 = cacheConfiguration(cacheName).setPartitionLossPolicy(PartitionLossPolicy.READ_WRITE_SAFE).setBackups(2).setRebalanceMode(CacheRebalanceMode.ASYNC).setIndexedTypes(Integer.class, Integer.class).setAffinity(new RendezvousAffinityFunction(false, 32)).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    CacheConfiguration ccfg2 = cacheConfiguration("indexed");
    ccfg2.setBackups(1);
    ccfg2.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    QueryEntity qryEntity = new QueryEntity(Integer.class.getName(), TestValue.class.getName());
    LinkedHashMap<String, String> fields = new LinkedHashMap<>();
    fields.put("v1", Integer.class.getName());
    fields.put("v2", Integer.class.getName());
    qryEntity.setFields(fields);
    QueryIndex qryIdx = new QueryIndex("v1", true);
    qryEntity.setIndexes(Collections.singleton(qryIdx));
    ccfg2.setQueryEntities(Collections.singleton(qryEntity));
    // Do not start filtered cache on coordinator.
    if (gridName.endsWith("0")) {
        cfg.setCacheConfiguration(ccfg1, ccfg2);
    } else {
        CacheConfiguration ccfg3 = cacheConfiguration("filtered");
        ccfg3.setPartitionLossPolicy(PartitionLossPolicy.READ_ONLY_SAFE);
        ccfg3.setBackups(1);
        ccfg3.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
        ccfg3.setNodeFilter(new CoordinatorNodeFilter());
        cfg.setCacheConfiguration(ccfg1, ccfg2, ccfg3);
    }
    DataStorageConfiguration memCfg = new DataStorageConfiguration();
    memCfg.setConcurrencyLevel(Runtime.getRuntime().availableProcessors() * 4);
    memCfg.setPageSize(1024);
    memCfg.setWalMode(WALMode.LOG_ONLY);
    DataRegionConfiguration memPlcCfg = new DataRegionConfiguration();
    memPlcCfg.setName("dfltDataRegion");
    memPlcCfg.setMaxSize(150 * 1024 * 1024);
    memPlcCfg.setInitialSize(100 * 1024 * 1024);
    memPlcCfg.setSwapPath("work/swap");
    memPlcCfg.setPersistenceEnabled(true);
    memCfg.setDefaultDataRegionConfiguration(memPlcCfg);
    cfg.setDataStorageConfiguration(memCfg);
    cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER));
    return cfg;
}
Also used : QueryEntity(org.apache.ignite.cache.QueryEntity) LinkedHashMap(java.util.LinkedHashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) QueryIndex(org.apache.ignite.cache.QueryIndex) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 40 with QueryIndex

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

the class GridQueryProcessor method prepareChangeOnStartedCache.

/**
 * Prepare change on started cache.
 *
 * @param op Operation.
 * @return Result: affected type, nop flag, error.
 */
private T3<QueryTypeDescriptorImpl, Boolean, SchemaOperationException> prepareChangeOnStartedCache(SchemaAbstractOperation op) {
    QueryTypeDescriptorImpl type = null;
    boolean nop = false;
    SchemaOperationException err = null;
    String cacheName = op.cacheName();
    if (op instanceof SchemaIndexCreateOperation) {
        SchemaIndexCreateOperation op0 = (SchemaIndexCreateOperation) op;
        QueryIndex idx = op0.index();
        // Make sure table exists.
        String tblName = op0.tableName();
        type = type(cacheName, tblName);
        if (type == null)
            err = new SchemaOperationException(SchemaOperationException.CODE_TABLE_NOT_FOUND, tblName);
        else {
            // Make sure that index can be applied to the given table.
            for (String idxField : idx.getFieldNames()) {
                if (!type.fields().containsKey(idxField)) {
                    err = new SchemaOperationException(SchemaOperationException.CODE_COLUMN_NOT_FOUND, idxField);
                    break;
                }
            }
        }
        // Check conflict with other indexes.
        if (err == null) {
            String idxName = op0.index().getName();
            QueryIndexKey idxKey = new QueryIndexKey(op.schemaName(), idxName);
            if (idxs.get(idxKey) != null) {
                if (op0.ifNotExists())
                    nop = true;
                else
                    err = new SchemaOperationException(SchemaOperationException.CODE_INDEX_EXISTS, idxName);
            }
        }
    } else if (op instanceof SchemaIndexDropOperation) {
        SchemaIndexDropOperation op0 = (SchemaIndexDropOperation) op;
        String idxName = op0.indexName();
        QueryIndexDescriptorImpl oldIdx = idxs.get(new QueryIndexKey(op.schemaName(), idxName));
        if (oldIdx == null) {
            if (op0.ifExists())
                nop = true;
            else
                err = new SchemaOperationException(SchemaOperationException.CODE_INDEX_NOT_FOUND, idxName);
        } else
            type = oldIdx.typeDescriptor();
    } else if (op instanceof SchemaAlterTableAddColumnOperation) {
        SchemaAlterTableAddColumnOperation op0 = (SchemaAlterTableAddColumnOperation) op;
        type = type(cacheName, op0.tableName());
        if (type == null) {
            if (op0.ifTableExists())
                nop = true;
            else
                err = new SchemaOperationException(SchemaOperationException.CODE_TABLE_NOT_FOUND, op0.tableName());
        } else {
            for (QueryField col : op0.columns()) {
                if (type.hasField(col.name())) {
                    if (op0.ifNotExists()) {
                        assert op0.columns().size() == 1;
                        nop = true;
                    } else
                        err = new SchemaOperationException(SchemaOperationException.CODE_COLUMN_EXISTS, col.name());
                }
            }
        }
    } else if (op instanceof SchemaAlterTableDropColumnOperation) {
        SchemaAlterTableDropColumnOperation op0 = (SchemaAlterTableDropColumnOperation) op;
        type = type(cacheName, op0.tableName());
        if (type == null) {
            if (op0.ifTableExists())
                nop = true;
            else
                err = new SchemaOperationException(SchemaOperationException.CODE_TABLE_NOT_FOUND, op0.tableName());
        } else {
            for (String name : op0.columns()) {
                if (err != null)
                    break;
                if (!type.hasField(name)) {
                    if (op0.ifExists()) {
                        assert op0.columns().size() == 1;
                        nop = true;
                    } else
                        err = new SchemaOperationException(SchemaOperationException.CODE_COLUMN_NOT_FOUND, name);
                    break;
                }
                err = QueryUtils.validateDropColumn(type, name);
            }
        }
    } else
        err = new SchemaOperationException("Unsupported operation: " + op);
    return new T3<>(type, nop, err);
}
Also used : SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) SchemaIndexCreateOperation(org.apache.ignite.internal.processors.query.schema.operation.SchemaIndexCreateOperation) SchemaIndexDropOperation(org.apache.ignite.internal.processors.query.schema.operation.SchemaIndexDropOperation) SchemaAlterTableAddColumnOperation(org.apache.ignite.internal.processors.query.schema.operation.SchemaAlterTableAddColumnOperation) QueryIndex(org.apache.ignite.cache.QueryIndex) SchemaAlterTableDropColumnOperation(org.apache.ignite.internal.processors.query.schema.operation.SchemaAlterTableDropColumnOperation) T3(org.apache.ignite.internal.util.typedef.T3)

Aggregations

QueryIndex (org.apache.ignite.cache.QueryIndex)89 QueryEntity (org.apache.ignite.cache.QueryEntity)46 LinkedHashMap (java.util.LinkedHashMap)35 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)26 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)24 ArrayList (java.util.ArrayList)21 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)20 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)14 Ignite (org.apache.ignite.Ignite)13 CacheException (javax.cache.CacheException)10 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)10 IgniteException (org.apache.ignite.IgniteException)9 HashMap (java.util.HashMap)8 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)8 Map (java.util.Map)7 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)7 HashSet (java.util.HashSet)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 BinaryObject (org.apache.ignite.binary.BinaryObject)5 CountDownLatch (java.util.concurrent.CountDownLatch)4