Example #1
0
    public async Task TestNullRows()
    {
        await using var miniCluster = await new MiniKuduClusterBuilder().BuildAsync();
        await using var client      = miniCluster.CreateClient();
        await using var session     = client.NewSession();

        var builder = ClientTestUtil.CreateAllTypesSchema(true)
                      .SetTableName(nameof(TestNullRows))
                      .CreateBasicRangePartition();

        var table = await client.CreateTableAsync(builder);

        int numRows    = 5;
        int currentRow = 0;

        for (int i = 0; i < numRows; i++)
        {
            var insert = ClientTestUtil.CreateAllNullsInsert(table, i);
            await session.EnqueueAsync(insert);
        }

        await session.FlushAsync();

        var scanner = client.NewScanBuilder(table).Build();

        await foreach (var resultSet in scanner)
        {
            foreach (var row in resultSet)
            {
                Assert.Equal(currentRow, row.GetInt32("key"));
                Assert.Equal(currentRow, row.GetNullableInt32("key"));

                Assert.True(row.IsNull("int8"));
                Assert.True(row.IsNull("int16"));
                Assert.True(row.IsNull("int32"));
                Assert.True(row.IsNull("int64"));
                Assert.True(row.IsNull("bool"));
                Assert.True(row.IsNull("float"));
                Assert.True(row.IsNull("double"));
                Assert.True(row.IsNull("string"));
                Assert.True(row.IsNull("varchar"));
                Assert.True(row.IsNull("binary"));
                Assert.True(row.IsNull("timestamp"));
                Assert.True(row.IsNull("date"));
                Assert.True(row.IsNull("decimal32"));
                Assert.True(row.IsNull("decimal64"));
                Assert.True(row.IsNull("decimal128"));

                Assert.Null(row.GetNullableByte("int8"));
                Assert.Null(row.GetNullableSByte("int8"));
                Assert.Null(row.GetNullableInt16("int16"));
                Assert.Null(row.GetNullableInt32("int32"));
                Assert.Null(row.GetNullableInt64("int64"));
                Assert.Null(row.GetNullableBool("bool"));
                Assert.Null(row.GetNullableFloat("float"));
                Assert.Null(row.GetNullableDouble("double"));
                Assert.Null(row.GetNullableString("string"));
                Assert.Null(row.GetNullableString("varchar"));
                Assert.Null(row.GetNullableBinary("binary"));
                Assert.Null(row.GetNullableDateTime("timestamp"));
                Assert.Null(row.GetNullableDateTime("date"));
                Assert.Null(row.GetNullableDecimal("decimal32"));
                Assert.Null(row.GetNullableDecimal("decimal64"));
                Assert.Null(row.GetNullableDecimal("decimal128"));

                Assert.Equal(0, row.GetSpan("int8").Length);
                Assert.Equal(0, row.GetSpan("int16").Length);
                Assert.Equal(0, row.GetSpan("int32").Length);
                Assert.Equal(0, row.GetSpan("int64").Length);
                Assert.Equal(0, row.GetSpan("bool").Length);
                Assert.Equal(0, row.GetSpan("float").Length);
                Assert.Equal(0, row.GetSpan("double").Length);
                Assert.Equal(0, row.GetSpan("string").Length);
                Assert.Equal(0, row.GetSpan("varchar").Length);
                Assert.Equal(0, row.GetSpan("binary").Length);
                Assert.Equal(0, row.GetSpan("timestamp").Length);
                Assert.Equal(0, row.GetSpan("date").Length);
                Assert.Equal(0, row.GetSpan("decimal32").Length);
                Assert.Equal(0, row.GetSpan("decimal64").Length);
                Assert.Equal(0, row.GetSpan("decimal128").Length);
                currentRow++;
            }
        }

        Assert.Equal(numRows, currentRow);
    }