You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Jiang Jacky <ji...@gmail.com> on 2023/06/01 04:51:21 UTC
2 caches joining error
Hello
Can someone share me with some good examples that how to make a join between 2 caches?
I am using ignite 2.7 and mocking up the example from the video https://youtu.be/4CQalha3MyY
I can query the table separately, however when I get the cache from “persons” and tried to join with “companies” it complains table “Company” is not existing.
Please share me the complete example including the configuration.
Thank you
Get Outlook for iOS<https://aka.ms/o0ukef>
Re: 2 caches joining error
Posted by Jiang Jacky <ji...@gmail.com>.
Hey, Tupitsyn
It is Scala, I have zipped all my project to you
I am testing in my local and the version of Ignite is 2.15.0
The issue is when I supply the column in “WHERE” clause, the column cannot be found, no matter I have defined the “QueryEntity”. You can also try the join query in my project.
Thank you.
Jacky
From: Pavel Tupitsyn <pt...@apache.org>
Date: Thursday, June 1, 2023 at 1:28 PM
To: user@ignite.apache.org <us...@ignite.apache.org>
Subject: Re: 2 caches joining error
Sorry I still can't run your code, it is not even Java? Closure? Kotlin?
Here is a working example of an SQL join:
https://gist.github.com/ptupitsyn/090b84182bbfe2f5e31bc90f56420672
Most likely you need to provide schema in the query, which is the cache name by default:
Select * from Person inner join \"companies\".Company on Person.companyId=Company.id
On Thu, Jun 1, 2023 at 7:40 PM Jiang Jacky <ji...@gmail.com>> wrote:
Hey, Typitsyn
I made some fixes in my own local.
The error is below
[A screenshot of a computer Description automatically generated with medium confidence]
package org.example
import org.apache.ignite.Ignition
import org.apache.ignite.cache.{CacheAtomicityMode, CacheKeyConfiguration, CacheMode, QueryEntity, QueryIndex}
import org.apache.ignite.cache.affinity.AffinityKey
import org.apache.ignite.cache.query.{SqlFieldsQuery, SqlQuery}
import org.apache.ignite.configuration.{CacheConfiguration, IgniteConfiguration}
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder
import java.util.concurrent.TimeUnit
import javax.cache.expiry.{CreatedExpiryPolicy, Duration}
/**
* @author ${user.name<http://user.name>}
*/
object App {
case class Person(id: Int, companyId: Int, name: String, price: Double)
case class Company(id: Int, name: String)
def main(args : Array[String]) {
putPersonToCache
putCompanyToCache
joinTest
}
private def joinTest = {
val cfg = new IgniteConfiguration()
cfg.setPeerClassLoadingEnabled(true)
Ignition.setClientMode(true)
val discoverySpi = new TcpDiscoverySpi
val ipFinder = new TcpDiscoveryVmIpFinder()
ipFinder.setAddresses(java.util.Arrays.asList("localhost:47500"))
discoverySpi.setIpFinder(ipFinder)
discoverySpi.setClientReconnectDisabled(false)
cfg.setDiscoverySpi(discoverySpi)
cfg.setCacheConfiguration(getPersonConf)
val ignite = Ignition.getOrStart(cfg)
val cache = ignite.getOrCreateCache[AffinityKey[Int], Person]("persons")
val qry = new SqlFieldsQuery("Select * from Person inner join Company on Person.companyId=Company.id", true)
val list = cache.query(qry).getAll
println(list)
}
private def putPersonToCache = {
val cfg = new IgniteConfiguration()
cfg.setPeerClassLoadingEnabled(false)
Ignition.setClientMode(true)
val discoverySpi = new TcpDiscoverySpi
val ipFinder = new TcpDiscoveryVmIpFinder()
ipFinder.setAddresses(java.util.Arrays.asList("localhost:47500"))
discoverySpi.setIpFinder(ipFinder)
discoverySpi.setClientReconnectDisabled(false)
cfg.setDiscoverySpi(discoverySpi)
cfg.setCacheConfiguration(getPersonConf)
val ignite = Ignition.getOrStart(cfg)
val cache = ignite.getOrCreateCache[AffinityKey[Int], Person]("persons")
val person1 = Person(1, 1, "test1", 1.0)
val person2 = Person(2, 1, "test2", 2.0)
val person3 = Person(3, 2, "test3", 3.0)
val person4 = Person(4, 2, "test4", 4.0)
val addToCache: Person => Unit = person => cache.put(new AffinityKey[Int](person.id<http://person.id>, person.companyId), person)
addToCache(person1)
addToCache(person2)
addToCache(person3)
addToCache(person4)
val qry1 = new SqlQuery(classOf[Person], "Select * from Person")
val list = cache.query(qry1).getAll
println(list)
}
private def putCompanyToCache = {
val cfg = new IgniteConfiguration()
cfg.setPeerClassLoadingEnabled(false)
Ignition.setClientMode(true)
val discoverySpi = new TcpDiscoverySpi
val ipFinder = new TcpDiscoveryVmIpFinder()
ipFinder.setAddresses(java.util.Arrays.asList("localhost:47500"))
discoverySpi.setIpFinder(ipFinder)
discoverySpi.setClientReconnectDisabled(false)
cfg.setDiscoverySpi(discoverySpi)
cfg.setCacheConfiguration(getCompanyConf)
val ignite = Ignition.getOrStart(cfg)
val cache = ignite.getOrCreateCache[Int, Company]("companies_cache")
val c1 = Company(1,"company1")
val c2 = Company(2, "company2")
val addToCache: Company => Unit = company => cache.put(company.id<http://company.id>, company)
addToCache(c1)
addToCache(c2)
val qry1 = new SqlQuery(classOf[Company], "Select * from Company")
val list = cache.query(qry1).getAll
println(list)
}
private def getPersonConf = {
val queryEntity = new QueryEntity(classOf[Int], classOf[Person])
.addQueryField("id", classOf[Int].getName, null)
.addQueryField("companyId", classOf[Int].getName, null)
.setIndexes(java.util.Arrays.asList(new QueryIndex("id"), new QueryIndex("companyId")))
new CacheConfiguration[AffinityKey[Int], Person]()
.setName("persons")
.setBackups(1)
.setCacheMode(CacheMode.PARTITIONED)
.setAtomicityMode(CacheAtomicityMode.ATOMIC)
.setSqlSchema("PUBLIC")
.setEventsDisabled(true)
.setQueryParallelism(5)
.setKeyConfiguration(new CacheKeyConfiguration("person", "companyId"))
.setIndexedTypes(classOf[AffinityKey[Int]], classOf[Person])
.setQueryEntities(java.util.Arrays.asList(queryEntity))
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.DAYS, 1)))
}
private def getCompanyConf = {
val queryEntity = new QueryEntity(classOf[Int], classOf[Company])
.addQueryField("id", classOf[Int].getName, null)
.addQueryField("companyId", classOf[Int].getName, null)
.setIndexes(java.util.Arrays.asList(new QueryIndex("id")))
new CacheConfiguration[Int, Company]()
.setName("companies_cache")
.setBackups(1)
.setCacheMode(CacheMode.PARTITIONED)
.setAtomicityMode(CacheAtomicityMode.ATOMIC)
.setSqlSchema("PUBLIC")
.setEventsDisabled(true)
.setQueryParallelism(5)
.setKeyConfiguration(new CacheKeyConfiguration("company", "id"))
.setIndexedTypes(classOf[Int], classOf[Company])
.setQueryEntities(java.util.Arrays.asList(queryEntity))
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.DAYS, 1)))
}
}
From: Jiang Jacky <ji...@gmail.com>>
Date: Thursday, June 1, 2023 at 12:25 PM
To: user@ignite.apache.org<ma...@ignite.apache.org> <us...@ignite.apache.org>>
Subject: Re: 2 caches joining error
Hey, I just wrote the dummy code, please let me know how can I make the join.
Thank you
package org.example
import org.apache.ignite.Ignition
import org.apache.ignite.cache.{CacheAtomicityMode, CacheKeyConfiguration, CacheMode, QueryEntity, QueryIndex}
import org.apache.ignite.cache.affinity.AffinityKey
import org.apache.ignite.cache.query.{SqlFieldsQuery, SqlQuery}
import org.apache.ignite.configuration.{CacheConfiguration, IgniteConfiguration}
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder
import java.util.concurrent.TimeUnit
import javax.cache.expiry.{CreatedExpiryPolicy, Duration}
/**
* @author ${user.name<http://user.name>}
*/
object App {
case class Person(id: Int, companyId: Int, name: String, price: Double)
case class Company(id: Int, name: String)
def main(args : Array[String]) {
putPersonToCache
putCompanyToCache
joinTest
}
private def joinTest = {
val cfg = new IgniteConfiguration()
cfg.setPeerClassLoadingEnabled(true)
Ignition.setClientMode(true)
val discoverySpi = new TcpDiscoverySpi
val ipFinder = new TcpDiscoveryVmIpFinder()
ipFinder.setAddresses(java.util.Arrays.asList("localhost:47100"))
discoverySpi.setIpFinder(ipFinder)
discoverySpi.setClientReconnectDisabled(false)
cfg.setDiscoverySpi(discoverySpi)
cfg.setCacheConfiguration(getPersonConf)
val ignite = Ignition.getOrStart(cfg)
val cache = ignite.getOrCreateCache[AffinityKey[Int], Person]("persons")
val qry = new SqlFieldsQuery("Select * from Person inner join Company on Person.companyId=Company.id", true)
val list = cache.query(qry).getAll
println(list)
}
private def putPersonToCache = {
val cfg = new IgniteConfiguration()
cfg.setPeerClassLoadingEnabled(true)
Ignition.setClientMode(true)
val discoverySpi = new TcpDiscoverySpi
val ipFinder = new TcpDiscoveryVmIpFinder()
ipFinder.setAddresses(java.util.Arrays.asList("127.0.0.1:47100<http://127.0.0.1:47100>"))
discoverySpi.setIpFinder(ipFinder)
discoverySpi.setClientReconnectDisabled(false)
cfg.setDiscoverySpi(discoverySpi)
cfg.setCacheConfiguration(getPersonConf)
val ignite = Ignition.getOrStart(cfg)
val cache = ignite.getOrCreateCache[AffinityKey[Int], Person]("persons")
val person1 = Person(1, 1, "test1", 1.0)
val person2 = Person(2, 1, "test2", 2.0)
val person3 = Person(3, 2, "test3", 3.0)
val person4 = Person(4, 2, "test4", 4.0)
val addToCache: Person => Unit = person => cache.put(new AffinityKey[Int](person.id<http://person.id>, person.companyId), person)
addToCache(person1)
addToCache(person2)
addToCache(person3)
addToCache(person4)
val qry1 = new SqlQuery(classOf[Person], "Select * from Person")
val list = cache.query(qry1).getAll
println(list)
}
private def putCompanyToCache = {
val cfg = new IgniteConfiguration()
cfg.setPeerClassLoadingEnabled(true)
Ignition.setClientMode(true)
val discoverySpi = new TcpDiscoverySpi
val ipFinder = new TcpDiscoveryVmIpFinder()
ipFinder.setAddresses(java.util.Arrays.asList("127.0.0.1:47100<http://127.0.0.1:47100>"))
discoverySpi.setIpFinder(ipFinder)
discoverySpi.setClientReconnectDisabled(false)
cfg.setDiscoverySpi(discoverySpi)
cfg.setCacheConfiguration(getCompanyConf)
val ignite = Ignition.getOrStart(cfg)
val cache = ignite.getOrCreateCache[Int, Company]("persons")
val c1 = Company(1,"company1")
val c2 = Company(2, "company2")
val addToCache: Company => Unit = company => cache.put(company.id<http://company.id>, company)
addToCache(c1)
addToCache(c2)
val qry1 = new SqlQuery(classOf[Person], "Select * from Company")
val list = cache.query(qry1).getAll
println(list)
}
private def getPersonConf = {
val queryEntity = new QueryEntity(classOf[Int], classOf[Person])
.addQueryField("id", classOf[Int].getName, null)
.addQueryField("companyId", classOf[Int].getName, null)
.setIndexes(java.util.Arrays.asList(new QueryIndex("id"), new QueryIndex("companyId")))
new CacheConfiguration[AffinityKey[Int], Person]()
.setName("persons")
.setBackups(1)
.setCacheMode(CacheMode.PARTITIONED)
.setAtomicityMode(CacheAtomicityMode.ATOMIC)
.setSqlSchema("PUBLIC")
.setEventsDisabled(true)
.setQueryParallelism(5)
.setKeyConfiguration(new CacheKeyConfiguration("person", "companyId"))
.setIndexedTypes(classOf[AffinityKey[Int]], classOf[Person])
.setQueryEntities(java.util.Arrays.asList(queryEntity))
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.DAYS, 1)))
}
private def getCompanyConf = {
val queryEntity = new QueryEntity(classOf[Int], classOf[Company])
.addQueryField("id", classOf[Int].getName, null)
.addQueryField("companyId", classOf[Int].getName, null)
.setIndexes(java.util.Arrays.asList(new QueryIndex("id")))
new CacheConfiguration[Int, Company]()
.setName("companies")
.setBackups(1)
.setCacheMode(CacheMode.PARTITIONED)
.setAtomicityMode(CacheAtomicityMode.ATOMIC)
.setSqlSchema("PUBLIC")
.setEventsDisabled(true)
.setQueryParallelism(5)
.setKeyConfiguration(new CacheKeyConfiguration("company", "id"))
.setIndexedTypes(classOf[Int], classOf[Company])
.setQueryEntities(java.util.Arrays.asList(queryEntity))
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.DAYS, 1)))
}
}
From: Jiang Jacky <ji...@gmail.com>>
Date: Thursday, June 1, 2023 at 11:00 AM
To: user@ignite.apache.org<ma...@ignite.apache.org> <us...@ignite.apache.org>>
Subject: Re: 2 caches joining error
Hey Tupitsyn
The code is in corporation and I cannot send to external. I will try to mock-up the same code in my PC and share with you shortly.
Appreciate for help.
Get Outlook for iOS<https://aka.ms/o0ukef>
________________________________
From: Pavel Tupitsyn <pt...@apache.org>>
Sent: Thursday, June 1, 2023 9:53:37 AM
To: user@ignite.apache.org<ma...@ignite.apache.org> <us...@ignite.apache.org>>
Subject: Re: 2 caches joining error
Can you please share the code as text, not as pictures?
On Thu, Jun 1, 2023 at 3:44 PM Jiang Jacky <ji...@gmail.com>> wrote:
Please review my dummy code, Thank you
[A computer screen with white text Description automatically generated with low confidence]
[A computer screen shot of a blue screen Description automatically generated with low confidence]
[A computer screen with white text Description automatically generated with low confidence]
From: Pavel Tupitsyn <pt...@apache.org>>
Date: Thursday, June 1, 2023 at 1:27 AM
To: user@ignite.apache.org<ma...@ignite.apache.org> <us...@ignite.apache.org>>
Subject: Re: 2 caches joining error
Hello, can you please share the code that does not work for you?
On Thu, Jun 1, 2023 at 7:52 AM Jiang Jacky <ji...@gmail.com>> wrote:
Hello
Can someone share me with some good examples that how to make a join between 2 caches?
I am using ignite 2.7 and mocking up the example from the video https://youtu.be/4CQalha3MyY
I can query the table separately, however when I get the cache from “persons” and tried to join with “companies” it complains table “Company” is not existing.
Please share me the complete example including the configuration.
Thank you
Get Outlook for iOS<https://aka.ms/o0ukef>
Re: 2 caches joining error
Posted by Pavel Tupitsyn <pt...@apache.org>.
Sorry I still can't run your code, it is not even Java? Closure? Kotlin?
Here is a working example of an SQL join:
https://gist.github.com/ptupitsyn/090b84182bbfe2f5e31bc90f56420672
Most likely you need to provide schema in the query, which is the cache
name by default:
Select * from Person inner join \"companies\".Company on
Person.companyId=Company.id
On Thu, Jun 1, 2023 at 7:40 PM Jiang Jacky <ji...@gmail.com> wrote:
> Hey, Typitsyn
>
>
>
> I made some fixes in my own local.
>
> The error is below
>
>
>
>
>
> [image: A screenshot of a computer Description automatically generated
> with medium confidence]
>
>
>
>
>
> package org.example
>
>
>
> import org.apache.ignite.Ignition
>
> import org.apache.ignite.cache.{CacheAtomicityMode, CacheKeyConfiguration,
> CacheMode, QueryEntity, QueryIndex}
>
> import org.apache.ignite.cache.affinity.AffinityKey
>
> import org.apache.ignite.cache.query.{SqlFieldsQuery, SqlQuery}
>
> import org.apache.ignite.configuration.{CacheConfiguration,
> IgniteConfiguration}
>
> import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi
>
> import
> org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder
>
>
>
> import java.util.concurrent.TimeUnit
>
> import javax.cache.expiry.{CreatedExpiryPolicy, Duration}
>
>
>
> /**
>
> * @author ${user.name}
>
> */
>
> object App {
>
>
>
>
>
>
>
> case class Person(id: Int, companyId: Int, name: String, price: Double)
>
> case class Company(id: Int, name: String)
>
>
>
> def main(args : Array[String]) {
>
> putPersonToCache
>
> putCompanyToCache
>
> joinTest
>
> }
>
>
>
> private def joinTest = {
>
> val cfg = new IgniteConfiguration()
>
> cfg.setPeerClassLoadingEnabled(true)
>
> Ignition.setClientMode(true)
>
> val discoverySpi = new TcpDiscoverySpi
>
> val ipFinder = new TcpDiscoveryVmIpFinder()
>
> ipFinder.setAddresses(java.util.Arrays.asList("localhost:47500"))
>
> discoverySpi.setIpFinder(ipFinder)
>
> discoverySpi.setClientReconnectDisabled(false)
>
> cfg.setDiscoverySpi(discoverySpi)
>
> cfg.setCacheConfiguration(getPersonConf)
>
> val ignite = Ignition.getOrStart(cfg)
>
> val cache = ignite.getOrCreateCache[AffinityKey[Int],
> Person]("persons")
>
> val qry = new SqlFieldsQuery("Select * from Person inner join Company
> on Person.companyId=Company.id", true)
>
> val list = cache.query(qry).getAll
>
> println(list)
>
>
>
> }
>
>
>
> private def putPersonToCache = {
>
> val cfg = new IgniteConfiguration()
>
> cfg.setPeerClassLoadingEnabled(false)
>
> Ignition.setClientMode(true)
>
> val discoverySpi = new TcpDiscoverySpi
>
> val ipFinder = new TcpDiscoveryVmIpFinder()
>
> ipFinder.setAddresses(java.util.Arrays.asList("localhost:47500"))
>
> discoverySpi.setIpFinder(ipFinder)
>
> discoverySpi.setClientReconnectDisabled(false)
>
> cfg.setDiscoverySpi(discoverySpi)
>
> cfg.setCacheConfiguration(getPersonConf)
>
> val ignite = Ignition.getOrStart(cfg)
>
> val cache = ignite.getOrCreateCache[AffinityKey[Int],
> Person]("persons")
>
> val person1 = Person(1, 1, "test1", 1.0)
>
> val person2 = Person(2, 1, "test2", 2.0)
>
> val person3 = Person(3, 2, "test3", 3.0)
>
> val person4 = Person(4, 2, "test4", 4.0)
>
>
>
> val addToCache: Person => Unit = person => cache.put(new
> AffinityKey[Int](person.id, person.companyId), person)
>
> addToCache(person1)
>
> addToCache(person2)
>
> addToCache(person3)
>
> addToCache(person4)
>
>
>
> val qry1 = new SqlQuery(classOf[Person], "Select * from Person")
>
> val list = cache.query(qry1).getAll
>
> println(list)
>
> }
>
>
>
> private def putCompanyToCache = {
>
> val cfg = new IgniteConfiguration()
>
> cfg.setPeerClassLoadingEnabled(false)
>
> Ignition.setClientMode(true)
>
> val discoverySpi = new TcpDiscoverySpi
>
> val ipFinder = new TcpDiscoveryVmIpFinder()
>
> ipFinder.setAddresses(java.util.Arrays.asList("localhost:47500"))
>
> discoverySpi.setIpFinder(ipFinder)
>
> discoverySpi.setClientReconnectDisabled(false)
>
> cfg.setDiscoverySpi(discoverySpi)
>
> cfg.setCacheConfiguration(getCompanyConf)
>
> val ignite = Ignition.getOrStart(cfg)
>
> val cache = ignite.getOrCreateCache[Int, Company]("companies_cache")
>
> val c1 = Company(1,"company1")
>
> val c2 = Company(2, "company2")
>
>
>
>
>
> val addToCache: Company => Unit = company => cache.put(company.id,
> company)
>
> addToCache(c1)
>
> addToCache(c2)
>
>
>
>
>
> val qry1 = new SqlQuery(classOf[Company], "Select * from Company")
>
> val list = cache.query(qry1).getAll
>
> println(list)
>
> }
>
>
>
> private def getPersonConf = {
>
>
>
> val queryEntity = new QueryEntity(classOf[Int], classOf[Person])
>
> .addQueryField("id", classOf[Int].getName, null)
>
> .addQueryField("companyId", classOf[Int].getName, null)
>
> .setIndexes(java.util.Arrays.asList(new QueryIndex("id"), new
> QueryIndex("companyId")))
>
>
>
> new CacheConfiguration[AffinityKey[Int], Person]()
>
> .setName("persons")
>
> .setBackups(1)
>
> .setCacheMode(CacheMode.PARTITIONED)
>
> .setAtomicityMode(CacheAtomicityMode.ATOMIC)
>
> .setSqlSchema("PUBLIC")
>
> .setEventsDisabled(true)
>
> .setQueryParallelism(5)
>
> .setKeyConfiguration(new CacheKeyConfiguration("person",
> "companyId"))
>
> .setIndexedTypes(classOf[AffinityKey[Int]], classOf[Person])
>
> .setQueryEntities(java.util.Arrays.asList(queryEntity))
>
> .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new
> Duration(TimeUnit.DAYS, 1)))
>
>
>
> }
>
>
>
> private def getCompanyConf = {
>
>
>
> val queryEntity = new QueryEntity(classOf[Int], classOf[Company])
>
> .addQueryField("id", classOf[Int].getName, null)
>
> .addQueryField("companyId", classOf[Int].getName, null)
>
> .setIndexes(java.util.Arrays.asList(new QueryIndex("id")))
>
>
>
> new CacheConfiguration[Int, Company]()
>
> .setName("companies_cache")
>
> .setBackups(1)
>
> .setCacheMode(CacheMode.PARTITIONED)
>
> .setAtomicityMode(CacheAtomicityMode.ATOMIC)
>
> .setSqlSchema("PUBLIC")
>
> .setEventsDisabled(true)
>
> .setQueryParallelism(5)
>
> .setKeyConfiguration(new CacheKeyConfiguration("company", "id"))
>
> .setIndexedTypes(classOf[Int], classOf[Company])
>
> .setQueryEntities(java.util.Arrays.asList(queryEntity))
>
> .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new
> Duration(TimeUnit.DAYS, 1)))
>
>
>
> }
>
> }
>
>
>
> *From: *Jiang Jacky <ji...@gmail.com>
> *Date: *Thursday, June 1, 2023 at 12:25 PM
> *To: *user@ignite.apache.org <us...@ignite.apache.org>
> *Subject: *Re: 2 caches joining error
>
> Hey, I just wrote the dummy code, please let me know how can I make the
> join.
>
> Thank you
>
>
>
> package org.example
>
>
>
> import org.apache.ignite.Ignition
>
> import org.apache.ignite.cache.{CacheAtomicityMode, CacheKeyConfiguration,
> CacheMode, QueryEntity, QueryIndex}
>
> import org.apache.ignite.cache.affinity.AffinityKey
>
> import org.apache.ignite.cache.query.{SqlFieldsQuery, SqlQuery}
>
> import org.apache.ignite.configuration.{CacheConfiguration,
> IgniteConfiguration}
>
> import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi
>
> import
> org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder
>
>
>
> import java.util.concurrent.TimeUnit
>
> import javax.cache.expiry.{CreatedExpiryPolicy, Duration}
>
>
>
> /**
>
> * @author ${user.name}
>
> */
>
> object App {
>
>
>
>
>
>
>
> case class Person(id: Int, companyId: Int, name: String, price: Double)
>
> case class Company(id: Int, name: String)
>
>
>
> def main(args : Array[String]) {
>
> putPersonToCache
>
> putCompanyToCache
>
> joinTest
>
> }
>
>
>
> private def joinTest = {
>
> val cfg = new IgniteConfiguration()
>
> cfg.setPeerClassLoadingEnabled(true)
>
> Ignition.setClientMode(true)
>
> val discoverySpi = new TcpDiscoverySpi
>
> val ipFinder = new TcpDiscoveryVmIpFinder()
>
> ipFinder.setAddresses(java.util.Arrays.asList("localhost:47100"))
>
> discoverySpi.setIpFinder(ipFinder)
>
> discoverySpi.setClientReconnectDisabled(false)
>
> cfg.setDiscoverySpi(discoverySpi)
>
> cfg.setCacheConfiguration(getPersonConf)
>
> val ignite = Ignition.getOrStart(cfg)
>
> val cache = ignite.getOrCreateCache[AffinityKey[Int],
> Person]("persons")
>
> val qry = new SqlFieldsQuery("Select * from Person inner join Company
> on Person.companyId=Company.id", true)
>
> val list = cache.query(qry).getAll
>
> println(list)
>
>
>
> }
>
>
>
> private def putPersonToCache = {
>
> val cfg = new IgniteConfiguration()
>
> cfg.setPeerClassLoadingEnabled(true)
>
> Ignition.setClientMode(true)
>
> val discoverySpi = new TcpDiscoverySpi
>
> val ipFinder = new TcpDiscoveryVmIpFinder()
>
> ipFinder.setAddresses(java.util.Arrays.asList("127.0.0.1:47100"))
>
> discoverySpi.setIpFinder(ipFinder)
>
> discoverySpi.setClientReconnectDisabled(false)
>
> cfg.setDiscoverySpi(discoverySpi)
>
> cfg.setCacheConfiguration(getPersonConf)
>
> val ignite = Ignition.getOrStart(cfg)
>
> val cache = ignite.getOrCreateCache[AffinityKey[Int],
> Person]("persons")
>
> val person1 = Person(1, 1, "test1", 1.0)
>
> val person2 = Person(2, 1, "test2", 2.0)
>
> val person3 = Person(3, 2, "test3", 3.0)
>
> val person4 = Person(4, 2, "test4", 4.0)
>
>
>
> val addToCache: Person => Unit = person => cache.put(new
> AffinityKey[Int](person.id, person.companyId), person)
>
> addToCache(person1)
>
> addToCache(person2)
>
> addToCache(person3)
>
> addToCache(person4)
>
>
>
> val qry1 = new SqlQuery(classOf[Person], "Select * from Person")
>
> val list = cache.query(qry1).getAll
>
> println(list)
>
> }
>
>
>
> private def putCompanyToCache = {
>
> val cfg = new IgniteConfiguration()
>
> cfg.setPeerClassLoadingEnabled(true)
>
> Ignition.setClientMode(true)
>
> val discoverySpi = new TcpDiscoverySpi
>
> val ipFinder = new TcpDiscoveryVmIpFinder()
>
> ipFinder.setAddresses(java.util.Arrays.asList("127.0.0.1:47100"))
>
> discoverySpi.setIpFinder(ipFinder)
>
> discoverySpi.setClientReconnectDisabled(false)
>
> cfg.setDiscoverySpi(discoverySpi)
>
> cfg.setCacheConfiguration(getCompanyConf)
>
> val ignite = Ignition.getOrStart(cfg)
>
> val cache = ignite.getOrCreateCache[Int, Company]("persons")
>
> val c1 = Company(1,"company1")
>
> val c2 = Company(2, "company2")
>
>
>
>
>
> val addToCache: Company => Unit = company => cache.put(company.id,
> company)
>
> addToCache(c1)
>
> addToCache(c2)
>
>
>
>
>
> val qry1 = new SqlQuery(classOf[Person], "Select * from Company")
>
> val list = cache.query(qry1).getAll
>
> println(list)
>
> }
>
>
>
> private def getPersonConf = {
>
>
>
> val queryEntity = new QueryEntity(classOf[Int], classOf[Person])
>
> .addQueryField("id", classOf[Int].getName, null)
>
> .addQueryField("companyId", classOf[Int].getName, null)
>
> .setIndexes(java.util.Arrays.asList(new QueryIndex("id"), new
> QueryIndex("companyId")))
>
>
>
> new CacheConfiguration[AffinityKey[Int], Person]()
>
> .setName("persons")
>
> .setBackups(1)
>
> .setCacheMode(CacheMode.PARTITIONED)
>
> .setAtomicityMode(CacheAtomicityMode.ATOMIC)
>
> .setSqlSchema("PUBLIC")
>
> .setEventsDisabled(true)
>
> .setQueryParallelism(5)
>
> .setKeyConfiguration(new CacheKeyConfiguration("person",
> "companyId"))
>
> .setIndexedTypes(classOf[AffinityKey[Int]], classOf[Person])
>
> .setQueryEntities(java.util.Arrays.asList(queryEntity))
>
> .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new
> Duration(TimeUnit.DAYS, 1)))
>
>
>
> }
>
>
>
> private def getCompanyConf = {
>
>
>
> val queryEntity = new QueryEntity(classOf[Int], classOf[Company])
>
> .addQueryField("id", classOf[Int].getName, null)
>
> .addQueryField("companyId", classOf[Int].getName, null)
>
> .setIndexes(java.util.Arrays.asList(new QueryIndex("id")))
>
>
>
> new CacheConfiguration[Int, Company]()
>
> .setName("companies")
>
> .setBackups(1)
>
> .setCacheMode(CacheMode.PARTITIONED)
>
> .setAtomicityMode(CacheAtomicityMode.ATOMIC)
>
> .setSqlSchema("PUBLIC")
>
> .setEventsDisabled(true)
>
> .setQueryParallelism(5)
>
> .setKeyConfiguration(new CacheKeyConfiguration("company", "id"))
>
> .setIndexedTypes(classOf[Int], classOf[Company])
>
> .setQueryEntities(java.util.Arrays.asList(queryEntity))
>
> .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new
> Duration(TimeUnit.DAYS, 1)))
>
>
>
> }
>
> }
>
>
>
> *From: *Jiang Jacky <ji...@gmail.com>
> *Date: *Thursday, June 1, 2023 at 11:00 AM
> *To: *user@ignite.apache.org <us...@ignite.apache.org>
> *Subject: *Re: 2 caches joining error
>
> Hey Tupitsyn
>
> The code is in corporation and I cannot send to external. I will try to
> mock-up the same code in my PC and share with you shortly.
>
> Appreciate for help.
>
>
>
>
>
> Get Outlook for iOS <https://aka.ms/o0ukef>
> ------------------------------
>
> *From:* Pavel Tupitsyn <pt...@apache.org>
> *Sent:* Thursday, June 1, 2023 9:53:37 AM
> *To:* user@ignite.apache.org <us...@ignite.apache.org>
> *Subject:* Re: 2 caches joining error
>
>
>
> Can you please share the code as text, not as pictures?
>
>
>
> On Thu, Jun 1, 2023 at 3:44 PM Jiang Jacky <ji...@gmail.com> wrote:
>
> Please review my dummy code, Thank you
>
>
>
> [image: A computer screen with white text Description automatically
> generated with low confidence]
>
> [image: A computer screen shot of a blue screen Description automatically
> generated with low confidence]
>
>
>
> [image: A computer screen with white text Description automatically
> generated with low confidence]
>
>
>
>
>
>
>
> *From: *Pavel Tupitsyn <pt...@apache.org>
> *Date: *Thursday, June 1, 2023 at 1:27 AM
> *To: *user@ignite.apache.org <us...@ignite.apache.org>
> *Subject: *Re: 2 caches joining error
>
> Hello, can you please share the code that does not work for you?
>
>
>
> On Thu, Jun 1, 2023 at 7:52 AM Jiang Jacky <ji...@gmail.com> wrote:
>
> Hello
>
> Can someone share me with some good examples that how to make a join
> between 2 caches?
>
> I am using ignite 2.7 and mocking up the example from the video
> https://youtu.be/4CQalha3MyY
>
> I can query the table separately, however when I get the cache from
> “persons” and tried to join with “companies” it complains table “Company”
> is not existing.
>
>
>
> Please share me the complete example including the configuration.
>
>
>
> Thank you
>
>
>
> Get Outlook for iOS <https://aka.ms/o0ukef>
>
>
Re: 2 caches joining error
Posted by Jiang Jacky <ji...@gmail.com>.
Hey, Typitsyn
I made some fixes in my own local.
The error is below
[A screenshot of a computer Description automatically generated with medium confidence]
package org.example
import org.apache.ignite.Ignition
import org.apache.ignite.cache.{CacheAtomicityMode, CacheKeyConfiguration, CacheMode, QueryEntity, QueryIndex}
import org.apache.ignite.cache.affinity.AffinityKey
import org.apache.ignite.cache.query.{SqlFieldsQuery, SqlQuery}
import org.apache.ignite.configuration.{CacheConfiguration, IgniteConfiguration}
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder
import java.util.concurrent.TimeUnit
import javax.cache.expiry.{CreatedExpiryPolicy, Duration}
/**
* @author ${user.name}
*/
object App {
case class Person(id: Int, companyId: Int, name: String, price: Double)
case class Company(id: Int, name: String)
def main(args : Array[String]) {
putPersonToCache
putCompanyToCache
joinTest
}
private def joinTest = {
val cfg = new IgniteConfiguration()
cfg.setPeerClassLoadingEnabled(true)
Ignition.setClientMode(true)
val discoverySpi = new TcpDiscoverySpi
val ipFinder = new TcpDiscoveryVmIpFinder()
ipFinder.setAddresses(java.util.Arrays.asList("localhost:47500"))
discoverySpi.setIpFinder(ipFinder)
discoverySpi.setClientReconnectDisabled(false)
cfg.setDiscoverySpi(discoverySpi)
cfg.setCacheConfiguration(getPersonConf)
val ignite = Ignition.getOrStart(cfg)
val cache = ignite.getOrCreateCache[AffinityKey[Int], Person]("persons")
val qry = new SqlFieldsQuery("Select * from Person inner join Company on Person.companyId=Company.id", true)
val list = cache.query(qry).getAll
println(list)
}
private def putPersonToCache = {
val cfg = new IgniteConfiguration()
cfg.setPeerClassLoadingEnabled(false)
Ignition.setClientMode(true)
val discoverySpi = new TcpDiscoverySpi
val ipFinder = new TcpDiscoveryVmIpFinder()
ipFinder.setAddresses(java.util.Arrays.asList("localhost:47500"))
discoverySpi.setIpFinder(ipFinder)
discoverySpi.setClientReconnectDisabled(false)
cfg.setDiscoverySpi(discoverySpi)
cfg.setCacheConfiguration(getPersonConf)
val ignite = Ignition.getOrStart(cfg)
val cache = ignite.getOrCreateCache[AffinityKey[Int], Person]("persons")
val person1 = Person(1, 1, "test1", 1.0)
val person2 = Person(2, 1, "test2", 2.0)
val person3 = Person(3, 2, "test3", 3.0)
val person4 = Person(4, 2, "test4", 4.0)
val addToCache: Person => Unit = person => cache.put(new AffinityKey[Int](person.id, person.companyId), person)
addToCache(person1)
addToCache(person2)
addToCache(person3)
addToCache(person4)
val qry1 = new SqlQuery(classOf[Person], "Select * from Person")
val list = cache.query(qry1).getAll
println(list)
}
private def putCompanyToCache = {
val cfg = new IgniteConfiguration()
cfg.setPeerClassLoadingEnabled(false)
Ignition.setClientMode(true)
val discoverySpi = new TcpDiscoverySpi
val ipFinder = new TcpDiscoveryVmIpFinder()
ipFinder.setAddresses(java.util.Arrays.asList("localhost:47500"))
discoverySpi.setIpFinder(ipFinder)
discoverySpi.setClientReconnectDisabled(false)
cfg.setDiscoverySpi(discoverySpi)
cfg.setCacheConfiguration(getCompanyConf)
val ignite = Ignition.getOrStart(cfg)
val cache = ignite.getOrCreateCache[Int, Company]("companies_cache")
val c1 = Company(1,"company1")
val c2 = Company(2, "company2")
val addToCache: Company => Unit = company => cache.put(company.id, company)
addToCache(c1)
addToCache(c2)
val qry1 = new SqlQuery(classOf[Company], "Select * from Company")
val list = cache.query(qry1).getAll
println(list)
}
private def getPersonConf = {
val queryEntity = new QueryEntity(classOf[Int], classOf[Person])
.addQueryField("id", classOf[Int].getName, null)
.addQueryField("companyId", classOf[Int].getName, null)
.setIndexes(java.util.Arrays.asList(new QueryIndex("id"), new QueryIndex("companyId")))
new CacheConfiguration[AffinityKey[Int], Person]()
.setName("persons")
.setBackups(1)
.setCacheMode(CacheMode.PARTITIONED)
.setAtomicityMode(CacheAtomicityMode.ATOMIC)
.setSqlSchema("PUBLIC")
.setEventsDisabled(true)
.setQueryParallelism(5)
.setKeyConfiguration(new CacheKeyConfiguration("person", "companyId"))
.setIndexedTypes(classOf[AffinityKey[Int]], classOf[Person])
.setQueryEntities(java.util.Arrays.asList(queryEntity))
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.DAYS, 1)))
}
private def getCompanyConf = {
val queryEntity = new QueryEntity(classOf[Int], classOf[Company])
.addQueryField("id", classOf[Int].getName, null)
.addQueryField("companyId", classOf[Int].getName, null)
.setIndexes(java.util.Arrays.asList(new QueryIndex("id")))
new CacheConfiguration[Int, Company]()
.setName("companies_cache")
.setBackups(1)
.setCacheMode(CacheMode.PARTITIONED)
.setAtomicityMode(CacheAtomicityMode.ATOMIC)
.setSqlSchema("PUBLIC")
.setEventsDisabled(true)
.setQueryParallelism(5)
.setKeyConfiguration(new CacheKeyConfiguration("company", "id"))
.setIndexedTypes(classOf[Int], classOf[Company])
.setQueryEntities(java.util.Arrays.asList(queryEntity))
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.DAYS, 1)))
}
}
From: Jiang Jacky <ji...@gmail.com>
Date: Thursday, June 1, 2023 at 12:25 PM
To: user@ignite.apache.org <us...@ignite.apache.org>
Subject: Re: 2 caches joining error
Hey, I just wrote the dummy code, please let me know how can I make the join.
Thank you
package org.example
import org.apache.ignite.Ignition
import org.apache.ignite.cache.{CacheAtomicityMode, CacheKeyConfiguration, CacheMode, QueryEntity, QueryIndex}
import org.apache.ignite.cache.affinity.AffinityKey
import org.apache.ignite.cache.query.{SqlFieldsQuery, SqlQuery}
import org.apache.ignite.configuration.{CacheConfiguration, IgniteConfiguration}
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder
import java.util.concurrent.TimeUnit
import javax.cache.expiry.{CreatedExpiryPolicy, Duration}
/**
* @author ${user.name}
*/
object App {
case class Person(id: Int, companyId: Int, name: String, price: Double)
case class Company(id: Int, name: String)
def main(args : Array[String]) {
putPersonToCache
putCompanyToCache
joinTest
}
private def joinTest = {
val cfg = new IgniteConfiguration()
cfg.setPeerClassLoadingEnabled(true)
Ignition.setClientMode(true)
val discoverySpi = new TcpDiscoverySpi
val ipFinder = new TcpDiscoveryVmIpFinder()
ipFinder.setAddresses(java.util.Arrays.asList("localhost:47100"))
discoverySpi.setIpFinder(ipFinder)
discoverySpi.setClientReconnectDisabled(false)
cfg.setDiscoverySpi(discoverySpi)
cfg.setCacheConfiguration(getPersonConf)
val ignite = Ignition.getOrStart(cfg)
val cache = ignite.getOrCreateCache[AffinityKey[Int], Person]("persons")
val qry = new SqlFieldsQuery("Select * from Person inner join Company on Person.companyId=Company.id", true)
val list = cache.query(qry).getAll
println(list)
}
private def putPersonToCache = {
val cfg = new IgniteConfiguration()
cfg.setPeerClassLoadingEnabled(true)
Ignition.setClientMode(true)
val discoverySpi = new TcpDiscoverySpi
val ipFinder = new TcpDiscoveryVmIpFinder()
ipFinder.setAddresses(java.util.Arrays.asList("127.0.0.1:47100"))
discoverySpi.setIpFinder(ipFinder)
discoverySpi.setClientReconnectDisabled(false)
cfg.setDiscoverySpi(discoverySpi)
cfg.setCacheConfiguration(getPersonConf)
val ignite = Ignition.getOrStart(cfg)
val cache = ignite.getOrCreateCache[AffinityKey[Int], Person]("persons")
val person1 = Person(1, 1, "test1", 1.0)
val person2 = Person(2, 1, "test2", 2.0)
val person3 = Person(3, 2, "test3", 3.0)
val person4 = Person(4, 2, "test4", 4.0)
val addToCache: Person => Unit = person => cache.put(new AffinityKey[Int](person.id, person.companyId), person)
addToCache(person1)
addToCache(person2)
addToCache(person3)
addToCache(person4)
val qry1 = new SqlQuery(classOf[Person], "Select * from Person")
val list = cache.query(qry1).getAll
println(list)
}
private def putCompanyToCache = {
val cfg = new IgniteConfiguration()
cfg.setPeerClassLoadingEnabled(true)
Ignition.setClientMode(true)
val discoverySpi = new TcpDiscoverySpi
val ipFinder = new TcpDiscoveryVmIpFinder()
ipFinder.setAddresses(java.util.Arrays.asList("127.0.0.1:47100"))
discoverySpi.setIpFinder(ipFinder)
discoverySpi.setClientReconnectDisabled(false)
cfg.setDiscoverySpi(discoverySpi)
cfg.setCacheConfiguration(getCompanyConf)
val ignite = Ignition.getOrStart(cfg)
val cache = ignite.getOrCreateCache[Int, Company]("persons")
val c1 = Company(1,"company1")
val c2 = Company(2, "company2")
val addToCache: Company => Unit = company => cache.put(company.id, company)
addToCache(c1)
addToCache(c2)
val qry1 = new SqlQuery(classOf[Person], "Select * from Company")
val list = cache.query(qry1).getAll
println(list)
}
private def getPersonConf = {
val queryEntity = new QueryEntity(classOf[Int], classOf[Person])
.addQueryField("id", classOf[Int].getName, null)
.addQueryField("companyId", classOf[Int].getName, null)
.setIndexes(java.util.Arrays.asList(new QueryIndex("id"), new QueryIndex("companyId")))
new CacheConfiguration[AffinityKey[Int], Person]()
.setName("persons")
.setBackups(1)
.setCacheMode(CacheMode.PARTITIONED)
.setAtomicityMode(CacheAtomicityMode.ATOMIC)
.setSqlSchema("PUBLIC")
.setEventsDisabled(true)
.setQueryParallelism(5)
.setKeyConfiguration(new CacheKeyConfiguration("person", "companyId"))
.setIndexedTypes(classOf[AffinityKey[Int]], classOf[Person])
.setQueryEntities(java.util.Arrays.asList(queryEntity))
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.DAYS, 1)))
}
private def getCompanyConf = {
val queryEntity = new QueryEntity(classOf[Int], classOf[Company])
.addQueryField("id", classOf[Int].getName, null)
.addQueryField("companyId", classOf[Int].getName, null)
.setIndexes(java.util.Arrays.asList(new QueryIndex("id")))
new CacheConfiguration[Int, Company]()
.setName("companies")
.setBackups(1)
.setCacheMode(CacheMode.PARTITIONED)
.setAtomicityMode(CacheAtomicityMode.ATOMIC)
.setSqlSchema("PUBLIC")
.setEventsDisabled(true)
.setQueryParallelism(5)
.setKeyConfiguration(new CacheKeyConfiguration("company", "id"))
.setIndexedTypes(classOf[Int], classOf[Company])
.setQueryEntities(java.util.Arrays.asList(queryEntity))
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.DAYS, 1)))
}
}
From: Jiang Jacky <ji...@gmail.com>
Date: Thursday, June 1, 2023 at 11:00 AM
To: user@ignite.apache.org <us...@ignite.apache.org>
Subject: Re: 2 caches joining error
Hey Tupitsyn
The code is in corporation and I cannot send to external. I will try to mock-up the same code in my PC and share with you shortly.
Appreciate for help.
Get Outlook for iOS<https://aka.ms/o0ukef>
________________________________
From: Pavel Tupitsyn <pt...@apache.org>
Sent: Thursday, June 1, 2023 9:53:37 AM
To: user@ignite.apache.org <us...@ignite.apache.org>
Subject: Re: 2 caches joining error
Can you please share the code as text, not as pictures?
On Thu, Jun 1, 2023 at 3:44 PM Jiang Jacky <ji...@gmail.com>> wrote:
Please review my dummy code, Thank you
[A computer screen with white text Description automatically generated with low confidence]
[A computer screen shot of a blue screen Description automatically generated with low confidence]
[A computer screen with white text Description automatically generated with low confidence]
From: Pavel Tupitsyn <pt...@apache.org>>
Date: Thursday, June 1, 2023 at 1:27 AM
To: user@ignite.apache.org<ma...@ignite.apache.org> <us...@ignite.apache.org>>
Subject: Re: 2 caches joining error
Hello, can you please share the code that does not work for you?
On Thu, Jun 1, 2023 at 7:52 AM Jiang Jacky <ji...@gmail.com>> wrote:
Hello
Can someone share me with some good examples that how to make a join between 2 caches?
I am using ignite 2.7 and mocking up the example from the video https://youtu.be/4CQalha3MyY
I can query the table separately, however when I get the cache from “persons” and tried to join with “companies” it complains table “Company” is not existing.
Please share me the complete example including the configuration.
Thank you
Get Outlook for iOS<https://aka.ms/o0ukef>
Re: 2 caches joining error
Posted by Jiang Jacky <ji...@gmail.com>.
Hey, I just wrote the dummy code, please let me know how can I make the join.
Thank you
package org.example
import org.apache.ignite.Ignition
import org.apache.ignite.cache.{CacheAtomicityMode, CacheKeyConfiguration, CacheMode, QueryEntity, QueryIndex}
import org.apache.ignite.cache.affinity.AffinityKey
import org.apache.ignite.cache.query.{SqlFieldsQuery, SqlQuery}
import org.apache.ignite.configuration.{CacheConfiguration, IgniteConfiguration}
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder
import java.util.concurrent.TimeUnit
import javax.cache.expiry.{CreatedExpiryPolicy, Duration}
/**
* @author ${user.name}
*/
object App {
case class Person(id: Int, companyId: Int, name: String, price: Double)
case class Company(id: Int, name: String)
def main(args : Array[String]) {
putPersonToCache
putCompanyToCache
joinTest
}
private def joinTest = {
val cfg = new IgniteConfiguration()
cfg.setPeerClassLoadingEnabled(true)
Ignition.setClientMode(true)
val discoverySpi = new TcpDiscoverySpi
val ipFinder = new TcpDiscoveryVmIpFinder()
ipFinder.setAddresses(java.util.Arrays.asList("localhost:47100"))
discoverySpi.setIpFinder(ipFinder)
discoverySpi.setClientReconnectDisabled(false)
cfg.setDiscoverySpi(discoverySpi)
cfg.setCacheConfiguration(getPersonConf)
val ignite = Ignition.getOrStart(cfg)
val cache = ignite.getOrCreateCache[AffinityKey[Int], Person]("persons")
val qry = new SqlFieldsQuery("Select * from Person inner join Company on Person.companyId=Company.id", true)
val list = cache.query(qry).getAll
println(list)
}
private def putPersonToCache = {
val cfg = new IgniteConfiguration()
cfg.setPeerClassLoadingEnabled(true)
Ignition.setClientMode(true)
val discoverySpi = new TcpDiscoverySpi
val ipFinder = new TcpDiscoveryVmIpFinder()
ipFinder.setAddresses(java.util.Arrays.asList("127.0.0.1:47100"))
discoverySpi.setIpFinder(ipFinder)
discoverySpi.setClientReconnectDisabled(false)
cfg.setDiscoverySpi(discoverySpi)
cfg.setCacheConfiguration(getPersonConf)
val ignite = Ignition.getOrStart(cfg)
val cache = ignite.getOrCreateCache[AffinityKey[Int], Person]("persons")
val person1 = Person(1, 1, "test1", 1.0)
val person2 = Person(2, 1, "test2", 2.0)
val person3 = Person(3, 2, "test3", 3.0)
val person4 = Person(4, 2, "test4", 4.0)
val addToCache: Person => Unit = person => cache.put(new AffinityKey[Int](person.id, person.companyId), person)
addToCache(person1)
addToCache(person2)
addToCache(person3)
addToCache(person4)
val qry1 = new SqlQuery(classOf[Person], "Select * from Person")
val list = cache.query(qry1).getAll
println(list)
}
private def putCompanyToCache = {
val cfg = new IgniteConfiguration()
cfg.setPeerClassLoadingEnabled(true)
Ignition.setClientMode(true)
val discoverySpi = new TcpDiscoverySpi
val ipFinder = new TcpDiscoveryVmIpFinder()
ipFinder.setAddresses(java.util.Arrays.asList("127.0.0.1:47100"))
discoverySpi.setIpFinder(ipFinder)
discoverySpi.setClientReconnectDisabled(false)
cfg.setDiscoverySpi(discoverySpi)
cfg.setCacheConfiguration(getCompanyConf)
val ignite = Ignition.getOrStart(cfg)
val cache = ignite.getOrCreateCache[Int, Company]("persons")
val c1 = Company(1,"company1")
val c2 = Company(2, "company2")
val addToCache: Company => Unit = company => cache.put(company.id, company)
addToCache(c1)
addToCache(c2)
val qry1 = new SqlQuery(classOf[Person], "Select * from Company")
val list = cache.query(qry1).getAll
println(list)
}
private def getPersonConf = {
val queryEntity = new QueryEntity(classOf[Int], classOf[Person])
.addQueryField("id", classOf[Int].getName, null)
.addQueryField("companyId", classOf[Int].getName, null)
.setIndexes(java.util.Arrays.asList(new QueryIndex("id"), new QueryIndex("companyId")))
new CacheConfiguration[AffinityKey[Int], Person]()
.setName("persons")
.setBackups(1)
.setCacheMode(CacheMode.PARTITIONED)
.setAtomicityMode(CacheAtomicityMode.ATOMIC)
.setSqlSchema("PUBLIC")
.setEventsDisabled(true)
.setQueryParallelism(5)
.setKeyConfiguration(new CacheKeyConfiguration("person", "companyId"))
.setIndexedTypes(classOf[AffinityKey[Int]], classOf[Person])
.setQueryEntities(java.util.Arrays.asList(queryEntity))
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.DAYS, 1)))
}
private def getCompanyConf = {
val queryEntity = new QueryEntity(classOf[Int], classOf[Company])
.addQueryField("id", classOf[Int].getName, null)
.addQueryField("companyId", classOf[Int].getName, null)
.setIndexes(java.util.Arrays.asList(new QueryIndex("id")))
new CacheConfiguration[Int, Company]()
.setName("companies")
.setBackups(1)
.setCacheMode(CacheMode.PARTITIONED)
.setAtomicityMode(CacheAtomicityMode.ATOMIC)
.setSqlSchema("PUBLIC")
.setEventsDisabled(true)
.setQueryParallelism(5)
.setKeyConfiguration(new CacheKeyConfiguration("company", "id"))
.setIndexedTypes(classOf[Int], classOf[Company])
.setQueryEntities(java.util.Arrays.asList(queryEntity))
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.DAYS, 1)))
}
}
From: Jiang Jacky <ji...@gmail.com>
Date: Thursday, June 1, 2023 at 11:00 AM
To: user@ignite.apache.org <us...@ignite.apache.org>
Subject: Re: 2 caches joining error
Hey Tupitsyn
The code is in corporation and I cannot send to external. I will try to mock-up the same code in my PC and share with you shortly.
Appreciate for help.
Get Outlook for iOS<https://aka.ms/o0ukef>
________________________________
From: Pavel Tupitsyn <pt...@apache.org>
Sent: Thursday, June 1, 2023 9:53:37 AM
To: user@ignite.apache.org <us...@ignite.apache.org>
Subject: Re: 2 caches joining error
Can you please share the code as text, not as pictures?
On Thu, Jun 1, 2023 at 3:44 PM Jiang Jacky <ji...@gmail.com>> wrote:
Please review my dummy code, Thank you
[A computer screen with white text Description automatically generated with low confidence]
[A computer screen shot of a blue screen Description automatically generated with low confidence]
[A computer screen with white text Description automatically generated with low confidence]
From: Pavel Tupitsyn <pt...@apache.org>>
Date: Thursday, June 1, 2023 at 1:27 AM
To: user@ignite.apache.org<ma...@ignite.apache.org> <us...@ignite.apache.org>>
Subject: Re: 2 caches joining error
Hello, can you please share the code that does not work for you?
On Thu, Jun 1, 2023 at 7:52 AM Jiang Jacky <ji...@gmail.com>> wrote:
Hello
Can someone share me with some good examples that how to make a join between 2 caches?
I am using ignite 2.7 and mocking up the example from the video https://youtu.be/4CQalha3MyY
I can query the table separately, however when I get the cache from “persons” and tried to join with “companies” it complains table “Company” is not existing.
Please share me the complete example including the configuration.
Thank you
Get Outlook for iOS<https://aka.ms/o0ukef>
Re: 2 caches joining error
Posted by Jiang Jacky <ji...@gmail.com>.
Hey Tupitsyn
The code is in corporation and I cannot send to external. I will try to mock-up the same code in my PC and share with you shortly.
Appreciate for help.
Get Outlook for iOS<https://aka.ms/o0ukef>
________________________________
From: Pavel Tupitsyn <pt...@apache.org>
Sent: Thursday, June 1, 2023 9:53:37 AM
To: user@ignite.apache.org <us...@ignite.apache.org>
Subject: Re: 2 caches joining error
Can you please share the code as text, not as pictures?
On Thu, Jun 1, 2023 at 3:44 PM Jiang Jacky <ji...@gmail.com>> wrote:
Please review my dummy code, Thank you
[A computer screen with white text Description automatically generated with low confidence]
[A computer screen shot of a blue screen Description automatically generated with low confidence]
[A computer screen with white text Description automatically generated with low confidence]
From: Pavel Tupitsyn <pt...@apache.org>>
Date: Thursday, June 1, 2023 at 1:27 AM
To: user@ignite.apache.org<ma...@ignite.apache.org> <us...@ignite.apache.org>>
Subject: Re: 2 caches joining error
Hello, can you please share the code that does not work for you?
On Thu, Jun 1, 2023 at 7:52 AM Jiang Jacky <ji...@gmail.com>> wrote:
Hello
Can someone share me with some good examples that how to make a join between 2 caches?
I am using ignite 2.7 and mocking up the example from the video https://youtu.be/4CQalha3MyY
I can query the table separately, however when I get the cache from “persons” and tried to join with “companies” it complains table “Company” is not existing.
Please share me the complete example including the configuration.
Thank you
Get Outlook for iOS<https://aka.ms/o0ukef>
Re: 2 caches joining error
Posted by Pavel Tupitsyn <pt...@apache.org>.
Can you please share the code as text, not as pictures?
On Thu, Jun 1, 2023 at 3:44 PM Jiang Jacky <ji...@gmail.com> wrote:
> Please review my dummy code, Thank you
>
>
>
> [image: A computer screen with white text Description automatically
> generated with low confidence]
>
> [image: A computer screen shot of a blue screen Description automatically
> generated with low confidence]
>
>
>
> [image: A computer screen with white text Description automatically
> generated with low confidence]
>
>
>
>
>
>
>
> *From: *Pavel Tupitsyn <pt...@apache.org>
> *Date: *Thursday, June 1, 2023 at 1:27 AM
> *To: *user@ignite.apache.org <us...@ignite.apache.org>
> *Subject: *Re: 2 caches joining error
>
> Hello, can you please share the code that does not work for you?
>
>
>
> On Thu, Jun 1, 2023 at 7:52 AM Jiang Jacky <ji...@gmail.com> wrote:
>
> Hello
>
> Can someone share me with some good examples that how to make a join
> between 2 caches?
>
> I am using ignite 2.7 and mocking up the example from the video
> https://youtu.be/4CQalha3MyY
>
> I can query the table separately, however when I get the cache from
> “persons” and tried to join with “companies” it complains table “Company”
> is not existing.
>
>
>
> Please share me the complete example including the configuration.
>
>
>
> Thank you
>
>
>
> Get Outlook for iOS <https://aka.ms/o0ukef>
>
>
Re: 2 caches joining error
Posted by Jiang Jacky <ji...@gmail.com>.
Please review my dummy code, Thank you
[A computer screen with white text Description automatically generated with low confidence]
[A computer screen shot of a blue screen Description automatically generated with low confidence]
[A computer screen with white text Description automatically generated with low confidence]
From: Pavel Tupitsyn <pt...@apache.org>
Date: Thursday, June 1, 2023 at 1:27 AM
To: user@ignite.apache.org <us...@ignite.apache.org>
Subject: Re: 2 caches joining error
Hello, can you please share the code that does not work for you?
On Thu, Jun 1, 2023 at 7:52 AM Jiang Jacky <ji...@gmail.com>> wrote:
Hello
Can someone share me with some good examples that how to make a join between 2 caches?
I am using ignite 2.7 and mocking up the example from the video https://youtu.be/4CQalha3MyY
I can query the table separately, however when I get the cache from “persons” and tried to join with “companies” it complains table “Company” is not existing.
Please share me the complete example including the configuration.
Thank you
Get Outlook for iOS<https://aka.ms/o0ukef>
Re: 2 caches joining error
Posted by Pavel Tupitsyn <pt...@apache.org>.
Hello, can you please share the code that does not work for you?
On Thu, Jun 1, 2023 at 7:52 AM Jiang Jacky <ji...@gmail.com> wrote:
> Hello
> Can someone share me with some good examples that how to make a join
> between 2 caches?
> I am using ignite 2.7 and mocking up the example from the video
> https://youtu.be/4CQalha3MyY
> I can query the table separately, however when I get the cache from
> “persons” and tried to join with “companies” it complains table “Company”
> is not existing.
>
> Please share me the complete example including the configuration.
>
> Thank you
>
> Get Outlook for iOS <https://aka.ms/o0ukef>
>