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

feat(c,format,python): implement error details #954

Merged
merged 1 commit into from
Aug 3, 2023

Conversation

lidavidm
Copy link
Member

@lidavidm lidavidm commented Aug 1, 2023

No description provided.

@lidavidm
Copy link
Member Author

lidavidm commented Aug 1, 2023

@zeroshade @kou @ywc88 this is the alternative to #946 using Kou's idea. It's very clearly unfinished, but it's much more straightforward to implement IMO.

If this seems roughly reasonable, and we prefer this to the other PR, I'll add all the tests/compatibility tests, finish up the implementation here, fix up the generated Go code, and copy over the bits of the other PR that are still useful.

Copy link
Member

@kou kou left a comment

Choose a reason for hiding this comment

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

+1

struct AdbcErrorDetails* details = (struct AdbcErrorDetails*)error->private_data;
free(details->message);

for (int i = 0; i < 2 * details->count; i++) {
Copy link
Member

Choose a reason for hiding this comment

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

It seems that we can use details->count instead of 2 * details->count here.

Copy link
Member Author

Choose a reason for hiding this comment

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

ah, good catch - at one point I had encoded both the keys and values in the same array

@lidavidm
Copy link
Member Author

lidavidm commented Aug 2, 2023

Hmm, the main weakness I see here is there's no way for us to augment an ArrowArrayStream with error details.

We could add something like this?

struct AdbcError* AdbcErrorFromArrayStream(struct ArrowArrayStream* stream);

that only works for an ArrowArrayStream produced by an ADBC driver. Thoughts?

(For this, the driver manager would have to wrap the ArrowArrayStream itself, but that's probably OK.)

@lidavidm lidavidm force-pushed the spec-1.1.0-errorext branch 7 times, most recently from a93bce5 to a291dcd Compare August 2, 2023 19:13
@lidavidm lidavidm marked this pull request as ready for review August 2, 2023 19:13
@lidavidm
Copy link
Member Author

lidavidm commented Aug 2, 2023

Minus the question above, I believe this is ready. If we think this is good, I'll merge this, then follow up and delete the error_details stuff/fix up and make the Go driver work, and also pull any improvements that are still applicable from the old PR.

@kou
Copy link
Member

kou commented Aug 2, 2023

Hmm, the main weakness I see here is there's no way for us to augment an ArrowArrayStream with error details.

When do we need this? When the last ArrowArrayStream::get_next() is failed? (ArrowArrayStream::get_last_error() can't return enough error information for the case, right?)

@lidavidm
Copy link
Member Author

lidavidm commented Aug 2, 2023

@kou yes, that's the case I'm thinking about. (For instance, for Flight SQL, if we get an error in the middle of the stream.) So in that case, AdbcErrorFromArrayStream would let us get the rest of the details.

It would be annoying to implement, but that's OK. The driver manager would wrap all ArrowArrayStream results with its own implementation, and return to the client its own implementation. The wrapper stream will store the original stream and struct AdbcDriver* private_driver in the ArrowArrayStream's private_data. When the caller calls AdbcErrorFromArrayStream, which is implemented by the driver manager, the driver manager can then forward the call to the driver's AdbcErrorFromArrayStream implementation.

@kou
Copy link
Member

kou commented Aug 3, 2023

Thanks but I'm not sure when/how to use AdbcErrorFromArrayStream() by caller yet.
Could you provide a code snippet for caller?

@lidavidm
Copy link
Member Author

lidavidm commented Aug 3, 2023

struct ArrowArrayStream stream = ...;

while (true) {
  struct ArrowArray batch;
  if (int code = stream.get_next(&stream, &batch); code != 0) {
    struct AdbcError* error = AdbcErrorFromArrayStream(&stream);
    if (error != nullptr) {
      std::cout << error->message << " SQLSTATE: " << error->sqlstate << std::endl;
      // Also use AdbcErrorGetDetailCount, etc.
    } else {
      std::cout << stream.get_last_error(&stream) << std::endl;
    }
  } else if (batch.release == nullptr) {
    break;
  }
  // Process batch
}

@lidavidm
Copy link
Member Author

lidavidm commented Aug 3, 2023

Since it looks like pitrou/zeroshade are unavailable and I don't want to be blocked, I'm going to merge this for now. If AdbcErrorFromArrayStream seems reasonable, I'll demo it in a follow-up PR.

@lidavidm lidavidm merged commit 7242c57 into apache:spec-1.1.0 Aug 3, 2023
2 checks passed
@lidavidm lidavidm deleted the spec-1.1.0-errorext branch August 3, 2023 13:58
@kou
Copy link
Member

kou commented Aug 3, 2023

Thanks.
I think that I can understand what you want to do. It seems reasonable.

@lidavidm
Copy link
Member Author

lidavidm commented Aug 3, 2023

Thanks for the help! I'll follow up with another PR and I hope that'll be the last in the ADBC 1.1.0 drafts...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants