示例#1
0
        private static async Task CreateScratchTable()
        {
            Trace.WriteLine("Creating Scratch table...");

            using (var client = new ArribaClient(ArribaServerUrl))
            {
                if (client.Tables.Contains("Scratch"))
                {
                    await client["Scratch"].DeleteAsync();
                }

                CreateTableRequest tableRequest = new CreateTableRequest("Scratch", 250000);
                var table = await client.CreateTableAsync(tableRequest);

                await table.SaveAsync();

                Trace.WriteLine("Done. Scratch table created.");
            }
        }
示例#2
0
        private static async Task ExampleShort()
        {
            // Connect to local Arriba server
            using (var client = new ArribaClient(ArribaServerUrl))
            {
                // Create Table [2 Partition Bits = 4 Partitions = 256k items]
                CreateTableRequest tableRequest = new CreateTableRequest("Test_" + DateTime.Now.Ticks.ToString(), 2);
                tableRequest.Columns.Add(new ColumnDetails("ID", "int", -1, String.Empty, true));
                tableRequest.Columns.Add(new ColumnDetails("Name", "string", null));
                tableRequest.Columns.Add(new ColumnDetails("Age", "int", -1));
                var table = await client.CreateTableAsync(tableRequest);

                // Add or Update items (CSV) [ID,Name,Age]
                using (MemoryStream ms = BuildSampleUserCsv())
                {
                    await table.ImportFileAsync(ms, "csv");
                }

                // Select ID, Name WHERE Age = 32
                SelectResult selectResult = await table.Select(new SelectQuery(new string[] { "ID" }, "Age = 32"));

                Console.WriteLine("Found {0:n0} 32 year olds (expected 2)", selectResult.Total);

                // Aggregate COUNT(*) WHERE {ALL} BY Age < 30, Age >= 30
                AggregationQuery aggregateQuery = new AggregationQuery("Count", new string[] { "ID" }, "");
                aggregateQuery.Dimensions.Add(new AggregationDimension("Age", "Age < 30", "Age >= 30"));
                AggregationResult aggregateResult = await table.Aggregate(aggregateQuery);

                Console.WriteLine("Found {0:n0} under 30 year olds (expected 1)", aggregateResult.Values[0, 1]);
                Console.WriteLine("Found {0:n0} over 30 year olds (expected 3)", aggregateResult.Values[1, 1]);
                Console.WriteLine("Found {0:n0} altogether (expected 4)", aggregateResult.Values[2, 1]);

                // Delete WHERE Age < 30
                int countDeleted = await table.Delete(SelectQuery.ParseWhere("Age < 30"));

                Console.WriteLine("Deleted {0:n0} users (expected 1)", countDeleted);
            }
        }
示例#3
0
        private static async Task Example()
        {
            using (var client = new ArribaClient(ArribaServerUrl))
            {
                // Create Table [2 Partition Bits = 4 Partitions = 256k items]
                CreateTableRequest tableRequest = new CreateTableRequest("Test_" + DateTime.Now.Ticks.ToString(), 2);
                tableRequest.Columns.Add(new ColumnDetails("ID", "int", -1, String.Empty, true));
                tableRequest.Columns.Add(new ColumnDetails("Name", "string", null));
                tableRequest.Columns.Add(new ColumnDetails("Age", "int", -1));
                var table = await client.CreateTableAsync(tableRequest);

                // Add columns (after creation)
                await table.AddColumnsAsync(new ColumnDetails[] { new ColumnDetails("Team", "string", null) });

                // Add items (CSV) [ID,Name,Age]
                using (MemoryStream ms = BuildSampleUserCsv())
                {
                    await table.ImportFileAsync(ms, "csv");
                }

                // Add items (DataBlock)
                DataBlock block = new DataBlock(
                    new string[] { "ID", "Name", "Age", "Team" },
                    1,
                    new Array[] {
                    new int[] { 4 },
                    new string[] { "Karl" },
                    new int[] { 30 },
                    new string[] { "VSPlat" }
                });
                await table.ImportDataBlock(block);

                // Get Table Information
                var d = await table.GetTableInformationAsync();

                // Select ID, Name WHERE Age = 32
                SelectResult selectResult = await table.Select(new SelectQuery(new string[] { "ID" }, "Age = 32"));

                Trace.WriteLine(String.Format("Found {0:n0} 32 year olds (expected 2)", selectResult.Total));

                // Aggregate COUNT(*) WHERE {ALL} BY Age < 30, Age >= 30
                AggregationQuery aggregateQuery = new AggregationQuery("Count", new string[] { "ID" }, "");
                aggregateQuery.Dimensions.Add(new AggregationDimension("Age", "Age < 30", "Age >= 30"));
                AggregationResult aggregateResult = await table.Aggregate(aggregateQuery);

                Trace.WriteLine(String.Format("Found {0:n0} under 30 year olds (expected 1)", aggregateResult.Values[0, 1]));
                Trace.WriteLine(String.Format("Found {0:n0} over 30 year olds (expected 3)", aggregateResult.Values[1, 1]));
                Trace.WriteLine(String.Format("Found {0:n0} altogether (expected 4)", aggregateResult.Values[2, 1]));

                // Delete WHERE ID = 2
                int countDeleted = await table.Delete(SelectQuery.ParseWhere("ID = 2"));

                Trace.WriteLine(String.Format("Deleted {0:n0} users (expected 1)", countDeleted));

                // Select ID, Name WHERE Age = 32 (again)
                selectResult = await table.Select(new SelectQuery(new string[] { "ID" }, "Age = 32"));

                Trace.WriteLine(String.Format("Found {0:n0} 32 year olds (expected 1)", selectResult.Total));

                // Add write permission to another user
                await table.GrantPermissionsAsync(Model.Security.PermissionScope.Reader, Model.Security.IdentityScope.User, "phil");

                SecurityPermissions permissions = await table.GetPermissionsAsync();

                Trace.WriteLine(String.Format("Expecting 'Phil' as reader. Readers: {0}", permissions.Readers.First().Name));

                // Deny myself write permission
                await table.RevokePermissionsAsync(Model.Security.PermissionScope.Reader, Model.Security.IdentityScope.User, "phil");

                permissions = await table.GetPermissionsAsync();

                Trace.WriteLine(String.Format("Found {0:n0} readers (expected 0)", permissions.Readers.Count()));

                // Delete table
                await table.DeleteAsync();
            }
        }