You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ignite.apache.org by "Nikolay Izhikov (JIRA)" <ji...@apache.org> on 2018/05/16 14:53:00 UTC
[jira] [Updated] (IGNITE-8516) Not null constraint doesn't checked
[ https://issues.apache.org/jira/browse/IGNITE-8516?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Nikolay Izhikov updated IGNITE-8516:
------------------------------------
Description:
User is able to insert null into the not null column through cache-api.
If one uncomment line {{entries.put(new Organization("2"), new Address("Some address"));}} - constraint applied and exception would be thrown.
The same behaviour is expected for the 1 entry map.
Reproducer:
{code:java}
package org.apache.ignite.internal.processors.sql;
public class IgniteNotNullBug extends GridCommonAbstractTest {
@Override protected void beforeTestsStarted() throws Exception {
startGrid(0);
Set<String> nn = new HashSet<>();
nn.add("address");
jcache(grid(0), cacheConfiguration(new QueryEntity(Organization.class.getName(), Address.class.getName())
.addQueryField("address", "java.lang.String", "address")
.setNotNullFields(nn)), "ORG_ADDRESS");
}
public void testPutNullField() throws Exception {
Map<Organization, Address> entries = new HashMap<>();
entries.put(new Organization("1"), new Address(null));
//entries.put(new Organization("2"), new Address("Some address"));
IgniteCache<Organization, Address> cache = jcache(0, "ORG_ADDRESS");
cache.putAll(entries);
System.out.println("cache.getConfiguration(CacheConfiguration) = " + cache.getConfiguration(CacheConfiguration.class).getQueryEntities());
List<?> objects = execSql("SELECT address FROM ORG_ADDRESS.ADDRESS");
assert ((List)objects.get(0)).get(0) == null;
}
protected CacheConfiguration cacheConfiguration(QueryEntity qryEntity) {
CacheConfiguration<?, ?> cache = defaultCacheConfiguration();
cache.setCacheMode(CacheMode.PARTITIONED);
cache.setAtomicityMode(CacheAtomicityMode.ATOMIC);
cache.setBackups(1);
cache.setWriteSynchronizationMode(FULL_SYNC);
cache.setQueryEntities(Collections.singletonList(qryEntity));
return cache;
}
private List<?> execSql(String sql, Object... args) {
SqlFieldsQuery qry = new SqlFieldsQuery(sql)
.setArgs(args);
return grid(0).context().query().querySqlFields(qry, true).getAll();
}
private static class Organization implements Serializable {
private final String name;
private Organization(String name) { this.name = name; }
}
private static class Address implements Serializable {
private final String address;
private Address(String address) { this.address = address; }
}
}
{code}
was:
User are able to insert null into the not null column through cache-api.
If one uncomment line {{entries.put(new Organization("2"), new Address("Some address"));}} - constraint applied and exception would be thrown.
Same behaviour are expected for the 1 entry map.
Reproducer:
{code:java}
package org.apache.ignite.internal.processors.sql;
public class IgniteNotNullBug extends GridCommonAbstractTest {
@Override protected void beforeTestsStarted() throws Exception {
startGrid(0);
Set<String> nn = new HashSet<>();
nn.add("address");
jcache(grid(0), cacheConfiguration(new QueryEntity(Organization.class.getName(), Address.class.getName())
.addQueryField("address", "java.lang.String", "address")
.setNotNullFields(nn)), "ORG_ADDRESS");
}
public void testPutNullField() throws Exception {
Map<Organization, Address> entries = new HashMap<>();
entries.put(new Organization("1"), new Address(null));
//entries.put(new Organization("2"), new Address("Some address"));
IgniteCache<Organization, Address> cache = jcache(0, "ORG_ADDRESS");
cache.putAll(entries);
System.out.println("cache.getConfiguration(CacheConfiguration) = " + cache.getConfiguration(CacheConfiguration.class).getQueryEntities());
List<?> objects = execSql("SELECT address FROM ORG_ADDRESS.ADDRESS");
assert ((List)objects.get(0)).get(0) == null;
}
protected CacheConfiguration cacheConfiguration(QueryEntity qryEntity) {
CacheConfiguration<?, ?> cache = defaultCacheConfiguration();
cache.setCacheMode(CacheMode.PARTITIONED);
cache.setAtomicityMode(CacheAtomicityMode.ATOMIC);
cache.setBackups(1);
cache.setWriteSynchronizationMode(FULL_SYNC);
cache.setQueryEntities(Collections.singletonList(qryEntity));
return cache;
}
private List<?> execSql(String sql, Object... args) {
SqlFieldsQuery qry = new SqlFieldsQuery(sql)
.setArgs(args);
return grid(0).context().query().querySqlFields(qry, true).getAll();
}
private static class Organization implements Serializable {
private final String name;
private Organization(String name) { this.name = name; }
}
private static class Address implements Serializable {
private final String address;
private Address(String address) { this.address = address; }
}
}
{code}
> Not null constraint doesn't checked
> -----------------------------------
>
> Key: IGNITE-8516
> URL: https://issues.apache.org/jira/browse/IGNITE-8516
> Project: Ignite
> Issue Type: Bug
> Components: sql
> Affects Versions: 2.4
> Reporter: Nikolay Izhikov
> Priority: Major
> Fix For: 2.6
>
>
> User is able to insert null into the not null column through cache-api.
> If one uncomment line {{entries.put(new Organization("2"), new Address("Some address"));}} - constraint applied and exception would be thrown.
> The same behaviour is expected for the 1 entry map.
> Reproducer:
> {code:java}
> package org.apache.ignite.internal.processors.sql;
> public class IgniteNotNullBug extends GridCommonAbstractTest {
> @Override protected void beforeTestsStarted() throws Exception {
> startGrid(0);
> Set<String> nn = new HashSet<>();
> nn.add("address");
> jcache(grid(0), cacheConfiguration(new QueryEntity(Organization.class.getName(), Address.class.getName())
> .addQueryField("address", "java.lang.String", "address")
> .setNotNullFields(nn)), "ORG_ADDRESS");
> }
> public void testPutNullField() throws Exception {
> Map<Organization, Address> entries = new HashMap<>();
> entries.put(new Organization("1"), new Address(null));
> //entries.put(new Organization("2"), new Address("Some address"));
> IgniteCache<Organization, Address> cache = jcache(0, "ORG_ADDRESS");
> cache.putAll(entries);
> System.out.println("cache.getConfiguration(CacheConfiguration) = " + cache.getConfiguration(CacheConfiguration.class).getQueryEntities());
> List<?> objects = execSql("SELECT address FROM ORG_ADDRESS.ADDRESS");
>
> assert ((List)objects.get(0)).get(0) == null;
> }
> protected CacheConfiguration cacheConfiguration(QueryEntity qryEntity) {
> CacheConfiguration<?, ?> cache = defaultCacheConfiguration();
> cache.setCacheMode(CacheMode.PARTITIONED);
> cache.setAtomicityMode(CacheAtomicityMode.ATOMIC);
> cache.setBackups(1);
> cache.setWriteSynchronizationMode(FULL_SYNC);
> cache.setQueryEntities(Collections.singletonList(qryEntity));
> return cache;
> }
> private List<?> execSql(String sql, Object... args) {
> SqlFieldsQuery qry = new SqlFieldsQuery(sql)
> .setArgs(args);
> return grid(0).context().query().querySqlFields(qry, true).getAll();
> }
> private static class Organization implements Serializable {
> private final String name;
> private Organization(String name) { this.name = name; }
> }
> private static class Address implements Serializable {
> private final String address;
> private Address(String address) { this.address = address; }
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)