use of org.apache.ignite.cache.QueryEntity in project ignite by apache.
the class IgniteCacheAbstractFieldsQuerySelfTest method testExecuteWithMetaDataAndCustomKeyPrecision.
/**
*/
@Test
public void testExecuteWithMetaDataAndCustomKeyPrecision() throws Exception {
QueryEntity qeWithPrecision = new QueryEntity().setKeyType("java.lang.String").setKeyFieldName("my_key").setValueType("CustomKeyType").addQueryField("my_key", "java.lang.String", "my_key").addQueryField("strField", "java.lang.String", "strField").setFieldsPrecision(ImmutableMap.of("strField", 999, "my_key", 777));
grid(0).getOrCreateCache(cacheConfiguration().setName("cacheWithCustomKeyPrecision").setQueryEntities(Collections.singleton(qeWithPrecision)));
GridQueryProcessor qryProc = grid(0).context().query();
qryProc.querySqlFields(new SqlFieldsQuery("INSERT INTO CustomKeyType(my_key, strField) VALUES(?, ?)").setSchema("cacheWithCustomKeyPrecision").setArgs("1", "ABC"), true);
qryProc.querySqlFields(new SqlFieldsQuery("INSERT INTO CustomKeyType(my_key, strField) VALUES(?, ?)").setSchema("cacheWithCustomKeyPrecision").setArgs("2", "DEF"), true);
QueryCursorImpl<List<?>> cursor = (QueryCursorImpl<List<?>>) qryProc.querySqlFields(new SqlFieldsQuery("SELECT my_key, strField FROM CustomKeyType").setSchema("cacheWithCustomKeyPrecision"), true);
List<GridQueryFieldMetadata> fieldsMeta = cursor.fieldsMeta();
int fldCnt = 0;
for (GridQueryFieldMetadata meta : fieldsMeta) {
switch(meta.fieldName()) {
case "STRFIELD":
assertEquals(999, meta.precision());
fldCnt++;
break;
case "MY_KEY":
assertEquals(777, meta.precision());
fldCnt++;
break;
default:
fail("Unknown field - " + meta.fieldName());
}
}
assertEquals("Metadata for all fields should be returned.", 2, fldCnt);
}
use of org.apache.ignite.cache.QueryEntity in project ignite by apache.
the class IgniteCacheAbstractFieldsQuerySelfTest method testDecimalColumnScaleAndPrecision.
/**
* Test that scale and precision returned correctly for Decimal column in result set:
*
* 1. Start node;
* 2. Create table with Decimal(3,0) column;
* 3. Insert a new row into the table;
* 4. Execute select with decimal row;
* 5. Check that selected decimal column has precision 3 and scale 0.
*
* @throws Exception If failed.
*/
@Test
public void testDecimalColumnScaleAndPrecision() throws Exception {
QueryEntity qeWithPrecision = new QueryEntity().setKeyType("java.lang.Long").setValueType("TestType").addQueryField("age", "java.math.BigDecimal", "age").setFieldsPrecision(ImmutableMap.of("age", 3)).setFieldsScale(ImmutableMap.of("age", 0));
grid(0).getOrCreateCache(cacheConfiguration().setName("cacheWithDecimalPrecisionAndScale").setQueryEntities(Collections.singleton(qeWithPrecision)));
GridQueryProcessor qryProc = grid(0).context().query();
qryProc.querySqlFields(new SqlFieldsQuery("INSERT INTO TestType(_key, age) VALUES(?, ?)").setSchema("cacheWithDecimalPrecisionAndScale").setArgs(1, new BigDecimal(160)), true);
QueryCursorImpl<List<?>> cursor = (QueryCursorImpl<List<?>>) qryProc.querySqlFields(new SqlFieldsQuery("SELECT age FROM TestType").setSchema("cacheWithDecimalPrecisionAndScale"), true);
List<GridQueryFieldMetadata> fieldsMeta = cursor.fieldsMeta();
assertEquals(1, fieldsMeta.size());
GridQueryFieldMetadata meta = fieldsMeta.get(0);
assertEquals(3, meta.precision());
assertEquals(0, meta.scale());
}
use of org.apache.ignite.cache.QueryEntity in project ignite by apache.
the class IgniteCacheAbstractQuerySelfTest method cacheConfiguration.
/**
* @return cache configuration
*/
protected CacheConfiguration cacheConfiguration() {
CacheConfiguration cc = defaultCacheConfiguration();
cc.setCacheMode(cacheMode());
cc.setAtomicityMode(atomicityMode());
cc.setNearConfiguration(nearCacheConfiguration());
cc.setWriteSynchronizationMode(FULL_SYNC);
cc.setCacheStoreFactory(new StoreFactory());
cc.setReadThrough(true);
cc.setWriteThrough(true);
cc.setLoadPreviousValue(true);
cc.setRebalanceMode(SYNC);
cc.setSqlFunctionClasses(SqlFunctions.class);
List<QueryEntity> entityList = new ArrayList<>();
QueryEntity qryEntity = new QueryEntity();
qryEntity.setKeyType(Integer.class.getName());
qryEntity.setValueType(Type1.class.getName());
qryEntity.addQueryField("id", Integer.class.getName(), null);
qryEntity.addQueryField("name", String.class.getName(), null);
qryEntity.setTableName("Type2");
qryEntity.setIndexes(Arrays.asList(new QueryIndex("id").setName("index~!@#$%^&*()_=-+;[]{}|?,.*`:nameWithNonLetterSymbols")));
entityList.add(qryEntity);
qryEntity = new QueryEntity();
qryEntity.setKeyType(Integer.class.getName());
qryEntity.setValueType(Type2.class.getName());
qryEntity.addQueryField("id", Integer.class.getName(), null);
qryEntity.addQueryField("name", String.class.getName(), null);
qryEntity.setTableName("Type1");
qryEntity.setIndexes(Arrays.asList(new QueryIndex("id")));
entityList.add(qryEntity);
qryEntity = new QueryEntity();
qryEntity.setKeyType(Integer.class.getName());
qryEntity.setValueType(ObjectValue2.class.getName());
qryEntity.addQueryField("strVal", String.class.getName(), null);
// Default index type
final QueryIndex strIdx = new QueryIndex();
strIdx.setFieldNames(Collections.singletonList("strVal"), true);
qryEntity.setIndexes(Arrays.asList(strIdx));
entityList.add(qryEntity);
cc.setQueryEntities(entityList);
if (cacheMode() != CacheMode.LOCAL)
cc.setAffinity(new RendezvousAffinityFunction());
// Explicitly set number of backups equal to number of grids.
if (cacheMode() == CacheMode.PARTITIONED)
cc.setBackups(gridCount());
return cc;
}
use of org.apache.ignite.cache.QueryEntity in project ignite by apache.
the class IgniteCacheDistributedJoinCustomAffinityMapper method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
List<CacheConfiguration> ccfgs = new ArrayList<>();
{
CacheConfiguration ccfg = configuration(PERSON_CACHE);
QueryEntity entity = new QueryEntity();
entity.setKeyType(Integer.class.getName());
entity.setValueType(Person.class.getName());
entity.addQueryField("orgId", Integer.class.getName(), null);
entity.setIndexes(F.asList(new QueryIndex("orgId")));
ccfg.setQueryEntities(F.asList(entity));
ccfgs.add(ccfg);
}
{
CacheConfiguration ccfg = configuration(PERSON_CACHE_CUSTOM_AFF);
ccfg.setAffinityMapper(new TestMapper());
QueryEntity entity = new QueryEntity();
entity.setKeyType(Integer.class.getName());
entity.setValueType(Person.class.getName());
entity.addQueryField("orgId", Integer.class.getName(), null);
entity.setIndexes(F.asList(new QueryIndex("orgId")));
ccfg.setQueryEntities(F.asList(entity));
ccfgs.add(ccfg);
}
{
CacheConfiguration ccfg = configuration(ORG_CACHE);
QueryEntity entity = new QueryEntity();
entity.setKeyType(Integer.class.getName());
entity.setValueType(Organization.class.getName());
ccfg.setQueryEntities(F.asList(entity));
ccfgs.add(ccfg);
}
{
CacheConfiguration ccfg = configuration(ORG_CACHE_REPL_CUSTOM);
ccfg.setCacheMode(REPLICATED);
ccfg.setAffinityMapper(new TestMapper());
QueryEntity entity = new QueryEntity();
entity.setKeyType(Integer.class.getName());
entity.setValueType(Organization.class.getName());
ccfg.setQueryEntities(F.asList(entity));
ccfgs.add(ccfg);
}
cfg.setCacheConfiguration(ccfgs.toArray(new CacheConfiguration[ccfgs.size()]));
return cfg;
}
use of org.apache.ignite.cache.QueryEntity in project ignite by apache.
the class IgniteCacheFullTextQueryNodeJoiningSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
CacheConfiguration cache = new CacheConfiguration(DEFAULT_CACHE_NAME);
cache.setCacheMode(PARTITIONED);
cache.setAtomicityMode(atomicityMode());
cache.setWriteSynchronizationMode(FULL_SYNC);
cache.setBackups(1);
cache.setRebalanceMode(CacheRebalanceMode.SYNC);
QueryEntity qryEntity = new QueryEntity();
qryEntity.setKeyType(AffinityKey.class.getName());
qryEntity.setValueType(IndexedEntity.class.getName());
LinkedHashMap<String, String> fields = new LinkedHashMap<>();
fields.put("val", String.class.getName());
qryEntity.setFields(fields);
qryEntity.setIndexes(Arrays.asList(new QueryIndex("val", QueryIndexType.FULLTEXT)));
cache.setQueryEntities(Arrays.asList(qryEntity));
cfg.setCacheConfiguration(cache);
TcpCommunicationSpi commSpi = new TcpCommunicationSpi();
commSpi.setSharedMemoryPort(-1);
cfg.setCommunicationSpi(commSpi);
return cfg;
}
Aggregations