ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From November <yufeng7...@126.com>
Subject Re: How does AffinityKey mapped?
Date Thu, 14 Jul 2016 05:16:40 GMT
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.

Mime
View raw message