Skip to content

feat: Implement BQL support (as discussed in #387) - #415

Open
ak-finccam wants to merge 1 commit into
Rblp:masterfrom
ak-finccam:feature/bql
Open

feat: Implement BQL support (as discussed in #387)#415
ak-finccam wants to merge 1 commit into
Rblp:masterfrom
ak-finccam:feature/bql

Conversation

@ak-finccam

Copy link
Copy Markdown

This work implements BQL support for Rblpapi. This code is inspired by polars-bloomberg (python package) and also the matthewgilbert/blp package.

Before implementing this, I have read issue #387 and picked up on the ideas and limitations discussed there.

  • I rely on jsonlite to parse the result from the BQL query. I did not vendor the C++ json library.
  • The response data contains typing information and we make use of that in .bqlColumn.
  • I added some tests with fixtures that contain either freely available or synthetic data based on the observed structure of the real response.
  • I did run all newly added tests and also the examples that polars-bloomberg gives in their docs against a live Terminal.

AI disclosure: This work was done using Claude Fable. I have limited knowledge of C++ and have only ever used Rblpapi but never looked too deep into the source code.

Implements BQL support as discussed in Rblp#387. The C++ layer sends a
'sendQuery' request to the //blp/bqlsvc service and returns the JSON
document(s) the service responds with; the R layer parses them into
properly-typed data.frames (one per data item in the query's get()
clause) using the column types the response itself declares, with
jsonlite as an optional (Suggests) dependency. bql(..., parse=FALSE)
returns the raw JSON for queries whose shape the parser cannot handle.

The 'NaN'/'NA' missing-value sentinels are applied to numeric columns
only so STRING columns keep legitimate 'NA' values (e.g. the ticker
of 'NA US Equity'). Item-level responseExceptions (type PARTIAL,
accompanying usable data) surface as warnings while the data is
returned; top-level exceptions raise errors.

Offline unit tests cover parsing, type mapping (including undeclared
types such as ENUM), NA handling, partial responses, grouped
aggregations (composite group ids, INT columns, ORIG_IDS nulls), and
error propagation via synthetic fixtures whose structure was verified
against live //blp/bqlsvc responses; no captured Bloomberg data is
included. A live test gated on RunRblpapiUnitTests exercises the
service end to end. Verified live against terminal API 3.24.6.1,
including all documented example queries of the polars-bloomberg
package (screens, SRCH results, segments, axes, return series).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@eddelbuettel

Copy link
Copy Markdown
Member

Thanks for sending this our way, it looks reasonably careful and complete. I appreciate the added tests.

However, I will not be in a position to fully review and test this as I do not currently have access to a Bbg terminal.

@ak-finccam

Copy link
Copy Markdown
Author

I appreciate the quick response!

Does this mean you are currently unable to merge any PRs or is there another maintainer that has a terminal?

I don't want to pressure you, it's just if you are unable to test / review / merge at this time then we will internally maintain a fork and install from that fork.

@eddelbuettel

Copy link
Copy Markdown
Member

@johnlaing may engage with this too and provide feedback. In the meantime I would absolutely dog-food my own PR if I were you and test the living daylight out of it by running it. That's a common pattern for most of us methinks.

@johnlaing

Copy link
Copy Markdown
Contributor

I do have a terminal so let me see what I can do. It may take some time to get to.

Comment thread R/bql.R
@ak-finccam

Copy link
Copy Markdown
Author

Thank you! We will dogfood this internally in the meantime.

@eddelbuettel

Copy link
Copy Markdown
Member

In case anybody (besides @johnlaing) follows along here and has a working Bbg terminal, we would still appreciate a test and a basic 'yep, it works as advertised' ...

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.

3 participants