public static void GetIterator()
        {
            Console.WriteLine("Start get iterator...");

            PrepareTable();
            PrepareData();

            OTSClient otsClient = Config.GetClient();
            // 读取 (0, "a")到(1000, "xyz")这个范围内的所有行
            PrimaryKey inclusiveStartPrimaryKey = new PrimaryKey
            {
                { "pk0", new ColumnValue(0) },
                { "pk1", new ColumnValue("a") }
            };

            PrimaryKey exclusiveEndPrimaryKey = new PrimaryKey
            {
                { "pk0", new ColumnValue(1000) },
                { "pk1", new ColumnValue("xyz") }
            };

            var cu      = new CapacityUnit(0, 0);
            var request = new GetIteratorRequest(TableName, GetRangeDirection.Forward, inclusiveStartPrimaryKey,
                                                 exclusiveEndPrimaryKey, cu);

            var iterator = otsClient.GetRangeIterator(request);

            foreach (var row in iterator)
            {
                PrintRow(row);
            }

            Console.WriteLine("Consumed CapacityUnit Counter:{0}", cu.Read);
        }
Пример #2
0
        public void GetRangeTest()
        {
            CreateTable();
            var otsClient = OTSClient;
            // 指定范围读取数据
            var startPrimaryKey = new PrimaryKey();

            startPrimaryKey.Add("PK0", new ColumnValue("TestData"));
            startPrimaryKey.Add("PK1", ColumnValue.INF_MIN);

            var endPrimaryKey = new PrimaryKey();

            endPrimaryKey.Add("PK0", new ColumnValue("TestData"));
            endPrimaryKey.Add("PK1", ColumnValue.INF_MAX);

            var consumed = new CapacityUnit(0, 0);

            var request = new GetIteratorRequest("SampleTable", GetRangeDirection.Forward,
                                                 startPrimaryKey, endPrimaryKey,
                                                 consumed);
            var iterator = OTSClient.GetRangeIterator(request);

            foreach (var rowData in iterator)
            {
                // 处理每一行数据
            }
            DeleteTable();
        }
        public static void GetIterator()
        {
            Console.WriteLine("Start get iterator...");

            PrepareTable();
            PrepareData();

            OTSClient otsClient = Config.GetClient();
            // 读取 (0, "a")到(1000, "xyz")这个范围内的所有行
            PrimaryKey inclusiveStartPrimaryKey = new PrimaryKey();

            inclusiveStartPrimaryKey.Add("pk0", new ColumnValue(0));
            inclusiveStartPrimaryKey.Add("pk1", new ColumnValue("a"));

            PrimaryKey exclusiveEndPrimaryKey = new PrimaryKey();

            exclusiveEndPrimaryKey.Add("pk0", new ColumnValue(1000));
            exclusiveEndPrimaryKey.Add("pk1", new ColumnValue("xyz"));

            var cu      = new CapacityUnit(0, 0);
            var request = new GetIteratorRequest(TableName, GetRangeDirection.Forward, inclusiveStartPrimaryKey,
                                                 exclusiveEndPrimaryKey, cu);

            var iterator = otsClient.GetRangeIterator(request);

            foreach (var row in iterator)
            {
                Console.WriteLine("-----------------");
                foreach (KeyValuePair <string, ColumnValue> entry in row.PrimaryKey)
                {
                    Console.WriteLine(entry.Key + ":" + PrintColumnValue(entry.Value));
                }
                foreach (KeyValuePair <string, ColumnValue> entry in row.Attribute)
                {
                    Console.WriteLine(entry.Key + ":" + PrintColumnValue(entry.Value));
                }
                Console.WriteLine("-----------------");
            }

            Console.WriteLine("Consumed CapacityUnit Counter:{0}", cu.Read);
        }
Пример #4
0
        public void GetRangeTest()
        {
            CreateTable();
            BatchWriteRow();
            var otsClient = OTSClient;
            // 指定范围读取数据
            var startPrimaryKey = new PrimaryKey
            {
                { "PK0", new ColumnValue("TestData") },
                { "PK1", ColumnValue.INF_MIN }
            };

            var endPrimaryKey = new PrimaryKey
            {
                { "PK0", new ColumnValue("TestData") },
                { "PK1", ColumnValue.INF_MAX }
            };

            var consumed = new CapacityUnit(0, 0);

            var request = new GetIteratorRequest(TestTableName,
                                                 GetRangeDirection.Forward,
                                                 startPrimaryKey,
                                                 endPrimaryKey,
                                                 consumed);

            request.QueryCriteria.MaxVersions = 1;

            var iterator = OTSClient.GetRangeIterator(request);

            foreach (var rowData in iterator)
            {
                Console.WriteLine(rowData);
            }

            DeleteTable();
        }