public async Task TestScanTokensConcurrentAlterTable() { var builder = new TableBuilder(_tableName) .SetNumReplicas(1) .AddColumn("key", KuduType.Int64, opt => opt.Key(true)) .AddColumn("a", KuduType.Int64); var table = await _client.CreateTableAsync(builder); var tokenBuilder = _client.NewScanTokenBuilder(table); var tokens = await tokenBuilder.IncludeTableMetadata(false).BuildAsync(); var tokensWithMetadata = await tokenBuilder.IncludeTableMetadata(true).BuildAsync(); var token = Assert.Single(tokens); var tokenWithMetadata = Assert.Single(tokensWithMetadata); // Drop a column await _client.AlterTableAsync(new AlterTableBuilder(table) .DropColumn("a")); await Assert.ThrowsAsync <KeyNotFoundException>( async() => await _client.NewScanBuilderFromTokenAsync(token)); var exception = await Assert.ThrowsAsync <NonRecoverableException>(async() => { var scanBuilder = await _client.NewScanBuilderFromTokenAsync(tokenWithMetadata); await scanBuilder.Build().CountAsync(); }); Assert.Contains("Some columns are not present in the current schema: a", exception.Message); // Add a column with the same name, type, and nullability. It will have a // different id-- it's a different column-- so the scan token will fail. await _client.AlterTableAsync(new AlterTableBuilder(table) .AddColumn("a", KuduType.Int64, opt => opt.DefaultValue(0L))); table = await _client.OpenTableAsync(_tableName); await Assert.ThrowsAsync <KeyNotFoundException>( async() => await _client.NewScanBuilderFromTokenAsync(token)); }
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)); }