Re: How does AffinityKey mapped?

2016-07-15 Thread vkulichenko
Hi,

I tried to reproduce the issue, but it works fine for me. Do you have a
small example that I can run and that will demonstrate the incorrect
behavior?

-Val



--
View this message in context: 
http://apache-ignite-users.70518.x6.nabble.com/How-does-AffinityKey-mapped-tp6260p6328.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.


Re: How does AffinityKey mapped?

2016-07-13 Thread November
Hi val

I come cross a problem while using inner join between two partition caches.
The inner join result is incomplete.

Following is my code. I use DTermKey as two caches' key. The inner join key
is DTerm, So I use [AffinityKeyMapped] on DTermKey.DTerm. Is there any thing
wrong?

var offerTermCache = ignite.GetOrCreateCache<DTermKey,
OfferTerm>("offerTermCache");
var productTermCache = ignite.GetOrCreateCache<DTermKey,
ProductTermCategory>("productTermCache");

class DTermKey
{
private long Id;

[AffinityKeyMapped]
private string DTerm;

public DTermKey(long id, string dTerm)
{
this.Id = id;
this.DTerm = dTerm;
}

public override bool Equals(object obj)
{
if (obj == null || !(obj is DTermKey))
{
return false;
}
else
{
DTermKey other = (DTermKey)obj;
return Id == other.Id && DTerm.Equals(other.DTerm);
}
}

public override int GetHashCode()
{
int hash = 13;
hash = (hash * 7) + Id.GetHashCode();
hash = (hash * 7) + DTerm.GetHashCode();

return hash;
}

public override string ToString()
{
return "DTermKey [id=" + Id + ", DTerm=" + DTerm + "]";
}
}

class OfferTerm
{
[QuerySqlField]
public string OfferId { get; set; }

[QuerySqlField]
public string Title { get; set; }

[QuerySqlField(IsIndexed = true)]
public string DTerm { get; set; }

public OfferTerm(string offerId, string title, string dTerm)
{
this.OfferId = offerId;
this.Title = title;
this.DTerm = dTerm;
}
}

class ProductTermCategory
{
[QuerySqlField(IsIndexed = true)]
public string DTerm { get; set; }

[QuerySqlField]
public double Entropy { get; set; }

public ProductTermCategory(string dTerm, double entropy)
{
this.DTerm = dTerm;
this.Entropy = entropy;
}
}


using (var productTermStreamer = ignite.GetDataStreamer<DTermKey,
ProductTermCategory>(productTermCache.Name))
{
using (StreamReader sr = new StreamReader(productTermPath))
{
long id = 0;
string line;
while ((line = sr.ReadLine()) != null)
{
string[] strs = line.Split('\t');
double entropy = double.Parse(strs[1]);
if (entropy <= EntropyThreshold &&
keywordsCache.ContainsKey(strs[0]))
{
productTermStreamer.AddData(new DTermKey(id++, strs[0]), new
ProductTermCategory(strs[0], entropy));
}
}
productTermStreamer.Flush();
}
}

id = 0;
var sql = new SqlFieldsQuery("select distinct OfferId, Title,
NormalizedStemmed from OfferFeed");
var queryResult = offerFeedCache.QueryFields(sql);
foreach (var fields in queryResult)
{
offerTermCache.Put(new DTermKey(id++, (string)fields[2]), new
OfferTerm((string)fields[0], (string)fields[1], (string)fields[2]));
}

ignite.DestroyCache(offerFeedCache.Name);

var joinSql = new SqlFieldsQuery(
"select OfferTerm.OfferId, OfferTerm.Title, ProductTermCategory.DTerm,
ProductTermCategory.Entropy " +
"from OfferTerm, \"productTermCache\".ProductTermCategory where
OfferTerm.DTerm = ProductTermCategory.DTerm");
using (StreamWriter sw = new StreamWriter(output))
{
foreach (var fields in offerTermCache.QueryFields(joinSql))
{
sw.WriteLine("{0}\t{1}\t{2}\t{3}", fields[0], fields[1], fields[2],
fields[3]);
}
}



--
View this message in context: 
http://apache-ignite-users.70518.x6.nabble.com/How-does-AffinityKey-mapped-tp6260p6299.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.


Re: How does AffinityKey mapped?

2016-07-13 Thread vkulichenko
Correct!

-Val



--
View this message in context: 
http://apache-ignite-users.70518.x6.nabble.com/How-does-AffinityKey-mapped-tp6260p6291.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.


Re: How does AffinityKey mapped?

2016-07-13 Thread November
Thanks for reply.

Just confirm I understand right.

IgniteCache<Integer, Organization> orgCache
IgniteCache<Integer, Company> comCache
IgniteCache<EmployeeKey, Employee> empCache

In these three caches. The partition function will use
EmployeeKey.organizationId to decide which node to store Employee.

If orgCache, comCache's key have the same value with
EmployeeKey.organizationId. Then all the three value will store in the same
node. Because the partition function is the same to specify data type?



--
View this message in context: 
http://apache-ignite-users.70518.x6.nabble.com/How-does-AffinityKey-mapped-tp6260p6288.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.


Re: How does AffinityKey mapped?

2016-07-13 Thread November
hi

I still have some confuse. If there are three cache like following.
Which cache will empCache collocate with? orgCache or comCache?
Since I don't see any other configuration in java example
org.apache.ignite.examples.binary.datagrid.CacheClientBinaryQueryExample
except @AffinityKeyMapped. Why EmployeeKey.organizationId map to
Organization.id but not any other class.

IgniteCache<Integer, Organization> orgCache
IgniteCache<Integer, Company> comCache
IgniteCache<EmployeeKey, Employee> empCache

public class EmployeeKey {
/** ID. */
private int id;

/** Organization ID. */
@AffinityKeyMapped
private int organizationId;
}

public class Organization {
/** */
private static final AtomicLong ID_GEN = new AtomicLong();

/** Organization ID (indexed). */
@QuerySqlField(index = true)
private Long id;

/** Organization name (indexed). */
@QuerySqlField(index = true)
private String name;

/** Address. */
private Address addr;

/** Type. */
private OrganizationType type;

/** Last update time. */
private Timestamp lastUpdated;
}

public class Company {
/** */
private static final AtomicLong ID_GEN = new AtomicLong();

/** Company ID (indexed). */
@QuerySqlField(index = true)
private Long id;

/** Company name (indexed). */
@QuerySqlField(index = true)
private String name;

}



--
View this message in context: 
http://apache-ignite-users.70518.x6.nabble.com/How-does-AffinityKey-mapped-tp6260p6278.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.


Re: How does AffinityKey mapped?

2016-07-13 Thread Vladislav Pyatkov
Hello,

You can to use both key with affinity part.

For example:

public class cache1Key {
private int uniqueId1;

@AffinityKeyMapped
private int DEV_LV;
}

public class cache2Key {
private int uniqueId2;

@AffinityKeyMapped
private int DEV_LV;
}

On Wed, Jul 13, 2016 at 4:48 PM, November <yufeng7...@126.com> wrote:

> Thanks for reply
>
> I have another question. There are two tables.
>
> CREATE TABLE  T1
>  ( LAT_IDSMALLINT,
>DEV_IDVARCHAR(20),
>DEV_LVSMALLINT
>  );
>
>   CREATE TABLE  T2
>  ( THE_DATE  DATE,
>DEV_ID   VARCHAR(20),
>DEV_LV  SMALLINT
>  );
>
>  SQL query:
> SELECT t1.* from t1, t2 where t2.DEV_LV = t1.DEV_LV
>
> I use cache1<cache1Key, cache1Value> and cache2<Integer, cache2Value> (use
> DEV_LV as key) to store it.
>
> public class cache1Key {
> private int DEV_LV;
>
> /** Organization ID. */
> @AffinityKeyMapped
> private int cache2_DEV_LV;
> }
>
> What if there are repeat DEV_LV in both tables(but the cache's key need to
> be unique) ? Is there any other way to achieve collocate using
> @AffinityKeyMapped?
>
>
>
> --
> View this message in context:
> http://apache-ignite-users.70518.x6.nabble.com/How-does-AffinityKey-mapped-tp6260p6275.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>



-- 
Vladislav Pyatkov


Re: How does AffinityKey mapped?

2016-07-13 Thread November
Thanks for reply

I have another question. There are two tables.

CREATE TABLE  T1
 ( LAT_IDSMALLINT,
   DEV_IDVARCHAR(20),
   DEV_LVSMALLINT
 );

  CREATE TABLE  T2
 ( THE_DATE  DATE,
   DEV_ID   VARCHAR(20),
   DEV_LV  SMALLINT
 );

 SQL query:
SELECT t1.* from t1, t2 where t2.DEV_LV = t1.DEV_LV

I use cache1<cache1Key, cache1Value> and cache2<Integer, cache2Value> (use
DEV_LV as key) to store it.

public class cache1Key {
private int DEV_LV;

/** Organization ID. */
@AffinityKeyMapped
private int cache2_DEV_LV;
}

What if there are repeat DEV_LV in both tables(but the cache's key need to
be unique) ? Is there any other way to achieve collocate using
@AffinityKeyMapped?



--
View this message in context: 
http://apache-ignite-users.70518.x6.nabble.com/How-does-AffinityKey-mapped-tp6260p6275.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.


Re: How does AffinityKey mapped?

2016-07-13 Thread Andrey Gura
Hi,

It is responsibility of AffinityKeyMapper interface implementation. By
default Ignite uses GridCacheDefaultAffinityKeyMapper class for this
purposes. But you can provide own mapper implementation using
CacheConfiguration.setAffinityMapper() method.

On Wed, Jul 13, 2016 at 11:58 AM, November <yufeng7...@126.com> wrote:

> Hi
>
> I have read http://apacheignite.gridgain.org/docs/affinity-collocation and
> java example.
>
> I don't know how AffinityKey map? Like following code in java example.
> How does ignite know EmployeeKey's organizationId should collocate with
> Organization's id (not other fields). I can't find anything map them in
> configuration.
>
> Another question: how to use AffinityKey in .Net. Will just replace
> @AffinityKeyMapped with [AffinityKeyMapped] work or there is other thing
> different?
>
> public class EmployeeKey {
> /** ID. */
> private int id;
>
> /** Organization ID. */
> @AffinityKeyMapped
> private int organizationId;
> }
>
> public class Organization {
> /** */
> private static final AtomicLong ID_GEN = new AtomicLong();
>
> /** Organization ID (indexed). */
> @QuerySqlField(index = true)
> private Long id;
>
> /** Organization name (indexed). */
> @QuerySqlField(index = true)
> private String name;
>
> /** Address. */
> private Address addr;
>
> /** Type. */
> private OrganizationType type;
>
> /** Last update time. */
>     private Timestamp lastUpdated;
>
> }
>
>
>
> --
> View this message in context:
> http://apache-ignite-users.70518.x6.nabble.com/How-does-AffinityKey-mapped-tp6260.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>



-- 
Andrey Gura
GridGain Systems, Inc.
www.gridgain.com


How does AffinityKey mapped?

2016-07-13 Thread November
Hi

I have read http://apacheignite.gridgain.org/docs/affinity-collocation and
java example.

I don't know how AffinityKey map? Like following code in java example. 
How does ignite know EmployeeKey's organizationId should collocate with
Organization's id (not other fields). I can't find anything map them in
configuration.

Another question: how to use AffinityKey in .Net. Will just replace
@AffinityKeyMapped with [AffinityKeyMapped] work or there is other thing
different?

public class EmployeeKey {
/** ID. */
private int id;

/** Organization ID. */
@AffinityKeyMapped
private int organizationId;
}

public class Organization {
/** */
private static final AtomicLong ID_GEN = new AtomicLong();

/** Organization ID (indexed). */
@QuerySqlField(index = true)
private Long id;

/** Organization name (indexed). */
@QuerySqlField(index = true)
private String name;

/** Address. */
private Address addr;

/** Type. */
private OrganizationType type;

/** Last update time. */
private Timestamp lastUpdated;

}



--
View this message in context: 
http://apache-ignite-users.70518.x6.nabble.com/How-does-AffinityKey-mapped-tp6260.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.