Giter VIP home page Giter VIP logo

Comments (3)

nberardi avatar nberardi commented on July 30, 2024

You found a type casting bug. The current work around would be do add the following to your code. So instead of having in your GetData method:

                return productFamily.Get(keys).FetchColumns(columns).FirstOrDefault().AsDynamic();

You would do this to force the right casting.

                var keys = new[] { key }; 
                return productFamily.Get(keys).FetchColumns(columns).FirstOrDefault().AsDynamic();

The current problem is the CompositeType was set to implicitly cast to "CassandraObject[]" and that is the type being used in the Get(...) signature, which is suppose to take in multiple keys. Let me know if the above works for you. This bug will be fixed next release.

from fluentcassandra.

nberardi avatar nberardi commented on July 30, 2024

I have been playing a bit more with fluentcassandra especially focusing on composite keys.
And I had another issue.

Here is the Column Family I use:
===================================================
ColumnFamily: Data
  Key Validation Class: org.apache.cassandra.db.marshal.CompositeType(org.apache.cassandra.db.marshal.AsciiType,org.apache.cassandra.db.marshal.AsciiType,org.apache.cassandra.db.marshal.TimeUUIDType)
  Default column value validator: org.apache.cassandra.db.marshal.BytesType
  Columns sorted by: org.apache.cassandra.db.marshal.AsciiType
  GC grace seconds: 864000
  Compaction min/max thresholds: 4/32
  Read repair chance: 0.1
  DC Local Read repair chance: 0.0
  Replicate on write: true
  Caching: KEYS_ONLY
  Bloom Filter FP chance: default
  Built indexes: []
  Compaction Strategy: org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy
  Compression Options:
    sstable_compression: org.apache.cassandra.io.compress.SnappyCompressor
===================================================

I now am testing a CF with a Composite Key of Type <AsciiType, AsciiType, TimeUUIDType>,
I use the code below to insert data, and it seems to work:

    public void InsertData(string keyspace, Data data, DateTimeOffset stamp)
    {
        using (var db = new CassandraContext(keyspace: keyspace, server: _server))
        {
            var productFamily = db.GetColumnFamily("Data");
            var key = new CompositeType<AsciiType, AsciiType, TimeUUIDType>(data.Key1, data.Key2, stamp);


            var post = productFamily.CreateRecord(key);
            db.Attach(post);
            foreach (var fieldValue in data.Values)
            {
                if (!post.TrySetColumn(fieldValue.Key, fieldValue.Value))
                    throw new InvalidDataException(string.Format("Can't add {0}:{1}", fieldValue.Key,
                                                                 fieldValue.Value));
            }
            db.SaveChanges();
        }
    }

And to retrieve the data I use:

    public dynamic GetData(string keyspace, string source, string product, DateTimeOffset stamp, params CassandraObject[] columns)
    {
        var key = new CompositeType<AsciiType, AsciiType, TimeUUIDType>(source, product, stamp);

        using (var db = new CassandraContext(keyspace: keyspace, server: _server))
        {
            var productFamily = db.GetColumnFamily("Data");
            var keys = new [] {key};
            return productFamily.Get(keys).FetchColumns(columns).FirstOrDefault().AsDynamic();
        }
    }

Of course in the 2 cases I use the same DateTimeOffset object, but the data returned is only composed of NullTypes.

Tell me if you need more details.

Thanks,
Pierre

from fluentcassandra.

nberardi avatar nberardi commented on July 30, 2024

Hi Pierre,

This is related to the fact that you are using TimeUUID. The clock sequence of TimeUUID changes with each request, and since Cassandra doesn't do a valid TimeUUID comparison and just does a byte comparison on Composite types, the value of TimeUUID changes each time you create it which changes the Composite byte value.

To fix this since it seems like you only need a date and not a TimeUUID, you can change the 3rd Composite type to a DateType instead of a TimeUUIDType and this should solve your problems.

Nick

from fluentcassandra.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.