コード例 #1
0
        private static Cassandra.IndexExpression VisitRelationalExpression(BinaryExpression exp)
        {
            Cassandra.IndexExpression indexExpression;

            var columnName = GetColumnName(exp.Left);
            var value      = CassandraObject.GetCassandraObjectFromObject(Expression.Lambda(exp.Right).Compile().DynamicInvoke(), CassandraType.BytesType);

            indexExpression = new Cassandra.IndexExpression {
                Column_name = columnName.ToBigEndian(),
                Value       = value.ToBigEndian()
            };

            switch (exp.NodeType)
            {
            case ExpressionType.Equal: indexExpression.Op = Cassandra.IndexOperator.EQ; break;

            case ExpressionType.GreaterThan: indexExpression.Op = Cassandra.IndexOperator.GT; break;

            case ExpressionType.GreaterThanOrEqual: indexExpression.Op = Cassandra.IndexOperator.GTE; break;

            case ExpressionType.LessThan: indexExpression.Op = Cassandra.IndexOperator.LT; break;

            case ExpressionType.LessThanOrEqual: indexExpression.Op = Cassandra.IndexOperator.LTE; break;

            default:
                throw new NotSupportedException(exp.NodeType.ToString() + " is not a supported relational criteria.");
            }

            return(indexExpression);
        }
コード例 #2
0
ファイル: Helper.cs プロジェクト: tjake/fluentcassandra
        public static CassandraSlicePredicate SetSchemaForSlicePredicate(CassandraSlicePredicate predicate, CassandraColumnFamilySchema schema, bool forSuperColumn = false)
        {
            CassandraType columnType = forSuperColumn ? schema.SuperColumnNameType : schema.ColumnNameType;

            if (predicate is CassandraRangeSlicePredicate)
            {
                var x      = (CassandraRangeSlicePredicate)predicate;
                var start  = CassandraObject.GetCassandraObjectFromObject(x.Start, columnType);
                var finish = CassandraObject.GetCassandraObjectFromObject(x.Finish, columnType);

                return(new CassandraRangeSlicePredicate(start, finish, x.Reversed, x.Count));
            }
            else if (predicate is CassandraColumnSlicePredicate)
            {
                var x    = (CassandraColumnSlicePredicate)predicate;
                var cols = x.Columns.ToList();

                for (int i = 0; i < cols.Count; i++)
                {
                    cols[i] = CassandraObject.GetCassandraObjectFromObject(cols[i], columnType);
                }

                return(new CassandraColumnSlicePredicate(cols));
            }

            return(null);
        }