Exemplo n.º 1
0
    public static int CalculateMaxPartitionKeySize(
        PartialRow row, PartitionSchema partitionSchema)
    {
        var hashSchemaSize = partitionSchema.HashBucketSchemas.Count * 4;

        // While the final partition key might not include any range columns,
        // we still need temporary space to encode the data to hash it.
        return(CalculateMaxPrimaryKeySize(row) + hashSchemaSize);
    }
Exemplo n.º 2
0
    private static void CheckPartitionKey(
        PartialRow row,
        PartitionSchema partitionSchema,
        byte[] expectedPartitionKey)
    {
        var         maxSize = KeyEncoder.CalculateMaxPartitionKeySize(row, partitionSchema);
        Span <byte> buffer  = stackalloc byte[maxSize];

        KeyEncoder.EncodePartitionKey(
            row,
            partitionSchema,
            buffer,
            out int bytesWritten);

        var partitionKey = buffer.Slice(0, bytesWritten).ToArray();

        Assert.Equal(expectedPartitionKey, partitionKey);
    }
Exemplo n.º 3
0
    public static void EncodePartitionKey(
        PartialRow row,
        PartitionSchema partitionSchema,
        Span <byte> destination,
        out int bytesWritten)
    {
        int localBytesWritten = 0;

        foreach (var hashSchema in partitionSchema.HashBucketSchemas)
        {
            var bucket = GetHashBucket(row, hashSchema, destination.Length);
            var slice  = destination.Slice(0, 4);
            BinaryPrimitives.WriteInt32BigEndian(slice, bucket);
            destination        = destination.Slice(4);
            localBytesWritten += 4;
        }

        var rangeColumns = partitionSchema.RangeSchema.ColumnIds;

        EncodeColumns(row, rangeColumns, destination, out int written);

        bytesWritten = localBytesWritten + written;
    }
 internal SqlAlterPartitionScheme(PartitionSchema partitionSchema, string filegroup)
     : base(SqlNodeType.Alter)
 {
     this.partitionSchema = partitionSchema;
     this.filegroup       = filegroup;
 }
 /// <inheritdoc/>
 /// <exception cref="NotSupportedException">Method is not supported.</exception>
 protected override IPathNode VisitPartitionSchema(PartitionSchema partitionSchema)
 {
     throw new NotSupportedException();
 }
Exemplo n.º 6
0
 public static SqlCreatePartitionScheme Create(PartitionSchema partitionSchema)
 {
     ArgumentValidator.EnsureArgumentNotNull(partitionSchema, "partitionSchema");
     return(new SqlCreatePartitionScheme(partitionSchema));
 }
Exemplo n.º 7
0
 public static SqlAlterPartitionScheme Alter(PartitionSchema partitionSchema, string filegroup)
 {
     ArgumentValidator.EnsureArgumentNotNull(partitionSchema, "partitionSchema");
     return(new SqlAlterPartitionScheme(partitionSchema, filegroup));
 }
Exemplo n.º 8
0
 public static SqlAlterPartitionScheme Alter(PartitionSchema partitionSchema)
 {
     ArgumentValidator.EnsureArgumentNotNull(partitionSchema, "partitionSchema");
     return(new SqlAlterPartitionScheme(partitionSchema, null));
 }
Exemplo n.º 9
0
    public void TestPartitionKeyEncoding()
    {
        var builder = new TableBuilder()
                      .AddColumn("a", KuduType.Int32, opt => opt.Key(true))
                      .AddColumn("b", KuduType.String, opt => opt.Key(true))
                      .AddColumn("c", KuduType.String, opt => opt.Key(true));

        var schema = GetSchema(builder);

        var partitionSchema = new PartitionSchema(
            new RangeSchema(new List <int> {
            0, 1, 2
        }),
            new List <HashBucketSchema>
        {
            new HashBucketSchema(new List <int> {
                0, 1
            }, 32, 0),
            new HashBucketSchema(new List <int> {
                2
            }, 32, 42)
        },
            schema);

        var rowA = new PartialRow(schema);

        rowA.SetInt32(0, 0);
        rowA.SetString(1, "");
        rowA.SetString(2, "");

        CheckPartitionKey(rowA, partitionSchema, new byte[]
        {
            0, 0, 0, 0,     // hash(0, "")
            0, 0, 0, 0x14,  // hash("")
            0x80, 0, 0, 0,  // a = 0
            0, 0            // b = ""; c is elided
        });

        var rowB = new PartialRow(schema);

        rowB.SetInt32(0, 1);
        rowB.SetString(1, "");
        rowB.SetString(2, "");

        CheckPartitionKey(rowB, partitionSchema, new byte[]
        {
            0, 0, 0, 0x5,   // hash(1, "")
            0, 0, 0, 0x14,  // hash("")
            0x80, 0, 0, 1,  // a = 1
            0, 0            // b = ""; c is elided
        });

        var rowC = new PartialRow(schema);

        rowC.SetInt32(0, 0);
        rowC.SetString(1, "b");
        rowC.SetString(2, "c");

        CheckPartitionKey(rowC, partitionSchema, new byte[]
        {
            0, 0, 0, 0x1A,      // hash(0, "b")
            0, 0, 0, 0x1D,      // hash("c")
            0x80, 0, 0, 0,      // a = 0
            (byte)'b', 0, 0,    // b = "b"
            (byte)'c'           // c = "c"
        });

        var rowD = new PartialRow(schema);

        rowD.SetInt32(0, 1);
        rowD.SetString(1, "b");
        rowD.SetString(2, "c");

        CheckPartitionKey(rowD, partitionSchema, new byte[]
        {
            0, 0, 0, 0,         // hash(1, "b")
            0, 0, 0, 0x1D,      // hash("c")
            0x80, 0, 0, 1,      // a = 1
            (byte)'b', 0, 0,    // b = "b"
            (byte)'c'           // c = "c"
        });
    }
 private void Init(CloudStorageAccount storageAccount)
 {
     _domainEventContext = new CloudTableContext<DomainEvent>(storageAccount, AggregateRootIdPropName);
     _latestVersionPartition = _domainEventContext.CreatePartitionSchema("LatestVersionPartition")
                                                  .SetRowKeyCriteria(domainEvt => domainEvt.AggregateRootId.SerializeToString())
                                                  .SetSchemaCriteria(domainEvt => true)
                                                  .SetIndexedPropertyCriteria(domainEvt => domainEvt.Sequence);
     _domainEventContext.AddPartitionSchema(_latestVersionPartition);
 }
Exemplo n.º 11
0
 public KuduPartitioner(KuduTable table, List <RemoteTablet> tablets)
 {
     _partitionSchema = table.PartitionSchema;
     _tablets         = tablets;
 }
Exemplo n.º 12
0
        /// <summary>
        /// The partition schemas are how your domain object gets sorted/categorized/grouped inside Azure Table
        /// storage. You create them in your client code and then "add" them to the CloudTableContext class
        /// that you're using to interact with the Table (in this case _userContext). 
        /// Remember, these are just schema definitions for one particular PartitionKey.
        /// 
        /// There is a DefaultSchema that get set on the CloudTableContext class automatically (in this case _userContext)
        /// which sets the PartitionKey to be the name of the object Type and the RowKey based on the Id property of the object
        /// provided during intialization.
        /// </summary>
        private void InitPartitionSchemas()
        {
            _usersInFloridaPartitionSchema = UserContext.CreatePartitionSchema()
                                                        .SetPartitionKey("UsersInFlorida")
                                                        .SetSchemaCriteria(user => user.UserAddress.State == "FL")
                /*The RowKey is set to the ID property by default, which in this case is the user.UserId*/
                                                        .SetIndexedPropertyCriteria(user => user.UserAddress.State);

            _firstNamePartitionSchema = UserContext.CreatePartitionSchema()
                                                   .SetPartitionKey("FirstName")
                                                   .SetSchemaCriteria(user => true)
                /*The RowKey is set to the ID property by default, which in this case is the user.UserId*/
                                                   .SetIndexedPropertyCriteria(user => user.FirstName);

            _userTypePartitionSchema = UserContext.CreatePartitionSchema()
                                                  .SetPartitionKey("UserTypePartition")
                                                  .SetSchemaCriteria(user => true)
                /*The RowKey is set to the ID property by default, which in this case is the user.UserId*/
                                                  .SetIndexedPropertyCriteria(user => user.GetType().Name);

            _userVersionPartitionSchema = UserContext.CreatePartitionSchema()
                                                     .SetPartitionKey("UserVersionPartition")
                                                     .SetSchemaCriteria(user => true)
                                                     .SetRowKeyCriteria(user => UserContext.GetChronologicalBasedRowKey())
                /*In this case we're keeping a version log so we want a new
                                                                                       RowKey created upon each write to the Table*/
                                                     .SetIndexedPropertyCriteria(user => user.UserId);

            // Now add the schemas that were just created to the CloudTableContext<User> instance (i.e. _userContext).
            UserContext.AddMultiplePartitionSchemas(new List<PartitionSchema<User>>
            {
                _usersInFloridaPartitionSchema,
                _firstNamePartitionSchema,
                _userTypePartitionSchema,
                _userVersionPartitionSchema
            });
        }
Exemplo n.º 13
0
 internal SqlDropPartitionScheme(PartitionSchema partitionSchema)
     : base(SqlNodeType.Drop)
 {
     this.partitionSchema = partitionSchema;
 }
 internal SqlCreatePartitionScheme(PartitionSchema partitionSchema)
     : base(SqlNodeType.Create)
 {
     this.partitionSchema = partitionSchema;
 }