Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for table comments #164

Merged
merged 1 commit into from
Jul 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Knet.Kudu.Client/AlterTableBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public AlterTableBuilder SetOwner(string owner)
return this;
}

/// <summary>
/// Change a table's comment.
/// </summary>
/// <param name="comment">The new table comment.</param>
public AlterTableBuilder SetComment(string comment)
{
_request.NewTableComment = comment;
return this;
}

/// <summary>
/// Add a new column to the table. The column defaults to a
/// nullable non-key column.
Expand Down
5 changes: 4 additions & 1 deletion src/Knet.Kudu.Client/KuduScanTokenBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ public async ValueTask<List<KuduScanToken>> BuildAsync(
tableMetadataPb.Owner = Table.Owner;
}

// TODO: Set table comment
if (Table.Comment is not null)
{
tableMetadataPb.Comment = Table.Comment;
}

if (Table.ExtraConfig.Count > 0)
{
Expand Down
5 changes: 5 additions & 0 deletions src/Knet.Kudu.Client/KuduTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public KuduTable(GetTableSchemaResponsePB schemaPb)
/// </summary>
public string Owner => SchemaPb.Owner;

/// <summary>
/// The comment on the table.
/// </summary>
public string Comment => SchemaPb.Comment;

public override string ToString() => TableName;

/// <summary>
Expand Down
10 changes: 10 additions & 0 deletions src/Knet.Kudu.Client/TableBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ public TableBuilder SetOwner(string owner)
return this;
}

/// <summary>
/// Set the table comment.
/// </summary>
/// <param name="comment">The table comment.</param>
public TableBuilder SetComment(string comment)
{
_createTableRequest.Comment = comment;
return this;
}

/// <summary>
/// Sets the dimension label for all tablets created at table creation time.
///
Expand Down
19 changes: 19 additions & 0 deletions test/Knet.Kudu.Client.FunctionalTests/AlterTableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,25 @@ await _client.AlterTableAsync(new AlterTableBuilder(table)
Assert.Equal(newOwner, table.Owner);
}

[SkippableFact]
public async Task TestAlterChangeComment()
{
var originalComment = "original comment";
var builder = new TableBuilder(nameof(TestAlterAddColumns))
.AddColumn("key", KuduType.Int32, opt => opt.Key(true))
.AddColumn("val", KuduType.Int32)
.SetRangePartitionColumns("key")
.SetComment(originalComment);

var table = await _client.CreateTableAsync(builder);
Assert.Equal(originalComment, table.Comment);

var newComment = "new comment";
await _client.AlterTableAsync(new AlterTableBuilder(table).SetComment(newComment));
table = await _client.OpenTableAsync(table.TableName);
Assert.Equal(newComment, table.Comment);
}

/// <summary>
/// Creates a new table with two int columns, c0 and c1. c0 is the primary key.
/// The table is hash partitioned on c0 into two buckets, and range partitioned
Expand Down