You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ignite.apache.org by "Sergey Kalashnikov (JIRA)" <ji...@apache.org> on 2017/01/18 14:27:26 UTC
[jira] [Commented] (IGNITE-1543) SqlQuery returns empty result set
when custom PortableIdMapper
[ https://issues.apache.org/jira/browse/IGNITE-1543?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15828164#comment-15828164 ]
Sergey Kalashnikov commented on IGNITE-1543:
--------------------------------------------
I have refreshed the reproducer code since it was pretty outdated and would not compile.
The issue is gone. The code I used is below.
{code}
package org.apache.ignite.examples.misc.client;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import org.apache.ignite.binary.BinaryIdMapper;
import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.binary.BinaryObjectBuilder;
import org.apache.ignite.binary.BinaryTypeConfiguration;
import org.apache.ignite.cache.CacheAtomicityMode;
import org.apache.ignite.cache.CacheTypeFieldMetadata;
import org.apache.ignite.cache.CacheTypeMetadata;
import org.apache.ignite.cache.QueryEntity;
import org.apache.ignite.cache.query.SqlQuery;
import org.apache.ignite.configuration.BinaryConfiguration;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.configuration.TransactionConfiguration;
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder;
import java.util.*;
public class ClientTest {
public static void main(String[] args) {
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setPeerClassLoadingEnabled(true);
BinaryMarshaller marshaller = new BinaryMarshaller();
BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
typeCfg.setTypeName("company");
typeCfg.setIdMapper(new BinaryIdMapper() {
@Override public int typeId(String clsName) {
System.out.println("Company mapper!!");
//Comment out this comparision and query will return non empty result set!
if (clsName.equals("company"))
return 123;
return 0;
}
@Override public int fieldId(int typeId, String fieldName) {
return 0;
}
});
BinaryConfiguration bcfg = new BinaryConfiguration();
bcfg.setTypeConfigurations(Arrays.asList(typeCfg));
cfg.setBinaryConfiguration(bcfg);
cfg.setMarshaller(marshaller);
TransactionConfiguration trCfg = new TransactionConfiguration();
trCfg.setTxSerializableEnabled(true);
cfg.setTransactionConfiguration(trCfg);
TcpDiscoverySpi spi = new TcpDiscoverySpi();
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
spi.setIpFinder(ipFinder);
ipFinder.setAddresses(Arrays.asList("127.0.0.1:47500..47509"));
cfg.setDiscoverySpi(spi);
CacheConfiguration compCacheCfg = new CacheConfiguration();
compCacheCfg.setName("company");
compCacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
boolean useQueryEntity = false;
if (!useQueryEntity) {
CacheTypeMetadata typeMetadata = new CacheTypeMetadata();
typeMetadata.setKeyType(Integer.class);
typeMetadata.setValueType("company");
CacheTypeFieldMetadata addrFieldMeta = new CacheTypeFieldMetadata();
addrFieldMeta.setJavaName("addr");
addrFieldMeta.setJavaType(String.class);
typeMetadata.setValueFields(Arrays.asList(addrFieldMeta));
typeMetadata.setQueryFields(new HashMap<String, Class<?>>() {{
put("addr", String.class);
}});
compCacheCfg.setTypeMetadata(Arrays.asList(typeMetadata));
} else {
compCacheCfg.setQueryEntities(new ArrayList<QueryEntity>() {{
QueryEntity e = new QueryEntity();
e.setKeyType("java.lang.Integer");
e.setValueType("company");
e.setFields(new LinkedHashMap<String, String>(){{
put("addr", "java.lang.String");
}});
add(e);
}});
}
cfg.setCacheConfiguration(compCacheCfg);
Ignite ignite = Ignition.start(cfg);
BinaryObjectBuilder builder = ignite.binary().builder("company");
builder.setField("addr", "USA");
IgniteCache<Integer, BinaryObject> cache = ignite.cache("company").withKeepBinary();
cache.put(0, builder.build());
System.out.println("Object after modifications: " + cache.get(0));
List<?> results = cache.query(new SqlQuery<>("company", "SELECT * FROM company")).getAll();
System.out.println("Query result: " + results);
System.out.println("Query size: " + results.size());
assert (results.size() == 1);
ignite.close();
}
}
{code}
> SqlQuery returns empty result set when custom PortableIdMapper
> --------------------------------------------------------------
>
> Key: IGNITE-1543
> URL: https://issues.apache.org/jira/browse/IGNITE-1543
> Project: Ignite
> Issue Type: Bug
> Components: SQL
> Affects Versions: ignite-1.4
> Reporter: Denis Magda
> Assignee: Sergey Kalashnikov
> Priority: Minor
> Fix For: 1.9
>
> Attachments: ClientTest.java
>
>
> Set custom {{PortableIdMapper}} for a type. Let this mapper to return some predefined id for this type (like 12345).
> Then execute SQL to get all the entries of this type. The query will return an empty result set.
> Seems that at some point of execution SQL engine or some other part of the platform uses default type to id mapping ignoring given {{PotableIdMapper}}.
> To reproduce:
> - Start a server node with portable marshaller enabled;
> - run the code attached (ClientTest.java).
> Add a test to our test suites.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)