Skip to content
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
21 changes: 21 additions & 0 deletions c/driver_manager/adbc_driver_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1764,6 +1764,12 @@ AdbcStatusCode StatementSetSubstraitPlan(struct AdbcStatement*, const uint8_t*,
return ADBC_STATUS_NOT_IMPLEMENTED;
}

AdbcStatusCode StatementRequestSchema(struct AdbcStatement*, struct ArrowSchema*,
struct AdbcError* error) {
SetError(error, "AdbcStatementRequestSchema not implemented");
return ADBC_STATUS_NOT_IMPLEMENTED;
}

/// Temporary state while the database is being configured.
struct TempDatabase {
std::unordered_map<std::string, std::string> options;
Expand Down Expand Up @@ -3159,6 +3165,17 @@ AdbcStatusCode AdbcStatementSetSubstraitPlan(struct AdbcStatement* statement,
error);
}

AdbcStatusCode AdbcStatementRequestSchema(struct AdbcStatement* statement,
struct ArrowSchema* schema,
struct AdbcError* error) {
if (!statement->private_driver) {
SetError(error, "AdbcStatementRequestSchema: must call AdbcStatementNew first");
return ADBC_STATUS_INVALID_STATE;
}
INIT_ERROR(error, statement);
return statement->private_driver->StatementRequestSchema(statement, schema, error);
}

const char* AdbcStatusCodeMessage(AdbcStatusCode code) {
#define CASE(CONSTANT) \
case ADBC_STATUS_##CONSTANT: \
Expand Down Expand Up @@ -3382,6 +3399,10 @@ AdbcStatusCode AdbcLoadDriverFromInitFunc(AdbcDriverInitFunc init_func, int vers
FILL_DEFAULT(driver, StatementSetOptionDouble);
FILL_DEFAULT(driver, StatementSetOptionInt);
}
if (version >= ADBC_VERSION_1_2_0) {
auto* driver = reinterpret_cast<struct AdbcDriver*>(raw_driver);
FILL_DEFAULT(driver, StatementRequestSchema);
}

return ADBC_STATUS_OK;

Expand Down
37 changes: 37 additions & 0 deletions c/include/arrow-adbc/adbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,9 @@ struct ADBC_EXPORT AdbcDriver {
AdbcStatusCode (*StatementExecuteMulti)(struct AdbcStatement*,
struct AdbcMultiResultSet*, struct AdbcError*);

AdbcStatusCode (*StatementRequestSchema)(struct AdbcStatement*, struct ArrowSchema*,
struct AdbcError*);

/// @}
};

Expand Down Expand Up @@ -2293,6 +2296,40 @@ AdbcStatusCode AdbcStatementExecuteSchema(struct AdbcStatement* statement,
struct ArrowSchema* schema,
struct AdbcError* error);

/// \brief Request the schema of the next statement execution
///
/// Allows the caller to request a specific schema based on prior

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we explicitly define the behavior if columns in the result schema are missing from the requested schema and the reverse (columns in the requested schema missing from the result schema)?

What about column ordering? I'm not making any suggestions about what the behavior should be, just that we should explicitly state what the expected behavior should be in those cases.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point...I will try to update the text tonight. Off the top of my head the ability to request a schema with more columns than the source or in a different order is useful, as is widening the allowed nullability. Requesting fewer columns is fishy. DataFusion has quite a nice programmatic definition of this (designed for casting struct columns to match each other, possibly from multiple Parquet files).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the status here?

Personally I'm fine saying that you have to match (at least to start), though allowing widened nullability seems fine, and if there's a use case we can define the rest. Reordering columns and such to me starts to feel like #13 a bit. If only everyone supported Substrait, things would be easy :P

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot about this...I'll put the language in sometime today. The intention is to align types in place for drivers where the inferred destination type is arbitrary, not to reorder (which places responsibility on the driver that's currently tricky to satisfy in C or C++).

/// information or user input. This may be used to ensure a
/// consistent schema when executing queries against a database
/// with row-based types (e.g., SQLite) or a database whose types
/// are implemented with row-based parameters where Arrow prefers
/// type-level parameters (e.g., NUMERIC for PostgreSQL). The
/// schema request is intended to modify only the types or
/// widen the nullability of types in the original schema;
/// column reordering or changing the number of returned columns
/// is not a goal of this feature.
///
/// The provided schema is a request and not a guarantee (i.e.,
/// callers must use the schema provided by the output stream to
/// interpret the result).
///
/// Calling AdbcStatementRequestSchema() must not affect the result
/// of AdbcStatementExecuteSchema (which always infers its result
/// from the input query).
///
/// \since ADBC API revision 1.2.0
///
/// \param[in] statement The statement to execute.
/// \param[in] schema The requested schema.
/// \param[out] error An optional location to return an error
/// message if necessary.
///
/// \return ADBC_STATUS_NOT_IMPLEMENTED if the driver does not support this.
ADBC_EXPORT
AdbcStatusCode AdbcStatementRequestSchema(struct AdbcStatement* statement,
struct ArrowSchema* schema,
struct AdbcError* error);

/// \brief Turn this statement into a prepared statement to be
/// executed multiple times.
///
Expand Down
21 changes: 21 additions & 0 deletions go/adbc/drivermgr/adbc_driver_manager.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions go/adbc/drivermgr/arrow-adbc/adbc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading