Skip to content

Trino.Data.ADO: CommandBehavior flags not switched on correctly in ExecuteDbDataReaderAsync #17

@stephen-zhao

Description

@stephen-zhao

Issue

I'm experimenting with the Trino.Data.ADO package by plugging it into where we are running a custom Trino ADO client. It seems to be very drop-in-replace, though there's currently an issue.

We are using Dapper to run the queries, and Dapper automatically passes in a CommandBehavior of

CommandBehavior.SequentialAccess | CommandBehavior.SingleResult

This value of CommandBehavior causes TrinoCommand::ExecuteDbDataReaderAsync to throw with a NotSupportedException.

Proposed Solution

It seems the CommandBehavior should be treated as a flags type, and care must be given to parse it out that way when implementing TrinoCommand::ExecuteDbDataReaderAsync. (ADO docs reference)

switch (behavior)
{
case CommandBehavior.Default:
// Single result means only run one query. Trino only supports one query.
case CommandBehavior.SingleResult:
queryExecutor = await RunQuery().ConfigureAwait(false);
break;
case CommandBehavior.SingleRow:
// Single row requires the reader to be created and the first row to be read.
queryExecutor = await RunQuery().ConfigureAwait(false);
return new TrinoDataReader(queryExecutor);
case CommandBehavior.SchemaOnly:
queryExecutor = await RunNonQuery().ConfigureAwait(false);
break;
case CommandBehavior.CloseConnection:
// Trino has no concept of a connection because every call is a new connection.
queryExecutor = await RunQuery().ConfigureAwait(false);
break;
default:
throw new NotSupportedException();

Instead of a switch, the individual bits should be extracted using bitwise AND test.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions