Example #1
0
    public async Task TestAlterAddColumns()
    {
        KuduTable table = await CreateTableAsync();

        await InsertRowsAsync(table, 0, 100);

        Assert.Equal(100, await ClientTestUtil.CountRowsAsync(_client, table));

        await _client.AlterTableAsync(new AlterTableBuilder(table)
                                      .AddColumn("addNonNull", KuduType.Int32, opt => opt
                                                 .Nullable(false)
                                                 .DefaultValue(100))
                                      .AddColumn("addNullable", KuduType.Int32)
                                      .AddColumn("addNullableDef", KuduType.Int32, opt => opt
                                                 .DefaultValue(200)));

        // Reopen table for the new schema.
        table = await _client.OpenTableAsync(_tableName);

        Assert.Equal(5, table.Schema.Columns.Count);

        // Add a row with addNullableDef=null
        var insert = table.NewInsert();

        insert.SetInt32("c0", 101);
        insert.SetInt32("c1", 101);
        insert.SetInt32("addNonNull", 101);
        insert.SetInt32("addNullable", 101);
        insert.SetNull("addNullableDef");
        await _session.EnqueueAsync(insert);

        await _session.FlushAsync();

        // Check defaults applied, and that row key=101
        var results = await ClientTestUtil.ScanTableToStringsAsync(_client, table);

        var expected = new List <string>(101);

        for (int i = 0; i < 100; i++)
        {
            expected.Add($"INT32 c0={i}, INT32 c1={i}, INT32 addNonNull=100, " +
                         "INT32 addNullable=NULL, INT32 addNullableDef=200");
        }

        expected.Add("INT32 c0=101, INT32 c1=101, INT32 addNonNull=101, " +
                     "INT32 addNullable=101, INT32 addNullableDef=NULL");

        Assert.Equal(
            expected.OrderBy(r => r),
            results.OrderBy(r => r));
    }
    private static async ValueTask InsertRowsAsync(
        IKuduSession session, KuduTable table, int startRow, int numRows)
    {
        var end = startRow + numRows;

        for (var i = startRow; i < end; i++)
        {
            var insert = ClientTestUtil.CreateBasicSchemaInsert(table, i);
            await session.EnqueueAsync(insert);
        }
    }
Example #3
0
    public async Task TestScanTokens()
    {
        var builder = ClientTestUtil.CreateManyStringsSchema()
                      .SetTableName(_tableName)
                      .AddHashPartitions(8, "key")
                      .CreateBasicRangePartition()
                      .AddSplitRow(row => row.SetString("key", "key_50"));

        var table = await _client.CreateTableAsync(builder);

        for (int i = 0; i < 100; i++)
        {
            var row = table.NewInsert();
            row.SetString("key", $"key_{i}");
            row.SetString("c1", $"c1_{i}");
            row.SetString("c2", $"c2_{i}");

            await _session.EnqueueAsync(row);
        }

        await _session.FlushAsync();

        var tokenBuilder = _client.NewScanTokenBuilder(table)
                           .SetEmptyProjection()
                           // For this test, make sure that we cover the case that not all tablets
                           // are returned in a single batch.
                           .SetFetchTabletsPerRangeLookup(4);

        List <KuduScanToken> tokens = await tokenBuilder.BuildAsync();

        Assert.Equal(16, tokens.Count);

        await using var newClient = _harness.CreateClient();
        var rowCount = await CountScanTokenRowsAsync(newClient, tokens);

        Assert.Equal(100, rowCount);
    }
Example #4
0
    public async Task TestBoolPredicates()
    {
        var builder = GetDefaultTableBuilder()
                      .SetTableName("bool-table")
                      .AddColumn("value", KuduType.Bool);

        var table = await _client.CreateTableAsync(builder);

        var values = new SortedSet <bool> {
            true, false
        };
        var testValues = new List <bool> {
            true, false
        };

        long i = 0;

        foreach (var value in values)
        {
            var insert = table.NewInsert();
            insert.SetInt64("key", i++);
            insert.SetBool("value", value);
            await _session.EnqueueAsync(insert);
        }

        var nullInsert = table.NewInsert();

        nullInsert.SetInt64("key", i);
        nullInsert.SetNull("value");
        await _session.EnqueueAsync(nullInsert);

        await _session.FlushAsync();

        await CheckPredicatesAsync(table, values, testValues);
    }