Skip to content

Commit 2bb5fd5

Browse files
GH-46087: [FlightSQL] Allow returning column remarks in FlightSQL's CommandGetTables (#46110)
Resolves #46087 ### Rationale for this change FlightSQL allows returning various column metadata in `CommandGetTables`, but one thing that's missing is human-readable column description. This PR proposes adding a new `ARROW:FLIGHT:SQL:REMARKS` metadata property taht will contain a comment describing a column. This is inspired by JDBC's [`DatabaseMetaData#getColumns()`](https://docs.oracle.com/javase/8/docs/api/java/sql/DatabaseMetaData.html#getColumns-java.lang.String-java.lang.String-java.lang.String-java.lang.String-) method, and later on I'm planning on adding this change to arrow-java as well. ### What changes are included in this PR? * A new column metadata property `ARROW:FLIGHT:SQL:REMARKS` * C++ `ColumnMetadata` implementation Please tell me if there's anything else in the other languages that I should add. ### Are these changes tested? Covered by existing tests; no new test cases added. ### Are there any user-facing changes? Yes, a couple new constants/methods added to the `ColumnMetadata` class and its builder * GitHub Issue: #46087 Authored-by: mateuszrzeszutek <rzeszut@pm.me> Signed-off-by: David Li <li.davidm96@gmail.com>
1 parent 81bb988 commit 2bb5fd5

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

cpp/src/arrow/flight/integration_tests/test_integration.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,7 @@ const std::shared_ptr<Schema>& GetQuerySchema() {
11671167
.IsSearchable(true)
11681168
.CatalogName("catalog_test")
11691169
.Precision(100)
1170+
.Remarks("test column")
11701171
.Build()
11711172
.metadata_map())});
11721173
return kSchema;
@@ -1187,6 +1188,7 @@ std::shared_ptr<Schema> GetQueryWithTransactionSchema() {
11871188
.IsSearchable(true)
11881189
.CatalogName("catalog_test")
11891190
.Precision(100)
1191+
.Remarks("test column")
11901192
.Build()
11911193
.metadata_map())});
11921194
return kSchema;

cpp/src/arrow/flight/sql/column_metadata.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const char* ColumnMetadata::kIsAutoIncrement = "ARROW:FLIGHT:SQL:IS_AUTO_INCREME
5555
const char* ColumnMetadata::kIsCaseSensitive = "ARROW:FLIGHT:SQL:IS_CASE_SENSITIVE";
5656
const char* ColumnMetadata::kIsReadOnly = "ARROW:FLIGHT:SQL:IS_READ_ONLY";
5757
const char* ColumnMetadata::kIsSearchable = "ARROW:FLIGHT:SQL:IS_SEARCHABLE";
58+
const char* ColumnMetadata::kRemarks = "ARROW:FLIGHT:SQL:REMARKS";
5859

5960
ColumnMetadata::ColumnMetadata(
6061
std::shared_ptr<const arrow::KeyValueMetadata> metadata_map)
@@ -114,6 +115,10 @@ arrow::Result<bool> ColumnMetadata::GetIsSearchable() const {
114115
return StringToBoolean(is_case_sensitive);
115116
}
116117

118+
arrow::Result<std::string> ColumnMetadata::GetRemarks() const {
119+
return metadata_map_->Get(kRemarks);
120+
}
121+
117122
ColumnMetadata::ColumnMetadataBuilder ColumnMetadata::Builder() {
118123
return ColumnMetadataBuilder{};
119124
}
@@ -185,6 +190,12 @@ ColumnMetadata::ColumnMetadataBuilder::IsSearchable(bool is_searchable) {
185190
return *this;
186191
}
187192

193+
ColumnMetadata::ColumnMetadataBuilder& ColumnMetadata::ColumnMetadataBuilder::Remarks(
194+
const std::string& remarks) {
195+
metadata_map_->Append(ColumnMetadata::kRemarks, remarks);
196+
return *this;
197+
}
198+
188199
ColumnMetadata::ColumnMetadataBuilder::ColumnMetadataBuilder()
189200
: metadata_map_(std::make_shared<arrow::KeyValueMetadata>()) {}
190201

cpp/src/arrow/flight/sql/column_metadata.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class ARROW_FLIGHT_SQL_EXPORT ColumnMetadata {
6666
/// \brief Constant variable to hold the value of the key that
6767
/// will be used in the KeyValueMetadata class.
6868
static const char* kIsSearchable;
69+
/// \brief Constant variable to hold the value of the key that
70+
/// will be used in the KeyValueMetadata class.
71+
static const char* kRemarks;
6972

7073
/// \brief Static initializer.
7174
static ColumnMetadataBuilder Builder();
@@ -110,6 +113,10 @@ class ARROW_FLIGHT_SQL_EXPORT ColumnMetadata {
110113
/// \return The IsSearchable.
111114
arrow::Result<bool> GetIsSearchable() const;
112115

116+
/// \brief Return the Remarks set in the KeyValueMetadata.
117+
/// \return The Remarks.
118+
arrow::Result<std::string> GetRemarks() const;
119+
113120
/// \brief Return the KeyValueMetadata.
114121
/// \return The KeyValueMetadata.
115122
const std::shared_ptr<const arrow::KeyValueMetadata>& metadata_map() const;
@@ -169,6 +176,11 @@ class ARROW_FLIGHT_SQL_EXPORT ColumnMetadata {
169176
/// \return A ColumnMetadataBuilder.
170177
ColumnMetadataBuilder& IsSearchable(bool is_searchable);
171178

179+
/// \brief Set the column description in the KeyValueMetadata object.
180+
/// \param[in] remarks The comment describing column.
181+
/// \return A ColumnMetadataBuilder.
182+
ColumnMetadataBuilder& Remarks(const std::string& remarks);
183+
172184
ColumnMetadata Build() const;
173185

174186
private:

format/FlightSql.proto

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,7 @@ message CommandGetDbSchemas {
12121212
* - ARROW:FLIGHT:SQL:IS_CASE_SENSITIVE - "1" indicates if the column is case-sensitive, "0" otherwise.
12131213
* - ARROW:FLIGHT:SQL:IS_READ_ONLY - "1" indicates if the column is read only, "0" otherwise.
12141214
* - ARROW:FLIGHT:SQL:IS_SEARCHABLE - "1" indicates if the column is searchable via WHERE clause, "0" otherwise.
1215+
* - ARROW:FLIGHT:SQL:REMARKS - A comment describing the column. This field has been added after all others, clients should be prepared to find it missing.
12151216
* The returned data should be ordered by catalog_name, db_schema_name, table_name, then table_type, followed by table_schema if requested.
12161217
*/
12171218
message CommandGetTables {
@@ -1678,6 +1679,7 @@ message ActionEndSavepointRequest {
16781679
* - ARROW:FLIGHT:SQL:IS_CASE_SENSITIVE - "1" indicates if the column is case-sensitive, "0" otherwise.
16791680
* - ARROW:FLIGHT:SQL:IS_READ_ONLY - "1" indicates if the column is read only, "0" otherwise.
16801681
* - ARROW:FLIGHT:SQL:IS_SEARCHABLE - "1" indicates if the column is searchable via WHERE clause, "0" otherwise.
1682+
* - ARROW:FLIGHT:SQL:REMARKS - A comment describing the column. This field has been added after all others, clients should be prepared to find it missing.
16811683
* - GetFlightInfo: execute the query.
16821684
*/
16831685
message CommandStatementQuery {
@@ -1703,6 +1705,7 @@ message CommandStatementQuery {
17031705
* - ARROW:FLIGHT:SQL:IS_CASE_SENSITIVE - "1" indicates if the column is case-sensitive, "0" otherwise.
17041706
* - ARROW:FLIGHT:SQL:IS_READ_ONLY - "1" indicates if the column is read only, "0" otherwise.
17051707
* - ARROW:FLIGHT:SQL:IS_SEARCHABLE - "1" indicates if the column is searchable via WHERE clause, "0" otherwise.
1708+
* - ARROW:FLIGHT:SQL:REMARKS - A comment describing the column. This field has been added after all others, clients should be prepared to find it missing.
17061709
* - GetFlightInfo: execute the query.
17071710
* - DoPut: execute the query.
17081711
*/
@@ -1739,6 +1742,7 @@ message TicketStatementQuery {
17391742
* - ARROW:FLIGHT:SQL:IS_CASE_SENSITIVE - "1" indicates if the column is case-sensitive, "0" otherwise.
17401743
* - ARROW:FLIGHT:SQL:IS_READ_ONLY - "1" indicates if the column is read only, "0" otherwise.
17411744
* - ARROW:FLIGHT:SQL:IS_SEARCHABLE - "1" indicates if the column is searchable via WHERE clause, "0" otherwise.
1745+
* - ARROW:FLIGHT:SQL:REMARKS - A comment describing the column. This field has been added after all others, clients should be prepared to find it missing.
17421746
*
17431747
* If the schema is retrieved after parameter values have been bound with DoPut, then the server should account
17441748
* for the parameters when determining the schema.
@@ -1857,7 +1861,7 @@ message DoPutPreparedStatementResult {
18571861
// statement should be considered invalid, and all subsequent requests for this prepared
18581862
// statement must use this new handle.
18591863
// The updated handle allows implementing query parameters with stateless services.
1860-
//
1864+
//
18611865
// When an updated handle is not provided by the server, clients should contiue
18621866
// using the previous handle provided by `ActionCreatePreparedStatementResonse`.
18631867
optional bytes prepared_statement_handle = 1;

0 commit comments

Comments
 (0)